:root {
  --bg:        #f1f5f9;
  --card:      #ffffff;
  --sidebar:   #0f172a;
  --text:      #0f172a;
  --muted:     #64748b;
  --border:    #e2e8f0;
  --primary:   #6366f1;
  --primary-h: #4f46e5;
  --green:     #10b981;
  --amber:     #f59e0b;
  --red:       #ef4444;
  --sw:        260px;
  --nh:        62px;
  --shadow: 0 12px 30px rgba(15,23,42,.12);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: "Inter", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}
[data-lucide] { width: 14px; height: 14px; stroke-width: 2; }
.layout { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sw);
  background: var(--sidebar);
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  gap: 2px;
  z-index: 200;
  overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 20px; border-bottom: 1px solid rgba(255,255,255,.07); margin-bottom: 6px; min-width: 0; }
.brand-mark { width: 30px; height: 30px; background: var(--primary); border-radius: 7px; display: grid; place-items: center; flex-shrink: 0; overflow: hidden; color:#fff; }
.brand-text { min-width: 0; flex: 1; }
.brand-name { font-size: .88rem; font-weight: 700; color: #fff; line-height: 1.2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub  { font-size: .7rem; color: rgba(255,255,255,.38); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-link { display: flex; align-items: center; gap: 9px; padding: 8px 12px; border-radius: 7px; text-decoration: none; font-size: .84rem; font-weight: 500; color: rgba(255,255,255,.5); transition: background .13s, color .13s; }
.nav-link:hover  { background: rgba(255,255,255,.07); color: rgba(255,255,255,.85); }
.nav-link.active { background: rgba(99,102,241,.25);  color: #fff; }
.nav-icon { width: 15px; height: 15px; display: grid; place-items: center; flex-shrink: 0; }
.sidebar-promo { margin-top: auto; padding-top: 16px; }
.sidebar-promo-inner { background: rgba(99,102,241,.15); border: 1px solid rgba(99,102,241,.25); border-radius: 10px; padding: 14px; }
.sidebar-promo-inner p:first-child { font-size: .8rem; font-weight: 700; color: #fff; margin-bottom: 4px; }
.sidebar-promo-inner p:last-of-type { font-size: .73rem; color: rgba(255,255,255,.45); line-height: 1.5; margin-bottom: 12px; }
.main { margin-left: var(--sw); flex: 1; display: flex; flex-direction: column; min-width: 0; }
.navbar {
  height: var(--nh);
  background: var(--card);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 24px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.menu-btn { display: none; width: 34px; height: 34px; border: 1px solid var(--border); background: var(--bg); border-radius: 7px; cursor: pointer; color: var(--muted); place-items: center; flex-shrink: 0; }
.nav-search { flex: 1; max-width: 300px; display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 7px 12px; position: relative; }
.nav-search input { border: none; background: none; outline: none; font-family: inherit; font-size: .83rem; color: var(--text); width: 100%; }
.nav-search input::placeholder { color: var(--muted); }
.nav-right { margin-left: auto; display: flex; align-items: center; gap: 8px; position: relative; }
.icon-btn { width: 34px; height: 34px; border-radius: 7px; border: 1px solid var(--border); background: var(--bg); cursor: pointer; display: grid; place-items: center; color: var(--muted); position: relative; transition: background .13s, color .13s; }
.icon-btn:hover { background: var(--border); color: var(--text); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--primary); color: #fff; font-size: .72rem; font-weight: 700; display: grid; place-items: center; cursor: pointer; border: none; font-family: inherit; }
.page { padding: 28px 24px; display: flex; flex-direction: column; gap: 22px; }
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.page-header h1 { font-size: 1.3rem; font-weight: 700; }
.page-header .sub { font-size: .82rem; color: var(--muted); margin-top: 3px; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 8px; font-family: inherit; font-size: .83rem; font-weight: 600; cursor: pointer; border: none; transition: background .13s; white-space: nowrap; text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-ghost { background: var(--card); color: var(--muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); }
.btn.action-delete { background: #fef2f2; color: #dc2626; border: 1px solid #fecaca; }
.btn.action-delete:hover { background: #fee2e2; color: #b91c1c; border-color: #fca5a5; }
.btn-promo { background: rgba(99,102,241,.2); color: #a5b4fc; border: 1px solid rgba(99,102,241,.3); width: 100%; justify-content: center; }
.btn-small { padding: 7px 12px; font-size: .76rem; }
.btn-full { width: 100%; justify-content: center; }
.backup-actions-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.stats.stats-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }
.stat { padding: 18px 20px; }
.stat-label { font-size: .73rem; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.stat-value { font-size: 1.9rem; font-weight: 800; margin: 8px 0 4px; line-height: 1; }
.table-card, .form-card, .settings-tabs-card { overflow: hidden; }
.notion-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.notion-toolbar-left { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; flex: 1; min-width: 0; }
.notion-toolbar-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.notion-search { display: flex; align-items: center; gap: 7px; background: var(--bg); border: 1px solid var(--border); border-radius: 7px; padding: 5px 10px; width: 200px; }
.notion-search input { border: none; background: none; outline: none; font: inherit; font-size: .8rem; color: var(--text); width: 100%; }
.notion-divider { width: 1px; height: 18px; background: var(--border); flex-shrink: 0; margin: 0 2px; }
.notion-filters { display: flex; align-items: center; gap: 3px; }
.notion-filter-btn { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 6px; border: 1px solid transparent; background: none; font: inherit; font-size: .76rem; font-weight: 500; color: var(--muted); cursor: pointer; white-space: nowrap; text-decoration: none; }
.notion-filter-btn.active { background: var(--bg); color: var(--text); font-weight: 600; border-color: var(--border); }
.notion-sort { display: flex; align-items: center; gap: 5px; background: var(--bg); border: 1px solid var(--border); border-radius: 7px; padding: 5px 9px; }
.notion-sort select { border: none; background: none; outline: none; font: inherit; font-size: .78rem; color: var(--text); cursor: pointer; }
.table-pager { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 12px 20px; border-top: 1px solid var(--border); }
.flash-wrap { display: flex; flex-direction: column; gap: 10px; }
.flash { border-radius: 8px; border: 1px solid transparent; padding: 10px 12px; font-size: .82rem; font-weight: 600; }
.flash-success { color: #166534; background: #f0fdf4; border-color: #bbf7d0; }
.flash-error { color: #991b1b; background: #fef2f2; border-color: #fecaca; }
.form-grid { display: grid; grid-template-columns: 1fr; gap: 12px; padding: 16px 20px 20px; }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field span { font-size: .73rem; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea { width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; font: inherit; font-size: .83rem; color: var(--text); background: #fff; }
.field input:focus, .field select:focus, .field textarea:focus { outline: 2px solid rgba(99,102,241,.2); border-color: var(--primary); }
.check-row { display: inline-flex; align-items: center; gap: 8px; font-size: .78rem; color: var(--muted); }
.empty-state { text-align: center; color: var(--muted); }
.table-wrap { overflow-x: auto; }
.settings-tabs { display: flex; align-items: center; gap: 8px; padding: 14px 16px; border-bottom: 1px solid var(--border); overflow-x: auto; }
.settings-tab { border: 1px solid var(--border); background: #fff; color: var(--muted); font: inherit; font-size: .8rem; font-weight: 600; padding: 7px 12px; border-radius: 8px; cursor: pointer; white-space: nowrap; text-decoration:none; }
.settings-tab.active { background: #eef2ff; border-color: #c7d2fe; color: #3730a3; }
.settings-submit-row, .drawer-submit-row { grid-column: 1 / -1; display: flex; justify-content: center; }
.drawer {
  position: fixed;
  inset: 0;
  z-index: 400;
  visibility: hidden;
  pointer-events: none;
}
.drawer.open { visibility: visible; pointer-events: auto; }
.drawer-overlay { position: absolute; inset: 0; background: rgba(15, 23, 42, .35); }
.drawer-panel {
  position: absolute;
  right: 0;
  top: 0;
  height: 100%;
  width: min(560px, 100%);
  background: #fff;
  border-left: 1px solid var(--border);
  box-shadow: -10px 0 25px rgba(15, 23, 42, .12);
  transform: translateX(100%);
  transition: transform .2s ease;
  overflow-y: auto;
}
.drawer.open .drawer-panel { transform: translateX(0); }
.drawer-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.drawer-head h2 { font-size: .94rem; font-weight: 700; }
.drawer-head .row-btn { width: auto; height: auto; min-height: 30px; padding: 6px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--card); color: var(--muted); display: inline-flex; align-items: center; justify-content: center; text-decoration:none; }
.drawer-form { padding-top: 14px; }
.drawer-divider { height: 1px; background: var(--border); margin: 6px 16px 0; }
.modal { position: fixed; inset: 0; z-index: 500; visibility: hidden; pointer-events: none; }
.modal.open { visibility: visible; pointer-events: auto; }
.modal-overlay { position: absolute; inset: 0; background: rgba(15, 23, 42, .45); }
.modal-panel { position: relative; width: min(520px, calc(100% - 24px)); margin: 8vh auto 0; background: #fff; border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 20px 45px rgba(15, 23, 42, .22); max-height: 86vh; display: flex; flex-direction: column; overflow: hidden; }

table { width: 100%; border-collapse: collapse; }
th { font-size: .7rem; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); padding: 10px 16px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { font-size: .855rem; color: var(--text); padding: 0 16px; height: 56px; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
th:not(:last-child), td:not(:last-child) { border-right: 1px solid var(--border); }
td.actions-cell { width: 1%; white-space: nowrap; padding-left: 8px; padding-right: 12px; position: sticky; right: 0; z-index: 2; background: #fff; box-shadow: -1px 0 0 var(--border); }
th:last-child { position: sticky; right: 0; z-index: 3; background: #fff; box-shadow: -1px 0 0 var(--border); }
tbody tr:hover { background: #f8fafc; }
tbody tr:hover td.actions-cell { background: #f8fafc; }
.row-actions { opacity: 1; transition: opacity .13s; display: flex; align-items: center; gap: 4px; justify-content: flex-end; }
.row-btn { width: 28px; height: 28px; border-radius: 6px; border: none; background: none; color: var(--muted); cursor: pointer; display: grid; place-items: center; }
.icon-btn [data-lucide],
.row-btn [data-lucide],
.action-icon-btn [data-lucide] { width: 13px; height: 13px; }
.tag { display: inline-flex; align-items: center; gap: 5px; padding: 4px 10px; border-radius: 999px; border: none; font-size: .73rem; font-weight: 600; }
.tag::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .7; }
.tag.confirmed { background: #f0fdf4; color: #16a34a; }
.tag.pending { background: #fffbeb; color: #d97706; }
.tag.cancelled { background: #fef2f2; color: #dc2626; }
.view-grid { padding: 14px 16px 16px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.view-item { display: flex; flex-direction: column; gap: 6px; }
.view-item.full { grid-column: 1 / -1; }
.view-item > span { font-size: .73rem; font-weight: 600; color: var(--muted); }
.view-value { min-height: 38px; border: 1px solid var(--border); border-radius: 8px; background: #fff; padding: 9px 10px; font-size: .83rem; display: flex; align-items: center; }
.view-actions { grid-column: 1 / -1; display: flex; justify-content: center; gap: 10px; }
.pager-pill { display: inline-flex; align-items: center; padding: 4px 10px; border-radius: 6px; font-size: .73rem; font-weight: 600; background: #f1f5f9; color: #475569; border: 1px solid #e2e8f0; }
.auth-shell { min-height: 100vh; background: radial-gradient(circle at top, #e0e7ff 0%, #f8fafc 45%, #f1f5f9 100%); display: grid; place-items: center; padding: 20px; }
.auth-card { width: min(420px, 100%); background: #fff; border: 1px solid var(--border); border-radius: 14px; box-shadow: 0 18px 40px rgba(15, 23, 42, .09); padding: 24px; display: flex; flex-direction: column; gap: 14px; }
.auth-card h1 { font-size: 1.35rem; font-weight: 800; }
.sub { font-size: .82rem; color: var(--muted); }
.action-icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.action-icon-btn:hover { background: var(--bg); border-color: #c7d0db; color: var(--text); }
.action-icon-view:hover { color: #0284c7; border-color: rgba(2,132,199,.35); background: rgba(2,132,199,.08); }
.action-icon-edit:hover { color: var(--primary); border-color: rgba(99,102,241,.35); background: rgba(99,102,241,.08); }
.action-icon-delete:hover { color: var(--red); border-color: rgba(239,68,68,.35); background: rgba(239,68,68,.08); }
.timeline { display: grid; gap: 10px; padding: 16px; }
.timeline-item { border: 1px solid var(--border); border-radius: 10px; padding: 10px 12px; display: grid; gap: 4px; }
.timeline-meta { font-size: .75rem; color: var(--muted); }
.kv-grid { display: grid; gap: 12px; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.compare-grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }

/* POS specific */
.pos-layout { display: grid; gap: 14px; grid-template-columns: 1.6fr 1fr; }
.pos-left, .pos-right { min-width: 0; }
.pos-categories { display: flex; gap: 8px; overflow-x: auto; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.pos-cat-btn { border: 1px solid var(--border); background: #fff; border-radius: 999px; padding: 6px 12px; font-size: .75rem; cursor: pointer; white-space: nowrap; }
.pos-cat-btn.active { background: #eef2ff; color: #312e81; border-color: #c7d2fe; }
.pos-grid { padding: 14px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; max-height: calc(100vh - 300px); overflow: auto; }
.pos-item { border: 1px solid var(--border); border-radius: 10px; background: #fff; padding: 12px; display: grid; gap: 8px; cursor: pointer; min-height: 100px; }
.pos-item:hover { border-color: #c7d2fe; box-shadow: 0 8px 20px rgba(99,102,241,.08); }
.pos-item h4 { font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pos-item p { font-size: .74rem; color: var(--muted); }
.pos-item .price { font-size: .9rem; font-weight: 700; }
.cart-card { display: grid; grid-template-rows: auto 1fr auto; max-height: calc(100vh - 150px); }
.cart-items { padding: 12px; overflow: auto; display: grid; gap: 8px; }
.cart-row { border: 1px solid var(--border); border-radius: 10px; padding: 10px; display: grid; gap: 8px; }
.cart-row-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.cart-row-title { font-size: .82rem; font-weight: 600; max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.qty-controls { display: flex; align-items: center; gap: 5px; }
.qty-btn { width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 7px; background: #fff; cursor: pointer; }
.qty-num { min-width: 24px; text-align: center; font-size: .82rem; }
.cart-foot { border-top: 1px solid var(--border); padding: 14px; display: grid; gap: 10px; }
.sum-row { display: flex; justify-content: space-between; font-size: .82rem; }
.sum-row.total { font-size: 1rem; font-weight: 800; }
.quick-actions { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.payment-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; padding: 16px; }
.payment-row { display: grid; gap: 6px; }
.receipt-wrap { max-width: 420px; margin: 20px auto; padding: 18px; border: 1px solid var(--border); border-radius: 12px; background: #fff; }
.receipt-line { display: flex; justify-content: space-between; gap: 8px; font-size: .82rem; padding: 4px 0; }
.receipt-head { text-align: center; display: grid; gap: 3px; margin-bottom: 10px; }
.text-truncate { max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

@media print {
  .no-print { display: none !important; }
  body { background: #fff; }
  .receipt-wrap { border: none; box-shadow: none; margin: 0 auto; }
}

@media (max-width: 1024px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stats.stats-5 { grid-template-columns: repeat(2, 1fr); }
  .form-grid-3, .form-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .notion-search { width: 160px; }
  .kv-grid, .compare-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pos-layout { grid-template-columns: 1fr; }
  .pos-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: none; }
  .cart-card { max-height: none; }
}

@media (max-width: 860px) {
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-btn { display: grid; }
}

@media (max-width: 540px) {
  .stats, .stats.stats-5 { grid-template-columns: 1fr; }
  .page { padding: 20px 16px; }
  .form-grid-3, .form-grid-2 { grid-template-columns: 1fr; }
  .notion-toolbar { flex-direction: column; align-items: flex-start; gap: 8px; }
  .notion-toolbar-right, .notion-search { width: 100%; }
  .table-pager { flex-direction: column; align-items: flex-start; }
  .view-grid, .kv-grid, .compare-grid { grid-template-columns: 1fr; }
  .pos-grid { grid-template-columns: 1fr; }
  .quick-actions { grid-template-columns: 1fr; }
  .payment-grid { grid-template-columns: 1fr; }
}
