:root {
    --bg: #eef2f7;
    --panel: #ffffff;
    --text: #111827;
    --muted: #667085;
    --line: #d7dee8;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --free: #22c55e;
    --free-dark: #15803d;
    --occupied: #ef4444;
    --occupied-dark: #b91c1c;
    --shadow: 0 14px 40px rgba(15, 23, 42, .12);
    color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}
button, input, select, textarea { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }

.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
    background:
        radial-gradient(circle at top left, rgba(37,99,235,.18), transparent 34%),
        radial-gradient(circle at bottom right, rgba(34,197,94,.13), transparent 30%),
        #eef2f7;
}
.login-card {
    width: min(100%, 420px);
    background: var(--panel);
    border: 1px solid rgba(255,255,255,.8);
    border-radius: 24px;
    padding: 32px;
    box-shadow: var(--shadow);
}
.login-card h1 { margin: 18px 0 6px; font-size: 28px; }
.login-card form { display: grid; gap: 18px; margin-top: 24px; }
.login-note { margin: 18px 0 0; color: var(--muted); font-size: 13px; line-height: 1.45; }
.brand-mark {
    width: 56px; height: 56px; border-radius: 18px;
    display: grid; place-items: center;
    color: white; background: linear-gradient(135deg, #2563eb, #0f172a);
    font-weight: 900; font-size: 28px;
    box-shadow: 0 10px 24px rgba(37,99,235,.28);
}
.brand-mark.small { width: 42px; height: 42px; border-radius: 13px; font-size: 21px; }

label { display: grid; gap: 7px; font-size: 13px; font-weight: 700; color: #344054; }
input, select, textarea {
    width: 100%; border: 1px solid #cbd5e1; border-radius: 11px;
    background: white; color: var(--text); padding: 12px 13px;
    outline: none; transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.14); }
input[readonly], textarea[readonly], select:disabled { background: #f8fafc; color: #334155; }
textarea { resize: vertical; min-height: 96px; }
.button {
    border: 0; border-radius: 11px; padding: 12px 16px; font-weight: 800;
    transition: transform .1s, background .15s;
}
.button:active { transform: translateY(1px); }
.button.primary { background: var(--primary); color: white; }
.button.primary:hover { background: var(--primary-dark); }
.button.full { width: 100%; }
.alert { padding: 11px 13px; border-radius: 10px; margin-top: 18px; font-size: 14px; }
.alert.error { background: #fef2f2; color: #991b1b; border: 1px solid #fecaca; }

.app-page { height: 100vh; overflow: hidden; display: grid; grid-template-rows: auto auto 1fr; }
.topbar {
    display: flex; align-items: center; justify-content: space-between; gap: 20px;
    background: #111827; color: white; padding: 12px 18px;
    box-shadow: 0 3px 14px rgba(15,23,42,.2); z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand strong { display: block; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand span { display: block; margin-top: 2px; color: #94a3b8; font-size: 12px; }
.user-actions { display: flex; align-items: center; gap: 9px; }
.role-badge { border-radius: 999px; padding: 6px 10px; font-size: 12px; font-weight: 800; white-space: nowrap; }
.role-badge.manager { background: rgba(37,99,235,.25); color: #bfdbfe; }
.role-badge.guard { background: rgba(34,197,94,.2); color: #bbf7d0; }
.icon-button {
    width: 38px; height: 38px; display: inline-grid; place-items: center;
    border-radius: 10px; border: 1px solid rgba(148,163,184,.25);
    background: rgba(255,255,255,.06); color: inherit; text-decoration: none; font-size: 20px;
}
.icon-button:hover { background: rgba(255,255,255,.12); }

.toolbar {
    min-height: 66px; background: white; border-bottom: 1px solid var(--line);
    display: flex; align-items: center; gap: 14px; padding: 10px 16px; z-index: 15;
}
.search-box { position: relative; display: block; width: min(330px, 32vw); }
.search-box span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #64748b; font-size: 20px; }
.search-box input { padding-left: 38px; }
.filter-group { display: flex; gap: 7px; }
.filter {
    border: 1px solid #cbd5e1; background: white; border-radius: 999px;
    padding: 8px 11px; color: #475569; font-weight: 700; font-size: 13px;
}
.filter b { margin-left: 5px; }
.filter.active { border-color: #93c5fd; background: #eff6ff; color: #1d4ed8; }
.legend { display: flex; align-items: center; gap: 14px; margin-left: auto; color: #475569; font-size: 12px; font-weight: 700; }
.legend span { display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.dot.free { background: var(--free); }
.dot.occupied { background: var(--occupied); }

.workspace { min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) 340px; }
.map-panel { position: relative; min-width: 0; min-height: 0; overflow: hidden; background: #d9e1ea; }
.map-viewport { width: 100%; height: 100%; overflow: hidden; touch-action: none; cursor: grab; }
.map-viewport.dragging { cursor: grabbing; }
#parkingMap { width: 100%; height: 100%; display: block; user-select: none; }
.parking-spot { cursor: pointer; transition: opacity .12s; }
.parking-spot:focus { outline: none; }
.parking-spot .shape { stroke-width: 2.2; vector-effect: non-scaling-stroke; }
.parking-spot.free .shape { fill: var(--free); stroke: var(--free-dark); }
.parking-spot.occupied .shape { fill: var(--occupied); stroke: var(--occupied-dark); }
.parking-spot text { fill: white; font-weight: 900; font-size: 9px; text-anchor: middle; dominant-baseline: central; pointer-events: none; paint-order: stroke; stroke: rgba(15,23,42,.55); stroke-width: 1.2px; }
.parking-spot.filtered-out { opacity: .08; pointer-events: none; }
.parking-spot.selected .shape { filter: url(#selectedGlow); stroke: #1d4ed8; stroke-width: 4; }
.road { fill: #b7c1cc; stroke: #94a3b8; stroke-width: 1.5; }
.road-label { fill: #64748b; font-size: 24px; font-weight: 900; letter-spacing: 8px; opacity: .6; text-anchor: middle; }
.zoom-controls {
    position: absolute; right: 14px; bottom: 46px; display: grid; gap: 7px;
    border-radius: 14px; padding: 7px; background: rgba(255,255,255,.95); box-shadow: var(--shadow);
}
.zoom-controls button { width: 42px; height: 42px; border: 1px solid #d6dee8; border-radius: 10px; background: white; font-size: 22px; font-weight: 800; }
.map-hint {
    position: absolute; left: 50%; bottom: 12px; transform: translateX(-50%);
    background: rgba(15,23,42,.78); color: white; padding: 7px 11px; border-radius: 999px;
    font-size: 11px; white-space: nowrap; pointer-events: none;
}

.details-panel { background: white; border-left: 1px solid var(--line); overflow: auto; padding: 22px; z-index: 10; }
.details-empty { min-height: 100%; display: grid; align-content: center; justify-items: center; text-align: center; color: var(--muted); padding: 30px 10px; }
.details-empty h2 { color: var(--text); margin: 14px 0 4px; }
.details-empty p { margin: 0; line-height: 1.45; }
.details-icon { width: 70px; height: 70px; display: grid; place-items: center; border-radius: 22px; background: #eff6ff; color: var(--primary); font-size: 32px; font-weight: 900; }
.details-header { display: flex; justify-content: space-between; align-items: start; }
.details-header h2 { margin: 3px 0 0; font-size: 30px; }
.eyebrow { color: #64748b; font-size: 11px; font-weight: 900; letter-spacing: .12em; text-transform: uppercase; }
.status-card { display: flex; justify-content: space-between; align-items: center; margin: 20px 0; padding: 14px; border: 1px solid var(--line); border-radius: 13px; }
.status-card span { color: var(--muted); font-size: 13px; }
.status-card strong { border-radius: 999px; padding: 6px 10px; font-size: 12px; }
.status-card strong.free { background: #dcfce7; color: #166534; }
.status-card strong.occupied { background: #fee2e2; color: #991b1b; }
#spotForm { display: grid; gap: 16px; }
.updated-at { font-size: 12px; color: var(--muted); margin-top: -3px; }
.mobile-only { display: none; }

.toast {
    position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
    opacity: 0; pointer-events: none; z-index: 100;
    background: #111827; color: white; padding: 11px 16px; border-radius: 12px;
    box-shadow: var(--shadow); transition: .2s; font-size: 14px;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: #991b1b; }
.settings-dialog { width: min(94vw, 460px); border: 0; border-radius: 20px; padding: 0; box-shadow: 0 24px 80px rgba(15,23,42,.28); }
.settings-dialog::backdrop { background: rgba(15,23,42,.56); backdrop-filter: blur(2px); }
.dialog-shell { padding: 24px; display: grid; gap: 17px; }
.dialog-header { display: flex; justify-content: space-between; align-items: start; }
.dialog-header h2 { margin: 4px 0 0; }
.dialog-header .icon-button { color: #334155; background: #f8fafc; }

@media (max-width: 920px) {
    .app-page { height: 100dvh; }
    .toolbar { flex-wrap: wrap; gap: 8px; padding: 9px 10px; }
    .search-box { width: 100%; order: 1; }
    .filter-group { order: 2; overflow-x: auto; max-width: calc(100vw - 20px); }
    .legend { display: none; }
    .workspace { grid-template-columns: 1fr; }
    .details-panel {
        position: fixed; left: 8px; right: 8px; bottom: 8px; top: auto;
        max-height: min(72vh, 620px); border: 1px solid var(--line); border-radius: 20px;
        transform: translateY(calc(100% + 20px)); transition: transform .2s ease; box-shadow: 0 18px 60px rgba(15,23,42,.24);
    }
    .details-panel.open { transform: translateY(0); }
    .details-empty { display: none; }
    .mobile-only { display: inline-grid; color: #334155; background: #f8fafc; }
    .map-hint { bottom: 10px; }
    .zoom-controls { right: 10px; bottom: 48px; }
}

@media (max-width: 560px) {
    .topbar { padding: 10px; }
    .brand strong { max-width: 170px; }
    .brand span { display: none; }
    .role-badge { display: none; }
    .filter { padding: 7px 10px; }
    .login-card { padding: 24px; border-radius: 20px; }
}
