/* ═════════════════════════════════════════════════════════════════════
   CentralPOS Waiter — v1.2 with Light/Dark theme
   ═════════════════════════════════════════════════════════════════════ */

/* ── Theme tokens (CSS variables) ────────────────────────────────────── */

:root {
    /* Surfaces */
    --bg-page:       #F8F9FC;
    --bg-card:       #FFFFFF;
    --bg-elevated:   #FFFFFF;
    --bg-input:      #F8F9FC;
    --bg-hover:      #F3F4F6;
    --bg-skeleton-a: #F3F4F6;
    --bg-skeleton-b: #E5E7EB;

    /* Borders */
    --border:        #E5E7EB;
    --border-soft:   #F3F4F6;

    /* Text */
    --text-primary:   #111827;
    --text-secondary: #6B7280;
    --text-muted:     #9CA3AF;
    --text-faint:     #D1D5DB;

    /* Brand (same in both modes for consistency) */
    --brand:        #3C6EF5;
    --brand-dark:   #2E59CD;
    --brand-light:  #EEF3FF;

    /* Accent backgrounds */
    --tile-brand:   #EEF3FF;
    --tile-green:   #ECFDF5;
    --tile-yellow:  #FEFCE8;
    --tile-red:     #FEF2F2;

    /* Shadows */
    --shadow-sm:  0 1px 2px rgba(0,0,0,0.04);
    --shadow-md:  0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg:  0 10px 30px rgba(0,0,0,0.12);
    --shadow-nav: 0 -2px 8px rgba(0,0,0,0.04);
}

html.dark {
    --bg-page:       #0D1117;
    --bg-card:       #161B22;
    --bg-elevated:   #21262D;
    --bg-input:      #0D1117;
    --bg-hover:      #21262D;
    --bg-skeleton-a: #21262D;
    --bg-skeleton-b: #30363D;

    --border:        #30363D;
    --border-soft:   #21262D;

    --text-primary:   #E6EDF3;
    --text-secondary: #8B949E;
    --text-muted:     #6E7681;
    --text-faint:     #484F58;

    /* Brand stays the same */
    --tile-brand:  #1F2A47;
    --tile-green:  #112B22;
    --tile-yellow: #2A2511;
    --tile-red:    #2D1518;

    --shadow-sm:  0 1px 2px rgba(0,0,0,0.4);
    --shadow-md:  0 4px 12px rgba(0,0,0,0.5);
    --shadow-lg:  0 10px 30px rgba(0,0,0,0.6);
    --shadow-nav: 0 -2px 12px rgba(0,0,0,0.5);
}

/* ── Base ─────────────────────────────────────────────────────────────── */

* {
    -webkit-tap-highlight-color: transparent;
    -webkit-touch-callout: none;
}
html, body {
    overscroll-behavior-y: none;
}
body {
    background: var(--bg-page);
    color: var(--text-primary);
}
input, textarea, button, select {
    font-family: inherit;
    -webkit-user-select: text;
    user-select: text;
}
button { cursor: pointer; }

/* ── Surfaces (sticky headers, cards, sheets) ────────────────────────── */

.surface-header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-soft);
    box-shadow: var(--shadow-sm);
}

.surface-card {
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    border-radius: 16px;
    box-shadow: var(--shadow-sm);
}

.surface-sheet {
    background: var(--bg-card);
}

/* Generic icon-only round button */
.icon-btn {
    padding: 10px;
    color: var(--text-secondary);
    border-radius: 10px;
    background: transparent;
    transition: background 0.15s ease, color 0.15s ease, transform 0.08s ease;
    line-height: 0;
}
.icon-btn:hover { color: var(--brand); background: var(--bg-hover); }
.icon-btn:active { transform: scale(0.92); }

.icon-btn-soft {
    color: var(--text-secondary);
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: transparent;
    transition: background 0.15s ease;
    border: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.icon-btn-soft:hover { background: var(--bg-hover); }

/* ── Form inputs ──────────────────────────────────────────────────────── */

.form-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 12px;
    font-size: 14px;
    color: var(--text-primary);
    transition: border-color 0.15s ease, background 0.15s ease;
}
.form-input:focus {
    outline: none;
    border-color: var(--brand);
    background: var(--bg-card);
}
.form-input::placeholder { color: var(--text-muted); }

.search-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 8px 36px 8px 36px;
    font-size: 14px;
    color: var(--text-primary);
    transition: border-color 0.15s ease, background 0.15s ease;
}
.search-input:focus {
    outline: none;
    border-color: var(--brand);
    background: var(--bg-card);
}
.search-input::placeholder { color: var(--text-muted); }

/* ── Primary buttons ──────────────────────────────────────────────────── */

.btn-primary-large {
    width: 100%;
    background: var(--brand);
    color: #FFFFFF;
    font-weight: 700;
    font-size: 17px;
    padding: 16px 20px;
    border-radius: 14px;
    border: none;
    box-shadow: 0 4px 12px rgba(60,110,245,0.3);
    transition: background 0.15s ease, transform 0.08s ease;
}
.btn-primary-large:hover { background: var(--brand-dark); }
.btn-primary-large:active { transform: scale(0.97); }

/* ── PIN + Numpad (Login) ──────────────────────────────────────────── */

.pin-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--border);
    transition: all 0.18s ease;
}
.pin-dot.filled {
    background: var(--brand);
    box-shadow: 0 0 0 4px rgba(60,110,245,0.16);
    transform: scale(1.05);
}

.num-btn {
    background: var(--bg-card);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 16px;
    height: 64px;
    font-size: 24px;
    font-weight: 600;
    transition: transform 0.08s ease, background 0.15s ease, border 0.15s ease;
    box-shadow: var(--shadow-sm);
}
.num-btn:active { background: var(--bg-hover); transform: scale(0.96); }

.num-btn-secondary {
    background: var(--bg-input);
    color: var(--text-secondary);
    border: 1px solid transparent;
    border-radius: 16px;
    height: 64px;
    font-size: 22px;
    font-weight: 600;
    transition: transform 0.08s ease, background 0.15s ease;
}
.num-btn-secondary#btn-login {
    background: var(--brand);
    color: #FFFFFF;
    box-shadow: 0 4px 12px rgba(60,110,245,0.3);
}
.num-btn-secondary#btn-login:active { background: var(--brand-dark); transform: scale(0.96); }
.num-btn-secondary#btn-clear:active { background: var(--border); transform: scale(0.96); }

.shake { animation: shakeKf 0.4s ease-in-out; }
@keyframes shakeKf {
    0%, 100% { transform: translateX(0); }
    20% { transform: translateX(-8px); }
    40% { transform: translateX(8px); }
    60% { transform: translateX(-6px); }
    80% { transform: translateX(6px); }
}

/* ── Tables ───────────────────────────────────────────────────────────── */

.table-card {
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    border-radius: 16px;
    padding: 16px 12px;
    text-align: left;
    transition: transform 0.08s ease, box-shadow 0.15s ease, border 0.15s ease;
    box-shadow: var(--shadow-sm);
    min-height: 110px;
    display: flex;
    flex-direction: column;
    color: var(--text-primary);
}
.table-card:active {
    transform: scale(0.97);
    box-shadow: var(--shadow-md);
}

/* Free table (light) */
.table-card.table-free {
    background: var(--bg-card);
    border-color: var(--border-soft);
}
html.dark .table-card.table-free {
    background: var(--bg-card);
    border-color: var(--border-soft);
}

/* Busy table — same warm gradient with dark adaptation */
.table-card.table-busy {
    background: linear-gradient(135deg, #FEF3C7 0%, #FDE68A 100%);
    border-color: #FBBF24;
    color: #111827;
}
html.dark .table-card.table-busy {
    background: linear-gradient(135deg, #2A2410 0%, #3D3315 100%);
    border-color: #94781E;
    color: #FCD34D;
}

.table-no {
    font-size: 28px;
    font-weight: 800;
    line-height: 1;
    margin-bottom: 6px;
    color: inherit;
}
.table-busy .table-no { color: #92400E; }
html.dark .table-busy .table-no { color: #FCD34D; }

.table-status {
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-secondary);
}
.table-busy .table-status { color: #B45309; }
.table-free .table-status { color: #059669; }
html.dark .table-busy .table-status { color: #D4A23A; }
html.dark .table-free .table-status { color: #34D399; }

.table-total {
    margin-top: 8px;
    font-size: 16px;
    font-weight: 700;
    color: #92400E;
}
html.dark .table-total { color: #FCD34D; }

.table-items {
    margin-top: 4px;
    font-size: 11px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.table-busy .table-items { color: #92400E; opacity: 0.8; }
html.dark .table-busy .table-items { color: #FCD34D; opacity: 0.7; }

/* Locked table — icazə yoxdur */
.table-card.table-locked {
    background: var(--bg-input);
    border-color: var(--border);
    opacity: 0.65;
    cursor: not-allowed;
    position: relative;
    color: var(--text-muted);
}
html.dark .table-card.table-locked {
    background: var(--bg-card);
    border-color: var(--border-soft);
    opacity: 0.45;
}
.table-card.table-locked:active {
    transform: none;
    box-shadow: var(--shadow-sm);
    animation: lockShake 0.4s ease-in-out;
}
.table-card.table-locked .table-no { color: var(--text-muted); }
.table-card.table-locked .table-status {
    color: var(--text-muted);
    font-style: italic;
    text-transform: none;
    letter-spacing: 0;
}

.table-lock-icon {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 18px;
    opacity: 0.7;
}

@keyframes lockShake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

/* ── Skeletons ──────────────────────────────────────────────────────── */

.skeleton-card,
.skeleton-row {
    background: linear-gradient(90deg,
        var(--bg-skeleton-a) 0%,
        var(--bg-skeleton-b) 50%,
        var(--bg-skeleton-a) 100%);
    background-size: 200% 100%;
    animation: skeletonShimmer 1.4s ease-in-out infinite;
    border-radius: 16px;
}
.skeleton-card { height: 110px; }
.skeleton-row { height: 110px; margin-bottom: 8px; }

@keyframes skeletonShimmer {
    0%   { background-position: 100% 0; }
    100% { background-position: -100% 0; }
}

/* ── Categories + Items ─────────────────────────────────────────────── */

#category-tabs {
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
#category-tabs::-webkit-scrollbar { display: none; }

.cat-tab {
    display: inline-block;
    padding: 8px 16px;
    margin-right: 6px;
    background: var(--bg-input);
    color: var(--text-secondary);
    border-radius: 999px;
    font-size: 13px;
    font-weight: 600;
    border: none;
    transition: all 0.15s ease;
    white-space: nowrap;
}
.cat-tab:active { transform: scale(0.96); }
.cat-tab.cat-tab-active {
    background: var(--brand);
    color: #FFFFFF;
    box-shadow: 0 2px 8px rgba(60,110,245,0.3);
}

.item-card {
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    border-radius: 14px;
    overflow: hidden;
    text-align: left;
    transition: transform 0.08s ease, box-shadow 0.15s ease;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-sm);
    position: relative;
    color: var(--text-primary);
}
.item-card:active {
    transform: scale(0.97);
    box-shadow: var(--shadow-md);
}

.item-img {
    width: 100%;
    height: 110px;
    object-fit: cover;
    background: var(--bg-input);
}
.item-img-placeholder {
    width: 100%;
    height: 110px;
    background: linear-gradient(135deg, var(--bg-input) 0%, var(--bg-hover) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
}

.item-cat-label {
    position: absolute;
    top: 6px;
    left: 6px;
    background: rgba(60,110,245,0.92);
    color: #FFFFFF;
    font-size: 10px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
}

.item-name {
    padding: 8px 10px 0 10px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    line-height: 1.2;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    min-height: 32px;
}

.item-price {
    padding: 4px 10px 10px 10px;
    font-size: 14px;
    font-weight: 700;
    color: var(--brand);
}

/* ── Cart ───────────────────────────────────────────────────────────── */

.cart-flash { animation: cartFlashKf 0.25s ease; }
@keyframes cartFlashKf {
    0%   { background: var(--brand); }
    50%  { background: var(--brand-dark); transform: scale(1.02); }
    100% { background: var(--brand); transform: scale(1); }
}

.cart-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border-soft);
}
.cart-row:last-child { border-bottom: none; }

.cart-row-info { flex: 1; min-width: 0; }
.cart-row-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.cart-row-price {
    font-size: 12px;
    color: var(--text-secondary);
}
.cart-row-note {
    margin-top: 4px;
    font-size: 11px;
    color: #B45309;
    background: rgba(252, 211, 77, 0.18);
    padding: 4px 8px;
    border-radius: 8px;
    display: inline-block;
}
html.dark .cart-row-note {
    color: #FCD34D;
    background: rgba(252, 211, 77, 0.10);
}

.cart-row-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-shrink: 0;
}

.qty-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 18px;
    font-weight: 700;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.08s ease, background 0.15s ease;
}
.qty-btn:active { transform: scale(0.92); }

.qty-plus  { background: rgba(60,110,245,0.15); color: var(--brand); }
.qty-minus { background: var(--bg-input); color: var(--text-primary); }
.qty-del   { background: rgba(239,68,68,0.15); color: #DC2626; font-size: 16px; }
html.dark .qty-del { color: #F87171; }

.qty-num {
    min-width: 24px;
    text-align: center;
    font-weight: 700;
    color: var(--text-primary);
    font-size: 15px;
}

/* ── Item bottom sheet (qty circles) ────────────────────────────────── */

#cart-modal > div,
#item-sheet > div {
    animation: slideUpKf 0.22s ease;
}
@keyframes slideUpKf {
    from { transform: translateY(100%); }
    to   { transform: translateY(0); }
}

.qty-circle {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 26px;
    font-weight: 700;
    border: none;
    transition: transform 0.08s ease, background 0.15s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}
.qty-circle:active { transform: scale(0.92); }
.qty-circle-active {
    background: var(--brand);
    color: #FFFFFF;
    box-shadow: 0 4px 12px rgba(60,110,245,0.3);
}
.qty-circle-active:active { background: var(--brand-dark); }

/* ── Bottom navigation ──────────────────────────────────────────────── */

.nav-btn {
    background: transparent;
    border: none;
    padding: 10px 4px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    color: var(--text-muted);
    font-size: 11px;
    font-weight: 600;
    transition: color 0.15s ease, transform 0.08s ease;
    position: relative;
}
.nav-btn:active { transform: scale(0.94); }

.nav-icon-wrap {
    position: relative;
    line-height: 0;
    padding: 4px;
}

.nav-label {
    line-height: 1;
}

.nav-btn.nav-btn-active {
    color: var(--brand);
}
.nav-btn.nav-btn-active svg {
    stroke-width: 2.4;
}
/* Active dot indicator above icon */
.nav-btn.nav-btn-active::before {
    content: '';
    position: absolute;
    top: 4px;
    left: 50%;
    transform: translateX(-50%);
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--brand);
}

.nav-badge {
    position: absolute;
    top: -2px;
    right: -8px;
    background: #EF4444;
    color: #FFFFFF;
    font-size: 10px;
    font-weight: 700;
    border-radius: 999px;
    min-width: 18px;
    height: 18px;
    padding: 0 5px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 0 2px var(--bg-card);
}

@supports (padding: env(safe-area-inset-bottom)) {
    #bottom-nav { padding-bottom: env(safe-area-inset-bottom); }
}

/* ── Orders (My Orders screen) ──────────────────────────────────────── */

.order-card {
    background: var(--bg-card);
    border: 1px solid var(--border-soft);
    border-radius: 14px;
    padding: 14px;
    box-shadow: var(--shadow-sm);
    color: var(--text-primary);
}

.order-card-top {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 8px;
    gap: 8px;
}

.order-table-no {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
    margin-right: 8px;
}

.order-time {
    font-size: 11px;
    color: var(--text-muted);
}

.order-status {
    font-size: 11px;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 999px;
    white-space: nowrap;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    flex-shrink: 0;
}
.order-status-pending  { background: #FEF3C7; color: #92400E; }
.order-status-picked   { background: #D1FAE5; color: #065F46; }
.order-status-rejected { background: #FEE2E2; color: #991B1B; }
html.dark .order-status-pending  { background: rgba(252, 211, 77, 0.15); color: #FCD34D; }
html.dark .order-status-picked   { background: rgba(34, 197, 94, 0.15);  color: #4ADE80; }
html.dark .order-status-rejected { background: rgba(239, 68, 68, 0.15);  color: #F87171; }

.order-items {
    font-size: 13px;
    color: var(--text-secondary);
    margin-bottom: 6px;
    line-height: 1.4;
}

.order-reason {
    margin-top: 6px;
    background: rgba(239,68,68,0.10);
    color: #B91C1C;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 500;
}
html.dark .order-reason {
    background: rgba(239,68,68,0.10);
    color: #F87171;
}

.order-ticket {
    margin-top: 6px;
    background: rgba(34,197,94,0.10);
    color: #047857;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 12px;
    font-weight: 600;
    display: inline-block;
}
html.dark .order-ticket {
    background: rgba(34,197,94,0.10);
    color: #34D399;
}

.order-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px dashed var(--border);
}
.order-id {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 600;
}
.order-total {
    font-size: 17px;
    font-weight: 800;
    color: var(--brand);
}

/* ── Profile ────────────────────────────────────────────────────────── */

.profile-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    width: 100%;
    background: transparent;
    border: none;
    text-decoration: none;
    color: inherit;
    transition: background 0.15s ease;
}
.profile-row:hover,
.profile-row:active {
    background: var(--bg-hover);
}

.stat-tile {
    border-radius: 12px;
    padding: 12px;
}
.stat-value {
    font-size: 22px;
    font-weight: 800;
    line-height: 1.1;
}
.stat-label {
    font-size: 11px;
    color: var(--text-secondary);
    margin-top: 4px;
    font-weight: 500;
}
.stat-tile-brand  { background: var(--tile-brand); }
.stat-tile-green  { background: var(--tile-green); }
.stat-tile-yellow { background: var(--tile-yellow); }
.stat-tile-red    { background: var(--tile-red); }

/* Theme + Language picker tiles */
.theme-tile,
.lang-tile {
    background: var(--bg-input);
    border: 2px solid transparent;
    border-radius: 12px;
    padding: 14px 8px;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: var(--text-secondary);
    transition: all 0.15s ease;
    text-align: center;
}
.theme-tile:active,
.lang-tile:active { transform: scale(0.96); }
.theme-tile.active,
.lang-tile.active {
    background: var(--brand-light);
    border-color: var(--brand);
    color: var(--brand);
}
html.dark .theme-tile.active,
html.dark .lang-tile.active {
    background: var(--tile-brand);
}
.lang-tile span:nth-child(2) {
    line-height: 1.1;
}

/* ── Pull-to-refresh ────────────────────────────────────────────────── */

#ptr-indicator {
    transition: opacity 0.2s ease;
}

/* ── Misc ───────────────────────────────────────────────────────────── */

#toast {
    transition: opacity 0.2s ease;
}

input, textarea, select {
    font-size: 16px;
}

@supports (padding: env(safe-area-inset-top)) {
    body {
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
    }
    #cart-bar { padding-bottom: env(safe-area-inset-bottom); }
    #net-banner { padding-top: calc(8px + env(safe-area-inset-top)); }
}

/* Theme transition smooth (only on opt-in via JS to avoid initial flash) */
.theme-transitioning,
.theme-transitioning * {
    transition: background-color 0.25s ease, color 0.25s ease, border-color 0.25s ease !important;
}
