/* ── CSS Variables ─────────────────────────────────────────── */
:root {
    --bg:             #f0f4f8;
    --surface:        #ffffff;
    --surface-2:      #f7f9fc;
    --border:         #e2e8f0;
    --text:           #1a202c;
    --text-muted:     #718096;
    --accent:         #0096c7;
    --accent-hover:   #007aab;
    --accent-subtle:  rgba(0, 150, 199, 0.08);
    --sidebar-bg:     #ffffff;
    --sidebar-border: #e2e8f0;
    --sidebar-text:   #4a5568;
    --sidebar-icon:   #a0aec0;
    --sidebar-active-bg:   rgba(0, 150, 199, 0.1);
    --sidebar-active-text: #0096c7;
    --shadow:         0 1px 3px rgba(0, 0, 0, 0.08);
    --shadow-lg:      0 4px 16px rgba(0, 0, 0, 0.10);
    --success:        #38a169;
    --warning-color:  #d69e2e;
    --danger:         #e53e3e;
    --badge-success-bg:   #c6f6d5; --badge-success-text:   #276749;
    --badge-warning-bg:   #fefcbf; --badge-warning-text:   #744210;
    --badge-danger-bg:    #fed7d7; --badge-danger-text:    #9b2c2c;
    --badge-info-bg:      #bee3f8; --badge-info-text:      #2c5282;
    --badge-neutral-bg:   #e2e8f0; --badge-neutral-text:   #4a5568;
    --input-bg:       #ffffff;
    --modal-overlay:  rgba(0, 0, 0, 0.45);
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg:             #0d0f1a;
        --surface:        #161927;
        --surface-2:      #1e2235;
        --border:         #2a2f4a;
        --text:           #e2e8f0;
        --text-muted:     #718096;
        --accent:         #00b4d8;
        --accent-hover:   #0096c7;
        --accent-subtle:  rgba(0, 180, 216, 0.12);
        --sidebar-bg:     #111425;
        --sidebar-border: #1e2235;
        --sidebar-text:   #8892b0;
        --sidebar-icon:   #4a5568;
        --sidebar-active-bg:   rgba(0, 180, 216, 0.15);
        --sidebar-active-text: #00b4d8;
        --shadow:         0 1px 3px rgba(0, 0, 0, 0.3);
        --shadow-lg:      0 4px 20px rgba(0, 0, 0, 0.45);
        --success:        #68d391;
        --warning-color:  #f6e05e;
        --danger:         #fc8181;
        --badge-success-bg:   #22543d; --badge-success-text:   #9ae6b4;
        --badge-warning-bg:   #5f370e; --badge-warning-text:   #fefcbf;
        --badge-danger-bg:    #742a2a; --badge-danger-text:    #fed7d7;
        --badge-info-bg:      #2a4365; --badge-info-text:      #bee3f8;
        --badge-neutral-bg:   #2d3748; --badge-neutral-text:   #a0aec0;
        --input-bg:       #1e2235;
        --modal-overlay:  rgba(0, 0, 0, 0.65);
    }
}

/* ── Reset ────────────────────────────────────────────────── */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
}

.hidden { display: none !important; }

/* ── App Layout ───────────────────────────────────────────── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
    width: 220px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    border-right: 1px solid var(--sidebar-border);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-brand {
    padding: 1.125rem 1rem;
    display: flex;
    align-items: center;
    gap: 0.625rem;
    border-bottom: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.sidebar-brand-icon {
    width: 32px;
    height: 32px;
    border-radius: 6px;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 16px;
}

.sidebar-brand-text h1 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1.2;
}

.sidebar-brand-text small {
    font-size: 0.68rem;
    color: var(--text-muted);
}

.sidebar-nav {
    flex: 1;
    padding: 0.75rem 0;
    overflow-y: auto;
}

.nav-section-label {
    padding: 0.625rem 1rem 0.25rem;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    width: 100%;
    padding: 0.5rem 1rem;
    border: none;
    background: none;
    cursor: pointer;
    color: var(--sidebar-text);
    font-size: 0.875rem;
    font-weight: 500;
    text-align: left;
    border-radius: 6px;
    margin: 1px 8px;
    width: calc(100% - 16px);
    transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
    background: var(--accent-subtle);
    color: var(--text);
}

.nav-item.active {
    background: var(--sidebar-active-bg);
    color: var(--sidebar-active-text);
    font-weight: 600;
}

.nav-item .nav-icon {
    width: 16px;
    text-align: center;
    color: var(--sidebar-icon);
    flex-shrink: 0;
}

.nav-item.active .nav-icon {
    color: var(--sidebar-active-text);
}

.nav-divider {
    height: 1px;
    background: var(--sidebar-border);
    margin: 0.375rem 0;
}

.sidebar-footer {
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--sidebar-border);
    flex-shrink: 0;
}

.sidebar-status {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.sidebar-status-item {
    font-size: 0.7rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 5px;
}

.status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--success);
    flex-shrink: 0;
}

/* ── Main Content ─────────────────────────────────────────── */
.main-wrapper {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.main-content {
    flex: 1;
    padding: 1.5rem;
    overflow-x: hidden;
}

/* ── Page Header ──────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
    gap: 0.75rem;
}

.page-header h2 {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--text);
}

.page-header p {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ── Tab Panels ───────────────────────────────────────────── */
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── Stat Cards ───────────────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.125rem 1rem;
    box-shadow: var(--shadow);
}

.stat-card-label {
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 0.375rem;
}

.stat-card-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text);
    line-height: 1;
}

.stat-card.total  { border-top: 3px solid var(--accent); }
.stat-card.active { border-top: 3px solid var(--success); }
.stat-card.trial  { border-top: 3px solid var(--warning-color); }
.stat-card.expired { border-top: 3px solid var(--danger); }

/* ── Toolbar ──────────────────────────────────────────────── */
.toolbar {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
}

/* ── Search + Filter Bar ──────────────────────────────────── */
.search-bar {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    flex-wrap: wrap;
    margin-bottom: 0.875rem;
}

.search-bar input {
    flex: 1;
    min-width: 200px;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text);
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.15s;
}

.search-bar input:focus {
    border-color: var(--accent);
}

.filter-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-bottom: 1rem;
}

.filter-pill {
    padding: 0.25rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.78rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.filter-pill:hover { border-color: var(--accent); color: var(--accent); }
.filter-pill.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ── Table ────────────────────────────────────────────────── */
.table-wrap {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: var(--shadow);
}

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 900px;
    font-size: 0.8125rem;
}

thead th {
    padding: 0.625rem 0.75rem;
    text-align: left;
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    background: var(--surface-2);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    user-select: none;
}

thead th.sortable { cursor: pointer; }
thead th.sortable:hover { color: var(--accent); }

tbody tr {
    border-bottom: 1px solid var(--border);
    transition: background 0.1s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--accent-subtle); }

tbody td {
    padding: 0.625rem 0.75rem;
    vertical-align: middle;
    color: var(--text);
}

.loading-row td {
    text-align: center;
    padding: 2rem;
    color: var(--text-muted);
}

/* ── Badges / Status ──────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    white-space: nowrap;
}

.badge-active   { background: var(--badge-success-bg); color: var(--badge-success-text); }
.badge-trial    { background: var(--badge-warning-bg); color: var(--badge-warning-text); }
.badge-expired,
.badge-disabled { background: var(--badge-danger-bg);  color: var(--badge-danger-text); }
.badge-pending  { background: var(--badge-info-bg);    color: var(--badge-info-text); }
.badge-neutral  { background: var(--badge-neutral-bg); color: var(--badge-neutral-text); }

/* ── ID cell ──────────────────────────────────────────────── */
.id-cell {
    display: flex;
    align-items: center;
    gap: 4px;
    font-family: ui-monospace, "Cascadia Code", "Fira Code", monospace;
    font-size: 0.75rem;
}

.copy-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 2px 4px;
    border-radius: 3px;
    font-size: 0.75rem;
    flex-shrink: 0;
    transition: color 0.15s;
}

.copy-btn:hover { color: var(--accent); }

.license-key {
    font-family: ui-monospace, "Cascadia Code", "Fira Code", monospace;
    font-size: 0.72rem;
    background: var(--surface-2);
    padding: 2px 5px;
    border-radius: 4px;
    border: 1px solid var(--border);
    color: var(--text);
}

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.875rem;
    border-radius: 6px;
    border: none;
    font-size: 0.8125rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, opacity 0.15s;
    white-space: nowrap;
    text-decoration: none;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary  { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }

.btn-secondary {
    background: var(--surface-2);
    color: var(--text);
    border: 1px solid var(--border);
}
.btn-secondary:hover:not(:disabled) { background: var(--border); }

.btn-success  { background: var(--success); color: #fff; }
.btn-danger   { background: var(--danger);  color: #fff; }
.btn-warning  { background: var(--warning-color); color: #fff; }

.btn-xs {
    padding: 0.2rem 0.5rem;
    font-size: 0.7rem;
    gap: 0.25rem;
}

.actions-cell {
    display: flex;
    gap: 0.375rem;
    flex-wrap: nowrap;
}

/* ── Form ─────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.375rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text);
    font-size: 0.875rem;
    outline: none;
    transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    border-color: var(--accent);
}

.form-group textarea { min-height: 80px; resize: vertical; }
.form-group small { font-size: 0.72rem; color: var(--text-muted); margin-top: 3px; display: block; }

.form-actions {
    display: flex;
    gap: 0.625rem;
    justify-content: flex-end;
    margin-top: 1.25rem;
}

/* ── Section Card ─────────────────────────────────────────── */
.section-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1.25rem;
    box-shadow: var(--shadow);
    margin-bottom: 1rem;
}

.section-card h3 {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 1rem;
    padding-bottom: 0.625rem;
    border-bottom: 1px solid var(--border);
}

/* ── Log select ───────────────────────────────────────────── */
select#logLimit {
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--input-bg);
    color: var(--text);
    font-size: 0.875rem;
    outline: none;
}

/* ── Spinner ──────────────────────────────────────────────── */
.spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    vertical-align: middle;
    margin-right: 6px;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── Modal ────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    background: var(--modal-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    padding: 1rem;
}

.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1.75rem;
    width: 100%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    position: relative;
}

.modal-content h2 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    color: var(--text);
}

.modal-subtitle {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 1.25rem;
}

.close {
    position: absolute;
    top: 1rem;
    right: 1.25rem;
    font-size: 1.5rem;
    cursor: pointer;
    color: var(--text-muted);
    line-height: 1;
}

.close:hover { color: var(--text); }

/* ── Notification status ──────────────────────────────────── */
.notify-success { color: var(--success); font-size: 0.85rem; }
.notify-error   { color: var(--danger);  font-size: 0.85rem; }

/* ── Expiry colors ────────────────────────────────────────── */
.expiry-ok      { color: var(--success); font-weight: 600; }
.expiry-soon    { color: var(--warning-color); font-weight: 600; }
.expiry-expired { color: var(--danger); font-weight: 600; }
.expiry-never   { color: var(--text-muted); font-style: italic; }

/* ── User info cell ───────────────────────────────────────── */
.user-name  { font-weight: 600; color: var(--text); display: block; }
.user-email { font-size: 0.72rem; color: var(--text-muted); }

/* ── Toast ────────────────────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    padding: 0.75rem 1.25rem;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 600;
    animation: toastIn 0.25s ease;
    max-width: 320px;
}

.toast-success { background: var(--success); color: #fff; }
.toast-error   { background: var(--danger);  color: #fff; }
.toast-info    { background: var(--accent);  color: #fff; }

@keyframes toastIn  { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; } }

/* ── Mobile ───────────────────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -220px;
        top: 0;
        height: 100vh;
        transition: left 0.25s ease;
        z-index: 200;
    }

    .sidebar.open { left: 0; }

    .sidebar-overlay {
        display: none;
        position: fixed;
        inset: 0;
        background: rgba(0,0,0,0.4);
        z-index: 190;
    }

    .sidebar-overlay.visible { display: block; }

    .mobile-header {
        display: flex !important;
        align-items: center;
        gap: 0.75rem;
        padding: 0.75rem 1rem;
        background: var(--surface);
        border-bottom: 1px solid var(--border);
        position: sticky;
        top: 0;
        z-index: 100;
    }

    .mobile-menu-btn {
        background: none;
        border: none;
        cursor: pointer;
        font-size: 1.25rem;
        color: var(--text);
        padding: 4px;
    }

    .mobile-title {
        font-weight: 700;
        font-size: 1rem;
        color: var(--text);
    }

    .main-content { padding: 1rem; }

    table { min-width: 700px; }

    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
