/* ── Reset & Variables ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #2d6a4f;
  --primary-dark: #1b4332;
  --primary-light: #74c69d;
  --accent: #f77f00;
  --accent-light: #fcbf49;
  --bg: #f4f6f9;
  --surface: #ffffff;
  --surface2: #f8f9fa;
  --border: #dee2e6;
  --text: #212529;
  --text-muted: #6c757d;
  --danger: #dc3545;
  --success: #198754;
  --warning: #ffc107;
  --info: #0dcaf0;
  --sidebar-w: 240px;
  --header-h: 56px;
  --radius: 8px;
  --shadow: 0 1px 4px rgba(0,0,0,.10);
  --shadow-md: 0 4px 12px rgba(0,0,0,.12);
  --transition: .18s ease;
}
html { font-size: 14px; }
body { font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
       background: var(--bg); color: var(--text); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
button { cursor: pointer; font: inherit; }
input, select, textarea { font: inherit; }

/* ── Layout ──────────────────────────────────────────────────────── */
#app { display: flex; min-height: 100vh; }

/* Sidebar */
#sidebar {
  width: var(--sidebar-w); background: var(--primary-dark); color: #fff;
  display: flex; flex-direction: column; position: fixed; top: 0; left: 0;
  height: 100vh; z-index: 100; transition: width var(--transition);
  overflow: hidden;
}
#sidebar.collapsed { width: 56px; }
#sidebar .brand {
  display: flex; align-items: center; gap: 10px; padding: 16px 14px;
  font-size: 1.1rem; font-weight: 700; white-space: nowrap;
  border-bottom: 1px solid rgba(255,255,255,.1);
}
#sidebar .brand .logo { font-size: 1.4rem; flex-shrink: 0; }
#sidebar .brand .brand-text { transition: opacity var(--transition); }
#sidebar.collapsed .brand-text { opacity: 0; pointer-events: none; }

#sidebar nav { flex: 1; overflow-y: auto; padding: 8px 0; }
#sidebar nav a {
  display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  color: rgba(255,255,255,.8); transition: background var(--transition), color var(--transition);
  white-space: nowrap;
}
#sidebar nav a:hover, #sidebar nav a.active {
  background: rgba(255,255,255,.12); color: #fff; text-decoration: none;
}
#sidebar nav a .nav-icon { font-size: 1.15rem; flex-shrink: 0; width: 24px; text-align: center; }
#sidebar nav a .nav-label { transition: opacity var(--transition); }
#sidebar.collapsed nav a .nav-label { opacity: 0; pointer-events: none; }
#sidebar nav .sep { border-top: 1px solid rgba(255,255,255,.08); margin: 6px 12px; }

/* Main content */
#main { margin-left: var(--sidebar-w); display: flex; flex-direction: column;
        min-height: 100vh; flex: 1; transition: margin-left var(--transition); }
#main.sidebar-collapsed { margin-left: 56px; }

/* Header */
#header {
  height: var(--header-h); background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 20px; gap: 12px;
  position: sticky; top: 0; z-index: 50;
}
#header .toggle-btn { background: none; border: none; font-size: 1.2rem; color: var(--text-muted); padding: 4px 8px; border-radius: 4px; }
#header .toggle-btn:hover { background: var(--bg); }
#header .page-title { font-weight: 600; font-size: 1rem; flex: 1; }
#header .header-right { display: flex; align-items: center; gap: 10px; }
#user-info { font-size: .85rem; color: var(--text-muted); }
#clock { font-size: .85rem; color: var(--text-muted); min-width: 80px; text-align: right; }

/* Page content */
#page { flex: 1; padding: 20px; }

/* ── Cards ────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 20px;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 16px; padding-bottom: 12px; border-bottom: 1px solid var(--border);
}
.card-title { font-size: 1rem; font-weight: 600; }
.stat-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card {
  background: var(--surface); border-radius: var(--radius); padding: 16px 20px;
  box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 4px;
}
.stat-card .stat-label { font-size: .8rem; color: var(--text-muted); }
.stat-card .stat-value { font-size: 1.6rem; font-weight: 700; color: var(--primary); }
.stat-card .stat-icon { font-size: 1.5rem; margin-bottom: 4px; }
.stat-card.accent .stat-value { color: var(--accent); }
.stat-card.success .stat-value { color: var(--success); }
.stat-card.danger .stat-value { color: var(--danger); }

/* ── Buttons ──────────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px;
  border-radius: 6px; border: 1px solid transparent; font-size: .9rem;
  font-weight: 500; transition: all var(--transition); white-space: nowrap;
}
.btn:hover { filter: brightness(.93); text-decoration: none; }
.btn:active { transform: scale(.97); }
.btn-primary   { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-accent    { background: var(--accent);  color: #fff; border-color: var(--accent); }
.btn-success   { background: var(--success); color: #fff; border-color: var(--success); }
.btn-danger    { background: var(--danger);  color: #fff; border-color: var(--danger); }
.btn-warning   { background: var(--warning); color: #333; border-color: var(--warning); }
.btn-outline   { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-ghost     { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-sm        { padding: 4px 10px; font-size: .82rem; }
.btn-lg        { padding: 11px 22px; font-size: 1rem; }
.btn-icon      { padding: 7px 9px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

/* ── Forms ────────────────────────────────────────────────────────── */
.form-row { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 14px; }
.form-group { display: flex; flex-direction: column; gap: 4px; flex: 1; min-width: 160px; }
.form-group.full { flex: 1 1 100%; }
.form-label { font-size: .85rem; font-weight: 500; color: var(--text); }
.form-label.required::after { content: ' *'; color: var(--danger); }
.form-control {
  padding: 8px 12px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--surface); color: var(--text); transition: border-color var(--transition);
  width: 100%;
}
.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(45,106,79,.15); }
.form-control.error { border-color: var(--danger); }
.form-hint { font-size: .78rem; color: var(--text-muted); }
.form-error { font-size: .78rem; color: var(--danger); }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236c757d' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }

/* ── Tables ───────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
thead th { background: var(--surface2); font-weight: 600; text-align: left; padding: 10px 12px; border-bottom: 2px solid var(--border); white-space: nowrap; }
tbody tr { border-bottom: 1px solid var(--border); transition: background var(--transition); }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 9px 12px; vertical-align: middle; }
.badge {
  display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: .75rem; font-weight: 600;
}
.badge-success  { background: #d1fae5; color: #065f46; }
.badge-danger   { background: #fee2e2; color: #991b1b; }
.badge-warning  { background: #fef9c3; color: #854d0e; }
.badge-info     { background: #e0f2fe; color: #075985; }
.badge-muted    { background: #f1f3f5; color: #495057; }
.badge-primary  { background: #d1fae5; color: var(--primary-dark); }

/* ── Modals ───────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200;
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-md);
  width: 100%; max-width: 520px; max-height: 90vh; display: flex; flex-direction: column;
}
.modal-lg { max-width: 780px; }
.modal-xl { max-width: 1000px; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-title { font-weight: 700; font-size: 1.05rem; }
.modal-close { background: none; border: none; font-size: 1.2rem; color: var(--text-muted); padding: 4px 8px; border-radius: 4px; }
.modal-close:hover { background: var(--bg); }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* ── Tabs ─────────────────────────────────────────────────────────── */
.tabs { display: flex; flex-wrap: wrap; border-bottom: 2px solid var(--border); margin-bottom: 20px; gap: 4px; }
.tab-btn {
  padding: 8px 16px; background: none; border: none; border-bottom: 3px solid transparent;
  font-size: .9rem; font-weight: 500; color: var(--text-muted); cursor: pointer;
  margin-bottom: -2px; transition: all var(--transition);
}
.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-pane { display: none; }
.tab-pane.active { display: block; }

/* ── Search & Filter bar ─────────────────────────────────────────── */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 16px; align-items: center; }
.search-box { position: relative; }
.search-box input { padding-left: 32px; }
.search-box::before { content: '🔍'; position: absolute; left: 8px; top: 50%; transform: translateY(-50%); font-size: .85rem; pointer-events: none; }

/* ── Alerts & Toast ──────────────────────────────────────────────── */
#toast-container { position: fixed; top: 70px; right: 20px; z-index: 300; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 12px 20px; border-radius: 8px; box-shadow: var(--shadow-md);
  font-size: .9rem; font-weight: 500; max-width: 320px;
  animation: slideIn .25s ease; display: flex; align-items: center; gap: 10px;
}
.toast.success { background: #d1fae5; color: #065f46; }
.toast.error   { background: #fee2e2; color: #991b1b; }
.toast.info    { background: #e0f2fe; color: #075985; }
.toast.warning { background: #fef9c3; color: #854d0e; }
@keyframes slideIn { from { transform: translateX(120%); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Pagination ──────────────────────────────────────────────────── */
.pagination { display: flex; align-items: center; gap: 4px; margin-top: 16px; flex-wrap: wrap; }
.page-btn {
  padding: 5px 10px; border: 1px solid var(--border); background: var(--surface);
  border-radius: 4px; cursor: pointer; font-size: .85rem; color: var(--text);
}
.page-btn:hover { background: var(--bg); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn[disabled] { opacity: .4; cursor: default; }

/* ── Misc helpers ─────────────────────────────────────────────────── */
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8  { gap: 8px; }
.gap-12 { gap: 12px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.text-center { text-align: center; }
.fw-bold { font-weight: 700; }
.text-danger  { color: var(--danger); }
.text-success { color: var(--success); }
.text-primary { color: var(--primary); }
.hidden { display: none !important; }
.loading { text-align: center; padding: 40px; color: var(--text-muted); font-size: 1.1rem; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
@media (max-width: 768px) {
  .grid-2,.grid-3,.grid-4 { grid-template-columns: 1fr; }
  #sidebar { width: 56px; }
  #main { margin-left: 56px; }
  #sidebar .brand-text,#sidebar nav a .nav-label { opacity: 0; pointer-events: none; }
  .stat-cards { grid-template-columns: 1fr 1fr; }
}

/* ── Login page ───────────────────────────────────────────────────── */
.login-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--primary-dark); }
.login-box { background: var(--surface); border-radius: 12px; padding: 40px; width: 360px; max-width: 95vw; box-shadow: var(--shadow-md); }
.login-box .login-logo { text-align: center; font-size: 2.5rem; margin-bottom: 8px; }
.login-box .login-title { text-align: center; font-size: 1.3rem; font-weight: 700; color: var(--primary-dark); margin-bottom: 4px; }
.login-box .login-sub { text-align: center; color: var(--text-muted); font-size: .85rem; margin-bottom: 24px; }

/* ── POS specific ─────────────────────────────────────────────────── */
.pos-layout { display: grid; grid-template-columns: 1fr 380px; gap: 16px; height: calc(100vh - var(--header-h) - 40px); }
.pos-menu-panel { overflow-y: auto; }
.pos-order-panel { display: flex; flex-direction: column; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.category-tabs { display: flex; gap: 6px; overflow-x: auto; padding: 12px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); margin-bottom: 12px; }
.cat-btn { padding: 8px 16px; border: 2px solid var(--border); background: var(--surface); border-radius: 20px; cursor: pointer; white-space: nowrap; font-size: .9rem; font-weight: 500; transition: all var(--transition); }
.cat-btn:hover, .cat-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.product-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; padding: 4px; }
.product-card { background: var(--surface); border: 2px solid var(--border); border-radius: 10px; padding: 14px 10px; cursor: pointer; text-align: center; transition: all var(--transition); user-select: none; box-shadow: var(--shadow); }
.product-card:hover { border-color: var(--primary); box-shadow: 0 4px 12px rgba(45,106,79,.2); transform: translateY(-2px); }
.product-card:active { transform: scale(.96); }
.product-card .p-name { font-weight: 600; font-size: .9rem; margin-bottom: 4px; }
.product-card .p-price { color: var(--accent); font-weight: 700; font-size: 1rem; }

.order-header { padding: 14px 16px; border-bottom: 1px solid var(--border); }
.order-items { flex: 1; overflow-y: auto; }
.order-item { display: flex; align-items: center; gap: 8px; padding: 10px 14px; border-bottom: 1px solid var(--border); }
.order-item .item-name { flex: 1; font-size: .9rem; font-weight: 500; }
.order-item .item-opts { font-size: .78rem; color: var(--text-muted); }
.order-item .item-qty { display: flex; align-items: center; gap: 4px; }
.qty-btn { width: 26px; height: 26px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); font-size: .9rem; font-weight: 700; cursor: pointer; }
.qty-btn:hover { background: var(--bg); }
.item-price { font-weight: 600; min-width: 60px; text-align: right; }
.order-footer { padding: 14px 16px; border-top: 2px solid var(--border); background: var(--surface2); }
.order-total { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.order-total .total-label { font-weight: 600; color: var(--text-muted); }
.order-total .total-amount { font-size: 1.6rem; font-weight: 800; color: var(--primary); }

/* ── KDS ─────────────────────────────────────────────────────────── */
.kds-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.kds-card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; border-left: 5px solid var(--border); }
.kds-card.status-open { border-left-color: var(--warning); }
.kds-card.status-cooking { border-left-color: var(--accent); }
.kds-card .kds-header { padding: 12px 14px; background: var(--surface2); display: flex; justify-content: space-between; align-items: center; }
.kds-card .kds-order-no { font-weight: 700; font-size: 1rem; }
.kds-card .kds-time { font-size: .8rem; color: var(--text-muted); }
.kds-card .kds-items { padding: 8px; }
.kds-item { display: flex; align-items: center; justify-content: space-between; padding: 7px 8px; border-radius: 6px; margin-bottom: 4px; background: var(--bg); cursor: pointer; transition: background var(--transition); }
.kds-item:hover { background: var(--border); }
.kds-item.done { opacity: .45; text-decoration: line-through; }
.kds-item .item-qty-badge { background: var(--primary); color: #fff; border-radius: 4px; padding: 1px 7px; font-size: .82rem; font-weight: 700; }
.kds-card .kds-actions { padding: 10px 14px; display: flex; gap: 8px; }
