:root {
    --bg: #f2f4f7;
    --bg-top: #e2ebff;
    --surface: #ffffff;
    --surface-alt: #f8fafc;
    --text: #1f2937;
    --muted: #6b7280;
    --border: #dbe2ea;
    --primary: #0052cc;
    --primary-hover: #003f9e;
    --danger-bg: #fef2f2;
    --danger-text: #991b1b;
    --warning-bg: #fff7ed;
    --warning-text: #9a3412;
    --success-bg: #ecfdf3;
    --success-text: #166534;
    --shadow: 0 10px 28px rgba(15, 23, 42, 0.05);
    --radius: 12px;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --bg-top: #1e293b;
    --surface: #111827;
    --surface-alt: #1f2937;
    --text: #e5e7eb;
    --muted: #9ca3af;
    --border: #374151;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger-bg: #3b1111;
    --danger-text: #fecaca;
    --warning-bg: #3f2a0f;
    --warning-text: #fde68a;
    --success-bg: #0f2f1f;
    --success-text: #bbf7d0;
    --shadow: 0 14px 30px rgba(0, 0, 0, 0.35);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: "Segoe UI", Tahoma, sans-serif;
    color: var(--text);
    background: radial-gradient(circle at top, var(--bg-top) 0%, var(--bg) 45%);
}

.app-shell {
    width: min(980px, 100% - 2rem);
    margin: 3rem auto;
    display: grid;
    gap: 1rem;
}

.search-card,
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow);
}

.search-card {
    text-align: center;
}

.title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
}

.title-actions {
    display: flex;
    align-items: center;
    gap: 0.45rem;
}

h1 {
    margin: 0;
    font-size: clamp(1.35rem, 2.4vw, 2rem);
}

.subtitle {
    margin: 0.5rem 0 1.25rem;
    color: var(--muted);
}

form {
    max-width: 620px;
    margin: 0 auto;
    text-align: left;
}

label {
    display: block;
    margin-bottom: 0.45rem;
    font-weight: 600;
}

.input-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.6rem;
}

input {
    width: 100%;
    padding: 0.75rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 1rem;
}

input:focus {
    border-color: #8ab4ff;
    outline: 2px solid #dbeafe;
}

button {
    border: 0;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    padding: 0.75rem 1rem;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s ease;
}

button:hover:not(:disabled) {
    background: var(--primary-hover);
}

.theme-toggle {
    width: auto;
}

.user-chip {
    border: 1px solid var(--border);
    background: var(--surface-alt);
    color: var(--muted);
    border-radius: 999px;
    padding: 0.3rem 0.55rem;
    font-size: 0.78rem;
    line-height: 1;
}

.action-btn {
    display: inline-block;
    text-decoration: none;
    border: 1px solid var(--border);
    background: var(--surface-alt);
    color: var(--text);
    border-radius: 10px;
    padding: 0.45rem 0.7rem;
    font-size: 0.82rem;
    font-weight: 600;
    line-height: 1;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.action-btn:hover:not(:disabled) {
    background: var(--surface);
    border-color: var(--muted);
}

button:disabled {
    opacity: 0.65;
    cursor: not-allowed;
}

.field-error {
    min-height: 1.25rem;
    margin: 0.45rem 0 0;
    color: var(--danger-text);
    font-size: 0.9rem;
}

.status {
    margin-top: 1rem;
    padding: 0.75rem 0.85rem;
    border-radius: 10px;
    text-align: left;
    font-size: 0.95rem;
}

.status.info {
    background: #eff6ff;
    color: #1d4ed8;
}

.status.success {
    background: var(--success-bg);
    color: var(--success-text);
}

.status.warning {
    background: var(--warning-bg);
    color: var(--warning-text);
}

.status.error {
    background: var(--danger-bg);
    color: var(--danger-text);
}

.results {
    display: grid;
    gap: 1rem;
}

.hidden {
    display: none !important;
}

h2 {
    margin: 0 0 0.7rem;
    font-size: 1.1rem;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
}

.summary-item {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 0.7rem;
}

.summary-item dt {
    margin: 0 0 0.25rem;
    color: var(--muted);
    font-size: 0.82rem;
}

.summary-item dd {
    margin: 0;
    font-weight: 700;
    font-size: 1rem;
}

.score-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.25rem 0.55rem;
    border-radius: 999px;
    font-size: 0.82rem;
    font-weight: 700;
}

.score-badge.low {
    background: #dcfce7;
    color: #166534;
}

.score-badge.medium {
    background: #fef9c3;
    color: #854d0e;
}

.score-badge.high {
    background: #fee2e2;
    color: #991b1b;
}

.summary-note {
    margin: 0.9rem 0 0;
    color: var(--muted);
    font-size: 0.92rem;
}

.breakdown-list {
    margin: 0;
    padding-left: 1.1rem;
}

.breakdown-list li {
    margin: 0.35rem 0;
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 700px;
}

th,
td {
    border-bottom: 1px solid var(--border);
    padding: 0.55rem 0.4rem;
    text-align: left;
    vertical-align: top;
    font-size: 0.9rem;
}

th {
    background: var(--surface-alt);
    font-weight: 700;
}

.empty {
    margin: 0;
    color: var(--muted);
}

/* ── Top navbar ─────────────────────────────────────── */
.top-nav {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1.25rem;
    height: 3.25rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
}

.top-nav__brand {
    font-weight: 700;
    font-size: 1rem;
    color: var(--text);
    text-decoration: none;
    letter-spacing: -0.01em;
}

.top-nav__brand:hover {
    color: var(--primary);
}

.top-nav__actions {
    display: flex;
    align-items: center;
    gap: 0.35rem;
}

button.nav-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2.25rem;
    height: 2.25rem;
    padding: 0;
    border: 1px solid transparent;
    border-radius: 8px;
    background: transparent;
    color: var(--muted);
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

button.nav-icon-btn,
.nav-icon-link {
    text-decoration: none;
}

button.nav-icon-btn:hover:not(:disabled) {
    background: var(--surface-alt);
    border-color: var(--border);
    color: var(--text);
}

.nav-icon-link:hover {
    background: var(--surface-alt);
    border-color: var(--border);
    color: var(--text);
}

button.nav-icon-btn:disabled {
    opacity: 0.4;
    cursor: default;
}

button.nav-icon-btn[aria-expanded="true"] {
    background: var(--surface-alt);
    border-color: var(--border);
    color: var(--text);
}

.nav-icon {
    width: 1.2rem;
    height: 1.2rem;
    fill: currentColor;
    display: block;
    flex-shrink: 0;
}

.nav-profile {
    position: relative;
}

.nav-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    min-width: 180px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 0.4rem 0;
    z-index: 200;
}

.nav-dropdown.is-open {
    display: block;
}

.nav-dropdown__greeting {
    display: block;
    padding: 0.5rem 0.9rem 0.4rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.25rem;
    pointer-events: none;
    user-select: none;
}

.nav-dropdown__meta {
    display: block;
    padding: 0 0.9rem 0.55rem;
    font-size: 0.78rem;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.25rem;
    pointer-events: none;
    user-select: none;
}

.nav-dropdown__item {
    display: block;
    padding: 0.55rem 0.9rem;
    font-size: 0.88rem;
    font-weight: 500;
    color: var(--text);
    text-decoration: none;
    transition: background 0.12s ease;
}

.nav-dropdown__item:hover {
    background: var(--surface-alt);
}

.nav-dropdown__item--danger {
    color: var(--danger-text);
}

.nav-dropdown__item--danger:hover {
    background: var(--danger-bg);
}

.top-nav ~ .app-shell {
    margin-top: 1.5rem;
}

.access-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.9rem;
}

.access-header h2,
.access-header p {
    margin: 0;
}

.access-header p {
    color: var(--muted);
    font-size: 0.92rem;
}

.usage-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 0.9rem;
}

.usage-card {
    padding: 0.85rem;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface-alt);
}

.usage-card__label {
    margin: 0 0 0.25rem;
    color: var(--muted);
    font-size: 0.82rem;
}

.usage-card__value {
    margin: 0;
    font-size: 1.05rem;
    font-weight: 700;
}

.access-message {
    margin: 0;
    color: var(--text);
}

.access-message + .access-message {
    margin-top: 0.55rem;
}

.access-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
    margin-top: 1rem;
}

.access-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
}

.access-link,
.access-button {
    min-width: 180px;
}

.access-button {
    width: auto;
}

.access-pill {
    display: inline-flex;
    align-items: center;
    padding: 0.3rem 0.65rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: var(--surface-alt);
    color: var(--text);
    font-size: 0.82rem;
    font-weight: 700;
    white-space: nowrap;
}

.settings-shell {
    gap: 1rem;
}

.settings-hero {
    text-align: left;
}

.settings-kicker {
    margin: 0 0 0.35rem;
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    text-transform: uppercase;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 1rem;
}

.settings-list {
    display: grid;
    gap: 0.7rem;
}

.settings-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding-bottom: 0.55rem;
    border-bottom: 1px solid var(--border);
}

.settings-row span {
    color: var(--muted);
    font-size: 0.9rem;
}

.settings-row strong {
    text-align: right;
    font-size: 0.95rem;
}

.settings-note {
    margin: 1rem 0 0;
    color: var(--muted);
    font-size: 0.92rem;
}

/* ── Responsive ──────────────────────────────────────── */
@media (max-width: 760px) {
    .app-shell {
        width: min(980px, 100% - 1rem);
        margin: 1.25rem auto;
    }

    .search-card,
    .card {
        padding: 1rem;
    }

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

    button:not(.nav-icon-btn) {
        width: 100%;
    }

    .title-row {
        flex-direction: column;
        align-items: flex-start;
    }

    .title-actions {
        width: 100%;
        flex-wrap: wrap;
    }

    .theme-toggle {
        width: auto;
    }

    .top-nav {
        padding: 0 0.75rem;
    }

    .top-nav__brand {
        font-size: 0.9rem;
    }

    .summary-grid {
        grid-template-columns: 1fr;
    }

    .usage-grid {
        grid-template-columns: 1fr;
    }

    .access-header {
        flex-direction: column;
    }

    .access-link,
    .access-button {
        width: 100%;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }
}
