:root {
    --primary: #1a56db;
    --primary-dark: #1240a8;
    --primary-light: #e8effc;
    --accent: #f59e0b;
    --success: #059669;
    --danger: #dc2626;
    --text: #1f2937;
    --text-muted: #6b7280;
    --bg: #f1f5f9;
    --card-bg: #ffffff;
    --border: #e2e8f0;
    --shadow: 0 1px 3px rgba(15, 23, 42, 0.06), 0 4px 16px rgba(15, 23, 42, 0.04);
    --radius: 12px;
    --sidebar-width: 260px;
    --topbar-height: 64px;
}

* { box-sizing: border-box; }

html {
    height: 100%;
}

body {
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    color: var(--text);
    background: var(--bg);
    margin: 0;
    min-height: 100%;
}

/* ─── App Shell (authenticated) ─── */
.app-shell {
    display: flex;
    min-height: 100vh;
    width: 100%;
}

.app-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    color: #e2e8f0;
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 1040;
    overflow-y: auto;
}

.sidebar-brand {
    padding: 1.25rem 1.25rem 1rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}

.sidebar-brand .brand-logo {
    color: #fff !important;
    text-decoration: none;
    font-weight: 700;
    font-size: 1.15rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.sidebar-nav {
    flex: 1;
    padding: 1rem 0.75rem;
}

.sidebar-label {
    display: block;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #94a3b8;
    padding: 0 0.75rem;
    margin-bottom: 0.5rem;
}

.sidebar-section {
    margin-bottom: 0.35rem;
}

.sidebar-section + .sidebar-section {
    margin-top: 0.85rem;
    padding-top: 0.85rem;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
}

.sidebar-section-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.35rem 0.75rem;
    margin-bottom: 0.35rem;
    border: none;
    border-radius: 6px;
    background: transparent;
    color: #94a3b8;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}

.sidebar-section-toggle:hover {
    background: rgba(255, 255, 255, 0.06);
    color: #cbd5e1;
}

.sidebar-section-toggle:focus-visible {
    outline: 2px solid rgba(96, 165, 250, 0.8);
    outline-offset: 2px;
}

.sidebar-chevron {
    font-size: 0.55rem;
    line-height: 1;
    transition: transform 0.2s ease;
    opacity: 0.85;
}

.sidebar-section.collapsed .sidebar-chevron {
    transform: rotate(-90deg);
}

.sidebar-section-items {
    overflow: hidden;
}

.sidebar-section.collapsed .sidebar-section-items {
    display: none;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.65rem 0.85rem;
    border-radius: 8px;
    color: #cbd5e1;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    margin-bottom: 0.15rem;
    transition: background 0.15s, color 0.15s;
}

.sidebar-link:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}

.sidebar-link.active {
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(26, 86, 219, 0.4);
}

.sidebar-icon {
    font-size: 1.1rem;
    width: 1.5rem;
    text-align: center;
}

.sidebar-footer {
    padding: 1rem;
    border-top: 1px solid rgba(255,255,255,0.08);
    margin-top: auto;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.sidebar-user-avatar {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    background: var(--primary);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.9rem;
    flex-shrink: 0;
}

.sidebar-user-name {
    font-size: 0.85rem;
    font-weight: 600;
    color: #f1f5f9;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

.sidebar-user-email {
    font-size: 0.72rem;
    color: #94a3b8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 160px;
}

.app-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    min-width: 0;
}

.app-topbar {
    height: var(--topbar-height);
    background: var(--card-bg);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 1.5rem;
    gap: 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.notification-bell {
    position: relative;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    text-decoration: none;
    font-size: 1.25rem;
    color: var(--text);
    transition: background 0.15s;
}

.notification-bell:hover {
    background: var(--bg);
    color: var(--primary);
}

.notification-badge {
    position: absolute;
    top: 2px;
    right: 2px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    border-radius: 999px;
    background: #dc2626;
    color: #fff;
    font-size: 0.65rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.notification-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.notification-item {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow);
}

.notification-item.unread {
    border-left: 4px solid var(--primary);
    background: var(--primary-light);
}

.notification-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--primary);
    flex-shrink: 0;
}

.notification-message {
    white-space: pre-line;
}

.notification-list-compact {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.notification-compact-item {
    padding: 0.65rem 0;
    border-bottom: 1px solid var(--border);
}

.notification-compact-item:last-child {
    border-bottom: none;
}

.notification-compact-item.unread {
    padding-left: 0.5rem;
    border-left: 3px solid var(--primary);
}

.topbar-title {
    font-weight: 600;
    font-size: 1.1rem;
    color: var(--text);
}

.app-alerts {
    padding: 0.75rem 1.5rem 0;
}

.app-main {
    flex: 1 0 auto;
    padding: 1.5rem;
    padding-bottom: 2.5rem;
}

.app-footer {
    flex-shrink: 0;
    padding: 1rem 1.5rem;
    background: var(--card-bg);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    font-size: 0.85rem;
}

/* ─── Guest layout ─── */
.app-guest {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-navbar {
    background: var(--card-bg) !important;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0,0,0,0.04);
    padding: 0.75rem 0;
    flex-shrink: 0;
}

.app-main-guest {
    flex: 1 0 auto;
}

.app-footer-guest {
    flex-shrink: 0;
    padding: 1.25rem 0;
    border-top: 1px solid var(--border);
    background: var(--card-bg);
    margin-top: auto;
}

.brand-logo {
    font-weight: 700;
    font-size: 1.25rem;
    color: var(--primary) !important;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-decoration: none;
}

.brand-icon { font-size: 1.5rem; }

/* ─── Hero ─── */
.hero-section {
    padding: 5rem 0 4rem;
    background: linear-gradient(135deg, #1a56db 0%, #0e3a8a 100%);
    color: white;
    border-radius: 0 0 2rem 2rem;
    margin-bottom: 3rem;
}

.hero-section h1 {
    font-weight: 700;
    font-size: clamp(2rem, 5vw, 3rem);
    line-height: 1.2;
}

.hero-section .lead {
    opacity: 0.9;
    font-size: 1.15rem;
    max-width: 540px;
}

/* ─── Cards ─── */
.feature-card, .stat-card, .auth-card, .dashboard-card, .meter-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

.feature-card, .stat-card, .meter-card {
    height: 100%;
    transition: transform 0.2s, box-shadow 0.2s;
}

.feature-card:hover, .meter-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.1);
}

.feature-icon {
    width: 48px;
    height: 48px;
    border-radius: 10px;
    background: var(--primary-light);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 1rem;
}

.stat-card .stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-card .stat-label {
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 600;
}

.stat-card-hero {
    border: 1px solid rgba(26, 86, 219, 0.15);
    background: linear-gradient(135deg, #f0f7ff 0%, #ffffff 100%);
}

.stat-card-hero.stat-card-warning {
    border-color: rgba(245, 158, 11, 0.35);
    background: linear-gradient(135deg, #fffbeb 0%, #ffffff 100%);
}

.stat-value-credit {
    font-size: 1.35rem !important;
    line-height: 1.3;
}

.stat-subvalue {
    color: var(--text-muted);
    font-size: 0.95rem;
    margin-top: 0.35rem;
}

/* ─── Page header ─── */
.page-header {
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-weight: 700;
    font-size: 1.65rem;
    margin-bottom: 0.25rem;
}

.page-header .page-subtitle {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin: 0;
}

.page-header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.page-header-actions > form {
    display: flex;
    margin: 0;
}

.page-header-actions .btn {
    white-space: nowrap;
}

.back-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    margin-bottom: 0.5rem;
}

.back-link:hover { color: var(--primary); }

/* ─── Meter detail ─── */
.meter-info-grid {
    display: grid;
    gap: 0.85rem;
}

.meter-info-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 1rem;
    padding-bottom: 0.85rem;
    border-bottom: 1px solid var(--border);
}

.meter-info-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.meter-info-label {
    color: var(--text-muted);
    font-size: 0.85rem;
    flex-shrink: 0;
}

.meter-info-value {
    font-size: 0.9rem;
    font-weight: 500;
    text-align: right;
}

.meter-actions-stack {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.card-action-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.5rem;
    align-items: stretch;
}

.card-action-row > a,
.card-action-row > form {
    margin: 0;
    min-width: 0;
}

.card-action-row > form {
    display: flex;
}

.card-action-row .btn {
    width: 100%;
}

/* ─── Auth ─── */
.auth-wrapper {
    min-height: calc(100vh - 160px);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
}

.auth-card {
    width: 100%;
    max-width: 440px;
}

.auth-card h2 {
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.auth-card .subtitle {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
}

/* ─── Forms ─── */
.form-control, .form-select {
    border-radius: 8px;
    border-color: var(--border);
    padding: 0.6rem 0.85rem;
    font-size: 0.9rem;
}

.form-control:focus, .form-select:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(26, 86, 219, 0.12);
}

.btn-primary {
    background: var(--primary);
    border-color: var(--primary);
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
}

.btn-primary:not(.btn-sm) {
    padding: 0.55rem 1.15rem;
}

.btn-primary:hover {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}

.btn-outline-primary,
.btn-outline-secondary,
.btn-outline-danger {
    border-radius: 8px;
    font-weight: 500;
}

/* ─── Status badges ─── */
.status-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.3rem 0.7rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    white-space: nowrap;
}

.status-badge.healthy { background: #d1fae5; color: #065f46; }
.status-badge.degraded { background: #fef3c7; color: #92400e; }
.status-badge.unhealthy { background: #fee2e2; color: #991b1b; }

/* ─── Password toggle ─── */
.password-input-wrapper { position: relative; }

.password-input-wrapper .password-input { padding-right: 2.75rem; }

.password-toggle-btn {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    border: none;
    background: transparent;
    color: var(--text-muted);
    padding: 0.25rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.password-toggle-btn:hover { color: var(--primary); }

/* ─── Empty state ─── */
.empty-state {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 3rem 2rem;
    text-align: center;
    color: var(--text-muted);
    background: var(--card-bg);
}

.coming-soon {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    text-align: center;
    color: var(--text-muted);
    background: var(--card-bg);
}

/* ─── Tables ─── */
.table { font-size: 0.9rem; }

.table thead th {
    font-weight: 600;
    color: var(--text-muted);
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    border-bottom-width: 1px;
}

/* ─── Responsive ─── */
.wallet-balance-card {
    background: linear-gradient(135deg, #1a56db 0%, #0e3a8a 100%);
    color: #fff;
    border: none;
}

.wallet-balance-card .stat-label,
.wallet-balance-card .text-muted {
    color: rgba(255, 255, 255, 0.85) !important;
}

.wallet-balance-card .stat-value {
    color: #fff;
}

.gateway-option {
    display: flex;
    gap: 0.75rem;
    align-items: flex-start;
    padding: 1rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 0.75rem;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.gateway-option:hover:not(.disabled) {
    border-color: var(--primary);
    background: var(--primary-light);
}

.gateway-option.active {
    border-color: var(--primary);
    background: var(--primary-light);
}

.gateway-option.disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.gateway-option input {
    margin-top: 0.25rem;
}

.gateway-option-body {
    flex: 1;
}

.config-snippet {
    background: #0f172a;
    color: #e2e8f0;
    padding: 1rem;
    border-radius: 8px;
    overflow-x: auto;
    margin: 0;
}

.recommendation-card {
    border: 1px solid var(--border);
    border-left-width: 4px;
    border-radius: var(--radius);
    padding: 1rem;
    background: var(--card-bg);
    height: 100%;
}

.assistant-chat { display: flex; flex-direction: column; min-height: 420px; }
.assistant-messages { flex: 1; max-height: 480px; overflow-y: auto; display: flex; flex-direction: column; gap: 0.75rem; }
.assistant-bubble { max-width: 85%; padding: 0.75rem 1rem; border-radius: 12px; background: var(--bg-subtle, #f3f4f6); }
.assistant-bubble.user { align-self: flex-end; background: #e8f0fe; }
.assistant-bubble.assistant { align-self: flex-start; }

.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.45);
    z-index: 1035;
}

.sidebar-backdrop.show {
    display: block;
}

@media (max-width: 991.98px) {
    .app-sidebar {
        transform: translateX(-100%);
        transition: transform 0.25s ease;
        box-shadow: 4px 0 24px rgba(0, 0, 0, 0.15);
    }

    .app-sidebar.show {
        transform: translateX(0);
    }

    .app-content {
        margin-left: 0;
    }

    .sidebar-toggle {
        font-size: 1.25rem;
        text-decoration: none;
        color: var(--text);
        padding: 0;
    }
}

/* PWA install / update banners */
.pwa-update-banner,
.pwa-install-banner {
    position: fixed;
    left: 50%;
    bottom: 20px;
    transform: translateX(-50%);
    z-index: 1080;
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: min(520px, calc(100vw - 32px));
    padding: 12px 16px;
    border-radius: 12px;
    background: #0f172a;
    color: #fff;
    box-shadow: 0 12px 32px rgba(15, 23, 42, 0.28);
    font-size: 0.9rem;
}

.pwa-install-banner {
    bottom: 72px;
}

.pwa-update-banner button,
.pwa-install-banner button {
    white-space: nowrap;
}

/* Legal pages */
.legal-page-header {
    max-width: 820px;
    margin: 0 auto 2rem;
}

.legal-page-title {
    font-size: clamp(1.75rem, 4vw, 2.25rem);
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.legal-page-subtitle {
    font-size: 1.05rem;
    margin-bottom: 0.35rem;
}

.legal-page-body {
    max-width: 820px;
    margin: 0 auto;
}

.legal-document section + section {
    margin-top: 2rem;
}

.legal-document h2 {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    color: var(--text);
}

.legal-document p,
.legal-document li {
    color: var(--text-muted);
    line-height: 1.7;
}

.legal-document ul {
    padding-left: 1.25rem;
}

.legal-table {
    font-size: 0.92rem;
}

.legal-table code {
    font-size: 0.85em;
    word-break: break-word;
}

.legal-page-footer {
    max-width: 820px;
    margin: 2.5rem auto 0;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 0.75rem;
    font-size: 0.9rem;
}

.legal-page-footer a {
    color: var(--primary);
    text-decoration: none;
}

.legal-page-footer a:hover {
    text-decoration: underline;
}

/* Cookie consent banner */
.cookie-consent-banner {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 1090;
    padding: 16px;
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    color: #f8fafc;
    box-shadow: 0 -8px 32px rgba(15, 23, 42, 0.25);
}

.cookie-consent-content {
    max-width: 1100px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    flex-wrap: wrap;
}

.cookie-consent-text {
    flex: 1 1 320px;
    font-size: 0.92rem;
    line-height: 1.6;
}

.cookie-consent-text a {
    color: #93c5fd;
    text-decoration: underline;
}

.cookie-consent-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.footer-legal {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
}

.footer-legal a {
    color: inherit;
    text-decoration: none;
}

.footer-legal a:hover {
    color: var(--primary);
    text-decoration: underline;
}
