/* ── Reset & Variables ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --gold:      #d97c2a;
    --gold-lt:   #e8b84b;
    --dark:      #1a1610;
    --darker:    #0f0d0a;
    --card:      #221d14;
    --surface3:  #2a2419;
    --border:    #3d3526;
    --text:      #ede0c8;
    --muted:     #8a7d66;
    --green:     #5dab67;
    --red:       #d95252;
    --blue:      #5b9bd9;
    --orange:    #d97c2a;
    --purple:    #9b70d0;
    --teal:      #4aada8;
    --yellow:    #e8b84b;
    --sidebar: 220px;
    --radius:  8px;
    --shadow:  0 4px 24px rgba(0,0,0,.5);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--darker);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: var(--dark); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ── Auth layout ───────────────────────────────────────────────────────────── */
.auth-body {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: var(--darker) url('../img/loginBackgr.png') center center / cover no-repeat;
    position: relative;
}

.auth-body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(10, 8, 4, 0.65);
    pointer-events: none;
}

.auth-container {
    width: 100%;
    max-width: 400px;
    padding: 1rem;
    position: relative;
    z-index: 1;
}

.auth-logo {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo-img {
    max-width: 200px;
    width: 100%;
    object-fit: contain;
    margin-bottom: 0.5rem;
}

.auth-logo p {
    color: var(--muted);
}

.auth-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 2rem;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}

.auth-card h2 {
    margin-bottom: 1.5rem;
    color: var(--gold);
    font-size: 1.4rem;
}

.auth-links {
    margin-top: 1rem;
    display: flex;
    justify-content: space-between;
}

.auth-links a {
    color: var(--gold-lt);
    text-decoration: none;
    font-size: 0.85rem;
}

.auth-links a:hover { text-decoration: underline; }

/* ── Game layout ───────────────────────────────────────────────────────────── */
.game-body {
    display: flex;
    min-height: 100vh;
    background: var(--darker) url('../img/mainBackgr.jpg') center top / cover no-repeat fixed;
    position: relative;
}

.game-body::before {
    content: '';
    position: fixed;
    inset: 0;
    background: rgba(10, 8, 4, 0.62);
    pointer-events: none;
    z-index: 0;
}

.game-body > * { position: relative; z-index: 1; }

.mobile-nav-toggle {
    display: none;
    position: sticky;
    top: 0;
    z-index: 3;
    width: 100%;
    border: 0;
    background: rgba(15, 13, 10, 0.96);
    color: var(--gold-lt);
    padding: 0.9rem 1rem;
    text-align: left;
    font-weight: 700;
    border-bottom: 1px solid var(--border);
}

.sidebar {
    width: var(--sidebar);
    background: var(--dark);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0;
    height: 100vh;
    overflow-y: auto;
    border-right: 1px solid var(--border);
}

.sidebar-header {
    padding: 1.5rem 1rem;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo-img {
    max-width: 160px;
    width: 100%;
    object-fit: contain;
    object-position: left center;
    display: block;
    margin-bottom: 0.25rem;
}

.sidebar-header .username {
    display: block;
    font-size: 0.8rem;
    color: var(--muted);
    margin-top: 0.25rem;
}

.nav-links {
    list-style: none;
    padding: 0.5rem 0;
    flex: 1;
}

.nav-links li a {
    display: block;
    padding: 0.7rem 1rem;
    color: var(--text);
    text-decoration: none;
    transition: background 0.2s, color 0.2s;
    font-size: 0.9rem;
    position: relative;
}

.nav-links li a:hover { background: rgba(217,124,42,0.1); color: var(--gold-lt); }
.nav-links li a.active { background: var(--border); color: var(--gold); font-weight: 600; }
.nav-links li a.admin-link { color: var(--orange); }

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

.main-content {
    margin-left: var(--sidebar);
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.status-bar {
    background: var(--dark);

    padding: 0.5rem 1.5rem;
    display: flex;
    gap: 1.5rem;
    font-size: 0.8rem;
    border-bottom: 1px solid var(--border);
    flex-wrap: wrap;
}

.status-bar span {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    color: var(--text);
    white-space: nowrap;
}

.status-bar i {
    color: var(--gold-lt);
    font-size: 0.95rem;
}

.page-content {
    padding: 1.5rem;
    flex: 1;
}

/* ── Page header ───────────────────────────────────────────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.page-header h1 {
    font-size: 1.6rem;
    color: var(--gold);
}

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

.form-group label {
    display: block;
    margin-bottom: 0.4rem;
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 500;
}

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], select, textarea {
    width: 100%;
    padding: 0.6rem 0.8rem;
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.15);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

input:focus, select:focus, textarea:focus {
    border-color: var(--gold);
}

textarea { min-height: 80px; resize: vertical; }

/* ── Buttons ───────────────────────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: opacity 0.2s, transform 0.1s;
    text-decoration: none;
    border: none;
}

.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary   { background: var(--gold); color: #000; }
.btn-danger    { background: var(--red); color: #fff; }
.btn-secondary { background: rgba(255,255,255,0.1); color: var(--text); }
.btn-block     { width: 100%; margin-top: 0.5rem; }
.btn-sm        { padding: 0.35rem 0.75rem; font-size: 0.8rem; }
.btn-logout    { display: block; text-align: center; color: var(--muted); text-decoration: none; font-size: 0.85rem; }
.btn-logout:hover { color: var(--red); }

/* ── Cards ─────────────────────────────────────────────────────────────────── */
.card {
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid rgba(255,255,255,0.07);
    overflow: hidden;
}

.card-header {
    padding: 0.75rem 1rem;
    background: rgba(0,0,0,0.2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.9rem;
}

.card-body {
    padding: 0.75rem 1rem;
}

.card-footer {
    padding: 0.6rem 1rem;
    border-top: 1px solid rgba(255,255,255,0.05);
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 1rem;
}

.section-card {
    background: var(--card);
    border-radius: var(--radius);
    border: 1px solid rgba(255,255,255,0.07);
    padding: 1.25rem;
    margin-bottom: 1.5rem;
}

.section-card h3 {
    font-size: 1rem;
    color: var(--gold);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

/* ── KPI grid ──────────────────────────────────────────────────────────────── */
.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.kpi-card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 1rem;
    border: 1px solid rgba(255,255,255,0.07);
    text-align: center;
}

.kpi-label {
    font-size: 0.75rem;
    color: var(--muted);
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.kpi-value {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--gold-lt);
}

.kpi-card.positive .kpi-value { color: var(--green); }
.kpi-card.negative .kpi-value { color: var(--red); }

.progress-bar {
    height: 4px;
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
    margin-top: 0.5rem;
    overflow: hidden;
}

.progress-bar .bar {
    height: 100%;
    border-radius: 2px;
    transition: width 0.4s ease;
}

/* ── Mini bar ──────────────────────────────────────────────────────────────── */
.mini-bar {
    height: 4px;
    background: rgba(255,255,255,0.1);
    border-radius: 2px;
    margin-top: 3px;
    overflow: hidden;
}

.mini-bar div {
    height: 100%;
    border-radius: 2px;
}

/* ── Badges ────────────────────────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 12px;
    font-size: 0.75rem;
    background: rgba(255,255,255,0.15);
    font-weight: 600;
}

.badge.hidden { display: none; }
.badge-level-1 { background: #2980b9; }
.badge-level-2 { background: #27ae60; }
.badge-level-3 { background: #d35400; }
.badge-level-4 { background: #8e44ad; }

/* ── Alerts / Flash ────────────────────────────────────────────────────────── */
.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.alert-success { background: rgba(46,204,113,0.2); border-left: 3px solid var(--green); }
.alert-error   { background: rgba(231,76,60,0.2);  border-left: 3px solid var(--red); }
.alert-info    { background: rgba(52,152,219,0.2); border-left: 3px solid var(--blue); }

.flash {
    padding: 0.6rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 0.5rem;
    font-size: 0.85rem;
    animation: fadeIn 0.2s ease;
}

.flash-success { background: rgba(46,204,113,0.25); color: #90ee90; }
.flash-error   { background: rgba(231,76,60,0.25);  color: #ff9999; }
.flash-info    { background: rgba(52,152,219,0.25); color: #add8e6; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; } }

#flash-container {
    position: fixed;
    bottom: 1rem;
    right: 1rem;
    z-index: 9999;
    max-width: 320px;
}

.back-to-top {
    position: fixed;
    right: 1rem;
    bottom: 5.25rem;
    z-index: 9998;
    width: 44px;
    height: 44px;
    border: 1px solid rgba(255,255,255,0.12);
    border-radius: 50%;
    display: grid;
    place-items: center;
    background: rgba(217,124,42,0.95);
    color: #fff;
    box-shadow: 0 12px 26px rgba(0,0,0,0.28);
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transform: translateY(8px);
    transition: opacity 0.18s ease, transform 0.18s ease, background 0.18s ease;
}

.back-to-top.visible {
    opacity: 1;
    pointer-events: auto;
    transform: translateY(0);
}

.back-to-top:hover {
    background: var(--gold);
}

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal.hidden { display: none; }

.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    backdrop-filter: blur(2px);
}

.modal-box {
    background: var(--card);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    position: relative;
    z-index: 10;
    border: 1px solid var(--border);
    max-height: 90vh;
    overflow-y: auto;
}

/* Admin: Event-Injektion — styled-select-Dropdown darf nicht von .modal-box abgeschnitten werden */
#eventModal .modal-box {
    overflow: visible;
    max-height: none;
}

.modal-box.wide { max-width: 700px; }

.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: none;
    border: none;
    color: var(--muted);
    cursor: pointer;
    font-size: 1.1rem;
}

.modal-box h3 {
    color: var(--gold);
    margin-bottom: 1rem;
    font-size: 1.2rem;
}

.choice-buttons {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}

/* ── Table ─────────────────────────────────────────────────────────────────── */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.data-table th, .data-table td {
    padding: 0.6rem 0.8rem;
    text-align: left;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.data-table th {
    background: rgba(0,0,0,0.3);
    color: var(--gold);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.data-table tr:hover td { background: rgba(255,255,255,0.03); }
.data-table .positive { color: var(--green); }
.data-table .negative { color: var(--red); }
.data-table .banned-row td { opacity: 0.6; }

/* ── Tutorial ───────────────────────────────────────────────────────────────── */
.tutorial-body { display: flex; flex-direction: column; gap: 0; }

.tut-section {
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid var(--border);
}
.tut-section:last-child { border-bottom: none; }
.tut-section h3 { margin: 0 0 .6rem; font-size: 1rem; }
.tut-section p, .tut-section li { line-height: 1.6; color: var(--muted); }
.tut-section ul, .tut-section ol { padding-left: 1.25rem; margin: .4rem 0; }
.tut-section li { margin-bottom: .25rem; }
.tut-section strong { color: var(--text); }

.formula-box {
    background: rgba(255,255,255,0.04);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .75rem 1rem;
    font-family: monospace;
    font-size: .9rem;
    color: var(--text);
    margin-top: .5rem;
}

/* ── Stats bar ─────────────────────────────────────────────────────────────── */
.stats-bar {
    display: flex;
    gap: 1.5rem;
    padding: 0.75rem 0;
    margin-bottom: 1rem;
    font-size: 0.85rem;
    color: var(--muted);
    flex-wrap: wrap;
}

.stats-bar b { color: var(--text); }

/* ── Metric ────────────────────────────────────────────────────────────────── */
.metric {
    font-size: 0.82rem;
    color: var(--muted);
    margin-bottom: 0.25rem;
}

.metric b { color: var(--text); }

/* ── Calendar ──────────────────────────────────────────────────────────────── */
.calendar-container {
    overflow-x: auto;
    background: rgba(15, 13, 10, 0.94);
    border: 1px solid rgba(232,184,75,0.22);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 0.75rem;
}

.calendar-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    min-width: 700px;
    background: rgba(26, 22, 16, 0.96);
    border-radius: 10px;
    overflow: hidden;
}

.calendar-table th, .calendar-table td {
    border: 1px solid rgba(232,184,75,0.13);
    padding: 0.55rem;
    text-align: center;
    vertical-align: middle;
    min-width: 90px;
    min-height: 50px;
}

.calendar-table th {
    background: rgba(10, 8, 4, 0.96);
    color: var(--gold-lt);
    font-size: 0.8rem;
}

.time-label {
    background: rgba(10, 8, 4, 0.9);
    color: var(--text);
    font-size: 0.75rem;
    min-width: 60px;
    font-weight: 700;
}

.cal-cell {
    cursor: pointer;
    transition: background 0.15s;
    min-height: 50px;
    background: rgba(34, 29, 20, 0.92);
}

.cal-cell:hover { background: rgba(217,124,42,0.24); }
.cal-cell.has-activity {
    background: linear-gradient(135deg, rgba(52,152,219,0.32), rgba(34,29,20,0.96));
    box-shadow: inset 0 0 0 1px rgba(255,255,255,0.05);
}

.act-label {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.28rem;
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--text);
    text-shadow: 0 1px 2px rgba(0,0,0,0.7);
}

.empty-slot {
    color: rgba(255,255,255,0.48);
    font-size: 1.2rem;
}

.activity-picker-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.5rem;
    max-height: 60vh;
    overflow-y: auto;
    margin-bottom: 1rem;
}

.act-pick-btn {
    padding: 0.5rem;
    border-radius: var(--radius);
    font-size: 0.78rem;
    cursor: pointer;
    border: 1px solid rgba(255,255,255,0.1);
    background: rgba(255,255,255,0.05);
    color: var(--text);
    transition: background 0.15s;
}

.act-pick-btn:hover { background: var(--border); }
.act-pick-btn.type-meal     { border-color: var(--orange); }
.act-pick-btn.type-therapy  { border-color: var(--green); }
.act-pick-btn.type-culture  { border-color: #9b59b6; }
.act-pick-btn.type-sports   { border-color: var(--blue); }
.act-pick-btn.type-social   { border-color: var(--gold); }

.analysis-row {
    display: flex;
    gap: 2rem;
    flex-wrap: wrap;
    font-size: 0.85rem;
}

.combo-item {
    font-size: 0.8rem;
    color: var(--gold-lt);
    padding: 0.2rem 0;
}

/* ── Achievement grid ──────────────────────────────────────────────────────── */
.achievement-grid { display: flex; flex-direction: column; gap: 1.5rem; }

.achieve-category h3 {
    color: var(--gold);
    font-size: 1rem;
    margin-bottom: 0.75rem;
}

.achieve-items {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 0.75rem;
}

.achieve-card {
    display: flex;
    align-items: flex-start;
    gap: 0.75rem;
    padding: 0.75rem;
    border-radius: var(--radius);
    border: 1px solid rgba(255,255,255,0.07);
    background: var(--card);
}

.achieve-card.locked { opacity: 0.45; }
.achieve-card.unlocked { border-color: var(--border); }

.achieve-icon { font-size: 1.5rem; }

.achieve-info strong {
    display: block;
    font-size: 0.9rem;
    color: var(--text);
}

.achieve-info p { font-size: 0.78rem; color: var(--muted); margin: 0.2rem 0; }
.achieve-points { font-size: 0.75rem; color: var(--gold); }

.achieve-recent {
    padding: 0.4rem 0;
    font-size: 0.85rem;
    color: var(--gold-lt);
}

/* ── Events ────────────────────────────────────────────────────────────────── */
.active-event {
    background: rgba(212,160,23,0.08);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.active-event h3 { color: var(--gold); margin-bottom: 0.5rem; }

.event-log-item {
    display: flex;
    justify-content: space-between;
    padding: 0.5rem 0;
    border-bottom: 1px solid rgba(255,255,255,0.05);
    font-size: 0.85rem;
    gap: 1rem;
    flex-wrap: wrap;
}

.event-type { color: var(--text); }
.event-status { color: var(--green); }
.event-time { color: var(--muted); font-size: 0.75rem; }
.event-effects {
    display: flex;
    gap: 0.35rem;
    flex-wrap: wrap;
}

.event-impact-grid {
    display: flex;
    gap: 0.45rem;
    flex-wrap: wrap;
    margin: 0.8rem 0;
}

.event-effect-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    border-radius: 999px;
    padding: 0.25rem 0.55rem;
    background: rgba(255,255,255,0.08);
    font-size: 0.78rem;
    font-weight: 700;
}

.event-effect-pill.positive {
    color: #9be4a6;
    background: rgba(93,171,103,0.18);
}

.event-effect-pill.negative {
    color: #ff9f9f;
    background: rgba(217,82,82,0.18);
}

.event-result-details {
    margin-top: 1rem;
    padding: 0.85rem;
    border-radius: 10px;
    border: 1px solid rgba(232,184,75,0.18);
    background: rgba(217,124,42,0.09);
}

/* ── Construction ──────────────────────────────────────────────────────────── */
.build-card.done    { opacity: 0.55; }
.build-card.locked  { opacity: 0.5; }
.build-card.inprog  { border-color: var(--orange) !important; }
.build-card.available { border-color: rgba(212,160,23,0.4); }

.project-card { padding: 1rem; margin-bottom: 0.75rem; display: flex; flex-wrap: wrap; gap: 1rem; align-items: center; }
.project-card strong { flex: 1; }

.status-label {
    font-size: 0.8rem;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
}

.status-label.done   { background: rgba(46,204,113,0.2); color: var(--green); }
.status-label.inprog { background: rgba(243,156,18,0.2); color: var(--orange); }
.status-label.locked { background: rgba(255,255,255,0.05); color: var(--muted); }

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

/* ── Medications ───────────────────────────────────────────────────────────── */
.med-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 0.75rem;
}

.order-row { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.5rem; }
.packs-input { width: 60px; }
.cost-preview { font-size: 0.8rem; color: var(--gold-lt); margin-top: 0.25rem; }
.low-stock { color: var(--red) !important; font-weight: 600; }

/* ── Admin ─────────────────────────────────────────────────────────────────── */
.admin-tabs { display: flex; gap: 0.5rem; margin-bottom: 1.5rem; flex-wrap: wrap; }

.tab-btn {
    padding: 0.5rem 1rem;
    border-radius: var(--radius);
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    color: var(--muted);
    cursor: pointer;
    font-size: 0.85rem;
    transition: all 0.2s;
}

.tab-btn.active { background: var(--border); color: var(--gold); border-color: var(--gold); }
.tab-btn:hover  { color: var(--text); }

.admin-tab { display: block; }
.admin-tab.hidden { display: none; }

/* ── Finance ───────────────────────────────────────────────────────────────── */
.finance-overview { margin-bottom: 1.5rem; }

.dashboard-grid {
    display: grid;
    grid-template-columns: minmax(0, 1.7fr) minmax(280px, 1fr);
    gap: 1.25rem;
}

.kpi-row {
    grid-column: 1 / -1;
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 0.75rem;
}

.dash-main,
.dash-side {
    display: grid;
    gap: 1rem;
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 0.75rem;
}

.card-link {
    color: var(--gold-lt);
    text-decoration: none;
    white-space: nowrap;
}

.badge-week {
    color: var(--gold-lt);
    font-size: 0.85rem;
}

.occupancy-bar-wrap,
.stat-grid {
    display: grid;
    gap: 0.75rem;
}

.occupancy-bar-label,
.stat-item {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
}

.progress-bar-track {
    height: 10px;
    background: rgba(255,255,255,0.08);
    border-radius: 999px;
    overflow: hidden;
}

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

.ach-preview-bar {
    display: grid;
    gap: 0.5rem;
}

.kpi-card {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: center;
    gap: 0.85rem;
    text-align: left;
    min-width: 0;
}

.kpi-card .progress-bar {
    grid-column: 1 / -1;
}

.kpi-body {
    min-width: 0;
}

.kpi-value {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: clamp(1rem, 1.15vw, 1.4rem);
}

.kpi-icon {
    width: 46px;
    height: 46px;
    border-radius: 14px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    color: #fff;
}

.kpi-green { background: linear-gradient(135deg, #3d8d54, #5dab67); }
.kpi-blue { background: linear-gradient(135deg, #4474b0, #5b9bd9); }
.kpi-purple { background: linear-gradient(135deg, #7d58a8, #9b70d0); }
.kpi-yellow { background: linear-gradient(135deg, #c79a24, #e8b84b); color: #20180c; }
.kpi-teal { background: linear-gradient(135deg, #3d8b87, #4aada8); }
.kpi-orange { background: linear-gradient(135deg, #b46520, #d97c2a); }

.slot-page {
    max-width: 720px;
    margin: 0 auto 1.5rem;
    background: rgba(34, 29, 20, 0.94);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: var(--shadow);
}

.slot-hero {
    text-align: center;
    margin-bottom: 1.5rem;
}

.slot-hero-icon {
    width: 72px;
    height: 72px;
    margin: 0 auto 1rem;
    border-radius: 20px;
    display: grid;
    place-items: center;
    background: linear-gradient(135deg, rgba(217,124,42,0.2), rgba(232,184,75,0.28));
    color: var(--gold-lt);
    font-size: 2rem;
}

.new-home-form {
    max-width: 480px;
    margin: 0 auto;
}

.form-input {
    width: 100%;
}

.form-hint {
    color: var(--muted);
    font-size: 0.9rem;
    margin-bottom: 1rem;
}

.mini-card {
    background: rgba(34, 29, 20, 0.92);
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 12px;
    padding: 0.85rem 1rem;
    min-width: 140px;
    overflow: hidden;
}

.mini-label {
    color: var(--muted);
    font-size: 0.78rem;
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.mini-value {
    color: var(--text);
    font-weight: 700;
    font-size: 1.05rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.stat-row,
.role-grid,
.catalog-grid,
.tab-bar {
    display: grid;
    gap: 0.9rem;
}

.stat-row,
.role-grid {
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    margin-bottom: 1rem;
}

.catalog-grid {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.tab-bar {
    grid-template-columns: repeat(auto-fit, minmax(110px, max-content));
    margin-bottom: 1rem;
}

.tab {
    padding: 0.55rem 0.9rem;
    border-radius: 999px;
    border: 1px solid rgba(255,255,255,0.08);
    background: rgba(255,255,255,0.04);
    color: var(--muted);
    cursor: pointer;
}

.tab.active {
    color: var(--gold-lt);
    border-color: rgba(232,184,75,0.35);
    background: rgba(217,124,42,0.12);
}

.care-badge,
.badge-green,
.badge-yellow,
.badge-red {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 0.22rem 0.55rem;
    font-size: 0.78rem;
    font-weight: 700;
}

.cl-1 { background: rgba(91,155,217,0.2); color: #85c1ff; }
.cl-2 { background: rgba(93,171,103,0.2); color: #9be4a6; }
.cl-3 { background: rgba(217,124,42,0.22); color: #ffbe7f; }
.cl-4 { background: rgba(155,112,208,0.22); color: #d4b3ff; }
.badge-green { background: rgba(93,171,103,0.2); color: #9be4a6; }
.badge-yellow { background: rgba(232,184,75,0.22); color: #ffd97c; }
.badge-red { background: rgba(217,82,82,0.22); color: #ff9f9f; }

.resident-file,
.resident-file-section {
    display: grid;
    gap: 1rem;
}

.resident-file-header {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.resident-file-avatar {
    width: 60px;
    height: 60px;
    border-radius: 18px;
    background: linear-gradient(135deg, rgba(217,124,42,0.28), rgba(232,184,75,0.32));
    display: grid;
    place-items: center;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--gold-lt);
}

.resident-file-meta,
.rf-label {
    color: var(--muted);
}

.resident-file-grid {
    display: grid;
    grid-template-columns: 160px 1fr;
    gap: 0.6rem 1rem;
}

.rf-value,
.rf-notes {
    color: var(--text);
}

.hire-preview {
    display: grid;
    gap: 0.55rem;
    margin-bottom: 1rem;
    background: rgba(217,124,42,0.09);
    border: 1px solid rgba(232,184,75,0.18);
    border-radius: 10px;
    padding: 0.8rem;
}

.hire-row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
}

.role-card {
    display: flex;
    gap: 0.85rem;
    background: rgba(34, 29, 20, 0.92);
    border: 1px solid rgba(255,255,255,0.07);
    border-radius: 12px;
    padding: 0.9rem;
}

.role-icon {
    width: 42px;
    height: 42px;
    border-radius: 12px;
    display: grid;
    place-items: center;
    background: rgba(217,124,42,0.12);
    color: var(--gold-lt);
}

.role-label {
    font-weight: 700;
    color: var(--text);
}

.role-count,
.role-morale {
    color: var(--muted);
    font-size: 0.85rem;
}

.role-salary {
    font-size: 0.85rem;
}

.qual-badge {
    display: inline-flex;
    padding: 0.22rem 0.5rem;
    border-radius: 999px;
    font-size: 0.76rem;
    font-weight: 700;
    background: rgba(255,255,255,0.08);
}

.settings-grid {
    display: grid;
    gap: 1rem;
    max-width: 760px;
}

.settings-info,
.settings-warn {
    color: var(--muted);
}

/* ── File grid ─────────────────────────────────────────────────────────────── */
.file-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    font-size: 0.9rem;
}

.file-grid div {
    padding: 0.5rem;
    background: rgba(0,0,0,0.2);
    border-radius: 4px;
}

/* ── Hire / Cost preview ───────────────────────────────────────────────────── */
.cost-preview {
    padding: 0.5rem;
    background: rgba(217,124,42,0.1);
    border-radius: 4px;
    font-size: 0.85rem;
    margin-bottom: 0.75rem;
    color: var(--gold-lt);
}

/* ── Utilities ─────────────────────────────────────────────────────────────── */
.muted   { color: var(--muted); font-size: 0.85rem; }
.loading { animation: pulse 1.5s infinite; }
.hidden  { display: none !important; }
.positive { color: var(--green); }
.negative { color: var(--red); }
.warning { color: var(--orange); }

.status-active     { color: var(--green); }
.status-discharged { color: var(--muted); }
.status-deceased   { color: var(--red); }

details summary { cursor: pointer; color: var(--gold-lt); font-size: 0.85rem; margin-top: 0.5rem; }

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50%       { opacity: 0.5; }
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
    .mobile-nav-toggle { display: block; }
    .sidebar {
        width: 100%;
        height: auto;
        position: fixed;
        top: 52px;
        left: 0;
        right: 0;
        transform: translateY(-120%);
        transition: transform 0.2s ease;
        z-index: 2;
    }
    .sidebar.mobile-open { transform: translateY(0); }
    .main-content { margin-left: 0; }
    .nav-links { display: block; }
    .nav-links li a { padding: 0.75rem 1rem; font-size: 0.9rem; }
    .kpi-grid { grid-template-columns: repeat(2, 1fr); }
    .file-grid { grid-template-columns: 1fr; }
    .dashboard-grid { grid-template-columns: 1fr; }
    .kpi-row { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .kpi-value { font-size: 1.05rem; }
    .page-content { padding: 1rem; }
    .status-bar { padding: 0.75rem 1rem; gap: 0.5rem 1rem; }
    #flash-container {
        left: 1rem;
        right: 1rem;
        max-width: none;
    }
    .back-to-top { bottom: 5rem; }
    .med-acc-header { flex-wrap: wrap; gap: .4rem; }
    .med-plan-form { grid-template-columns: 1fr 1fr; }
}

/* Medication accordion — overflow visible so custom select panels are not clipped */
#tab-bewohner .card { overflow: visible; }
.med-accordion-row { border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: .5rem; overflow: visible; }
.med-acc-header {
    width: 100%; display: flex; align-items: center; gap: .75rem;
    padding: .65rem 1rem; background: var(--card-bg); border: none;
    cursor: pointer; text-align: left; color: var(--text);
}
.med-acc-header:hover { background: var(--hover, rgba(255,255,255,.04)); }
.med-acc-name  { font-weight: 600; flex-shrink: 0; }
.med-acc-meta  { flex: 1; font-size: .85em; }
.med-acc-icon  { margin-left: auto; transition: transform .2s; flex-shrink: 0; }
.med-acc-icon.rotated { transform: rotate(180deg); }
.med-acc-body  { background: var(--bg); }

/* Custom selects (native <option> lists cannot be styled on Windows Chromium) */
.med-plan-form { align-items: stretch; }
.med-plan-form > div { min-width: 0; }
.styled-select { position: relative; width: 100%; }
.styled-select--empty { padding: 0.6rem 0.8rem; font-size: 0.9rem; }
.styled-select-trigger {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.6rem 0.8rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    cursor: pointer;
    text-align: left;
    outline: none;
    transition: border-color 0.2s;
}
.styled-select-trigger:hover { border-color: rgba(255, 255, 255, 0.22); }
.styled-select-trigger:focus-visible { border-color: var(--gold); }
.styled-select-trigger[aria-expanded="true"] { border-color: var(--gold); }
.styled-select-value { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.styled-select-chevron { flex-shrink: 0; font-size: 0.75rem; opacity: 0.85; transition: transform 0.2s; }
.styled-select-trigger[aria-expanded="true"] .styled-select-chevron { transform: rotate(180deg); }
.styled-select-panel {
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    z-index: 120;
    margin: 0;
    padding: 0.3rem 0;
    list-style: none;
    max-height: min(50vh, 280px);
    overflow-y: auto;
    background: var(--surface3);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}
.styled-select-option {
    display: block;
    width: 100%;
    padding: 0.45rem 0.75rem;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 0.9rem;
    text-align: left;
    cursor: pointer;
    font-family: inherit;
    line-height: 1.35;
}
.styled-select-option:hover,
.styled-select-option:focus-visible {
    background: rgba(255, 255, 255, 0.08);
    outline: none;
}
.styled-select-option[aria-current="true"] {
    background: rgba(217, 124, 42, 0.22);
    color: var(--gold-lt);
}

/* EmergencyRoom sterile clinical theme */
:root {
    --gold: #e53935;
    --gold-lt: #00a6b4;
    --dark: #eef6f8;
    --darker: #dfecef;
    --card: rgba(255, 255, 255, 0.94);
    --surface3: #f4fafb;
    --border: rgba(7, 54, 66, 0.14);
    --text: #073642;
    --muted: #63767d;
    --green: #1d9a66;
    --red: #d83b36;
    --blue: #1478a8;
    --orange: #f28c28;
    --purple: #6b64c7;
    --teal: #00a6b4;
    --yellow: #f1c54b;
    --shadow: 0 18px 55px rgba(20, 74, 88, 0.16);
}

body {
    background:
        radial-gradient(circle at 12% 10%, rgba(0, 166, 180, 0.14), transparent 28rem),
        radial-gradient(circle at 90% 8%, rgba(229, 57, 53, 0.10), transparent 24rem),
        linear-gradient(135deg, #f8fdff 0%, #e7f4f7 52%, #f6fbfc 100%);
    color: var(--text);
}

.auth-body,
.game-body {
    background:
        linear-gradient(90deg, rgba(248, 253, 255, 0.95), rgba(231, 244, 247, 0.90)),
        repeating-linear-gradient(0deg, rgba(7, 54, 66, 0.035) 0 1px, transparent 1px 42px),
        repeating-linear-gradient(90deg, rgba(7, 54, 66, 0.028) 0 1px, transparent 1px 42px);
}

.auth-body::before,
.game-body::before {
    background:
        linear-gradient(120deg, rgba(255, 255, 255, 0.78), rgba(255, 255, 255, 0.22)),
        radial-gradient(circle at 72% 24%, rgba(0, 166, 180, 0.10), transparent 22rem);
}

.sidebar {
    background: rgba(248, 253, 255, 0.96);
    border-right: 1px solid rgba(7, 54, 66, 0.13);
    box-shadow: 12px 0 30px rgba(7, 54, 66, 0.06);
}

.sidebar-header,
.sidebar-footer,
.status-bar,
.page-header {
    border-color: rgba(7, 54, 66, 0.12);
}

.sidebar-logo-img,
.auth-logo-img {
    filter: drop-shadow(0 12px 24px rgba(0, 166, 180, 0.14));
}

.nav-links li a {
    border-left: 3px solid transparent;
}

.nav-links li a:hover {
    background: rgba(0, 166, 180, 0.08);
    color: #007887;
}

.nav-links li a.active {
    background: linear-gradient(90deg, rgba(229, 57, 53, 0.12), rgba(0, 166, 180, 0.08));
    border-left-color: #e53935;
    color: #073642;
}

.status-bar {
    background: rgba(255, 255, 255, 0.88);
    backdrop-filter: blur(14px);
}

.card,
.section-card,
.kpi-card,
.mini-card,
.slot-page,
.modal-box,
.auth-card,
.role-card {
    background: rgba(255, 255, 255, 0.93);
    border-color: rgba(7, 54, 66, 0.12);
    box-shadow: var(--shadow);
}

.card-header,
.data-table th {
    background: rgba(0, 166, 180, 0.07);
}

.page-header h1,
.auth-card h2,
.section-card h3,
.modal-box h3,
.data-table th {
    color: #0b7d8b;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
select,
textarea,
.styled-select-trigger {
    background: rgba(248, 253, 255, 0.92);
    border-color: rgba(7, 54, 66, 0.18);
    color: var(--text);
}

input:focus,
select:focus,
textarea:focus,
.styled-select-trigger:focus-visible,
.styled-select-trigger[aria-expanded="true"] {
    border-color: #00a6b4;
    box-shadow: 0 0 0 3px rgba(0, 166, 180, 0.14);
}

.btn-primary {
    background: linear-gradient(135deg, #e53935, #ff6b5f);
    color: #fff;
}

.btn-secondary {
    background: rgba(7, 54, 66, 0.06);
    color: #073642;
    border: 1px solid rgba(7, 54, 66, 0.12);
}

.progress-bar-fill,
.progress-bar .bar {
    background: linear-gradient(90deg, #e53935, #00a6b4);
}

.kpi-green { background: linear-gradient(135deg, #1d9a66, #43c18e); }
.kpi-blue { background: linear-gradient(135deg, #1478a8, #44b7d0); }
.kpi-purple { background: linear-gradient(135deg, #695ec7, #9c92f0); }
.kpi-yellow { background: linear-gradient(135deg, #f1c54b, #ffe18a); color: #073642; }
.kpi-teal { background: linear-gradient(135deg, #008c98, #00c0d2); }
.kpi-orange { background: linear-gradient(135deg, #e53935, #f28c28); }

.active-event,
.event-result-details,
.hire-preview,
.cost-preview {
    background: rgba(0, 166, 180, 0.08);
    border-color: rgba(0, 166, 180, 0.22);
}

.back-to-top {
    background: #e53935;
    color: #fff;
}

.auth-card,
.slot-page {
    border-top: 4px solid #e53935;
}

.game-body::after {
    content: "";
    position: fixed;
    right: 2.2rem;
    bottom: 2rem;
    width: min(34vw, 420px);
    aspect-ratio: 1.7;
    pointer-events: none;
    opacity: 0.11;
    background:
        linear-gradient(#073642, #073642) 0 50% / 100% 4px no-repeat,
        linear-gradient(90deg, transparent 0 8%, #073642 8% 13%, transparent 13% 21%, #073642 21% 26%, transparent 26% 42%, #e53935 42% 48%, transparent 48% 57%, #073642 57% 62%, transparent 62% 100%) 0 50% / 100% 42% no-repeat;
}

@media (max-width: 768px) {
    .mobile-nav-toggle {
        background: rgba(248, 253, 255, 0.98);
        color: #073642;
    }

    .sidebar {
        box-shadow: 0 16px 36px rgba(7, 54, 66, 0.12);
    }
}
