:root {
    --blue: #2563eb;
    --blue-dark: #1d4ed8;
    --green: #16a34a;
    --green-light: #22c55e;
    --red: #dc2626;
    --gray-900: #111827;
    --gray-700: #374151;
    --gray-500: #6b7280;
    --gray-200: #e5e7eb;
    --gray-100: #f3f4f6;
    --bg: #f4f5f7;
    --radius: 12px;
    --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, "Segoe UI", "Sarabun", sans-serif;
    background: var(--bg);
    color: #1f2328;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
h1, h2, h3 { margin: 0; }

/* ---------- login ---------- */
.login-page {
    display: flex; align-items: center; justify-content: center; min-height: 100vh;
    background: linear-gradient(160deg, var(--blue) 0%, #1e3a8a 100%);
}
.login-box {
    background: #fff; padding: 36px 32px; border-radius: 16px;
    box-shadow: 0 20px 50px rgba(0,0,0,.25); width: 320px;
}
.login-box h1 { font-size: 21px; margin: 0 0 18px; color: var(--gray-900); }
.login-box label { display: block; font-size: 13px; margin: 14px 0 5px; color: var(--gray-700); }
.login-box input {
    width: 100%; padding: 11px 12px; border: 1px solid var(--gray-200); border-radius: 8px; font-size: 15px;
}
.login-box input:focus { outline: 2px solid var(--blue); outline-offset: 1px; }
.login-box button {
    margin-top: 22px; width: 100%; padding: 13px; border: none; border-radius: 8px;
    background: var(--blue); color: #fff; font-size: 15px; font-weight: 600; cursor: pointer;
    transition: background .15s;
}
.login-box button:hover { background: var(--blue-dark); }
.error { color: var(--red); font-size: 13px; }
.flash-ok { color: var(--green); font-size: 14px; font-weight: 600; }
.empty-hint { color: var(--gray-500); font-size: 14px; }

/* ---------- admin shell ---------- */
.topbar {
    display: flex; justify-content: space-between; align-items: center;
    background: var(--gray-900); color: #fff; padding: 14px 24px;
    position: sticky; top: 0; z-index: 10; box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.topbar a {
    text-decoration: none; color: #d1d5db; margin-left: 18px; font-size: 14px; font-weight: 500;
    transition: color .15s;
}
.topbar a:hover { color: #fff; }
.topbar a.active { color: #fff; border-bottom: 2px solid var(--blue); padding-bottom: 2px; }
.topbar .brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.topbar-logo { width: 26px; height: 26px; border-radius: 6px; object-fit: cover; }

.container { max-width: 1100px; margin: 0 auto; padding: 24px 20px 60px; }
.page-title { font-size: 22px; font-weight: 700; margin-bottom: 18px; color: var(--gray-900); }

.card {
    background: #fff; border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px;
    box-shadow: var(--shadow); border: 1px solid rgba(0,0,0,.03);
}
.card h3 { font-size: 16px; margin-bottom: 12px; color: var(--gray-900); }

.stat-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.stat-box {
    flex: 1; min-width: 170px; background: #fff; border-radius: var(--radius); padding: 18px;
    box-shadow: var(--shadow);
}
.stat-box .label { font-size: 13px; color: var(--gray-500); }
.stat-box .value { font-size: 28px; font-weight: 700; margin-top: 6px; color: var(--gray-900); }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 10px 10px; border-bottom: 1px solid var(--gray-100); }
th { color: var(--gray-500); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .03em; }
tr:last-child td { border-bottom: none; }

.btn {
    display: inline-block; padding: 9px 16px; border-radius: 8px; border: none;
    background: var(--blue); color: #fff; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none;
    transition: background .15s, transform .1s;
}
.btn:hover { background: var(--blue-dark); }
.btn:active { transform: scale(.97); }
.btn.secondary { background: var(--gray-500); }
.btn.secondary:hover { background: #55606e; }
.btn.danger { background: var(--red); }
.btn.danger:hover { background: #b91c1c; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn:disabled { background: var(--gray-200); color: var(--gray-500); cursor: not-allowed; }

.inline-form { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }

.form-row { margin-bottom: 12px; }
.form-row label { display: block; font-size: 13px; margin-bottom: 5px; color: var(--gray-700); }
.form-row input, .form-row select {
    width: 100%; padding: 9px 10px; border: 1px solid var(--gray-200); border-radius: 8px; font-size: 14px;
}
.form-row input:focus, .form-row select:focus { outline: 2px solid var(--blue); outline-offset: 1px; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge.open { background: #dcfce7; color: #166534; }
.badge.new { background: #fee2e2; color: #991b1b; }

/* ---------- menu management: item cards ---------- */
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 14px; margin-bottom: 16px; }
.item-edit-card {
    border: 1px solid var(--gray-100); border-radius: var(--radius); padding: 14px;
    display: flex; flex-direction: column; gap: 8px; background: #fafafa;
}
.item-thumb-wrap { position: relative; display: block; cursor: pointer; align-self: center; }
.item-thumb {
    width: 88px; height: 88px; border-radius: 10px; object-fit: cover; display: block;
    background: var(--gray-100);
}
.item-thumb-placeholder {
    width: 88px; height: 88px; border-radius: 10px; display: flex; align-items: center; justify-content: center;
    background: var(--gray-100); font-size: 32px;
}
.thumb-file-input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.thumb-edit-label {
    display: block; text-align: center; font-size: 11px; color: var(--blue); margin-top: 4px; font-weight: 600;
}
.item-name-input {
    width: 100%; padding: 7px 9px; border: 1px solid var(--gray-200); border-radius: 7px; font-size: 14px; font-weight: 600;
    text-align: center;
}
.price-input-wrap {
    display: flex; align-items: center; gap: 4px; justify-content: center; color: var(--blue); font-weight: 600;
}
.price-input-wrap input {
    width: 80px; padding: 6px 8px; border: 1px solid var(--gray-200); border-radius: 7px; font-size: 14px; text-align: center;
}
.item-status { text-align: center; }
.item-actions { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; }

.preview-banner {
    background: #111827; color: #fde68a; text-align: center; font-size: 12px; font-weight: 600;
    padding: 8px 12px;
}

/* ---------- customer ordering page ---------- */
.menu-page { max-width: 480px; margin: 0 auto; padding-bottom: 100px; background: #fff; min-height: 100vh; }
.menu-header {
    background: linear-gradient(135deg, var(--blue), var(--blue-dark)); color: #fff; padding: 20px 16px;
    text-align: center; position: sticky; top: 0; z-index: 5;
}
.menu-header .restaurant-logo {
    width: 64px; height: 64px; border-radius: 14px; object-fit: cover; margin-bottom: 8px;
    border: 2px solid rgba(255,255,255,.6);
}
.menu-header .table-label { font-size: 13px; opacity: .85; }
.menu-header .table-name { font-size: 24px; font-weight: 700; margin-top: 2px; }

.category-nav {
    display: flex; gap: 8px; overflow-x: auto; padding: 12px 16px; background: #fff;
    position: sticky; top: 76px; z-index: 4; border-bottom: 1px solid var(--gray-100);
    -ms-overflow-style: none; scrollbar-width: none;
}
.category-nav::-webkit-scrollbar { display: none; }
.category-nav a {
    flex-shrink: 0; padding: 7px 14px; border-radius: 20px; background: var(--gray-100); color: var(--gray-700);
    font-size: 13px; font-weight: 600; text-decoration: none; scroll-snap-align: start;
    transition: background .15s, color .15s;
}
.category-nav a.active { background: var(--blue); color: #fff; }

.category-title { padding: 18px 16px 6px; font-weight: 700; color: var(--gray-900); font-size: 16px; scroll-margin-top: 130px; }
.menu-item {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    background: #fff; margin: 8px 12px; padding: 10px; border-radius: var(--radius);
    box-shadow: var(--shadow); transition: box-shadow .2s;
}
.menu-item.bump { animation: item-bump .3s ease; }
@keyframes item-bump {
    0% { box-shadow: var(--shadow); }
    30% { box-shadow: 0 0 0 3px rgba(37,99,235,.35); }
    100% { box-shadow: var(--shadow); }
}
.menu-item-img {
    width: 60px; height: 60px; border-radius: 10px; object-fit: cover; flex-shrink: 0; background: var(--gray-100);
}
.menu-item-img-placeholder {
    width: 60px; height: 60px; border-radius: 10px; flex-shrink: 0; background: var(--gray-100);
    display: flex; align-items: center; justify-content: center; font-size: 24px;
}
.menu-item .info { flex: 1; min-width: 0; }
.menu-item .name { font-weight: 600; font-size: 15px; }
.menu-item .price { color: var(--blue); font-size: 14px; margin-top: 2px; font-weight: 600; }
.menu-item .item-note { color: var(--gray-500); font-size: 12px; margin-top: 2px; font-style: italic; }
.menu-item .sold-out-tag { color: var(--gray-500); font-size: 12px; }

.qty-control { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.qty-control button {
    width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--gray-200); background: #fff;
    font-size: 17px; cursor: pointer; line-height: 1; color: var(--gray-700);
}
.qty-control button:active { background: var(--gray-100); }
.qty-control span { min-width: 18px; text-align: center; font-weight: 600; }

.cart-bar {
    position: fixed; bottom: 0; left: 0; right: 0; background: var(--gray-900); color: #fff;
    padding: 14px 20px; display: flex; justify-content: space-between; align-items: center;
    box-shadow: 0 -4px 16px rgba(0,0,0,.15);
}
.cart-bar button {
    background: var(--green-light); color: #08300f; border: none; padding: 12px 20px; border-radius: 10px;
    font-weight: 700; font-size: 15px; cursor: pointer;
}
.cart-bar button:disabled { background: #4b5563; color: #9ca3af; }

.confirm-page { max-width: 480px; margin: 40px auto; padding: 0 16px; text-align: center; animation: confirm-fade-in .35s ease; }
.confirm-page .big-check { font-size: 60px; animation: confirm-pop .4s cubic-bezier(.34,1.56,.64,1); }
@keyframes confirm-fade-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes confirm-pop { from { transform: scale(.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.toast {
    position: fixed; left: 50%; bottom: 90px; transform: translate(-50%, 10px);
    background: var(--gray-900); color: #fff; padding: 11px 20px; border-radius: 30px;
    font-size: 13px; font-weight: 600; opacity: 0; pointer-events: none;
    transition: opacity .2s, transform .2s; z-index: 30; max-width: calc(100% - 40px); text-align: center;
    box-shadow: 0 8px 24px rgba(0,0,0,.25);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- dashboard order cards ---------- */
.order-card { position: relative; }
.order-card .table-heading { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.order-card .table-heading h3 { font-size: 17px; }
.order-card.flash { animation: flash-highlight 1.6s ease-out; }
@keyframes flash-highlight {
    0% { box-shadow: 0 0 0 4px rgba(37,99,235,.5); }
    100% { box-shadow: var(--shadow); }
}

/* ---------- checkout ---------- */
.checkout-page { max-width: 560px; }

.steps { display: flex; align-items: center; margin-bottom: 20px; }
.step { display: flex; flex-direction: column; align-items: center; gap: 6px; flex-shrink: 0; }
.step-circle {
    width: 30px; height: 30px; border-radius: 50%; background: var(--gray-200); color: var(--gray-500);
    display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px;
    transition: background .2s, color .2s;
}
.step-label { font-size: 11px; color: var(--gray-500); font-weight: 600; white-space: nowrap; }
.step.active .step-circle { background: var(--blue); color: #fff; }
.step.active .step-label { color: var(--blue); }
.step.done .step-circle { background: var(--green-light); color: #08300f; font-size: 0; }
.step.done .step-circle::after { content: '✓'; font-size: 14px; }
.step-line { flex: 1; height: 2px; background: var(--gray-200); margin: 0 8px 18px; }

.receipt-card h3 { margin-bottom: 4px; }
.receipt-list { margin-top: 8px; }
.receipt-row {
    display: flex; justify-content: space-between; gap: 12px; padding: 9px 0;
    border-bottom: 1px dashed var(--gray-200); font-size: 14px;
}
.receipt-row:last-child { border-bottom: none; }
.receipt-qty { color: var(--gray-500); font-size: 13px; }
.receipt-price { font-weight: 600; white-space: nowrap; }
.receipt-total {
    display: flex; justify-content: space-between; align-items: center; margin-top: 12px;
    padding-top: 14px; border-top: 2px solid var(--gray-900); font-weight: 700; font-size: 19px;
}

.payment-cards { display: flex; gap: 12px; margin-bottom: 4px; }
.payment-card {
    position: relative; flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px;
    padding: 16px 10px; border: 2px solid var(--gray-200); border-radius: var(--radius); cursor: pointer;
    transition: border-color .15s, background .15s;
}
.payment-card input { position: absolute; opacity: 0; pointer-events: none; }
.payment-icon { font-size: 26px; }
.payment-name { font-weight: 700; font-size: 14px; color: var(--gray-700); }
.payment-check {
    position: absolute; top: 8px; right: 8px; width: 18px; height: 18px; border-radius: 50%;
    background: var(--blue); color: #fff; font-size: 11px; display: none; align-items: center; justify-content: center;
}
.payment-card.selected { border-color: var(--blue); background: #eff6ff; }
.payment-card.selected .payment-check { display: flex; }
.payment-card.selected .payment-name { color: var(--blue); }

.cash-box { margin-top: 14px; padding: 14px; background: var(--gray-100); border-radius: 10px; }
.quick-cash { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.quick-cash-btn {
    padding: 7px 14px; border-radius: 20px; border: 1px solid var(--gray-200); background: #fff;
    font-size: 13px; font-weight: 600; color: var(--blue); cursor: pointer; transition: background .15s;
}
.quick-cash-btn:hover { background: #eff6ff; }
.change-display { font-size: 22px; font-weight: 700; margin-top: 10px; }
.change-display.negative { color: var(--red); }
.change-display.positive { color: var(--green); }

.closed-summary { text-align: center; }
.closed-badge { font-size: 17px; font-weight: 700; color: var(--green); margin-bottom: 12px; }
.closed-summary .receipt-row { text-align: left; }

/* ---------- history ---------- */
.history-card { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; }
.history-meta { color: var(--gray-500); font-size: 13px; margin-top: 4px; }
.history-total { text-align: right; font-weight: 700; font-size: 17px; }
.filter-bar { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 4px; }

/* ---------- footer ---------- */
.app-footer { text-align: center; padding: 22px 16px; font-size: 12px; color: var(--gray-500); }
.login-page .app-footer { position: fixed; bottom: 0; left: 0; right: 0; color: rgba(255,255,255,.75); }

/* ---------- orders queue page ---------- */
.page-title-row { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.page-title-row .page-title { margin-bottom: 0; }
.live-dot {
    width: 10px; height: 10px; border-radius: 50%; background: var(--green-light);
    box-shadow: 0 0 0 rgba(34,197,94,.6); animation: live-pulse 1.8s infinite;
}
@keyframes live-pulse {
    0% { box-shadow: 0 0 0 0 rgba(34,197,94,.5); }
    70% { box-shadow: 0 0 0 8px rgba(34,197,94,0); }
    100% { box-shadow: 0 0 0 0 rgba(34,197,94,0); }
}

.elapsed-badge {
    font-size: 12px; font-weight: 700; padding: 4px 10px; border-radius: 20px; white-space: nowrap;
}
.elapsed-badge.ok { background: #dcfce7; color: #166534; }
.elapsed-badge.warn { background: #fef3c7; color: #92400e; }
.elapsed-badge.late { background: #fee2e2; color: #991b1b; }

.order-card .table-heading h3 { display: flex; align-items: center; gap: 8px; }
.order-card-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; flex-wrap: wrap; gap: 10px; }
.order-total { font-weight: 700; margin: 0; }
.order-card-actions { display: flex; gap: 8px; }

tr.item-unseen { background: #eff6ff; }
.dot-new {
    display: inline-block; width: 7px; height: 7px; border-radius: 50%; background: var(--red);
    margin-left: 4px; vertical-align: middle;
}

.notice-banner {
    display: flex; justify-content: space-between; align-items: center; gap: 12px;
    background: #eff6ff; border: 1px solid #bfdbfe; color: var(--blue-dark);
    padding: 14px 18px; border-radius: var(--radius); margin-bottom: 20px;
    text-decoration: none; font-weight: 600; font-size: 14px; transition: background .15s;
}
.notice-banner:hover { background: #dbeafe; }
.notice-banner.alert { background: #fef3c7; border-color: #fde68a; color: #92400e; }
.notice-banner.alert:hover { background: #fde68a; }
.notice-banner-arrow { font-size: 13px; white-space: nowrap; }

/* ---------- sales trend chart ---------- */
.trend-chart { display: flex; align-items: flex-end; gap: 10px; height: 160px; padding-top: 10px; }
.trend-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; }
.trend-bar-wrap { flex: 1; width: 100%; display: flex; align-items: flex-end; justify-content: center; }
.trend-bar {
    width: 60%; min-width: 18px; background: linear-gradient(180deg, var(--blue), var(--blue-dark));
    border-radius: 6px 6px 0 0; transition: height .3s ease;
}
.trend-amount { font-size: 11px; color: var(--gray-500); margin-top: 6px; }
.trend-label { font-size: 12px; font-weight: 600; color: var(--gray-700); margin-top: 2px; }

/* ---------- confirm modal ---------- */
.modal-overlay {
    display: none; position: fixed; inset: 0; background: rgba(17,24,39,.55);
    align-items: center; justify-content: center; z-index: 50; padding: 16px;
}
.modal-overlay.open { display: flex; animation: modal-fade-in .15s ease; }
.modal-box {
    background: #fff; border-radius: 18px; padding: 26px; width: 100%; max-width: 360px;
    box-shadow: 0 24px 60px rgba(0,0,0,.3); text-align: center; animation: modal-pop .2s cubic-bezier(.34,1.56,.64,1);
}
@keyframes modal-fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-pop { from { transform: scale(.92); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.modal-icon { font-size: 38px; margin-bottom: 6px; }
.modal-box h3 { font-size: 17px; margin-bottom: 14px; }
.modal-summary { text-align: left; }
.modal-row {
    display: flex; justify-content: space-between; padding: 8px 0; border-bottom: 1px solid var(--gray-100);
    font-size: 14px;
}
.modal-row:last-child { border-bottom: none; }
.modal-row.highlight { color: var(--green); font-weight: 700; font-size: 16px; }
.modal-warning { font-size: 12px; color: var(--gray-500); margin: 14px 0 0; text-align: left; }
.modal-actions { display: flex; gap: 10px; margin-top: 18px; }
.modal-actions .btn { flex: 1; text-align: center; }

/* ---------- QR preview ---------- */
.preview-wrap { display: flex; flex-direction: column; align-items: center; text-align: center; }
.preview-wrap .empty-hint { max-width: 440px; margin-bottom: 20px; }
.phone-frame {
    position: relative; width: 320px; height: 650px; background: var(--gray-900); border-radius: 40px;
    padding: 14px; box-shadow: 0 20px 50px rgba(0,0,0,.3);
}
.phone-notch {
    position: absolute; top: 14px; left: 50%; transform: translateX(-50%); width: 120px; height: 22px;
    background: var(--gray-900); border-radius: 0 0 14px 14px; z-index: 2;
}
.phone-frame iframe {
    width: 100%; height: 100%; border: 0; border-radius: 26px; background: #fff; display: block;
}
.preview-actions { display: flex; gap: 10px; margin-top: 20px; flex-wrap: wrap; justify-content: center; }

/* ---------- history duration ---------- */
.history-duration { color: var(--gray-500); font-weight: 400; }
