/* ── Reset & base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }

:root {
    --bg:          #f0f0f0;
    --surface:     #ffffff;
    --surface-2:   #f8f8f8;
    --surface-3:   #efefef;
    --border:      #e0e0e0;
    --border-2:    #d0d0d0;
    --text:        #111111;
    --text-muted:  #666666;
    --text-dim:    #aaaaaa;
    --accent:      #ffe500;
    --accent-h:    #ffd000;
    --accent-dim:  #fff9c0;
    --accent-text: #000;
    --nav-bg:      #ffe500;
    --nav-text:    #000000;
    --nav-muted:   #555555;
    --green:       #16a34a;
    --green-dim:   #dcfce7;
    --red:         #dc2626;
    --red-dim:     #fee2e2;
    --radius:      8px;
    --radius-sm:   5px;
    --shadow:      0 1px 4px rgba(0,0,0,.10), 0 4px 16px rgba(0,0,0,.08);
    --shadow-sm:   0 1px 3px rgba(0,0,0,.08);
    --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    --mono:        'SF Mono', 'Consolas', 'Cascadia Code', monospace;
}

body {
    margin: 0;
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* ── Global nav ───────────────────────────────────────────── */
.global-nav {
    background: var(--nav-bg);
    border-bottom: none;
    position: sticky;
    top: 0;
    z-index: 50;
}

.global-nav__inner {
    display: flex;
    align-items: center;
    gap: 16px;
    height: 52px;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: var(--nav-text);
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.01em;
}

.nav-brand__logo {
    height: 28px;
    width: auto;
    display: block;
    flex-shrink: 0;
}

.nav-divider {
    width: 1px;
    height: 20px;
    background: rgba(0,0,0,.2);
}

.nav-crumb {
    font-size: 0.85rem;
    color: var(--nav-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}
.nav-crumb a { color: var(--nav-muted); text-decoration: none; }
.nav-crumb a:hover { color: var(--nav-text); }
.nav-crumb__sep { color: rgba(0,0,0,.4); }
.nav-crumb__current { color: var(--nav-text); }

.nav-spacer { flex: 1; }

.nav-badge {
    font-size: 0.75rem;
    padding: 3px 10px;
    border-radius: 20px;
    font-weight: 600;
    background: rgba(0,0,0,.12);
    border: 1px solid rgba(0,0,0,.2);
    color: #000;
}

/* ── Home page ────────────────────────────────────────────── */
.home-page {
    min-height: calc(100vh - 52px);
    padding: 40px 0;
}

.home-page__inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 32px;
}

.home-header {
    margin-bottom: 32px;
}

.home-header h1 {
    margin: 0 0 4px;
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
}

.home-header p {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.carpark-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}

.carpark-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    text-decoration: none;
    color: var(--text);
    display: flex;
    flex-direction: column;
    transition: border-color .15s, box-shadow .15s, transform .15s;
    cursor: pointer;
    box-shadow: var(--shadow-sm);
}

.carpark-card:hover {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent), var(--shadow);
    transform: translateY(-2px);
    color: var(--text);
    text-decoration: none;
}

.carpark-card__thumb {
    width: 100%;
    height: 160px;
    background: var(--surface-3);
    overflow: hidden;
    position: relative;
    border-bottom: 1px solid var(--border);
}

.carpark-card__thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: center;
    display: block;
    opacity: 0.9;
    transition: opacity .15s;
}

.carpark-card:hover .carpark-card__thumb img { opacity: 1; }

.carpark-card__thumb-placeholder {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-dim);
    font-size: 2.5rem;
}

.carpark-card__body {
    padding: 16px 20px;
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.carpark-card__name {
    font-weight: 700;
    font-size: 1rem;
    letter-spacing: -0.01em;
    color: var(--text);
}

.carpark-card__meta {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.carpark-card__stat {
    display: flex;
    align-items: center;
    gap: 5px;
}

.stat-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}
.stat-dot--total  { background: #111; }
.stat-dot--free   { background: var(--green); }

.carpark-card__cta {
    margin-top: auto;
    padding: 8px 0 0;
    border-top: 1px solid var(--border);
    font-size: 0.82rem;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 4px;
    font-weight: 500;
}
.carpark-card:hover .carpark-card__cta { color: var(--text); }

/* ── Map page layout ──────────────────────────────────────── */
.map-page {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 52px);
}

/* ── Toolbar ──────────────────────────────────────────────── */


.map-toolbar {
    display: flex;
    align-items: center;
    gap: 0;
    padding: 5px 12px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    flex-wrap: wrap;
    row-gap: 4px;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0 12px;
    border-right: 1px solid var(--border);
}

.toolbar-group:first-child { padding-left: 0; }
.toolbar-group:last-child  { border-right: none; }

.toolbar-btn {
    background: var(--surface-2);
    border: 1px solid var(--border-2);
    color: var(--text);
    padding: 4px 11px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.8rem;
    font-family: var(--font);
    line-height: 1.5;
    transition: background .12s, border-color .12s;
}

.toolbar-btn:hover { background: var(--surface-3); border-color: #bbb; }
.toolbar-btn:active { transform: translateY(1px); }
.toolbar-btn--active { background: var(--accent); border-color: var(--accent-h); color: #000; font-weight: 600; }
.toolbar-btn--active:hover { background: var(--accent-h); }
.toolbar-btn--save { background: #166534; border-color: #15803d; color: #fff; }
.toolbar-btn--save:hover { background: #15803d; }
.toolbar-btn--danger { background: var(--red-dim); border-color: #fca5a5; color: var(--red); font-weight: 600; }
.toolbar-btn--danger:hover { background: #fecaca; }

.zoom-display {
    font-size: 0.78rem;
    color: var(--text-muted);
    min-width: 42px;
    text-align: center;
    font-variant-numeric: tabular-nums;
    font-family: var(--mono);
}

.toolbar-label {
    font-size: 0.78rem;
    color: var(--text-muted);
}

.toolbar-edit { display: none; }
.toolbar-edit--visible {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.coord-display {
    font-size: 0.74rem;
    font-family: var(--mono);
    color: var(--text-muted);
    min-width: 300px;
    white-space: nowrap;
}

.step-input, .space-number-input {
    background: var(--surface);
    border: 1px solid var(--border-2);
    color: var(--text);
    padding: 3px 6px;
    border-radius: var(--radius-sm);
    font-size: 0.78rem;
    font-family: var(--font);
}
.step-input { width: 60px; }
.space-number-input { width: 68px; }
.step-input:focus, .space-number-input:focus {
    outline: none;
    border-color: #999;
    box-shadow: 0 0 0 2px rgba(0,0,0,.1);
}

.toolbar-separator {
    width: 1px;
    height: 18px;
    background: var(--border-2);
    margin: 0 4px;
    flex-shrink: 0;
}

.nudge-pad {
    display: grid;
    grid-template-columns: repeat(3, 24px);
    grid-template-rows: repeat(3, 24px);
    gap: 2px;
}

.nudge-btn {
    background: var(--surface-2);
    border: 1px solid var(--border-2);
    color: var(--text);
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    width: 24px;
    height: 24px;
    transition: background .1s;
}
.nudge-btn:hover { background: var(--accent-dim); border-color: #bbb; }
.nudge-up    { grid-column: 2; grid-row: 1; }
.nudge-left  { grid-column: 1; grid-row: 2; }
.nudge-right { grid-column: 3; grid-row: 2; }
.nudge-down  { grid-column: 2; grid-row: 3; }

/* ── Map container ────────────────────────────────────────── */
.map-loading {
    position: absolute;
    inset: 0;
    z-index: 10;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: #1a1a1a;
    color: #888;
    font-size: 0.9rem;
}
.map-loading[hidden] { display: none; }

.map-loading__spinner {
    width: 20px;
    height: 20px;
    border: 2px solid #333;
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    flex-shrink: 0;
}
@keyframes spin { to { transform: rotate(360deg); } }

.map-container {
    position: relative;
    flex: 1;
    overflow: hidden;
    cursor: grab;
    user-select: none;
    background: #1a1a1a;
}

.map-img {
    position: absolute;
    top: 0; left: 0;
    transform-origin: 0 0;
    display: block;
    max-width: none;
    pointer-events: none;
    user-select: none;
}

.map-overlay {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    pointer-events: none;
}

/* ── Modal ────────────────────────────────────────────────── */
.space-modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
}
.space-modal[hidden] { display: none; }

.space-modal__backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,.5);
    backdrop-filter: blur(3px);
}

.space-modal__panel {
    position: relative;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 28px 28px 24px;
    min-width: 320px;
    max-width: 460px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0,0,0,.2);
    color: var(--text);
}

.space-modal__close {
    position: absolute;
    top: 12px; right: 16px;
    background: var(--surface-3);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 0.85rem;
    cursor: pointer;
    line-height: 1;
    width: 28px;
    height: 28px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background .12s, color .12s;
}
.space-modal__close:hover { background: var(--border); color: var(--text); }

.space-modal__content h2 {
    margin: 0 0 14px;
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: var(--text);
}

.status {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    margin-bottom: 18px;
}
.status::before {
    content: '';
    width: 7px;
    height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
}
.status--free { background: var(--green-dim); color: #15803d; border: 1px solid #bbf7d0; }
.status--free::before { background: var(--green); }
.status--occupied { background: var(--red-dim); color: #dc2626; border: 1px solid #fecaca; }
.status--occupied::before { background: var(--red); }

.detail-table {
    width: 100%;
    border-collapse: collapse;
}
.detail-table th, .detail-table td {
    text-align: left;
    padding: 7px 10px;
    border-bottom: 1px solid var(--border);
    font-size: 0.875rem;
}
.detail-table tr:last-child th,
.detail-table tr:last-child td { border-bottom: none; }
.detail-table th { color: var(--text-muted); width: 110px; font-weight: 500; }
.detail-table td { color: var(--text); font-weight: 500; }

.modal-loading, .modal-error {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.875rem;
}