:root {
  --primary: #F97316;
  --primary-dark: #EA580C;
  --primary-light: #FFEDD5;
  --primary-lighter: #FFF7ED;
  --white: #FFFFFF;
  --text: #1F2937;
  --text-muted: #6B7280;
  --border: #E5E7EB;
  --bg: #FAFAFA;
  --success: #16A34A;
  --success-light: #DCFCE7;
  --warning: #D97706;
  --warning-light: #FEF3C7;
  --danger: #DC2626;
  --danger-light: #FEE2E2;
  --info: #2563EB;
  --info-light: #DBEAFE;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 14px rgba(0,0,0,0.08);
  --sidebar-w: 232px;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; }
.material-symbols-outlined {
  font-family: 'Material Symbols Outlined';
  font-weight: normal;
  font-style: normal;
  font-size: 18px !important;
  line-height: 1;
  letter-spacing: normal;
  text-transform: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  -webkit-font-smoothing: antialiased;
}
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: #E5E7EB; border-radius: 8px; }
.hidden { display: none !important; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 16px; border-radius: var(--radius-sm); border: 1px solid transparent;
  font-size: 14px; font-weight: 600; transition: all .15s ease; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-secondary { background: var(--white); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--primary-lighter); border-color: var(--primary); }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--primary-lighter); color: var(--primary-dark); }
.btn-sm { padding: 6px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.icon-btn { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--border); background: #fff; display: inline-flex; align-items: center; justify-content: center; }
.icon-btn:hover { border-color: var(--primary); color: var(--primary); }

/* ---------- Login ---------- */
.login-body { background: linear-gradient(135deg, #FFF7ED 0%, #FFEDD5 100%); }
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-card { background: #fff; border-radius: 20px; box-shadow: var(--shadow-md); padding: 40px 36px; width: 100%; max-width: 380px; }
.login-brand { text-align: center; margin-bottom: 24px; }
.brand-mark { width: 56px; height: 56px; border-radius: 16px; background: var(--primary); color: #fff; font-size: 26px; font-weight: 800; display: flex; align-items: center; justify-content: center; margin: 0 auto 14px; }
.login-brand h1 { margin: 0; font-size: 26px; letter-spacing: 1px; color: var(--text); }
.login-brand .subtitle { margin: 4px 0 0; color: var(--text-muted); font-size: 13.5px; }
.login-brand .powered { margin: 10px 0 0; color: var(--primary); font-size: 11.5px; font-weight: 600; }
.login-form .field { margin-bottom: 16px; }
.login-hint { text-align: center; margin-top: 18px; font-size: 11.5px; color: var(--text-muted); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.field input, .field select, .field textarea {
  padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  font-size: 14px; background: #fff; color: var(--text); outline: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }
.form-error { background: var(--danger-light); color: var(--danger); padding: 8px 10px; border-radius: 8px; font-size: 12.5px; margin-bottom: 12px; }
.form-success { background: var(--success-light); color: var(--success); padding: 8px 10px; border-radius: 8px; font-size: 12.5px; margin-bottom: 12px; }
.form-row { display: flex; gap: 12px; }
.form-row .field { flex: 1; }

/* ---------- App layout ---------- */
.app-shell { display: flex; height: 100vh; overflow: hidden; }
.sidebar {
  width: var(--sidebar-w); background: #1C1208; color: #F3E9DD; flex-shrink: 0;
  display: flex; flex-direction: column; padding: 18px 12px; overflow-y: auto;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; }
.sidebar-brand .mark { width: 38px; height: 38px; background: var(--primary); border-radius: 10px; display: flex; align-items: center; justify-content: center; font-weight: 800; color: #fff; }
.sidebar-brand .name { font-size: 17px; font-weight: 800; letter-spacing: .5px; }
.sidebar-brand .tag { font-size: 10px; color: #C9A98B; }
.nav-list { list-style: none; margin: 0; padding: 0; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 10px;
  color: #E7D9C7; font-size: 13.5px; font-weight: 500; margin-bottom: 3px; transition: all .15s; cursor: pointer;
}
.nav-item:hover { background: #2A1D10; color: #fff; }
.nav-item.active { background: var(--primary); color: #fff; }
.nav-icon {
  width: 18px; height: 18px; display: inline-flex; align-items: center; justify-content: center;
  font-size: 18px; line-height: 1; color: inherit; flex-shrink: 0;
}
.sidebar-footer { padding: 10px; font-size: 10.5px; color: #9C8570; border-top: 1px solid #2A1D10; margin-top: 8px; }

.main-area { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  height: 60px; background: #fff; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 24px; flex-shrink: 0;
}
.topbar h2 { margin: 0; font-size: 18px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--text-muted); }
.user-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary-light); color: var(--primary-dark); display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px; }

.content { flex: 1; overflow-y: auto; padding: 22px 24px 40px; }
.page { display: none; }
.page.active { display: block; }

/* ---------- Cards / grids ---------- */
.card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.dashboard-stats { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.stat-card { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat-card .label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
.stat-card .value { font-size: 24px; font-weight: 800; margin-top: 6px; color: var(--text); }
.stat-card.accent .value { color: var(--primary); }
.stat-card.warn .value { color: var(--warning); }
.stat-card.danger .value { color: var(--danger); }
.stat-card.ok .value { color: var(--success); }

.section-title { font-size: 15px; font-weight: 700; margin: 0 0 12px; }
.drive-status { display: flex; align-items: flex-start; gap: 9px; padding: 10px 12px; margin: 0 0 14px; border: 1px solid var(--border); border-radius: 8px; font-size: 12px; }
.drive-status b { display: block; font-size: 12.5px; }
.drive-status small { display: block; margin-top: 3px; color: var(--text-muted); line-height: 1.35; }
.drive-status-dot { width: 9px; height: 9px; margin-top: 4px; border-radius: 50%; flex: 0 0 auto; background: var(--danger); }
.drive-status.connected { background: var(--success-light); border-color: #BBE7CF; }
.drive-status.connected .drive-status-dot { background: var(--success); }
.drive-status.disconnected { background: #FFF8F0; border-color: #F1D4B5; }
.drive-disconnect { margin-left: auto; flex-shrink: 0; }
.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }
@media (max-width: 1100px) { .two-col { grid-template-columns: 1fr; } }
.settings-grid { display: grid; grid-template-columns: minmax(0, 1.15fr) minmax(320px, .85fr); gap: 16px; align-items: start; }
.settings-column { display: grid; gap: 16px; align-content: start; min-width: 0; }
.settings-card { min-width: 0; }
.settings-card .section-title { padding-bottom: 11px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.settings-grid .form-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 14px; }
.settings-grid .form-row .field { min-width: 0; }
.settings-grid .field input, .settings-grid .field select { width: 100%; min-width: 0; }
.settings-grid .btn { min-height: 40px; }
.settings-support-details { display: grid; gap: 14px; }
.settings-support-details span { display: block; margin-bottom: 4px; color: var(--text-muted); font-size: 12px; }
.settings-support-details a { color: var(--text); font-weight: 600; text-decoration: none; }
.settings-support-details a:hover { color: var(--primary-dark); }
@media (max-width: 900px) { .settings-grid { grid-template-columns: minmax(0, 1fr); } }
@media (max-width: 520px) { .settings-grid .form-row { grid-template-columns: minmax(0, 1fr); gap: 0; } }
@media (max-width: 900px) { .dashboard-stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@media (max-width: 620px) { .dashboard-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; } }

/* ---------- Filters / toolbar ---------- */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 16px; }
.toolbar .search-box { position: relative; flex: 1; min-width: 200px; }
.toolbar input[type="text"], .toolbar input[type="search"], .toolbar select, .toolbar input[type="date"] {
  padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13.5px; background: #fff;
}
.toolbar input[type="text"] { width: 100%; }
.chip-filters { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { padding: 7px 14px; border-radius: 999px; border: 1px solid var(--border); background: #fff; font-size: 12.5px; font-weight: 600; color: var(--text-muted); }
.chip.active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: #fff; }
table.data-table { width: 100%; border-collapse: collapse; min-width: 640px; }
table.data-table th { text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); background: var(--primary-lighter); padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.data-table td { padding: 10px 14px; border-bottom: 1px solid #F1F1F1; font-size: 13.5px; vertical-align: middle; }
table.data-table tr:last-child td { border-bottom: none; }
table.data-table tr:hover td { background: #FFFBF5; }
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge.available, .badge.active, .badge.completed { background: var(--success-light); color: var(--success); }
.badge.low_stock { background: var(--warning-light); color: var(--warning); }
.badge.out_of_stock, .badge.disabled, .badge.cancelled { background: var(--danger-light); color: var(--danger); }
.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); font-size: 13.5px; }

/* ---------- Billing screen ---------- */
.billing-layout { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; height: calc(100vh - 122px); min-height: 430px; align-items: stretch; }
 .billing-mobile-tabs { display: none; }
.billing-left { display: flex; flex-direction: column; min-height: 0; height: 100%; }
.item-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; overflow-y: auto; padding: 2px; flex: 1; align-content: start; }
.item-card { background: #fff; border: 1px solid var(--border); border-radius: 10px; padding: 9px 8px 8px; cursor: pointer; transition: all .12s; text-align: left; min-height: 100px; height: 100px; display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start; }
.item-card:hover { border-color: var(--primary); box-shadow: 0 2px 8px rgba(249,115,22,.15); transform: translateY(-1px); }
.item-card:disabled, .item-card.out { opacity: .45; cursor: not-allowed; }
.item-card .iname { font-weight: 700; font-size: 12.8px; margin-bottom: 3px; line-height: 1.3; width: 100%; min-height: 33px; max-height: 33px; overflow: hidden; display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.item-card .iprice { color: var(--primary); font-weight: 700; font-size: 12.8px; }
.item-card .istock { font-size: 10.5px; color: var(--text-muted); margin-top: 2px; line-height: 1.3; }

.bill-panel { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); display: flex; flex-direction: column; box-shadow: var(--shadow); overflow: hidden; min-height: 0; height: 100%; max-height: 100%; }
.bill-header { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.bill-header .bnum { font-weight: 800; color: var(--primary); font-size: 15px; }
.bill-items { flex: 1 1 auto; overflow-y: auto; padding: 8px 12px; min-height: 150px; max-height: 100%; }
.bill-line { display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; align-items: center; padding: 8px 4px; border-bottom: 1px solid #F3F3F3; gap: 8px; }
.bill-line .bl-name { font-size: 12.8px; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bill-line .bl-price { font-size: 11.5px; color: var(--text-muted); margin-top: 3px; }
.qty-ctrl { display: flex; align-items: center; gap: 6px; }
.qty-ctrl button { width: 24px; height: 24px; border-radius: 6px; border: 1px solid var(--border); background: #fff; font-weight: 700; }
.qty-ctrl span { min-width: 18px; text-align: center; font-weight: 700; font-size: 13px; }
.bl-total { font-weight: 700; font-size: 12.8px; min-width: 64px; text-align: right; }
.bl-remove { color: var(--danger); background: none; border: none; font-size: 15px; padding: 2px 4px; }
.bill-summary { padding: 10px 14px; border-top: 1px solid var(--border); background: #FFFBF5; }
.sum-row { display: flex; justify-content: space-between; font-size: 12.8px; margin-bottom: 6px; color: var(--text-muted); }
.sum-row.grand { font-size: 17px; font-weight: 800; color: var(--text); border-top: 1px dashed var(--border); padding-top: 8px; margin-top: 4px; }
.bill-footer-actions { padding: 10px 14px 12px; display: flex; flex-direction: column; gap: 8px; border-top: 1px solid var(--border); }
.payment-methods { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 6px; }
.pm-btn { padding: 8px 4px; border-radius: 8px; border: 1px solid var(--border); background: #fff; font-size: 11.5px; font-weight: 700; text-align: center; }
.pm-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
@media (max-width: 1000px) {
  .billing-layout { grid-template-columns: minmax(0, 1fr); gap: 14px; height: auto; min-height: 0; max-height: none; align-items: start; }
  .billing-mobile-tabs { display: grid; grid-template-columns: minmax(0, .7fr) minmax(0, 1.3fr); gap: 4px; padding: 4px; border: 1px solid var(--border); border-radius: 10px; background: #F3F4F6; }
  .billing-mobile-tabs button { min-width: 0; min-height: 48px; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 7px 10px; border: 0; border-radius: 7px; background: transparent; color: var(--text-muted); font: inherit; font-weight: 600; }
  .billing-mobile-tabs button.active { background: #fff; color: var(--text); box-shadow: var(--shadow); }
  .mobile-bill-status { min-width: 0; display: flex; align-items: flex-end; flex-direction: column; gap: 1px; font-size: 10px; line-height: 1.2; }
  .mobile-bill-status b { color: var(--primary-dark); font-size: 12px; }
  .billing-layout[data-mobile-view="menu"] .bill-panel { display: none; }
  .billing-layout[data-mobile-view="cart"] .billing-left { display: none; }
  .billing-left { height: auto; min-height: 0; }
  .item-grid { flex: none; grid-template-columns: repeat(auto-fill, minmax(min(100%, 140px), 1fr)); overflow: visible; }
  .bill-panel { height: auto; max-height: none; min-height: 0; }
  .bill-items { flex: 0 1 auto; max-height: 320px; min-height: 110px; }
}
@media (max-width: 600px) {
  .billing-layout { gap: 12px; }
  .billing-left .toolbar { display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; }
  .billing-left .toolbar .search-box, .billing-left .toolbar > select { width: 100%; min-width: 0; }
  .item-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 0; }
  .item-card { height: 112px; min-height: 112px; padding: 11px 10px; border-radius: 8px; }
  .bill-panel { border-radius: 10px; }
  .bill-items { max-height: 36vh; min-height: 96px; padding: 6px 10px; }
  .bill-line {
    grid-template-columns: minmax(0, 1fr) auto 32px;
    grid-template-areas: "name quantity remove" "total quantity remove";
    gap: 2px 8px;
    padding: 10px 2px;
  }
  .bill-line > div:first-child { grid-area: name; min-width: 0; }
  .bill-line .qty-ctrl { grid-area: quantity; gap: 5px; }
  .bill-line .qty-ctrl button { width: 32px; height: 32px; border-radius: 8px; }
  .bill-line .bl-total { grid-area: total; min-width: 0; text-align: left; }
  .bill-line .bl-remove { grid-area: remove; width: 32px; height: 32px; align-self: center; border-radius: 8px; }
  .bill-summary { padding: 12px; }
  .bill-footer-actions { padding: 12px; }
  .payment-methods { gap: 8px; }
  .pm-btn { min-height: 44px; font-size: 13px; }
  #completeBillBtn { min-height: 48px; font-size: 15px; }
}

/* ---------- Modal ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 20px; }
.modal { background: #fff; border-radius: 16px; padding: 26px; width: 100%; max-width: 440px; max-height: 90vh; overflow-y: auto; box-shadow: var(--shadow-md); }
.modal.modal-lg { max-width: 640px; }
.modal h2 { margin: 0 0 6px; font-size: 18px; }
.modal-sub { color: var(--text-muted); font-size: 13px; margin: 0 0 16px; }
.modal-actions { display: flex; gap: 10px; margin-top: 16px; }
.modal-actions .btn { flex: 1; }
.modal-close { position: absolute; }

/* ---------- Toast ---------- */
#toastContainer { position: fixed; top: 18px; right: 18px; z-index: 200; display: flex; flex-direction: column; gap: 10px; align-items: flex-end; }
.toast {
  display: flex; align-items: center; gap: 10px; background: #1F2937; color: #fff; padding: 12px 16px; border-radius: 12px;
  font-size: 13px; box-shadow: var(--shadow-md); min-width: 220px; max-width: 320px; animation: slideIn .2s ease;
}
.toast-icon { font-size: 18px; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.warning { background: var(--warning); }
.toast.confirm { background: var(--info); }
.toast.info { background: #334155; }
@keyframes slideIn { from { opacity: 0; transform: translateX(16px); } to { opacity: 1; transform: translateX(0); } }

/* ---------- Misc ---------- */
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.muted { color: var(--text-muted); }
.text-right { text-align: right; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.tag-row { display: flex; gap: 8px; flex-wrap: wrap; }
.support-footer { text-align: center; font-size: 11.5px; color: var(--text-muted); margin-top: 24px; padding-top: 14px; border-top: 1px solid var(--border); }
.chart-box { background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding-top: 10px; }
.bar-chart .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; }
.bar-chart .bar { width: 100%; background: var(--primary); border-radius: 4px 4px 0 0; min-height: 2px; transition: height .3s; }
.bar-chart .bar-label { font-size: 9.5px; color: var(--text-muted); margin-top: 4px; white-space: nowrap; }
.responsive-hide-sm { }
@media (max-width: 720px) {
  :root { --sidebar-w: 0px; }
  .sidebar { position: fixed; left: -240px; top: 0; bottom: 0; z-index: 90; width: 232px; transition: left .2s; }
  .sidebar.open { left: 0; }
  .content { padding: 16px; }
}
