:root {
    --gold: #c9a84c;
    --gold-hover: #b8973e;
    --gold-glow: rgba(201,168,76,.25);
    --bg: #0d0d0d;
    --bg-card: #1a1a1a;
    --bg-card-hover: #222;
    --border: #2a2a2a;
    --text: #e8e8e8;
    --text-muted: #888;
    --radius: 12px;
    --green: #2e7d32;
    --green-light: #4caf50;
    --red: #c62828;
    --font: 'Segoe UI', system-ui, -apple-system, sans-serif;
    --transition: .15s ease;
    --tap: 48px; /* minimum touch target */
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { height: 100%; }

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    min-height: 100%;
    -webkit-font-smoothing: antialiased;
    /* prevent double-tap zoom on buttons */
    touch-action: manipulation;
}

a { color: var(--gold); text-decoration: none; }
button { font-family: var(--font); cursor: pointer; touch-action: manipulation; }

/* ── HEADER ─────────────────────────────────────────────────────── */
.bar-header {
    position: sticky;
    top: 0;
    z-index: 100;
    background: #111;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    height: 52px;
}

.bar-header .brand {
    font-size: 1rem;
    font-weight: 700;
    color: var(--gold);
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 5px;
}

.brand-name { color: var(--gold); }
.brand-user, .brand-tag {
    color: var(--text-muted);
    font-weight: 400;
    font-size: .8rem;
}

.bar-header .spacer { flex: 1; }

.desktop-nav { display: flex; gap: 4px; }

.desktop-nav a {
    display: flex;
    align-items: center;
    height: 36px;
    padding: 0 14px;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 8px;
    font-size: .82rem;
    text-decoration: none;
    white-space: nowrap;
    transition: all var(--transition);
}

.desktop-nav a.active {
    background: var(--gold);
    border-color: var(--gold);
    color: #000;
    font-weight: 600;
}

.btn-logout {
    display: flex;
    align-items: center;
    height: 36px;
    padding: 0 14px;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 8px;
    font-size: .82rem;
    white-space: nowrap;
    transition: all var(--transition);
}

.btn-logout:active { border-color: var(--red); color: var(--red); }

@media (max-width: 640px) {
    .desktop-nav { display: none; }
    .desktop-only { display: none !important; }
    .brand-name { display: none; }
}

/* ── BOTTOM NAV (mobile only) ───────────────────────────────────── */
.bottom-nav {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 200;
    background: #111;
    border-top: 1px solid var(--border);
    padding-bottom: env(safe-area-inset-bottom);
}

@media (max-width: 640px) { .bottom-nav { display: flex; } }

.bn-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    height: 60px;
    background: none;
    border: none;
    color: var(--text-muted);
    text-decoration: none;
    font-family: var(--font);
    cursor: pointer;
    transition: color var(--transition);
    -webkit-tap-highlight-color: transparent;
}

.bn-item.active { color: var(--gold); }
.bn-item:active { opacity: .6; }

.bn-icon { font-size: 1.4rem; line-height: 1; }
.bn-label { font-size: .65rem; }

/* ── LOGIN PAGE ──────────────────────────────────────────────────── */
.login-page {
    min-height: 100dvh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.login-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 36px 28px;
    width: 100%;
    max-width: 400px;
}

.login-box h1 {
    color: var(--gold);
    font-size: 1.6rem;
    margin-bottom: 4px;
}

.login-box .subtitle {
    color: var(--text-muted);
    font-size: .88rem;
    margin-bottom: 28px;
}

.form-group { margin-bottom: 16px; }

.form-group label {
    display: block;
    font-size: .83rem;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    font-family: var(--font);
    font-size: 1rem;
    padding: 13px 14px;
    transition: border-color var(--transition);
    outline: none;
    min-height: var(--tap);
    -webkit-appearance: none;
}

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

.btn-primary {
    display: block;
    width: 100%;
    background: var(--gold);
    color: #000;
    border: none;
    border-radius: 10px;
    font-size: 1rem;
    font-weight: 700;
    padding: 15px;
    transition: background var(--transition);
    margin-top: 8px;
    min-height: var(--tap);
}

.btn-primary:active { background: var(--gold-hover); }
.btn-primary:disabled { opacity: .6; }

.error-msg {
    background: rgba(198,40,40,.12);
    border: 1px solid var(--red);
    color: #ef9a9a;
    border-radius: 8px;
    padding: 12px 14px;
    font-size: .88rem;
    margin-top: 14px;
    display: none;
}

/* ── PLAN DE SALLE ───────────────────────────────────────────────── */
.salle-page {
    padding: 0;
    display: flex;
    flex-direction: column;
    /* Desktop: fill viewport below header */
    height: calc(100dvh - 52px);
}

.plan-container {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    position: relative;
    overflow: hidden;
    /* Desktop default */
    flex: 1;
    margin: 12px 16px 16px;
}

/* Mobile: shrink for bottom nav */
@media (max-width: 640px) {
    .salle-page {
        height: calc(100dvh - 52px - 60px - env(safe-area-inset-bottom));
    }
    .salle-page .plan-container {
        margin: 0;
        border-radius: 0;
        border: none;
        border-top: 1px solid var(--border);
    }
}

/* Admin plan editor always keeps a visible height */
.plan-editor {
    aspect-ratio: 16 / 9;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-height: 200px;
}

/* Hide the generic bg in editor */
.plan-editor .plan-bg { display: none; }

.plan-bg {
    position: absolute;
    inset: 0;
    background:
        linear-gradient(rgba(201,168,76,.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(201,168,76,.03) 1px, transparent 1px);
    background-size: 40px 40px;
    pointer-events: none;
}

/* Viewport layer that gets the CSS transform */
.plan-viewport {
    position: absolute;
    inset: 0;
    transform-origin: 0 0;
    cursor: grab;
}

.plan-viewport:active { cursor: grabbing; }

/* Tables keep pointer cursor */
.plan-viewport .plan-table { cursor: pointer; }
.plan-editor .plan-viewport .plan-table { cursor: grab; }

/* Round tables */
.plan-table.circle {
    border-radius: 50%;
}

.plan-table.circle .tbl-name,
.plan-table.circle .tbl-badge,
.plan-table.circle .tbl-empty {
    font-size: .72rem;
    text-align: center;
}

/* Auto-size button in edit panel */
.btn-autosize {
    width: 100%;
    height: var(--tap);
    background: none;
    border: 1px solid var(--gold);
    color: var(--gold);
    border-radius: 10px;
    font-size: .85rem;
    transition: all var(--transition);
}
.btn-autosize:active { background: var(--gold-glow); }

/* Room walls rectangle — JS overrides left/top/width/height for dynamic sizing */
.room-walls {
    position: absolute;
    left: 5%; top: 5%;
    width: 90%; height: 90%;
    pointer-events: none;
    background: rgba(255,255,255,.015);
    border: 8px solid #4a3c2e;
    box-shadow:
        inset 0 0 0 2px #2e2418,
        0 0 0 1px #2e2418;
    border-radius: 2px;
}

/* Grid drawn inside room walls only (editor) — background-size set by JS */
.plan-editor .room-walls {
    background-image:
        linear-gradient(rgba(201,168,76,.1) 1px, transparent 1px),
        linear-gradient(90deg, rgba(201,168,76,.1) 1px, transparent 1px);
    background-size: 5.56% 5.56%; /* default 18×18, overridden by JS */
}

/* Room size toolbar controls */
.room-size-ctrl {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-left: auto;
}
.room-size-label { font-size: .8rem; color: var(--muted); white-space: nowrap; }
.room-dim-ctrl {
    display: flex;
    align-items: center;
    gap: 4px;
}
.room-adj {
    width: 26px; height: 26px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--gold);
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    line-height: 1;
    display: flex; align-items: center; justify-content: center;
    transition: background var(--transition);
}
.room-adj:hover { background: var(--gold-glow); }
#roomWLabel, #roomHLabel {
    min-width: 22px;
    text-align: center;
    font-size: .85rem;
    font-weight: 600;
    color: var(--text);
}
.dim-unit { font-size: .78rem; color: var(--muted); }

/* Zoom controls overlay */
.zoom-controls {
    position: absolute;
    bottom: 10px;
    right: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    z-index: 10;
}

.zoom-btn {
    width: 40px;
    height: 40px;
    background: rgba(17,17,17,.85);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 10px;
    font-size: 1.2rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(4px);
    transition: border-color var(--transition), color var(--transition);
}

.zoom-btn:active { border-color: var(--gold); color: var(--gold); }

.zoom-reset { font-size: .9rem; }

.plan-table {
    position: absolute;
    background: #1f1f1f;
    border: 2px solid var(--border);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
    user-select: none;
    min-width: 48px;
    min-height: 48px;
    padding: 4px;
    transition: border-color var(--transition), background var(--transition);
}

.plan-table:active {
    transform: scale(.96);
    border-color: var(--gold);
}

.plan-table.has-orders {
    background: rgba(201,168,76,.14);
    border-color: var(--gold);
}

.plan-table.selected {
    border-color: var(--gold);
    box-shadow: 0 0 0 3px var(--gold-glow);
}

.plan-table .tbl-name {
    font-size: .78rem;
    font-weight: 700;
    color: var(--text);
    text-align: center;
    line-height: 1.1;
}

.plan-table .tbl-badge {
    background: var(--gold);
    color: #000;
    border-radius: 20px;
    font-size: .62rem;
    font-weight: 700;
    padding: 1px 6px;
    text-align: center;
}

.plan-table .tbl-empty {
    font-size: .62rem;
    color: var(--text-muted);
}

/* ── MODAL COMMANDE ─────────────────────────────────────────────── */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.75);
    z-index: 500;
    display: none;
    align-items: flex-end;
}

.modal-overlay.open { display: flex; }

.modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-height: 92dvh;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    /* safe area for iPhone home bar */
    padding-bottom: env(safe-area-inset-bottom);
}

@media (min-width: 640px) {
    .modal-overlay {
        align-items: center;
        justify-content: center;
        padding: 20px;
    }
    .modal-box {
        border-radius: 20px;
        max-width: 560px;
        max-height: 88vh;
    }
}

/* drag handle on mobile */
.modal-box::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 10px auto 4px;
    flex-shrink: 0;
}

@media (min-width: 640px) {
    .modal-box::before { display: none; }
}

.modal-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 18px 12px;
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    background: var(--bg-card);
    z-index: 1;
}

.modal-header h3 { font-size: 1.05rem; color: var(--gold); flex: 1; }

.modal-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.4rem;
    width: var(--tap);
    height: var(--tap);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: color var(--transition);
    margin-right: -8px;
}

.modal-close:active { color: var(--text); background: var(--border); }

.modal-body { padding: 14px 18px; flex: 1; }

/* Order items */
.order-items { margin-bottom: 12px; }

.order-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.order-item .item-name { flex: 1; font-size: .95rem; }

.order-item .item-price {
    font-size: .82rem;
    color: var(--text-muted);
    min-width: 52px;
    text-align: right;
}

.qty-ctrl {
    display: flex;
    align-items: center;
    gap: 4px;
}

.qty-btn {
    width: var(--tap);
    height: var(--tap);
    border-radius: 50%;
    border: 1px solid var(--border);
    background: none;
    color: var(--text);
    font-size: 1.2rem;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition);
}

.qty-btn:active { transform: scale(.9); }
.qty-btn.plus:active { border-color: var(--gold); color: var(--gold); }
.qty-btn.minus:active { border-color: var(--red); color: var(--red); }

.qty-val {
    font-weight: 700;
    font-size: 1rem;
    min-width: 24px;
    text-align: center;
}

.order-empty {
    text-align: center;
    padding: 28px 0;
    color: var(--text-muted);
    font-size: .9rem;
}

.order-total {
    display: flex;
    justify-content: space-between;
    font-weight: 700;
    font-size: 1rem;
    padding: 10px 0 6px;
    border-top: 2px solid var(--border);
    margin-top: 4px;
    color: var(--gold);
}

/* Drink selector */
.drink-selector { margin-top: 16px; }

.drink-selector h4 {
    font-size: .78rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .06em;
    margin-bottom: 10px;
}

.drink-cats {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
    margin-bottom: 12px;
    padding-bottom: 4px;
    /* hide scrollbar */
    scrollbar-width: none;
    -ms-overflow-style: none;
}
.drink-cats::-webkit-scrollbar { display: none; }

.cat-btn {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 20px;
    padding: 0 16px;
    height: 36px;
    font-size: .85rem;
    white-space: nowrap;
    flex-shrink: 0;
    transition: all var(--transition);
}

.cat-btn.active {
    background: var(--gold);
    border-color: var(--gold);
    color: #000;
    font-weight: 600;
}

.cat-btn:active { opacity: .8; }

.drink-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 10px;
}

@media (max-width: 400px) {
    .drink-grid { grid-template-columns: 1fr 1fr; }
}

.drink-btn {
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    border-radius: 12px;
    padding: 14px 10px;
    font-size: .9rem;
    text-align: center;
    min-height: 64px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    transition: all var(--transition);
    line-height: 1.3;
}

.drink-btn:active {
    border-color: var(--gold);
    background: rgba(201,168,76,.15);
    transform: scale(.97);
}

.drink-btn .d-price {
    font-size: .75rem;
    color: var(--gold);
    font-weight: 600;
}

.btn-clear-table {
    display: block;
    width: 100%;
    background: none;
    border: 1px solid var(--red);
    color: var(--red);
    border-radius: 10px;
    padding: 0;
    height: var(--tap);
    font-size: .88rem;
    margin-top: 18px;
    transition: all var(--transition);
}

.btn-clear-table:active { background: rgba(198,40,40,.15); }

/* ── ADMIN PAGE ─────────────────────────────────────────────────── */
.admin-page {
    padding: 12px 16px 16px;
}

@media (max-width: 640px) {
    .admin-page {
        padding-bottom: calc(60px + env(safe-area-inset-bottom) + 12px);
    }
}

.admin-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: .9rem;
    padding: 12px 8px;
    border-bottom: 3px solid transparent;
    margin-bottom: -1px;
    transition: all var(--transition);
    min-height: var(--tap);
}

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

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Admin card */
.admin-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    margin-bottom: 12px;
}

.admin-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
}

.admin-card-header h3 { font-size: .95rem; }

.btn-add {
    background: var(--gold);
    color: #000;
    border: none;
    border-radius: 8px;
    height: 38px;
    padding: 0 16px;
    font-size: .85rem;
    font-weight: 700;
    white-space: nowrap;
}

.btn-add:active { background: var(--gold-hover); }

.list-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    min-height: 56px;
}

.list-item:last-child { border-bottom: none; }

.list-item .item-info { flex: 1; min-width: 0; }

.list-item .item-name {
    font-weight: 600;
    font-size: .9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.list-item .item-sub {
    font-size: .75rem;
    color: var(--text-muted);
    margin-top: 2px;
}

.badge-actif {
    font-size: .7rem;
    padding: 3px 9px;
    border-radius: 20px;
    font-weight: 600;
    white-space: nowrap;
    flex-shrink: 0;
}

.badge-actif.on { background: rgba(46,125,50,.2); color: var(--green-light); }
.badge-actif.off { background: rgba(198,40,40,.15); color: #ef9a9a; }

.btn-icon {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 8px;
    height: 36px;
    padding: 0 10px;
    font-size: .8rem;
    white-space: nowrap;
    flex-shrink: 0;
}

.btn-icon:active { border-color: var(--gold); color: var(--gold); }
.btn-icon.danger:active { border-color: var(--red); color: var(--red); }

/* Plan editor */
.plan-editor-toolbar {
    display: flex;
    gap: 10px;
    margin-bottom: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.plan-editor-toolbar span {
    font-size: .8rem;
    color: var(--text-muted);
}

.plan-editor .plan-table { cursor: grab; }

.edit-panel {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-top: 12px;
}

.edit-panel h4 {
    font-size: .85rem;
    color: var(--gold);
    margin-bottom: 14px;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    margin-bottom: 10px;
}

@media (max-width: 400px) {
    .form-row { grid-template-columns: 1fr; }
}

.btn-row {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.btn-save {
    flex: 1;
    background: var(--gold);
    color: #000;
    border: none;
    border-radius: 10px;
    height: var(--tap);
    font-weight: 700;
    font-size: .9rem;
}

.btn-save:active { background: var(--gold-hover); }
.btn-save:disabled { opacity: .6; }

.btn-delete {
    background: none;
    border: 1px solid var(--red);
    color: var(--red);
    border-radius: 10px;
    height: var(--tap);
    padding: 0 16px;
    font-size: .88rem;
}

.btn-delete:active { background: rgba(198,40,40,.15); }

/* Inline form */
.inline-form {
    background: var(--bg);
    border: 1px solid var(--gold);
    border-radius: var(--radius);
    padding: 16px;
    margin-top: 10px;
    display: none;
}

.inline-form.open { display: block; }

.inline-form h4 {
    font-size: .85rem;
    color: var(--gold);
    margin-bottom: 12px;
}

.form-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
}

.btn-cancel-inline {
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    border-radius: 10px;
    height: var(--tap);
    padding: 0 16px;
    font-size: .88rem;
}

.btn-cancel-inline:active { color: var(--text); }

/* Loading */
.loading {
    text-align: center;
    padding: 32px;
    color: var(--text-muted);
    font-size: .88rem;
}
