/* ─── TOKENS ────────────────────────────────────────────────────────────── */
:root {
  --bg:        #0f1117;
  --surface:   #181c25;
  --surface2:  #1e2330;
  --border:    #2a3045;
  --border-h:  #3a4260;
  --accent:    #4f7cff;
  --accent-d:  #3a62e0;
  --green:     #22c55e;
  --yellow:    #f59e0b;
  --red:       #ef4444;
  --text:      #e8ecf3;
  --text-muted:#8892a4;
  --text-dim:  #5a6478;
  --sidebar-w: 220px;
  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 4px 24px rgba(0,0,0,.45);
}

/* ─── RESET ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; background: var(--bg); color: var(--text); font-family: 'Inter', sans-serif; font-size: 14px; line-height: 1.5; }
input, select, textarea, button { font-family: inherit; font-size: inherit; }
a { text-decoration: none; color: inherit; }
svg { width: 18px; height: 18px; fill: currentColor; flex-shrink: 0; }
.hidden { display: none !important; }

/* ─── LOGIN ─────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 60% 30%, #1a2040 0%, var(--bg) 65%);
}
.login-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 40px; width: 360px; box-shadow: var(--shadow);
}
.login-logo { display: flex; align-items: center; gap: 14px; margin-bottom: 32px; }
.logo-mark {
  width: 44px; height: 44px; border-radius: 10px;
  background: var(--accent); color: #fff; font-weight: 700; font-size: 20px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.logo-mark.sm { width: 32px; height: 32px; font-size: 15px; border-radius: 7px; }
.login-title { font-size: 18px; font-weight: 700; }
.login-sub   { font-size: 12px; color: var(--text-muted); }

/* ─── LAYOUT ─────────────────────────────────────────────────────────────── */
#app { height: 100%; }
#main-app { display: flex; height: 100vh; }

/* ─── SIDEBAR ────────────────────────────────────────────────────────────── */
#sidebar {
  width: var(--sidebar-w); background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; flex-shrink: 0;
  padding: 0 0 16px;
}
.sidebar-logo {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 18px 12px; font-weight: 700; font-size: 16px;
  border-bottom: 1px solid var(--border); margin-bottom: 10px;
}
#sidebar-nav { flex: 1; padding: 0 10px; display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius-sm);
  color: var(--text-muted); font-size: 13.5px; font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-item:hover  { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(79,124,255,.15); color: var(--accent); }
.nav-item.active svg { color: var(--accent); }

.sidebar-footer {
  padding: 12px 14px 0; border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent-d); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; flex-shrink: 0;
}
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: var(--text-muted); text-transform: capitalize; }
#btn-logout {
  margin-left: auto; background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 4px; border-radius: 6px; display: flex;
}
#btn-logout:hover { color: var(--red); }

/* ─── CONTENT ────────────────────────────────────────────────────────────── */
#content-area { flex: 1; overflow-y: auto; padding: 28px 32px; }
.page { max-width: 1280px; margin: 0 auto; }

/* ─── PAGE HEADER ────────────────────────────────────────────────────────── */
.page-header { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.page-title  { font-size: 22px; font-weight: 700; flex: 1; }
.page-subtitle { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* ─── STATS GRID ─────────────────────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px,1fr)); gap: 16px; margin-bottom: 28px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 20px 22px;
}
.stat-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 8px; }
.stat-value { font-size: 30px; font-weight: 700; line-height: 1; }
.stat-value.green  { color: var(--green); }
.stat-value.yellow { color: var(--yellow); }
.stat-value.red    { color: var(--red); }
.stat-value.blue   { color: var(--accent); }

/* ─── TABLE CARD ─────────────────────────────────────────────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden; margin-bottom: 20px;
}
.card-header {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.card-title { font-weight: 600; font-size: 14px; flex: 1; }
.card-body  { padding: 20px; }

/* ─── TABLE ──────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  padding: 10px 14px; text-align: left;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
td {
  padding: 12px 14px; border-bottom: 1px solid var(--border);
  font-size: 13px; vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface2); }
.mono { font-family: 'JetBrains Mono', monospace; font-size: 12px; }

/* ─── FORMS ──────────────────────────────────────────────────────────────── */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; }
input[type=text], input[type=password], input[type=email], input[type=number],
input[type=date], select, textarea {
  background: var(--surface2); border: 1px solid var(--border);
  color: var(--text); border-radius: var(--radius-sm);
  padding: 9px 12px; outline: none; transition: border .15s;
  width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 14px; }
.err-msg { background: rgba(239,68,68,.12); border: 1px solid rgba(239,68,68,.3); border-radius: var(--radius-sm); padding: 9px 12px; color: var(--red); font-size: 13px; margin-bottom: 12px; }

/* ─── BUTTONS ────────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--accent); color: #fff; border: none;
  padding: 9px 18px; border-radius: var(--radius-sm); font-weight: 600;
  cursor: pointer; transition: background .15s; display: inline-flex; align-items: center; gap: 7px;
}
.btn-primary:hover { background: var(--accent-d); }
.btn-secondary {
  background: var(--surface2); color: var(--text); border: 1px solid var(--border);
  padding: 9px 18px; border-radius: var(--radius-sm); font-weight: 500;
  cursor: pointer; transition: background .15s; display: inline-flex; align-items: center; gap: 7px;
}
.btn-secondary:hover { background: var(--border); }
.btn-danger {
  background: rgba(239,68,68,.12); color: var(--red); border: 1px solid rgba(239,68,68,.25);
  padding: 6px 12px; border-radius: var(--radius-sm); font-weight: 500; cursor: pointer;
  font-size: 12px;
}
.btn-sm { padding: 5px 10px !important; font-size: 12px !important; }
.w-full { width: 100%; justify-content: center; }

/* ─── TOOLBAR ────────────────────────────────────────────────────────────── */
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.search-box {
  flex: 1; min-width: 200px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 12px; color: var(--text); outline: none;
}
.search-box:focus { border-color: var(--accent); }
.filter-select {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 8px 10px; color: var(--text);
}

/* ─── BADGES ─────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; justify-content: center;
  padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600;
}
.badge-green  { background: rgba(34,197,94,.15);   color: var(--green); }
.badge-yellow { background: rgba(245,158,11,.15);  color: var(--yellow); }
.badge-red    { background: rgba(239,68,68,.15);   color: var(--red); }
.badge-blue   { background: rgba(79,124,255,.15);  color: var(--accent); }
.badge-gray   { background: rgba(138,146,164,.15); color: var(--text-muted); }

/* ─── MODAL ──────────────────────────────────────────────────────────────── */
#modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.65);
  display: flex; align-items: center; justify-content: center; z-index: 1000;
}
#modal-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; width: min(600px, 95vw); max-height: 90vh;
  display: flex; flex-direction: column; box-shadow: var(--shadow);
}
#modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: 16px;
}
#modal-close {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 18px; line-height: 1;
}
#modal-close:hover { color: var(--text); }
#modal-body { padding: 22px; overflow-y: auto; }

/* ─── CAMERA SCANNER ─────────────────────────────────────────────────────── */
#scanner-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.8);
  display: flex; align-items: center; justify-content: center; z-index: 1100;
}
#scanner-box {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; width: min(420px, 95vw);
  display: flex; flex-direction: column; box-shadow: var(--shadow); overflow: hidden;
}
#scanner-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  font-weight: 700; font-size: 16px;
}
#scanner-close {
  background: none; border: none; color: var(--text-muted); cursor: pointer;
  font-size: 18px; line-height: 1;
}
#scanner-close:hover { color: var(--text); }
#qr-reader { width: 100%; }
#qr-reader video { width: 100% !important; border-radius: 0; }
#scanner-hint { text-align: center; padding: 12px 22px 18px; font-size: 12px; }
.btn-scan-inline {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; flex-shrink: 0; padding: 0; font-size: 16px;
}

/* ─── PRODUCT SEARCH DROPDOWN ────────────────────────────────────────────── */
.search-dropdown-wrap { position: relative; }
.search-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0; z-index: 50;
  background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  box-shadow: var(--shadow); max-height: 240px; overflow-y: auto;
}
.search-dropdown-item { padding: 9px 12px; cursor: pointer; font-size: 13px; border-bottom: 1px solid var(--border); }
.search-dropdown-item:last-child { border-bottom: none; }
.search-dropdown-item:hover { background: var(--surface); }
.search-dropdown-item .sd-sub { color: var(--text-muted); font-size: 11px; margin-top: 2px; }
.search-dropdown-empty { padding: 10px 12px; color: var(--text-muted); font-size: 12px; }

/* ─── TOAST ──────────────────────────────────────────────────────────────── */
#toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 2000; }
.toast {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 12px 18px;
  font-size: 13px; font-weight: 500; max-width: 320px;
  animation: slide-in .2s ease; box-shadow: var(--shadow);
}
.toast.success { border-color: rgba(34,197,94,.4); color: var(--green); }
.toast.error   { border-color: rgba(239,68,68,.4); color: var(--red); }
@keyframes slide-in { from { transform: translateX(40px); opacity:0; } to { transform: none; opacity:1; } }

/* ─── MISC ───────────────────────────────────────────────────────────────── */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.section-title { font-size: 13px; font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); margin-bottom: 12px; }
.empty-state { padding: 48px; text-align: center; color: var(--text-muted); }
.empty-state svg { width: 40px; height: 40px; margin-bottom: 12px; opacity: .3; }
.photo-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.photo-thumb { width: 80px; height: 80px; border-radius: var(--radius-sm); object-fit: cover; border: 1px solid var(--border); }
.qty-num { font-family: 'JetBrains Mono', monospace; font-weight: 700; font-size: 18px; }
.text-muted { color: var(--text-muted); }
.text-green  { color: var(--green); }
.text-red    { color: var(--red); }
.text-yellow { color: var(--yellow); }
.flex-gap { display: flex; align-items: center; gap: 8px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-12 { margin-bottom: 12px; }
.scan-area { border: 2px dashed var(--border); border-radius: var(--radius); padding: 20px; text-align: center; cursor: pointer; transition: border-color .15s; }
.scan-area:hover { border-color: var(--accent); }
.tag { display: inline-block; background: var(--surface2); border: 1px solid var(--border); border-radius: 4px; padding: 2px 7px; font-size: 11px; font-family: 'JetBrains Mono', monospace; }

/* ─── STORE TABS ─────────────────────────────────────────────────────────── */
.store-tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.store-tab {
  padding: 7px 16px; border-radius: 20px; font-size: 13px; font-weight: 500;
  cursor: pointer; border: 1px solid var(--border); background: var(--surface);
  transition: all .15s; color: var(--text-muted);
}
.store-tab.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ─── LOCATION TREE ──────────────────────────────────────────────────────── */
.loc-tree { list-style: none; }
.loc-item { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); margin-bottom: 6px; display: flex; align-items: center; gap: 10px; }
.loc-item .loc-name { flex: 1; font-weight: 500; }
.loc-path { font-size: 11px; color: var(--text-muted); }
.loc-children { margin-left: 24px; margin-top: 6px; }

@media (max-width: 768px) {
  :root { --sidebar-w: 0px; }
  #sidebar { display: none; }
  #content-area { padding: 16px; }
  .form-row, .form-row-3, .two-col { grid-template-columns: 1fr; }
}
