/* ===== Modern Swiss Theme — Light + Dark ===== */
:root {
    /* === LIGHT MODE === */
    --primary: #0D7377;
    --primary-hover: #0A5C60;
    --primary-light: #E3F4F4;
    --accent: #14B8A6;

    --bg: #FFFFFF;
    --surface: #F7F9FA;
    --surface-2: #EFF2F4;
    --text: #0F1923;
    --text-secondary: #5A6A78;
    --text-tertiary: #8FA0B0;
    --border: #DDE4EA;
    --border-2: #C8D3DC;

    --success: #0B9266;
    --success-bg: #E6F7F2;
    --error: #D93025;
    --error-bg: #FDECEA;
    --warning: #C07D00;
    --warning-bg: #FEF5E0;

    --radius: 12px;
    --radius-sm: 8px;
    --shadow: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.10), 0 2px 4px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.12), 0 4px 8px rgba(15, 23, 42, 0.06);
    --transition: 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* === DARK MODE === */
[data-theme="dark"] {
    --primary: #0E8A8F;
    --primary-hover: #10A0A6;
    --primary-light: rgba(14, 138, 143, 0.14);
    --accent: #2DD4BF;

    --bg: #0D1117;
    --surface: #161D27;
    --surface-2: #1C2535;
    --text: #EEF2F6;
    --text-secondary: #8A9BB0;
    --text-tertiary: #566070;
    --border: #1E2D3D;
    --border-2: #253344;

    --success: #0FA876;
    --success-bg: rgba(15, 168, 118, 0.12);
    --error: #E84040;
    --error-bg: rgba(232, 64, 64, 0.10);
    --warning: #E09A00;
    --warning-bg: rgba(224, 154, 0, 0.10);

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.30);
    --shadow-md: 0 4px 16px rgba(0, 0, 0, 0.40), 0 2px 4px rgba(0, 0, 0, 0.25);
    --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.50), 0 4px 8px rgba(0, 0, 0, 0.30);
}

/* ===== Smooth theme transitions ===== */
*, *::before, *::after {
    transition-property: background-color, border-color, color, box-shadow;
    transition-duration: 0.25s;
    transition-timing-function: cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Reset ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 16px; -webkit-text-size-adjust: 100%; }
body {
    font-family: 'DM Sans', 'Segoe UI', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    letter-spacing: -0.01em;
    -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 1rem; }

/* ===== Layout ===== */
.app { display: flex; flex-direction: column; min-height: 100vh; }

/* ===== Header / Nav ===== */
.header {
    background: var(--bg);
    border-bottom: 1px solid var(--border);
    padding: 0 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 0 rgba(15, 23, 42, 0.02);
}
.header-inner {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
    gap: 12px;
}
.logo {
    font-weight: 700;
    font-size: 1.2rem;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 8px;
    letter-spacing: -0.03em;
}
.logo svg { width: 28px; height: 28px; }

/* ===== Theme Toggle ===== */
.theme-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    background: none;
    border: none;
    padding: 4px;
    margin-left: auto;
}

.theme-toggle-track {
    width: 44px;
    height: 24px;
    background: #D1DCE5;
    border-radius: 12px;
    border: 1.5px solid var(--border-2);
    position: relative;
    flex-shrink: 0;
}

[data-theme="dark"] .theme-toggle-track {
    background: var(--primary);
    border-color: var(--primary);
}

.theme-toggle-knob {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #FFFFFF;
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.26s cubic-bezier(0.34, 1.56, 0.64, 1) !important;
}

[data-theme="dark"] .theme-toggle-knob {
    transform: translateX(20px);
    background: #EEF2F6;
}

/* ===== Header logout (desktop only) ===== */
.header-logout { display: none; }
@media (min-width: 768px) {
    .header-logout { display: inline-flex; }
}

/* ===== Hamburger ===== */
.hamburger {
    display: flex;
    flex-direction: column;
    gap: 5px;
    background: none;
    border: none;
    padding: 8px;
    margin-left: auto;
}
.hamburger span {
    display: block;
    width: 24px;
    height: 2px;
    background: var(--text);
    border-radius: 2px;
    transition: var(--transition);
}

/* ===== Nav (mobile: slide-down overlay) ===== */
.nav-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    z-index: 150;
}
.nav-overlay.active { display: block; }
.nav {
    display: none;
    position: fixed;
    top: 0;
    right: 0;
    width: 280px;
    max-width: 85vw;
    height: 100%;
    background: var(--surface);
    z-index: 200;
    flex-direction: column;
    padding: 24px 16px;
    box-shadow: var(--shadow-lg);
    transform: translateX(100%);
    transition: transform 0.3s ease;
}
.nav.active { display: flex; transform: translateX(0); }
.nav-close {
    align-self: flex-end;
    background: none;
    border: none;
    font-size: 1.5rem;
    padding: 8px;
    color: var(--text-secondary);
    margin-bottom: 16px;
}
.nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-radius: var(--radius-sm);
    color: var(--text);
    font-weight: 500;
    transition: var(--transition);
    font-size: 1rem;
}
.nav a:hover, .nav a.active { background: var(--primary-light); color: var(--primary); }
.nav a svg { width: 20px; height: 20px; flex-shrink: 0; }
.nav-user {
    margin-top: auto;
    padding-top: 16px;
    border-top: 1px solid var(--border);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

/* ===== Desktop nav ===== */
@media (min-width: 768px) {
    .hamburger { display: none; }
    .theme-toggle { margin-left: 0; }
    .nav {
        display: flex !important;
        position: static;
        width: auto;
        height: auto;
        flex-direction: row;
        padding: 0;
        box-shadow: none;
        transform: none;
        gap: 4px;
    }
    .nav a { padding: 10px 14px; font-size: 0.875rem; }
    .nav-close { display: none; }
    .nav-user { display: none; }
}

/* ===== Main ===== */
.main {
    flex: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px 16px;
    width: 100%;
}
@media (min-width: 768px) {
    .main { padding: 32px 24px; }
}

/* ===== Auth Pages ===== */
.auth-container {
    max-width: 420px;
    margin: 40px auto;
}
.auth-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-md);
    padding: 32px 24px;
    border: 1px solid var(--border);
}
@media (min-width: 768px) {
    .auth-card { padding: 40px 32px; }
}
.auth-card h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 8px;
}
.auth-card p.subtitle {
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 0.9rem;
}

/* ===== Forms ===== */
.form-group {
    margin-bottom: 20px;
}
.form-group label {
    display: block;
    font-weight: 500;
    font-size: 0.875rem;
    margin-bottom: 6px;
    color: var(--text);
}
.form-input {
    width: 100%;
    padding: 12px 16px;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 1rem;
    transition: var(--transition);
    background: var(--surface);
    color: var(--text);
}
.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: inset 0 0 0 1px var(--primary), 0 0 0 3px rgba(13, 115, 119, 0.08);
    background: var(--bg);
}
.form-input::placeholder { color: var(--text-tertiary); }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-weight: 600;
    font-size: 0.9rem;
    border: none;
    transition: var(--transition);
    min-height: 48px;
    text-transform: none;
}
.btn-primary {
    background: var(--primary);
    color: #fff;
    width: 100%;
    box-shadow: 0 2px 6px rgba(13, 115, 119, 0.15);
}
.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(13, 115, 119, 0.25);
    transform: translateY(-1px);
}
.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.btn-secondary {
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--surface-2); border-color: var(--primary-light); }
.btn-danger {
    background: var(--error);
    color: #fff;
}
.btn-danger:hover { opacity: 0.9; }
.btn-sm {
    padding: 8px 16px;
    font-size: 0.8rem;
    min-height: 36px;
}
.btn-icon {
    background: none;
    border: none;
    padding: 8px;
    color: var(--text-secondary);
    min-height: auto;
}
.btn-icon:hover { color: var(--error); }
.btn-link {
    background: none;
    border: none;
    color: var(--primary);
    padding: 8px 0;
    font-weight: 500;
    min-height: auto;
}

/* ===== Cards ===== */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: none;
    padding: 20px;
    transition: var(--transition);
}
.card:hover {
    border-color: var(--primary-light);
    box-shadow: 0 2px 8px rgba(13, 115, 119, 0.08);
}

/* ===== Key cards ===== */
.keys-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: 1fr;
}
@media (min-width: 640px) {
    .keys-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
    .keys-grid { grid-template-columns: repeat(3, 1fr); }
}
.key-card { position: relative; }
.key-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}
.key-card-header h3 {
    font-size: 1rem;
    font-weight: 600;
    word-break: break-all;
}
.key-badge {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}
.key-badge.active { background: var(--success-bg); color: var(--success); }
.key-badge.expiring { background: var(--warning-bg); color: var(--warning); }
.key-badge.expired { background: var(--error-bg); color: var(--error); }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 600;
}
.badge.success { background: var(--success-bg); color: var(--success); }
.badge.error   { background: var(--error-bg);   color: var(--error); }
.badge.warning { background: var(--warning-bg); color: var(--warning); }

.key-meta {
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 0.85rem;
    color: var(--text-secondary);
}
.key-meta-row { display: flex; justify-content: space-between; }
.key-actions {
    display: flex;
    gap: 8px;
    margin-top: 16px;
    padding-top: 16px;
    border-top: 1px solid var(--border);
}
.key-value {
    background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
    border-radius: 12px;
    padding: 16px 20px;
    margin-top: 16px;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    box-shadow: 0 4px 16px rgba(13, 115, 119, 0.15);
    transition: var(--transition);
}
.key-value:hover {
    box-shadow: 0 8px 24px rgba(13, 115, 119, 0.25);
}
.key-value-text {
    flex: 1;
    min-width: 0;
    font-family: 'Courier New', 'SF Mono', monospace;
    font-size: 0.85rem;
    color: #fff;
    font-weight: 500;
    letter-spacing: 0.01em;
    word-break: break-all;
    line-height: 1.4;
    user-select: all;
}
.key-value .copy-btn {
    flex-shrink: 0;
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 8px;
    padding: 8px 16px;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    color: #fff;
    transition: var(--transition);
    white-space: nowrap;
}
.key-value .copy-btn:hover {
    background: rgba(255, 255, 255, 0.35);
    border-color: rgba(255, 255, 255, 0.5);
    transform: translateY(-2px);
}
.key-value .copy-btn:active {
    transform: translateY(0);
    background: rgba(255, 255, 255, 0.25);
}

/* ===== Tariff cards ===== */
.tariffs-grid {
    display: grid;
    gap: 20px;
    grid-template-columns: 1fr;
}
@media (min-width: 640px) {
    .tariffs-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (min-width: 1024px) {
    .tariffs-grid { grid-template-columns: repeat(3, 1fr); }
}
.tariff-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px 20px;
    transition: var(--transition);
    position: relative;
    text-align: left;
}

.tariff-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--primary);
    border-radius: var(--radius) var(--radius) 0 0;
}

.tariff-card:hover {
    border-color: var(--primary);
    box-shadow: 0 4px 16px rgba(13, 115, 119, 0.12);
    transform: translateY(-2px);
}

.tariff-card h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 8px;
}
.tariff-price {
    font-size: 2.4rem;
    font-weight: 700;
    color: var(--primary);
    margin: 16px 0;
}
.tariff-price span {
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--text-secondary);
}
.tariff-features {
    list-style: none;
    text-align: left;
    margin: 16px 0 24px;
}
.tariff-features li {
    padding: 6px 0;
    font-size: 0.9rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 8px;
}
.tariff-features li::before {
    content: "✓";
    color: var(--success);
    font-weight: 700;
}

/* ===== Table ===== */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}
.table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}
.table th, .table td {
    text-align: left;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.table th {
    background: var(--surface);
    font-weight: 600;
    color: var(--text-secondary);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.table tr:last-child td { border-bottom: none; }
.table tr:hover td { background: var(--primary-light); }

/* ===== Admin metrics ===== */
.metrics-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(2, 1fr);
}
@media (min-width: 768px) {
    .metrics-grid { grid-template-columns: repeat(4, 1fr); }
}
.metric-card {
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: none;
    border: 1px solid var(--border);
    padding: 20px;
    transition: var(--transition);
}
.metric-card:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(13, 115, 119, 0.08);
}
.metric-card .metric-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 8px;
}
.metric-card .metric-value {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--text);
}
.metric-card .metric-sub {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* ===== Modal ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 300;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal-overlay.active { display: flex; }
.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px rgba(15, 23, 42, 0.15);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    padding: 28px 24px;
}
@media (min-width: 768px) {
    .modal { padding: 32px; }
}
.modal h2 {
    font-size: 1.25rem;
    margin-bottom: 20px;
}
.modal-actions {
    display: flex;
    gap: 12px;
    margin-top: 24px;
    justify-content: flex-end;
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    top: 16px;
    right: 16px;
    z-index: 999;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    background: var(--surface);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 280px;
    max-width: 400px;
    animation: slideIn 0.3s ease;
    font-size: 0.9rem;
    border: 1px solid var(--border);
}
.toast.success { border-left: 4px solid var(--success); }
.toast.error { border-left: 4px solid var(--error); }
.toast.info { border-left: 4px solid var(--primary); }
@keyframes slideIn {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

/* ===== Loading ===== */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-page {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 60vh;
}
.page-loading .spinner { width: 32px; height: 32px; }

/* ===== Empty state ===== */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--text-secondary);
}
.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    opacity: 0.15;
    color: var(--primary);
}
.empty-state h3 { margin-bottom: 8px; color: var(--text); }

/* ===== Empty keys state ===== */
.empty-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 32px 24px;
    text-align: center;
}
.empty-card-icon { font-size: 2.8rem; line-height: 1; margin-bottom: 10px; }
.empty-card-title { font-size: 1.05rem; font-weight: 700; margin-bottom: 6px; }
.empty-card-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 20px;
    max-width: 320px;
    margin-left: auto;
    margin-right: auto;
}

/* ===== Trial block (inside empty-card) ===== */
.trial-block {
    background: linear-gradient(135deg, var(--primary-light) 0%, var(--surface) 100%);
    border: 1px solid var(--border-2);
    border-radius: var(--radius-sm);
    padding: 16px;
    text-align: left;
    max-width: 380px;
    margin: 0 auto;
}
.trial-block-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}
.trial-avail-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: var(--success-bg);
    color: var(--success);
    font-size: 0.68rem;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 20px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.trial-block-name {
    font-size: 0.9rem;
    font-weight: 700;
}
.trial-features {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 14px;
}
.trial-feat {
    font-size: 0.78rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 3px;
}
.trial-feat::before { content: '✓'; color: var(--success); font-weight: 700; }
.btn-trial {
    display: block;
    width: 100%;
    padding: 11px;
    background: var(--primary);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 700;
    text-align: center;
    cursor: pointer;
    box-shadow: 0 2px 8px rgba(13, 115, 119, 0.25);
    transition: background var(--transition), box-shadow var(--transition);
}
.btn-trial:hover { background: var(--primary-hover); box-shadow: 0 4px 12px rgba(13, 115, 119, 0.35); }
.btn-trial:disabled { opacity: 0.6; cursor: not-allowed; }
.trial-note {
    font-size: 0.7rem;
    color: var(--text-tertiary);
    text-align: center;
    margin-top: 6px;
}

/* ===== Trial badge on key cards ===== */
.key-badge.trial { background: #e8f0fe; color: #1a56db; }
[data-theme="dark"] .key-badge.trial { background: rgba(26, 86, 219, 0.15); color: #6ca0f6; }

/* ===== Section header ===== */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}
.section-header h2 {
    font-size: 1.5rem;
    color: var(--text);
    font-weight: 600;
    letter-spacing: -0.02em;
}

/* ===== Tabs (admin) ===== */
.tabs {
    display: flex;
    gap: 4px;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
}
.tab {
    padding: 12px 20px;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    font-weight: 500;
    color: var(--text-secondary);
    white-space: nowrap;
    transition: var(--transition);
}
.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

/* ===== Helpers ===== */
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-sm { font-size: 0.85rem; }
.text-muted { color: var(--text-secondary); }
.hidden { display: none !important; }
