:root {
    --bg: #0b1120;
    --surface: #111827;
    --surface-2: #1e293b;
    --border: #263248;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --primary: #6366f1;
    --primary-hover: #4f46e5;
    --emerald: #10b981;
    --amber: #f59e0b;
    --sky: #38bdf8;
    --rose: #f43f5e;
    --radius: 12px;
    --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Inter, sans-serif;
    --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font-family: var(--font);
    background: radial-gradient(circle at top right, #172554 0%, var(--bg) 52%);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.5;
}

.hidden {
    display: none !important;
}

/* Auth */
.auth-shell {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: 100%;
    max-width: 430px;
    background: rgba(17, 24, 39, 0.94);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.45);
}

.brand-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 22px;
}

.brand-header h1 {
    margin: 0;
    font-size: 1.25rem;
}

.brand-header p {
    margin: 2px 0 0;
    color: var(--muted);
    font-size: 0.875rem;
}

.brand-badge {
    width: 42px;
    height: 42px;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), #0ea5e9);
    display: grid;
    place-items: center;
    font-weight: 700;
    letter-spacing: 0.03em;
    flex-shrink: 0;
}

.auth-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px;
    background: var(--bg);
    padding: 4px;
    border-radius: 10px;
    margin-bottom: 18px;
}

.tab-btn {
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 9px 12px;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}

.tab-btn.active {
    background: var(--surface-2);
    color: var(--text);
}

.auth-form,
.modal-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.field label {
    font-size: 0.82rem;
    font-weight: 600;
    color: #cbd5e1;
}

.field input,
.field select {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
    font-size: 0.95rem;
}

.field input:focus,
.field select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.22);
}

.field-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.demo-box {
    margin-top: 4px;
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(56, 189, 248, 0.08);
    border: 1px solid rgba(56, 189, 248, 0.22);
    font-size: 0.82rem;
    color: #bae6fd;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    flex-wrap: wrap;
}

.demo-box code {
    font-family: var(--mono);
    background: rgba(15, 23, 42, 0.7);
    padding: 1px 5px;
    border-radius: 4px;
}

/* Buttons */
.btn {
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 9px 15px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.btn-primary {
    background: var(--primary);
    color: #fff;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-ghost {
    background: transparent;
    border-color: var(--border);
    color: var(--text);
}

.btn-ghost:hover {
    background: var(--surface-2);
}

.btn-danger-ghost {
    background: transparent;
    border-color: rgba(244, 63, 94, 0.35);
    color: #fda4af;
}

.btn-danger-ghost:hover {
    background: rgba(244, 63, 94, 0.15);
}

.btn-sm {
    padding: 6px 10px;
    font-size: 0.8rem;
}

.btn-full {
    width: 100%;
}

.btn-link {
    background: none;
    border: 0;
    color: var(--sky);
    font-weight: 600;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
}

.icon-btn {
    background: none;
    border: 0;
    color: var(--muted);
    font-size: 1.5rem;
    line-height: 1;
    cursor: pointer;
}

/* Alerts */
.alert {
    padding: 10px 12px;
    border-radius: 8px;
    font-size: 0.875rem;
    margin-bottom: 12px;
}

.alert-error {
    background: rgba(244, 63, 94, 0.14);
    border: 1px solid rgba(244, 63, 94, 0.38);
    color: #fecdd3;
}

/* Topbar & Dashboard */
.topbar {
    border-bottom: 1px solid var(--border);
    background: rgba(11, 17, 32, 0.85);
    backdrop-filter: blur(10px);
    position: sticky;
    top: 0;
    z-index: 20;
}

.topbar-inner {
    max-width: 1180px;
    margin: 0 auto;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    flex-wrap: wrap;
}

.brand-inline {
    display: flex;
    align-items: center;
    gap: 12px;
}

.brand-title {
    display: block;
    font-weight: 700;
    font-size: 1.05rem;
}

.brand-sub {
    display: block;
    font-size: 0.78rem;
    color: var(--muted);
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.user-pill {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 999px;
    background: var(--surface);
    border: 1px solid var(--border);
    font-size: 0.85rem;
}

.user-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--emerald);
}

.container {
    max-width: 1180px;
    margin: 0 auto;
    padding: 24px 20px 48px;
}

/* KPIs */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}

.kpi-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}

.kpi-label {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
    margin-bottom: 6px;
}

.kpi-value {
    font-size: 1.75rem;
    font-weight: 700;
}

.text-emerald { color: var(--emerald); }
.text-amber { color: var(--amber); }
.text-sky { color: var(--sky); }
.text-rose { color: var(--rose); }

/* Toolbar */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 18px;
    flex-wrap: wrap;
}

.filter-pills {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.pill {
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    border-radius: 999px;
    padding: 7px 13px;
    font-size: 0.83rem;
    font-weight: 600;
    cursor: pointer;
}

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

.search-box input {
    min-width: 260px;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}

.toolbar-right {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.window-setting {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    font-size: 0.82rem;
    color: var(--muted);
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 6px 10px;
}

.window-setting select {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 3px 6px;
    font-size: 0.82rem;
}

.expiry-banner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 16px;
    border-radius: 12px;
    margin-bottom: 18px;
    background: rgba(245, 158, 11, 0.12);
    border: 1px solid rgba(245, 158, 11, 0.35);
    color: #fde68a;
    font-size: 0.9rem;
    flex-wrap: wrap;
}

.provider-row {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}

.env-tag {
    font-size: 0.7rem;
    font-weight: 700;
    padding: 2px 7px;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: #cbd5e1;
}

.env-Production {
    border-color: rgba(99, 102, 241, 0.45);
    color: #c7d2fe;
}

.env-Staging {
    border-color: rgba(56, 189, 248, 0.45);
    color: #bae6fd;
}

.env-Dev {
    border-color: rgba(148, 163, 184, 0.4);
    color: #cbd5e1;
}

.btn-renew {
    background: rgba(16, 185, 129, 0.14);
    border-color: rgba(16, 185, 129, 0.35);
    color: #6ee7b7;
}

.btn-renew:hover {
    background: rgba(16, 185, 129, 0.24);
}

.sync-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 5px 10px;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 600;
    background: rgba(16, 185, 129, 0.14);
    border: 1px solid rgba(16, 185, 129, 0.35);
    color: #6ee7b7;
    cursor: pointer;
}

.sync-pill.reconnect {
    background: rgba(245, 158, 11, 0.14);
    border-color: rgba(245, 158, 11, 0.35);
    color: #fde68a;
}

/* License Cards */
.licenses-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
    gap: 16px;
}

.license-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.license-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.provider-name {
    margin: 0;
    font-size: 1.08rem;
    font-weight: 700;
}

.license-notes {
    margin: 3px 0 0;
    font-size: 0.82rem;
    color: var(--muted);
}

.badge {
    font-size: 0.74rem;
    font-weight: 700;
    padding: 4px 9px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

.badge-active {
    background: rgba(16, 185, 129, 0.16);
    color: #6ee7b7;
    border: 1px solid rgba(16, 185, 129, 0.35);
}

.badge-expiring_soon {
    background: rgba(245, 158, 11, 0.16);
    color: #fcd34d;
    border: 1px solid rgba(245, 158, 11, 0.35);
}

.badge-scheduled {
    background: rgba(56, 189, 248, 0.16);
    color: #7dd3fc;
    border: 1px solid rgba(56, 189, 248, 0.35);
}

.badge-expired {
    background: rgba(244, 63, 94, 0.16);
    color: #fda4af;
    border: 1px solid rgba(244, 63, 94, 0.35);
}

.api-key-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
}

.api-key-value {
    font-family: var(--mono);
    font-size: 0.82rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.api-key-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.dates-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    font-size: 0.84rem;
}

.date-cell span {
    display: block;
    color: var(--muted);
    font-size: 0.75rem;
}

.countdown-box {
    background: rgba(30, 41, 59, 0.55);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px;
}

.countdown-label {
    font-size: 0.75rem;
    color: var(--muted);
    margin-bottom: 6px;
}

.countdown-timer {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
    text-align: center;
}

.cd-unit {
    background: var(--bg);
    border-radius: 8px;
    padding: 7px 4px;
}

.cd-num {
    display: block;
    font-family: var(--mono);
    font-size: 1.05rem;
    font-weight: 700;
}

.cd-lbl {
    font-size: 0.68rem;
    color: var(--muted);
    text-transform: uppercase;
}

.progress-track {
    height: 6px;
    background: var(--bg);
    border-radius: 999px;
    overflow: hidden;
    margin-top: 10px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--emerald), var(--primary));
}

.progress-fill.warn {
    background: linear-gradient(90deg, var(--amber), var(--rose));
}

.card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    flex-wrap: wrap;
}

.checked-meta {
    font-size: 0.75rem;
    color: var(--muted);
}

.card-actions {
    display: flex;
    gap: 6px;
}

.empty-state {
    text-align: center;
    padding: 48px 20px;
    background: var(--surface);
    border: 1px dashed var(--border);
    border-radius: 14px;
}

.empty-state p {
    color: var(--muted);
    max-width: 440px;
    margin: 8px auto 18px;
}

/* Modal */
.modal {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: grid;
    place-items: center;
    padding: 20px;
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(2, 6, 23, 0.75);
}

.modal-card {
    position: relative;
    width: 100%;
    max-width: 480px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 22px;
    box-shadow: 0 24px 64px rgba(0, 0, 0, 0.55);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
}

.modal-header h2 {
    margin: 0;
    font-size: 1.15rem;
}

.duration-preview {
    font-size: 0.83rem;
    color: #bae6fd;
    background: rgba(56, 189, 248, 0.08);
    border: 1px solid rgba(56, 189, 248, 0.2);
    border-radius: 8px;
    padding: 8px 10px;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 6px;
}

.toast {
    position: fixed;
    right: 20px;
    bottom: 20px;
    z-index: 60;
    background: var(--surface-2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 10px 16px;
    border-radius: 10px;
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.4);
    font-size: 0.88rem;
}

@media (max-width: 760px) {
    .kpi-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .field-row {
        grid-template-columns: 1fr;
    }

    .search-box input {
        min-width: 100%;
    }
}
