:root {
    --primary: #e2e8f0;
    --surface: #111827;
    --strong-text: #e2e8f0;
    --primary-soft: #1e293b;
    --accent: #fb7185;
    --bg: #020617;
    --card: #0f172a;
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #334155;
    --danger: #f43f5e;
    --success: #34d399;
    --radius: 18px;
    --shadow: 0 20px 50px rgba(15, 23, 42, 0.35);
}

/* Force hide any theme switch UI — application is dark-only */
.theme-switch { display: none !important; }


body.theme-dark {
    --primary: #e2e8f0;
    --surface: #111827;
    --strong-text: #e2e8f0;
    --primary-soft: #1e293b;
    --accent: #fb7185;
    --bg: #020617;
    --card: #0f172a;
    --text-main: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #334155;
    --danger: #f43f5e;
    --success: #34d399;
    --shadow: 0 20px 50px rgba(15, 23, 42, 0.35);
}

h1, h2, h3, h4, h5, h6 {
    color: var(--text-main);
}

.view-title {
    color: var(--text-main);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    background: var(--bg);
    color: var(--text-main);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); }

.btn,
.btn-action,
.btn-del,
.btn-secondary {
    min-height: 46px;
    border: 0;
    border-radius: 18px;
    padding: 13px 18px;
    font-weight: 800;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}

.btn:hover,
.btn-action:hover,
.btn-del:hover,
.btn-secondary:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 26px rgba(15, 23, 42, 0.28);
}

.btn-main,
.btn-action {
    background: linear-gradient(135deg, #fb7185, #f43f5e);
    color: #ffffff;
}

.btn-main:hover,
.btn-action:hover {
    background: linear-gradient(135deg, #f43f5e, #fb7185);
}

.btn-sub,
.btn-secondary {
    background: rgba(255,255,255,0.05);
    color: #e2e8f0;
    border: 1px solid rgba(148,163,184,0.18);
}

.btn-del {
    background: rgba(244,63,94,0.95);
    color: #ffffff;
}

.remember-row {
    display: flex;
    gap: 10px;
    align-items: flex-start;
    margin: 10px 0;
    color: var(--text-main);
    font-weight: 700;
    line-height: 1.45;
}

.remember-row input {
    margin-top: 3px;
    accent-color: var(--accent);
}

.app-footer {
    width: 100%;
    padding: 18px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
}

.app-footer strong { color: var(--accent); }


.pwa-install-banner {
    position: fixed;
    left: 16px;
    right: 16px;
    bottom: 16px;
    z-index: 99999;
    max-width: 760px;
    margin: 0 auto;
    background: var(--card);
    border: 1px solid rgba(148,163,184,0.08);
    border-radius: 12px;
    box-shadow: 0 18px 50px rgba(2, 6, 23, 0.6);
    padding: 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    animation: installSlide 0.25s ease both;
}

.pwa-install-banner div { flex: 1; min-width: 0; }
.pwa-install-banner strong { display: block; color: var(--primary); }
.pwa-install-banner span { display: block; color: var(--text-muted); font-size: 13px; line-height: 1.4; }
.pwa-close { border: 0; background: #F1F5F9; color: var(--text-muted); width: 36px; height: 36px; border-radius: 8px; cursor: pointer; }

@keyframes installSlide {
    from { opacity: 0; transform: translateY(16px); }
    to { opacity: 1; transform: translateY(0); }
}

.legal-shell {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.legal-nav {
    background: var(--surface);
    color: var(--strong-text);
    padding: 14px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.legal-brand {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--strong-text);
    font-weight: 900;
    text-decoration: none;
}

.legal-brand img { width: 32px; height: 32px; object-fit: contain; }

.legal-card {
    max-width: 900px;
    width: calc(100% - 32px);
    margin: 28px auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 30px;
    box-shadow: var(--shadow);
}

.legal-card h1 {
    margin: 0 0 16px;
    color: var(--primary);
    font-size: 30px;
}

.legal-card h1 {
    margin: 0 0 16px;
    color: var(--primary);
    font-size: 30px;
}

.legal-card p,
.legal-card li {
    color: var(--text-muted);
    line-height: 1.65;
}

.notice {
    border-radius: 18px;
    padding: 16px 18px;
    border: 1px solid rgba(148,163,184,0.16);
    background: rgba(15,23,42,0.92);
    color: #f8fafc;
}

.notice.error {
    background: rgba(244,63,94,0.15);
    color: #fecdd3;
    border-color: rgba(244,63,94,0.28);
}

.notice.success {
    background: rgba(34,197,94,0.12);
    color: #d9f99d;
    border-color: rgba(34,197,94,0.26);
}

.app-nav {
    background: var(--surface);
    padding: 14px 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    box-shadow: 0 2px 12px rgba(0,0,0,0.05);
    position: sticky;
    top: 0;
    z-index: 999;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    color: white;
    font-size: 22px;
    font-weight: 900;
    text-decoration: none;
}

.nav-brand span { color: #10b981; }
.nav-brand img { max-height: 32px; width: auto; object-fit: contain; }

.sidebar-toggle {
    display: none;
    background: rgba(255,255,255,0.08);
    color: var(--strong-text);
    border: 1px solid rgba(255,255,255,0.18);
    width: 40px;
    height: 40px;
    border-radius: 8px;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
}

.sidebar hr {
    border-color: rgba(255,255,255,0.12);
}

.nav-user { display: flex; align-items: center; gap: 16px; }
.user-badge { background: rgba(255,255,255,0.08); padding: 6px 14px; border-radius: 20px; font-size: 13px; color: var(--strong-text); font-weight: 700; }
.logout-btn { color: #FB7185; text-decoration: none; font-size: 13px; font-weight: 800; display:inline-flex; align-items:center; gap:8px; }

.wrapper {
    max-width: 1300px;
    margin: 24px auto;
    padding: 0 16px;
    display: grid;
    grid-template-columns: 260px 1fr;
    gap: 24px;
}

.sidebar {
    background: var(--surface);
    border-radius: 22px;
    padding: 20px;
    border: 1px solid rgba(148,163,184,0.12);
    height: fit-content;
    box-shadow: var(--shadow);
}

.side-link {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 14px 18px;
    background: none;
    border: none;
    text-align: left;
    font-size: 14px;
    font-weight: 700;
    color: #cbd5e1;
    cursor: pointer;
    border-radius: 16px;
    margin-bottom: 8px;
    text-decoration: none;
    transition: all 0.2s ease;
}

.side-link:hover { background: rgba(251,113,133,0.14); color: #fff; padding-left: 20px; }
.side-link.active { background: rgba(251,113,133,0.18); color: #fff; box-shadow: 0 10px 22px rgba(251,113,133,0.18); }
.sb-icon { font-size: 16px; }
.nav-alert { position:absolute; right:10px; top:50%; transform:translateY(-50%); background:#f43f5e; color:white; font-size:10px; font-weight:900; padding:2px 6px; border-radius:10px; }

.main-panel {
    background: rgba(15,23,42,0.95);
    border-radius: 24px;
    padding: 26px;
    border: 1px solid rgba(148,163,184,0.12);
    min-width: 0;
    box-shadow: var(--shadow);
}

.page-head {
    display: flex;
    justify-content: space-between;
    gap: 18px;
    align-items: flex-start;
    margin-bottom: 24px;
}

.page-kicker {
    margin: 0 0 6px;
    color: var(--accent);
    font-size: 12px;
    font-weight: 900;
    text-transform: uppercase;
}

.page-title {
    margin: 0;
    color: var(--text-main);
    font-size: 30px;
    font-weight: 900;
    display: flex;
    align-items: center;
    gap: 10px;
}

.page-subtitle {
    max-width: 720px;
    margin: 10px 0 0;
    color: var(--text-muted);
    line-height: 1.6;
}

.settings-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.card-view,
.contact-card {
    background: rgba(15,23,42,0.96);
    border: 1px solid rgba(148,163,184,0.12);
    border-radius: 22px;
    padding: 24px;
    box-shadow: var(--shadow);
}

.card-view {
    position: relative;
    overflow: hidden;
}

.card-view::before,
.contact-card::before {
    content: "";
    display: block;
    width: 44px;
    height: 3px;
    background: var(--accent);
    border-radius: 999px;
    margin-bottom: 16px;
}

.card-view h2,
.contact-card h2 {
    margin: 0 0 16px;
    color: var(--text-main);
    font-size: 18px;
    font-weight: 900;
    display: flex;
    align-items: center;
    gap: 8px;
}


.input-group input,
.input-group textarea,
.input-group select {
    width: 100%;
    min-height: 50px;
    padding: 14px 16px;
    border: 1px solid rgba(148,163,184,0.16);
    border-radius: 18px;
    color: #f8fafc;
    background: rgba(15,23,42,0.98);
    font-size: 15px;
    outline: none;
    transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.input-group input::placeholder,
.input-group textarea::placeholder,
.input-group select::placeholder {
    color: #94a3b8;
}

.input-group input:focus,
.input-group textarea:focus,
.input-group select:focus {
    border-color: #fb7185;
    box-shadow: 0 0 0 4px rgba(251,113,133,0.18);
    background: rgba(15,23,42,1);
}

.field-note {
    margin: 10px 0 0;
    color: #94a3b8;
    font-size: 13px;
    line-height: 1.5;
}

.theme-switch {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}

.theme-switch__option {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    min-height: 52px;
    padding: 12px 16px;
    border: 1px solid rgba(148,163,184,0.18);
    border-radius: 16px;
    background: rgba(255,255,255,0.04);
    color: var(--text-main);
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.18s ease, border-color 0.18s ease, color 0.18s ease, transform 0.15s ease;
}

.theme-switch__option:hover {
    transform: translateY(-1px);
}

.theme-switch__option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.theme-switch__option:has(input:checked) {
    background: rgba(251,113,133,0.12);
    border-color: var(--accent);
}

.theme-switch__option input:checked + span {
    color: var(--accent);
}

.theme-switch__option input:not(:checked) + span {
    color: var(--text-main);
}

.contact-card {
    position: relative;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.contact-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 28px rgba(15, 23, 42, 0.1);
}

.contact-card > i {
    width: 42px;
    height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
    background: #ECFDF5;
    border-radius: 10px;
    color: var(--accent);
    font-size: 24px;
}

.contact-card p {
    margin: 0 0 14px;
    color: var(--text-muted);
    line-height: 1.55;
}

.contact-card a {
    font-weight: 900;
    word-break: break-word;
}

.contact-layout {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 340px;
    gap: 18px;
    align-items: start;
}

.contact-form-panel {
    min-width: 0;
}

.contact-side-panel {
    position: sticky;
    top: 92px;
}

.contact-channel {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 14px;
    border-radius: 16px;
    border: 1px solid rgba(148,163,184,0.14);
    background: rgba(255,255,255,0.04);
    color: var(--text-main);
    text-decoration: none;
    margin-bottom: 10px;
}

.contact-channel i {
    color: var(--accent);
    font-size: 20px;
}

.contact-channel strong,
.contact-channel span {
    display: block;
}

.contact-channel span {
    color: var(--text-muted);
    overflow-wrap: anywhere;
}

.contact-channel strong {
    color: var(--text-main);
    margin-bottom: 3px;
}

.contact-note {
    margin-top: 16px;
    padding: 14px;
    border-radius: 16px;
    background: rgba(251,113,133,0.12);
    color: #fecdd3;
    font-weight: 800;
    line-height: 1.5;
}

.section-view { display: none; width: 100%; animation: fadeIn 0.25s ease; }
.section-view.active { display: block; }

.weather-banner {
    background: linear-gradient(135deg, #0A2540 0%, #1E3A8A 100%);
    color: white;
    padding: 24px;
    border-radius: 12px;
    margin-bottom: 24px;
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 18px 24px;
    align-items: center;
    box-shadow: 0 6px 20px rgba(30, 58, 138, 0.15);
}

.weather-info h3 { font-size: 20px; font-weight: 800; margin: 0; }
.weather-info p { font-size: 13px; opacity: 0.85; margin-top: 4px; }
.weather-temp { display: flex; align-items: center; gap: 14px; justify-content: flex-end; min-width: 220px; }
.temp-degree { font-size: 42px; font-weight: 900; color: var(--accent); white-space: nowrap; }
.temp-condition { font-size: 12px; background: rgba(255,255,255,0.16); padding: 6px 14px; border-radius: 20px; font-weight: 700; backdrop-filter: blur(4px); white-space: nowrap; }
.weather-metrics { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.weather-metric { background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.16); border-radius: 10px; padding: 10px 12px; font-size: 13px; font-weight: 800; display:flex; align-items:center; gap:8px; min-width:0; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Modal & code input animations */
.code-modal-backdrop { animation: modalFade 240ms ease both; }
.code-modal-backdrop .code-digit { transition: transform 160ms ease, box-shadow 160ms ease; }
.code-modal-backdrop .code-digit:focus { transform: translateY(-4px); box-shadow: 0 10px 30px rgba(10,37,64,0.12); outline: none; }
.code-modal-backdrop .btn { transition: transform 180ms cubic-bezier(.2,.9,.3,1), box-shadow 180ms ease; }

@keyframes modalFade { from { opacity: 0; transform: scale(.98); } to { opacity:1; transform: scale(1); } }

/* Ticket animations */
.ticket-card { animation: ticketReveal 420ms cubic-bezier(.16,.8,.24,1) both; transform-origin: top center; }
@keyframes ticketReveal { 0% { opacity:0; transform: translateY(12px) scale(.98) } 60% { opacity:1; transform: translateY(-6px) scale(1.02) } 100% { transform: translateY(0) scale(1) } }
.ticket-qr { transition: transform 260ms ease, box-shadow 260ms ease; }
.ticket-card:hover .ticket-qr { transform: translateY(-6px) scale(1.02); box-shadow: 0 12px 30px rgba(10,37,64,0.12); }

/* MZK card subtle entrance */
.mzk-card { transition: transform 220ms ease, box-shadow 220ms ease; }
.mzk-card:hover { transform: translateY(-6px); box-shadow: 0 16px 36px rgba(10,37,64,0.08); }

/* Buttons: ripple-like focus */
.btn:active { transform: translateY(0); box-shadow: 0 6px 18px rgba(15,23,42,0.08); }

/* Password criteria micro-animation */
.pw-crit { padding: 10px 12px; border-radius: 14px; margin: 6px 6px 0 0; display: inline-flex; align-items: center; font-weight: 800; font-size: 13px; background: rgba(255,255,255,0.04); color: #cbd5e1; border: 1px solid rgba(148,163,184,0.12); transition: all 180ms ease; }
.pw-crit.ok { background: rgba(52,211,153,0.14); color: #a7f3d0; border-color: rgba(52,211,153,0.28); }
.pw-crit.bad { opacity: 0.95; }

/* small helpers */
.btn-disabled{opacity:0.6;cursor:not-allowed;transform:none}


@media (max-width: 900px) {
    body { padding-bottom: 24px; }
    .app-nav { padding: 10px 12px; gap: 10px; }
    .sidebar-toggle { display: inline-flex; }
    .nav-brand { font-size: 17px; min-width: 0; }
    .nav-brand img { max-height: 28px; }
    .nav-user { gap: 8px; }
    .user-badge { display: none; }
    .wrapper { grid-template-columns: 1fr; margin: 12px auto; gap: 0; padding: 0 10px; }
    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        bottom: 0;
        width: min(82vw, 310px);
        background: var(--surface);
        border-radius: 0;
        border: none;
        display: block;
        overflow-y: auto;
        padding: 72px 12px 16px;
        box-shadow: 10px 0 30px rgba(0,0,0,0.22);
        z-index: 1200;
        transform: translateX(-105%);
        transition: transform 0.25s ease;
    }
    .sidebar.open { transform: translateX(0); }
    .side-link {
        color: #CBD5E1;
        width: 100%;
        padding: 13px 14px;
        margin-bottom: 6px;
        font-size: 14px;
        background: rgba(255,255,255,0.04);
    }
    .side-link:hover { color: white; padding-left: 18px; }
    .side-link.active { background: rgba(255,255,255,0.12); color: white; box-shadow: none; }
    .sb-text { font-size: 14px; font-weight: 700; white-space: nowrap; }
    .sb-icon { font-size: 18px; width: 22px; text-align: center; }
    .main-panel { padding: 14px; border: none; background: transparent; box-shadow:none; }
    .page-head { margin-bottom: 16px; }
    .page-title { font-size: 23px; }
    .settings-grid,
    .contact-grid,
    .contact-layout { grid-template-columns: 1fr; }
    .contact-side-panel { position: static; }
    .card-view,
    .contact-card { padding: 18px; }
    .weather-banner { grid-template-columns: 1fr; gap: 14px; }
    .weather-temp { justify-content: flex-start; min-width: 0; flex-wrap: wrap; }
    .weather-metrics { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
    .legal-card {
        margin: 12px auto;
        padding: 22px;
        width: calc(100% - 20px);
    }
    .legal-card h1 { font-size: 24px; }
}

@media (max-width: 520px) {
    .pwa-install-banner {
        left: 10px;
        right: 10px;
        bottom: 10px;
        align-items: stretch;
        flex-direction: column;
    }

    .pwa-install-banner .btn-action {
        width: 100%;
    }

    .pwa-close {
        position: absolute;
        top: 10px;
        right: 10px;
    }

    .pwa-install-banner div {
        padding-right: 42px;
    }
}

html,
html.theme-dark,
body,
body.theme-dark {
    background: #020617 !important;
    color: #e2e8f0 !important;
    color-scheme: dark;
}

body,
.main-panel,
.sidebar,
.card-view,
.contact-card,
.premium-card,
.form-box,
.weather-card,
.mzk-card,
.mzk-result-card,
.chat-container,
.chat-body,
.chat-footer,
.legal-card {
    background-color: #0f172a !important;
    color: #e2e8f0 !important;
    border-color: #334155 !important;
}

.app-nav,
.legal-nav {
    background: #111827 !important;
    color: #e2e8f0 !important;
}

input,
textarea,
select,
.field-grp input,
.field-grp select,
.field-grp textarea,
.input-group input,
.input-group textarea,
.input-group select,
.chat-footer input {
    background: #020617 !important;
    color: #f8fafc !important;
    border-color: #334155 !important;
}

input::placeholder,
textarea::placeholder {
    color: #94a3b8 !important;
}

p,
label,
li,
span,
div,
h1,
h2,
h3,
h4,
h5,
h6 {
    color: inherit;
}

.text-slate-900,
.text-slate-800,
.text-slate-700,
.text-slate-600,
.text-slate-500,
.text-black {
    color: #e2e8f0 !important;
}

.bg-white,
.bg-slate-50,
.bg-slate-100 {
    background-color: #0f172a !important;
}

/* Shared dark system safeguards: components supplied by individual modules
   inherit the same palette and remain usable on narrow viewports. */
.pwa-close { background:#1e293b; color:#e2e8f0; border:1px solid #475569; }
.modal, .modal-content, .modal-dialog, .code-modal, .code-modal-content,
.form-box, .premium-card, .card-header, .table-wrap { background-color:#0f172a; color:#e2e8f0; border-color:#334155; }
/* Legacy module fragments still contain a few inline light utility colours. */
[style*="background:#F8FAFC"], [style*="background: #F8FAFC"],
[style*="background:#F1F5F9"], [style*="background: #F1F5F9"],
[style*="background:#FFFFFF"], [style*="background: #FFFFFF"] { background-color:#0f172a !important; }
[style*="color:#0f172a"], [style*="color: #0f172a"],
[style*="color:#0F172A"], [style*="color: #0F172A"] { color:#e2e8f0 !important; }
table { max-width:100%; border-color:#334155; color:#e2e8f0; }
th { background:#1e293b; color:#f8fafc; }
td { border-color:#334155; color:#cbd5e1; }
.table-responsive, .table-wrap { width:100%; overflow-x:auto; -webkit-overflow-scrolling:touch; }
img, svg, video, canvas { max-width:100%; }
button, input, select, textarea { max-width:100%; }
.resident-card-shell { max-width:860px; margin:32px auto; padding:18px; }
.resident-card { background:var(--card); border:1px solid var(--border); border-radius:22px; padding:28px; color:var(--text-main); box-shadow:var(--shadow); }
.resident-card h1 { margin:0 0 8px; font-size:24px; font-weight:900; }
.resident-card > p { color:var(--text-muted); margin:0 0 22px; }
.resident-card-content { display:flex; gap:24px; align-items:center; justify-content:space-between; flex-wrap:wrap; }
.resident-card-details { min-width:0; flex:1 1 260px; }
.resident-card-name { overflow-wrap:anywhere; font-weight:900; font-size:22px; }
.resident-card-id { color:var(--text-muted); margin-top:8px; font-weight:700; overflow-wrap:anywhere; }
.resident-card-qr { width:min(260px, 100%); aspect-ratio:1; flex:0 1 260px; background:#fff; padding:10px; border-radius:18px; }
.resident-card-qr img { display:block; width:100%; height:100%; object-fit:contain; }
.resident-card-disclaimer { margin-top:22px; color:#cbd5e1; font-size:13px; line-height:1.55; }

@media (max-width: 640px) {
    .page-head { flex-direction:column; }
    .page-title { overflow-wrap:anywhere; }
    .btn, .btn-action, .btn-del, .btn-secondary { min-height:48px; }
    .resident-card-shell { margin:12px auto; padding:10px; }
    .resident-card { padding:20px; border-radius:18px; }
    .resident-card-content { align-items:stretch; }
    .resident-card-qr { margin:0 auto; width:min(240px, 100%); flex-basis:240px; }
}
