/* Cachette – bordsbokning */

:root {
    --bg:        #100e0c;
    --panel:     #191614;
    --panel-2:   #221e1a;
    --line:      #332d26;
    --line-soft: #262119;
    --text:      #f0eae2;
    --muted:     #a59a8c;
    --brass:     #d3aa42;
    --brass-dim: #8a6f2b;

    --free:      #4f9d69;
    --free-bg:   rgba(79, 157, 105, .16);
    --busy:      #bf5a52;
    --busy-bg:   rgba(191, 90, 82, .20);
    --partly:    #d99a24;
    --partly-bg: rgba(217, 154, 36, .26);

    --radius: 12px;
    --topbar-h: 52px;
    --datebar-h: 56px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior-y: none;
}

button, input, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; }

/* ---------- Topbar ---------- */

.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 14px;
    padding-top: env(safe-area-inset-top);
    background: rgba(16, 14, 12, .94);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line-soft);
}

.wordmark {
    font-family: "Didot", "Bodoni 72", Georgia, "Times New Roman", serif;
    font-size: 20px;
    letter-spacing: .16em;
    text-transform: uppercase;
    color: var(--brass);
    white-space: nowrap;
}

.tabs {
    display: flex;
    gap: 4px;
    margin-left: auto;
    background: var(--panel);
    border: 1px solid var(--line-soft);
    border-radius: 999px;
    padding: 3px;
}

.tab {
    border: 0;
    background: transparent;
    color: var(--muted);
    padding: 6px 14px;
    border-radius: 999px;
    cursor: pointer;
    white-space: nowrap;
    font-size: 14px;
}

.tab[aria-selected="true"] {
    background: var(--panel-2);
    color: var(--text);
    box-shadow: inset 0 0 0 1px var(--line);
}

.linkish {
    color: var(--muted);
    text-decoration: none;
    font-size: 13px;
    white-space: nowrap;
}
.linkish:hover { color: var(--text); }

/* ---------- Datumrad ---------- */

.datebar {
    position: sticky;
    top: calc(var(--topbar-h) + env(safe-area-inset-top));
    z-index: 20;
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: rgba(16, 14, 12, .94);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line-soft);
    flex-wrap: wrap;
}

.stepper {
    width: 34px;
    height: 34px;
    flex: none;
    border-radius: 9px;
    border: 1px solid var(--line);
    background: var(--panel);
    color: var(--text);
    font-size: 19px;
    line-height: 1;
    cursor: pointer;
}
.stepper:hover { background: var(--panel-2); }

.date-field input {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 7px 10px;
    min-width: 138px;
    color-scheme: dark;
}

.daymeta {
    color: var(--muted);
    font-size: 13px;
    margin-left: auto;
    text-align: right;
}
.daymeta strong { color: var(--text); font-weight: 500; }

/* ---------- Knappar & fält ---------- */

.btn {
    border-radius: 9px;
    border: 1px solid var(--line);
    background: var(--panel);
    padding: 8px 14px;
    cursor: pointer;
    white-space: nowrap;
}
.btn:hover { background: var(--panel-2); }

.btn-primary {
    background: var(--brass);
    border-color: var(--brass);
    color: #1a1408;
    font-weight: 600;
}
.btn-primary:hover { background: #e0b850; }
.btn-primary:disabled { opacity: .55; cursor: default; }

.btn-ghost { color: var(--muted); font-size: 14px; padding: 7px 12px; }
.btn-ghost:hover { color: var(--text); }

.btn-danger { color: var(--busy); border-color: rgba(191, 90, 82, .45); }
.btn-danger:hover { background: var(--busy-bg); }

.btn-block { width: 100%; }

.select,
.form input {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 9px 10px;
    color-scheme: dark;
    width: 100%;
}
.select { appearance: none; padding-right: 26px;
    background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                      linear-gradient(135deg, var(--muted) 50%, transparent 50%);
    background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
}
.form input:focus, .select:focus { outline: 2px solid var(--brass-dim); outline-offset: 1px; }

.icon-btn {
    border: 0; background: transparent; color: var(--muted);
    font-size: 26px; line-height: 1; cursor: pointer; padding: 0 4px;
}
.icon-btn:hover { color: var(--text); }

/* ---------- Vyer ---------- */

main { padding: 14px; }
.view { display: none; }
body[data-view="plan"] #view-plan,
body[data-view="free"] #view-free { display: block; }

/* ---------- Tidsfilter ---------- */

.timefilter {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.tf-label { color: var(--muted); font-size: 13px; }
.timefilter .select { width: auto; min-width: 96px; }
.dash { color: var(--muted); }

/* ---------- Planen ---------- */

.planbox {
    background: var(--panel);
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    padding: 10px;
    position: relative;
}

.plan { display: block; width: 100%; height: auto; }

.plan .stool {
    fill: none;
    stroke: #3a332b;
    stroke-width: 2;
}

.plan .fixture rect {
    fill: rgba(255, 255, 255, .025);
    stroke: #3a332b;
    stroke-width: 2;
}
.plan .fixture.is-solid rect { fill: #2b2620; stroke: #3a332b; }
.plan .fixture-label {
    fill: var(--muted);
    font-size: 22px;
    letter-spacing: .22em;
    text-anchor: middle;
    dominant-baseline: middle;
}

.plan .table { cursor: pointer; }
.plan .table-shape {
    fill: var(--free-bg);
    stroke: var(--free);
    stroke-width: 2.5;
    transition: fill .12s ease, stroke .12s ease;
}
.plan .table-label {
    fill: var(--text);
    font-size: 30px;
    font-weight: 600;
    text-anchor: middle;
    dominant-baseline: middle;
    pointer-events: none;
}
.plan .table-label.is-tight { font-size: 24px; }
.plan .table-sub {
    fill: var(--muted);
    font-size: 12px;
    text-anchor: middle;
    dominant-baseline: middle;
    pointer-events: none;
}

.plan .table.is-busy .table-shape { fill: var(--busy-bg); stroke: var(--busy); }
.plan .table.is-partly .table-shape { fill: var(--partly-bg); stroke: var(--partly); }
.plan .table.is-busy .table-sub { fill: #e3a49e; }
.plan .table.is-partly .table-sub { fill: #e2c288; }

.plan .table:hover .table-shape,
.plan .table:focus-visible .table-shape { stroke-width: 4; }
.plan .table:focus-visible { outline: none; }

.plan .table.is-selected .table-shape {
    stroke: var(--brass);
    stroke-width: 4.5;
}

.plan .table-badge.is-hidden { display: none; }
.plan .table-badge circle { fill: var(--brass); }
.plan .table-badge text {
    fill: #1a1408;
    font-size: 15px;
    font-weight: 700;
    text-anchor: middle;
    dominant-baseline: middle;
}

.closed-note {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: 64px;
    margin: 0;
    background: rgba(16, 14, 12, .78);
    color: var(--muted);
    border-radius: var(--radius);
    font-size: 16px;
}
.closed-note[hidden] { display: none; }

/* ---------- Legend ---------- */

.legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    padding: 12px 2px 0;
    color: var(--muted);
    font-size: 13px;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }
.swatch {
    width: 13px; height: 13px; border-radius: 4px; display: inline-block;
    border: 2px solid var(--free); background: var(--free-bg);
}
.swatch.is-busy { border-color: var(--busy); background: var(--busy-bg); }
.swatch.is-partly { border-color: var(--partly); background: var(--partly-bg); }

/* ---------- Sidokolumn / dagens lista ---------- */

.side-column { margin-top: 20px; }

.side-head {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 10px;
}
.side-head h2 { font-size: 15px; letter-spacing: .02em; }

.count-pill {
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 999px;
    padding: 1px 9px;
    font-size: 12px;
    color: var(--muted);
}

.daylist { display: flex; flex-direction: column; gap: 8px; }

.bcard {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--panel);
    border: 1px solid var(--line-soft);
    border-left: 3px solid var(--brass-dim);
    border-radius: 10px;
    padding: 10px 12px;
    cursor: pointer;
    text-align: left;
    width: 100%;
}
.bcard:hover { background: var(--panel-2); }

.bcard-table {
    flex: none;
    width: 34px; height: 34px;
    display: grid; place-items: center;
    border-radius: 8px;
    background: var(--panel-2);
    border: 1px solid var(--line);
    font-weight: 600;
}
.bcard-main { min-width: 0; flex: 1; display: block; }
.bcard-name { display: block; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bcard-meta { display: block; color: var(--muted); font-size: 13px; }
.bcard-time { color: var(--text); font-variant-numeric: tabular-nums; font-size: 14px; white-space: nowrap; }

.empty {
    color: var(--muted);
    font-size: 14px;
    padding: 18px 12px;
    text-align: center;
    border: 1px dashed var(--line);
    border-radius: 10px;
}

/* ---------- Lediga bord (rutnät) ---------- */

.freebar {
    display: flex;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    margin-bottom: 12px;
}
.inline-field { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 14px; }
.inline-field .select { width: auto; }
.hint { color: var(--muted); font-size: 13px; margin: 0; }

.grid-scroll {
    overflow-x: auto;
    border: 1px solid var(--line-soft);
    border-radius: var(--radius);
    background: var(--panel);
    -webkit-overflow-scrolling: touch;
}

table.grid { border-collapse: separate; border-spacing: 0; width: 100%; }

table.grid th, table.grid td { padding: 0; }

table.grid thead th {
    position: sticky;
    top: 0;
    background: var(--panel);
    color: var(--muted);
    font-weight: 500;
    font-size: 11px;
    font-variant-numeric: tabular-nums;
    padding: 8px 0 6px;
    border-bottom: 1px solid var(--line);
    min-width: 46px;
    white-space: nowrap;
}

table.grid th.rowhead {
    position: sticky;
    left: 0;
    z-index: 2;
    background: var(--panel);
    text-align: left;
    padding: 0 10px;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line-soft);
    min-width: 92px;
    white-space: nowrap;
}
table.grid thead th.rowhead { z-index: 3; }

.rowhead-inner { display: flex; align-items: baseline; gap: 7px; }
.rowhead-name { font-weight: 600; color: var(--text); }
.rowhead-seats { color: var(--muted); font-size: 12px; font-weight: 400; }

table.grid td {
    border-bottom: 1px solid var(--line-soft);
    border-right: 1px solid var(--line-soft);
    height: 40px;
}

.cell {
    display: block;
    width: 100%;
    height: 38px;
    border: 0;
    background: var(--free-bg);
    cursor: pointer;
    position: relative;
}
.cell:hover { background: rgba(79, 157, 105, .3); }
.cell.is-busy { background: var(--busy-bg); cursor: pointer; }
.cell.is-busy:hover { background: rgba(191, 90, 82, .34); }
.cell.is-busy.is-start::after {
    content: attr(data-name);
    position: absolute;
    left: 6px; top: 50%;
    transform: translateY(-50%);
    max-width: calc(var(--span, 1) * 100% - 12px);
    font-size: 12px;
    color: #f0c6c1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    pointer-events: none;
    z-index: 1;
}
.cell.is-past { opacity: .4; }

/* ---------- Overlay / bokningspanel ---------- */

.overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    background: rgba(6, 5, 4, .62);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    backdrop-filter: blur(2px);
}
.overlay[hidden] { display: none; }

.sheet {
    background: var(--panel);
    border: 1px solid var(--line);
    border-bottom: 0;
    border-radius: 18px 18px 0 0;
    width: 100%;
    max-width: 560px;
    max-height: 92vh;
    display: flex;
    flex-direction: column;
    animation: rise .18s ease-out;
}
@keyframes rise { from { transform: translateY(24px); opacity: .6; } }

.sheet-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 16px 18px 12px;
    border-bottom: 1px solid var(--line-soft);
}
.sheet-head h2 { font-size: 19px; }
.sheet-sub { margin: 3px 0 0; color: var(--muted); font-size: 13px; }

.sheet-body {
    padding: 14px 18px calc(18px + env(safe-area-inset-bottom));
    overflow-y: auto;
}

.existing { display: flex; flex-direction: column; gap: 8px; margin-bottom: 16px; }
.existing:empty { display: none; }

.ex-item {
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 10px 12px;
}
.ex-top { display: flex; align-items: baseline; gap: 10px; }
.ex-time { font-variant-numeric: tabular-nums; color: var(--brass); font-weight: 600; }
.ex-name { font-weight: 500; }
.ex-meta { color: var(--muted); font-size: 13px; margin-top: 2px; }
.ex-actions { display: flex; gap: 8px; margin-top: 10px; }
.ex-actions .btn { padding: 5px 11px; font-size: 13px; }

.form { display: flex; flex-direction: column; gap: 12px; }
.form-title { font-size: 14px; color: var(--muted); font-weight: 500; letter-spacing: .04em; text-transform: uppercase; }
.row { display: flex; gap: 12px; }
.row > .field { flex: 1; min-width: 0; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 13px; color: var(--muted); }

.form-error {
    margin: 0;
    background: var(--busy-bg);
    border: 1px solid rgba(191, 90, 82, .5);
    color: #f0c6c1;
    border-radius: 9px;
    padding: 9px 11px;
    font-size: 14px;
}

.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 2px; }

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(20px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-left: 3px solid var(--free);
    border-radius: 10px;
    padding: 10px 16px;
    font-size: 14px;
    z-index: 60;
    box-shadow: 0 8px 26px rgba(0, 0, 0, .5);
}

/* ---------- Login ---------- */

.login-page { display: grid; place-items: center; min-height: 100vh; padding: 20px; }
.login-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 30px 26px;
    width: 100%;
    max-width: 320px;
    text-align: center;
}
.login-card .wordmark { font-size: 26px; }
.login-sub { color: var(--muted); font-size: 13px; margin: 6px 0 22px; letter-spacing: .05em; }
.pin-field {
    background: var(--panel-2);
    border: 1px solid var(--line);
    border-radius: 9px;
    padding: 12px;
    width: 100%;
    text-align: center;
    letter-spacing: .3em;
    margin-bottom: 14px;
}
.login-error { color: #f0c6c1; font-size: 14px; margin: 0 0 12px; }

/* ---------- Smala telefoner ---------- */

@media (max-width: 560px) {
    .topbar { gap: 8px; padding: 0 10px; }
    .wordmark { font-size: 15px; letter-spacing: .1em; }
    .tabs { padding: 2px; }
    .tab { padding: 6px 11px; font-size: 13px; }
    .linkish { font-size: 12px; }
    .daymeta { width: 100%; text-align: left; margin-left: 0; }
    main { padding: 12px; }
}

/* ---------- Datorläge ---------- */

@media (min-width: 900px) {
    main { padding: 20px 24px; max-width: 1500px; margin: 0 auto; }

    body[data-view="plan"] #view-plan {
        display: flex;
        justify-content: center;
        align-items: flex-start;
        gap: 28px;
    }

    .plan-column { flex: 0 0 auto; }
    .side-column { flex: 1 1 420px; max-width: 460px; }

    /* Hela planen ska rymmas utan att man behöver skrolla. */
    .planbox {
        height: calc(100vh - var(--topbar-h) - var(--datebar-h) - 132px);
        min-height: 460px;
        aspect-ratio: 740 / 1500;   /* samma proportion som planens viewBox */
        width: auto;
        display: flex;
        margin: 0 auto;
    }
    .plan { height: 100%; width: 100%; }
    .plan-column > .timefilter,
    .plan-column > .legend { justify-content: center; }

    .side-column {
        margin-top: 0;
        position: sticky;
        top: calc(var(--topbar-h) + var(--datebar-h) + 20px);
        max-height: calc(100vh - var(--topbar-h) - var(--datebar-h) - 40px);
        display: flex;
        flex-direction: column;
    }
    .daylist { overflow-y: auto; padding-right: 4px; }

    .overlay { align-items: center; }
    .sheet { border-radius: 16px; border-bottom: 1px solid var(--line); max-height: 86vh; }

    table.grid td { height: 34px; }
    .cell { height: 32px; }
    table.grid thead th { min-width: 54px; font-size: 12px; }
    table.grid th.rowhead { min-width: 120px; }
}

@media (min-width: 1280px) {
    body[data-view="plan"] #view-plan { grid-template-columns: minmax(0, 1fr) 400px; }
}
