/* ==========================================================================
   MenuList POS - тъмна, touch-first тема за сервитьорски екран и KDS
   ========================================================================== */

:root {
    --bg: #12141a;
    --bg-elev: #1b1e27;
    --bg-elev2: #242835;
    --border: #313749;
    --text: #eef0f6;
    --text-dim: #9aa1b5;
    --accent: #2dd4bf;
    --accent-dark: #14b8a6;
    --warn: #fbbf24;
    --info: #60a5fa;
    --danger: #f87171;
    --ok: #4ade80;
    --radius: 14px;
    --touch: 52px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
    font-size: 16px;
    overscroll-behavior: none;
}

button {
    font-family: inherit;
    font-size: inherit;
    color: inherit;
    background: none;
    border: none;
    cursor: pointer;
}

/* --------------------------------------------------------------------------
   Layout / екрани
   -------------------------------------------------------------------------- */

.pos-screen { display: none; min-height: 100dvh; flex-direction: column; }
.pos-screen.active { display: flex; }

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

.pos-header .org-name {
    font-weight: 700;
    font-size: 1.05rem;
    margin-right: auto;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.header-link {
    color: var(--text-dim);
    text-decoration: none;
    font-size: 0.85rem;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    white-space: nowrap;
}
.header-link:active { background: var(--bg-elev2); }

.staff-chip {
    color: var(--accent);
    font-size: 0.85rem;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 10px;
    white-space: nowrap;
}

.live-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--warn);
    flex-shrink: 0;
}
.live-dot.live { background: var(--ok); }

.icon-btn {
    min-width: 42px;
    min-height: 42px;
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text-dim);
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.icon-btn:active { background: var(--bg-elev2); }

/* --------------------------------------------------------------------------
   Бутони
   -------------------------------------------------------------------------- */

.btn {
    min-height: var(--touch);
    padding: 0 20px;
    border-radius: var(--radius);
    font-weight: 700;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}
.btn-primary { background: var(--accent); color: #06241f; }
.btn-primary:active { background: var(--accent-dark); }
.btn-primary:disabled { background: var(--bg-elev2); color: var(--text-dim); }
.btn-ghost { border: 1px solid var(--border); color: var(--text); }
.btn-ghost:active { background: var(--bg-elev2); }
.btn-danger { background: var(--danger); color: #2b0707; }

/* --------------------------------------------------------------------------
   Login екран
   -------------------------------------------------------------------------- */

.login-wrap {
    margin: auto;
    width: min(380px, 92vw);
    display: flex;
    flex-direction: column;
    gap: 14px;
    padding: 24px 0;
}
.login-wrap .logo { font-size: 2rem; text-align: center; }
.login-wrap h1 { text-align: center; font-size: 1.3rem; margin: 0; }
.login-wrap p.hint { color: var(--text-dim); text-align: center; margin: 0; font-size: 0.9rem; }

.login-wrap input {
    min-height: var(--touch);
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 0 16px;
    font-size: 1rem;
}
.login-wrap input:focus { outline: 2px solid var(--accent); border-color: transparent; }

/* --------------------------------------------------------------------------
   PIN екран
   -------------------------------------------------------------------------- */

.pin-wrap {
    margin: auto;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 18px;
    padding: 24px;
}
.pin-wrap h2 { margin: 0; font-size: 1.15rem; color: var(--text-dim); font-weight: 500; }

.pin-dots {
    min-height: 34px;
    font-size: 1.6rem;
    letter-spacing: 10px;
    color: var(--accent);
}

.pin-pad {
    display: grid;
    grid-template-columns: repeat(3, 76px);
    gap: 12px;
}
.pin-pad button {
    height: 76px;
    border-radius: 50%;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    font-size: 1.5rem;
    font-weight: 600;
}
.pin-pad button:active { background: var(--bg-elev2); }
.pin-pad .pin-ok { background: var(--accent); color: #06241f; border: none; }

/* --------------------------------------------------------------------------
   Карта на масите
   -------------------------------------------------------------------------- */

.floor-zones { padding: 14px; display: flex; flex-direction: column; gap: 20px; }
.floor-zone h3 {
    margin: 0 0 10px;
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
}
.floor-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
    gap: 12px;
}

.table-card {
    min-height: 104px;
    border-radius: var(--radius);
    border: 2px solid var(--border);
    background: var(--bg-elev);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 8px;
}
.table-card:active { transform: scale(0.97); }
.table-card .table-name { font-weight: 800; font-size: 1.15rem; }
.table-card .table-total { font-weight: 700; color: var(--text); font-size: 0.95rem; }
.table-card .table-minutes,
.table-card .table-free-label { font-size: 0.75rem; color: var(--text-dim); }

.table-card.status-free { border-color: var(--border); }
.table-card.status-occupied { border-color: var(--warn); background: rgba(251, 191, 36, 0.08); }
.table-card.status-bill_requested { border-color: var(--info); background: rgba(96, 165, 250, 0.1); }

/* --------------------------------------------------------------------------
   Екран за поръчка
   -------------------------------------------------------------------------- */

.order-layout { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.category-bar {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding: 10px 14px;
    scrollbar-width: none;
}
.category-bar::-webkit-scrollbar { display: none; }

.category-pill {
    padding: 10px 16px;
    border-radius: 999px;
    border: 1px solid var(--border);
    color: var(--text-dim);
    white-space: nowrap;
    min-height: 44px;
}
.category-pill.active { background: var(--accent); border-color: var(--accent); color: #06241f; font-weight: 700; }

.menu-items-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    padding: 0 14px 14px;
    overflow-y: auto;
    flex: 1;
    min-height: 120px;
    align-content: start;
}

.menu-item-btn {
    min-height: 76px;
    border-radius: var(--radius);
    background: var(--bg-elev);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: center;
    gap: 4px;
    padding: 10px 12px;
    text-align: left;
}
.menu-item-btn:active { background: var(--bg-elev2); transform: scale(0.98); }
.menu-item-btn .mi-name { font-weight: 600; font-size: 0.92rem; line-height: 1.2; }
.menu-item-btn .mi-price { color: var(--accent); font-size: 0.85rem; font-weight: 700; }

/* Количка + изпратени */
.order-panel {
    border-top: 1px solid var(--border);
    background: var(--bg-elev);
    max-height: 46dvh;
    overflow-y: auto;
    padding: 10px 14px;
}

.sent-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-dim);
    margin: 4px 0 6px;
}

.sent-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    color: var(--text-dim);
    font-size: 0.92rem;
    border-bottom: 1px dashed var(--border);
}
.sent-row.voided { text-decoration: line-through; opacity: 0.5; }
.sent-row .sr-name { flex: 1; min-width: 0; }
.sent-row .sr-status { font-size: 0.78rem; white-space: nowrap; }
.sent-row .sr-void {
    min-width: 36px;
    min-height: 36px;
    border-radius: 8px;
    color: var(--danger);
    border: 1px solid var(--border);
}

.cart-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}
.cart-row .cart-name { flex: 1; min-width: 0; font-weight: 600; }
.cart-row .cart-name em { color: var(--text-dim); font-style: normal; font-size: 0.85rem; }
.cart-row .cart-price { color: var(--accent); font-weight: 700; white-space: nowrap; }

.cart-qty-controls { display: flex; align-items: center; gap: 4px; }
.cart-qty-controls button {
    min-width: 40px;
    min-height: 40px;
    border-radius: 10px;
    border: 1px solid var(--border);
    font-size: 1.2rem;
}
.cart-qty-controls span { min-width: 24px; text-align: center; font-weight: 700; }

/* Долна лента с общата сума */
.order-footer {
    position: sticky;
    bottom: 0;
    background: var(--bg-elev);
    border-top: 1px solid var(--border);
    padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.order-total-line {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 1.05rem;
}
.order-total-line strong { font-size: 1.25rem; color: var(--accent); }
.order-actions { display: flex; gap: 10px; }
.order-actions .btn { flex: 1; }

/* --------------------------------------------------------------------------
   KDS
   -------------------------------------------------------------------------- */

.kds-board {
    flex: 1;
    display: flex;
    gap: 14px;
    overflow-x: auto;
    padding: 14px;
    align-items: flex-start;
}

.kds-card {
    min-width: 250px;
    max-width: 300px;
    background: var(--bg-elev);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    flex-shrink: 0;
}
.kds-card.late { border-color: var(--danger); }

.kds-card-header {
    display: flex;
    justify-content: space-between;
    padding: 10px 14px;
    background: var(--bg-elev2);
    font-weight: 800;
}
.kds-card.late .kds-card-header { background: rgba(248, 113, 113, 0.18); }
.kds-minutes { color: var(--text-dim); font-weight: 600; }
.kds-card.late .kds-minutes { color: var(--danger); }

.kds-item {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    gap: 8px;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    font-size: 1.1rem;
}
.kds-item:active { background: rgba(74, 222, 128, 0.15); }
.kds-item .ki-qty { font-weight: 800; color: var(--accent); }
.kds-item .ki-name { font-weight: 600; flex: 1; }
.kds-item .ki-note { width: 100%; color: var(--warn); font-size: 0.9rem; }

.kds-empty {
    margin: auto;
    color: var(--text-dim);
    font-size: 1.3rem;
}

.station-list {
    margin: auto;
    display: flex;
    flex-direction: column;
    gap: 12px;
    width: min(360px, 90vw);
}
.station-btn {
    min-height: 64px;
    border-radius: var(--radius);
    background: var(--bg-elev);
    border: 1px solid var(--border);
    font-size: 1.15rem;
    font-weight: 700;
}
.station-btn:active { background: var(--bg-elev2); }

/* --------------------------------------------------------------------------
   Модали, тостове, празни състояния
   -------------------------------------------------------------------------- */

.pos-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 20px;
}
.pos-modal {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px;
    width: min(420px, 100%);
    display: flex;
    flex-direction: column;
    gap: 14px;
}
.pos-modal h3 { margin: 0; }
.pos-modal-body p { color: var(--text-dim); margin: 8px 0 0; }
.close-total {
    font-size: 1.9rem;
    font-weight: 800;
    color: var(--accent);
    text-align: center;
    padding: 10px 0;
}
.pos-modal-input {
    min-height: var(--touch);
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    color: var(--text);
    padding: 0 14px;
    font-size: 1rem;
}
.pos-modal-actions { display: flex; gap: 10px; }
.pos-modal-actions .btn { flex: 1; }

#posToast {
    position: fixed;
    left: 50%;
    bottom: 24px;
    transform: translate(-50%, 20px);
    background: var(--bg-elev2);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 12px 20px;
    border-radius: 12px;
    opacity: 0;
    pointer-events: none;
    transition: all 0.2s ease;
    z-index: 200;
    max-width: 90vw;
    text-align: center;
}
#posToast.show { opacity: 1; transform: translate(-50%, 0); }
#posToast.error { border-color: var(--danger); }
#posToast.success { border-color: var(--ok); }

.pos-empty {
    margin: 40px auto;
    text-align: center;
    color: var(--text-dim);
    line-height: 1.6;
}
.pos-empty-inline { color: var(--text-dim); padding: 20px 6px; }

.disabled-wrap {
    margin: auto;
    text-align: center;
    color: var(--text-dim);
    padding: 24px;
    line-height: 1.7;
}
.disabled-wrap h2 { color: var(--text); }
