/* ── TOKENS ──────────────────────────────────────────── */
:root {
  --bg:        #f4f5f7;
  --bg-white:  #ffffff;
  --bg-off:    #f9fafb;

  --border:    #e2e5ea;
  --border-dk: #cdd1d9;

  --text:      #1a1d23;
  --text-2:    #5a6070;
  --text-3:    #9ba3b0;

  --blue:      #2563eb;
  --blue-lt:   #eff4ff;
  --blue-dk:   #1d4ed8;

  --green:     #16a34a;
  --green-lt:  #f0fdf4;
  --amber:     #d97706;
  --amber-lt:  #fffbeb;
  --red:       #dc2626;
  --red-lt:    #fef2f2;

  --sidebar-w: 220px;
  --topbar-h:  56px;
  --radius:    10px;
  --radius-sm: 6px;
  --shadow:    0 1px 4px rgba(0,0,0,.08), 0 4px 16px rgba(0,0,0,.04);
}

/* ── RESET ───────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; overflow-x: hidden; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
  line-height: 1.5;
}
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; border: none; background: none; font-family: inherit; font-size: inherit; }
input, select, textarea { font-family: inherit; font-size: inherit; }
svg { display: block; }

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-dk); border-radius: 99px; }

/* ── SIDEBAR ─────────────────────────────────────────── */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-white);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  z-index: 100;
  transition: transform .25s ease;
}

.sidebar-logo {
  display: flex; align-items: center; gap: .6rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid var(--border);
}
.logo-icon {
  width: 32px; height: 32px;
  background: var(--blue);
  border-radius: 8px;
  display: grid; place-items: center;
  flex-shrink: 0;
}
.logo-icon svg { width: 16px; height: 16px; color: #fff; }
.logo-text {
  font-size: 1rem; font-weight: 700; color: var(--text);
  letter-spacing: -.01em;
}

.sidebar-nav {
  flex: 1; padding: .75rem .6rem;
  display: flex; flex-direction: column; gap: 2px;
  overflow-y: auto;
}

.nav-item {
  display: flex; align-items: center; gap: .65rem;
  padding: .55rem .75rem;
  border-radius: var(--radius-sm);
  color: var(--text-2);
  font-size: .875rem; font-weight: 500;
  transition: background .12s, color .12s;
  text-align: left; width: 100%;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--blue-lt); color: var(--blue); font-weight: 600; }
.nav-item .badge {
  margin-left: auto; background: var(--red);
  color: #fff; font-size: .68rem; font-weight: 700;
  border-radius: 99px; padding: 1px 6px; min-width: 18px; text-align: center;
}

.sidebar-footer {
  padding: .75rem 1.1rem;
  border-top: 1px solid var(--border);
}
.connection-status {
  display: flex; align-items: center; gap: .45rem;
  font-size: .78rem; color: var(--text-3);
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--border-dk); flex-shrink: 0;
  transition: background .3s;
}
.status-dot.connected { background: var(--green); }
.status-dot.error     { background: var(--red); }

.sidebar-footer { display: flex; flex-direction: column; gap: .5rem; }
.user-info {
  display: flex; align-items: center; gap: .45rem;
  font-size: .78rem; color: var(--text-2);
  padding-bottom: .5rem; border-bottom: 1px solid var(--border);
}
.user-info svg { width: 14px; height: 14px; flex-shrink: 0; color: var(--text-3); }
.user-email {
  flex: 1; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; font-size: .76rem;
}
.logout-btn {
  margin-left: auto; padding: .2rem .3rem;
  border-radius: 4px; color: var(--text-3);
  transition: background .12s, color .12s;
}
.logout-btn:hover { background: var(--red-lt); color: var(--red); }
.logout-btn svg { width: 14px; height: 14px; }

/* ── MAIN ────────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  flex: 1; display: flex; flex-direction: column; min-height: 100vh;
  max-width: calc(100vw - var(--sidebar-w));
  overflow-x: hidden;
}

/* ── TOPBAR ──────────────────────────────────────────── */
.topbar {
  position: sticky; top: 0; z-index: 50;
  height: var(--topbar-h);
  background: var(--bg-white);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .75rem;
  padding: 0 1.5rem;
}
.menu-toggle { display: none; color: var(--text-2); padding: .25rem; }
.menu-toggle svg { width: 20px; height: 20px; }
.topbar-title { font-size: .95rem; font-weight: 700; flex: 1; }
.topbar-date { font-size: .78rem; color: var(--text-3); }

/* ── VIEWS ───────────────────────────────────────────── */
.view { display: none; padding: 1.5rem; flex-direction: column; gap: 1.25rem; max-width: 100%; }
.view.active { display: flex; animation: fadeUp .18s ease; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(5px); } to { opacity: 1; transform: none; } }

/* ── STATS ───────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 1rem;
}
.stat-card {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  display: flex; align-items: flex-start; gap: .85rem;
  box-shadow: var(--shadow);
}
.stat-icon {
  width: 40px; height: 40px; border-radius: 9px;
  display: grid; place-items: center; flex-shrink: 0;
  margin-top: .1rem;
}
.stat-icon svg { width: 19px; height: 19px; }
.stat-icon.purple { background: #eef2ff; color: #4f46e5; }
.stat-icon.amber  { background: var(--amber-lt); color: var(--amber); }
.stat-icon.red    { background: var(--red-lt); color: var(--red); }
.stat-icon.green  { background: var(--green-lt); color: var(--green); }
.stat-info { display: flex; flex-direction: column; gap: .15rem; min-width: 0; }
.stat-label { font-size: .72rem; color: var(--text-3); font-weight: 500; white-space: nowrap; }
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--text); line-height: 1.15; }

/* ── DASH GRID ───────────────────────────────────────── */
.dash-grid { display: grid; grid-template-columns: 1fr 300px; gap: 1rem; }
@media (max-width: 900px) { .dash-grid { grid-template-columns: 1fr; } }

/* ── CARD ────────────────────────────────────────────── */
.card {
  background: var(--bg-white);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.1rem 1.25rem;
  box-shadow: var(--shadow);
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: .85rem;
}
.card-header h3 { font-size: .875rem; font-weight: 700; }
.btn-link {
  font-size: .8rem; color: var(--blue); font-weight: 600;
  background: none; border: none; cursor: pointer;
}
.btn-link:hover { text-decoration: underline; }

/* ── TABLES ──────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .84rem; }
thead th {
  text-align: left; font-size: .72rem; font-weight: 600; color: var(--text-3);
  text-transform: uppercase; letter-spacing: .05em;
  padding: .55rem .75rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-off);
  white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-off); }
tbody td { padding: .7rem .75rem; vertical-align: middle; }
.loading-row { text-align: center; color: var(--text-3); padding: 2rem!important; font-size: .85rem; }
.empty-row { text-align: center; color: var(--text-3); padding: 2.5rem!important; font-size: .85rem; }

/* ── STATUS BADGES ───────────────────────────────────── */
.badge-status {
  display: inline-flex; align-items: center;
  font-size: .72rem; font-weight: 600; border-radius: 4px;
  padding: .2rem .55rem;
}
.badge-status.active       { background: var(--green-lt); color: var(--green); }
.badge-status.low_stock    { background: var(--amber-lt); color: var(--amber); }
.badge-status.out_of_stock { background: var(--red-lt); color: var(--red); }
.badge-status.inactive     { background: var(--bg); color: var(--text-3); }
.badge-status.discontinued { background: var(--red-lt); color: var(--red); }

/* ── CATEGORY CHART ──────────────────────────────────── */
.cat-chart { display: flex; flex-direction: column; gap: .7rem; margin-top: .25rem; }
.cat-row { display: flex; flex-direction: column; gap: .3rem; }
.cat-label-row { display: flex; justify-content: space-between; font-size: .78rem; }
.cat-name { color: var(--text-2); }
.cat-count { color: var(--text); font-weight: 600; }
.cat-bar-track { height: 5px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.cat-bar-fill  { height: 100%; background: var(--blue); border-radius: 99px; transition: width .5s ease; }

/* ── TOOLBAR ─────────────────────────────────────────── */
.toolbar { display: flex; align-items: center; gap: .65rem; flex-wrap: wrap; }
.search-wrap { position: relative; flex: 1; min-width: 180px; }
.search-wrap svg {
  position: absolute; left: .65rem; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--text-3); pointer-events: none;
}
.search-wrap input {
  width: 100%; padding: .55rem .75rem .55rem 2.1rem;
  background: var(--bg-white); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  outline: none; transition: border-color .12s;
}
.search-wrap input:focus { border-color: var(--blue); }
.filter-select {
  padding: .55rem .75rem;
  background: var(--bg-white); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  outline: none; cursor: pointer; transition: border-color .12s;
}
.filter-select:focus { border-color: var(--blue); }

/* ── TABLE CARD ──────────────────────────────────────── */
.table-card { padding: 0; overflow: hidden; }
.table-card table { font-size: .82rem; }
.table-card tbody td { padding: .75rem 1rem; }
.table-card thead th { padding: .7rem 1rem; }

.action-btn {
  padding: .3rem .65rem; border-radius: 4px; font-size: .77rem; font-weight: 600;
  transition: background .12s;
}
.action-btn.edit   { background: var(--blue-lt); color: var(--blue); }
.action-btn.edit:hover { background: #dbeafe; }
.action-btn.delete { background: var(--red-lt); color: var(--red); margin-left: .3rem; }
.action-btn.delete:hover { background: #fecaca; }

.pagination {
  display: flex; align-items: center; justify-content: flex-end; gap: .4rem;
  padding: .75rem 1rem; border-top: 1px solid var(--border);
  font-size: .8rem; color: var(--text-2);
}
.pg-btn {
  padding: .3rem .65rem; background: var(--bg-white);
  border: 1px solid var(--border); border-radius: 4px;
  color: var(--text); font-size: .78rem;
  transition: background .12s, border-color .12s;
}
.pg-btn:hover:not(:disabled) { border-color: var(--blue); color: var(--blue); }
.pg-btn:disabled { opacity: .4; cursor: not-allowed; }
.pg-btn.active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ── FORM ────────────────────────────────────────────── */
.form-container { max-width: 820px; }
.form-header { margin-bottom: 1.25rem; }
.form-header h2 { font-size: 1.2rem; font-weight: 700; margin-bottom: .2rem; }
.form-header p  { color: var(--text-2); font-size: .85rem; }

fieldset {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 1.25rem; margin-bottom: 1rem;
  background: var(--bg-white); box-shadow: var(--shadow);
}
legend {
  font-size: .72rem; font-weight: 700; color: var(--blue);
  text-transform: uppercase; letter-spacing: .07em;
  padding: 0 .4rem; background: var(--bg-white);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .85rem; margin-top: .85rem; }
.field { display: flex; flex-direction: column; gap: .35rem; }
.field.full-width { grid-column: 1 / -1; }

label { font-size: .8rem; font-weight: 600; color: var(--text-2); }
.req  { color: var(--red); }

input[type="text"], input[type="number"], input[type="url"],
input[type="date"], select, textarea {
  padding: .55rem .75rem;
  background: var(--bg-white); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text);
  outline: none; transition: border-color .12s, box-shadow .12s;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37,99,235,.1);
}
input.invalid, select.invalid { border-color: var(--red); }
textarea { resize: vertical; }
select option { background: var(--bg-white); }

.error-msg { font-size: .74rem; color: var(--red); min-height: 1em; }

.form-actions { display: flex; gap: .65rem; justify-content: flex-end; margin-top: 1.25rem; }

.btn-primary {
  padding: .6rem 1.25rem; border-radius: var(--radius-sm);
  background: var(--blue); color: #fff;
  font-weight: 600; font-size: .875rem;
  display: inline-flex; align-items: center; gap: .45rem;
  transition: background .12s;
}
.btn-primary:hover { background: var(--blue-dk); }
.btn-primary:active { background: #1e40af; }

.btn-secondary {
  padding: .6rem 1.25rem; border-radius: var(--radius-sm);
  background: var(--bg-white); border: 1px solid var(--border);
  color: var(--text); font-weight: 600; font-size: .875rem;
  transition: background .12s, border-color .12s;
}
.btn-secondary:hover { background: var(--bg); border-color: var(--border-dk); }

.btn-danger {
  padding: .6rem 1.25rem; border-radius: var(--radius-sm);
  background: var(--red); color: #fff; font-weight: 600; font-size: .875rem;
  transition: background .12s;
}
.btn-danger:hover { background: #b91c1c; }

/* spinner */
.spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: #fff; border-radius: 50%;
  animation: spin .55s linear infinite;
}
.hidden { display: none!important; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── TOAST ───────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 1.5rem; right: 1.5rem; z-index: 999;
  padding: .75rem 1.1rem; border-radius: var(--radius-sm);
  font-weight: 600; font-size: .84rem;
  max-width: 320px; box-shadow: var(--shadow);
  animation: slideUp .2s ease;
}
.toast.success { background: var(--green-lt); border: 1px solid #bbf7d0; color: var(--green); }
.toast.error   { background: var(--red-lt);   border: 1px solid #fecaca; color: var(--red); }
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ── ALERTS ──────────────────────────────────────────── */
.alerts-header { margin-bottom: .5rem; }
.alerts-header h2 { font-size: 1.15rem; font-weight: 700; }
.alerts-header p  { color: var(--text-2); font-size: .84rem; margin-top: .2rem; }
.alerts-list { display: flex; flex-direction: column; gap: .6rem; }
.alert-item {
  background: var(--bg-white); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .85rem 1.1rem;
  display: flex; align-items: center; gap: .85rem;
  box-shadow: var(--shadow);
}
.alert-item.critical { border-left: 3px solid var(--red); }
.alert-item.warning  { border-left: 3px solid var(--amber); }
.alert-item.expiry   { border-left: 3px solid var(--blue); }
.alert-icon { width: 34px; height: 34px; border-radius: 8px; display: grid; place-items: center; flex-shrink: 0; }
.alert-icon svg { width: 17px; height: 17px; }
.alert-icon.red   { background: var(--red-lt);   color: var(--red); }
.alert-icon.amber { background: var(--amber-lt); color: var(--amber); }
.alert-icon.blue  { background: var(--blue-lt);  color: var(--blue); }
.alert-info { flex: 1; }
.alert-name { font-weight: 600; font-size: .875rem; }
.alert-desc { font-size: .78rem; color: var(--text-2); margin-top: .1rem; }
.alert-action {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 4px; padding: .3rem .75rem;
  font-size: .78rem; font-weight: 600; color: var(--text);
  transition: background .12s; cursor: pointer;
}
.alert-action:hover { background: var(--border); }

/* ── SQL BLOCK ───────────────────────────────────────── */
.sql-block {
  background: #1e293b; border: 1px solid #334155;
  border-radius: var(--radius-sm); padding: .85rem 1rem;
  font-family: 'Courier New', monospace; font-size: .78rem;
  color: #7dd3fc; overflow-x: auto; white-space: pre;
  margin-top: .75rem; line-height: 1.65;
}
.config-hint { font-size: .84rem; line-height: 1.6; }

/* ── MODAL ───────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 200; backdrop-filter: blur(3px);
  animation: fadeUp .15s ease;
}
.modal {
  background: var(--bg-white); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem;
  max-width: 420px; width: 90%; box-shadow: var(--shadow);
}
.modal.wide-modal { max-width: 680px; max-height: 88vh; overflow-y: auto; }
.modal h3 { font-size: 1rem; font-weight: 700; margin-bottom: .4rem; }
.modal p  { color: var(--text-2); font-size: .85rem; margin-bottom: 1.25rem; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .85rem; }
.modal-header h3 { margin: 0; }
.modal-close { color: var(--text-3); font-size: 1rem; padding: .2rem .45rem; border-radius: 4px; }
.modal-close:hover { background: var(--bg); color: var(--text); }
.modal-actions { display: flex; gap: .6rem; justify-content: flex-end; margin-top: 1.25rem; }

#edit-form-body .form-grid { margin-top: 0; }
#edit-form-body fieldset { margin-bottom: .65rem; }

/* ── QTY STEPPER ─────────────────────────────────────── */
.qty-stepper {
  display: inline-flex; align-items: center;
  border: 1px solid var(--border); border-radius: 6px;
  overflow: hidden; background: var(--bg-white);
}
.qty-btn {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  font-size: 1rem; font-weight: 700; line-height: 1;
  color: var(--text-2); background: var(--bg-off);
  border: none; cursor: pointer;
  transition: background .1s, color .1s;
  flex-shrink: 0;
}
.qty-btn:hover:not(:disabled) { background: var(--border); color: var(--text); }
.qty-btn.minus:hover:not(:disabled) { background: #fee2e2; color: var(--red); }
.qty-btn.plus:hover:not(:disabled)  { background: #dcfce7; color: var(--green); }
.qty-btn:disabled { opacity: .35; cursor: not-allowed; }
.qty-val {
  min-width: 34px; text-align: center;
  font-size: .85rem; font-weight: 700;
  padding: 0 4px; color: var(--text);
  border-left: 1px solid var(--border);
  border-right: 1px solid var(--border);
  line-height: 28px;
}

/* ── SIMPLE ENTRY FORM ───────────────────────────────── */
.entry-timestamp {
  display: flex; align-items: center; gap: .5rem;
  font-size: .8rem; color: var(--text-2);
  background: var(--bg-white); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: .55rem .9rem;
  margin-bottom: 1rem; width: fit-content;
}
.entry-timestamp svg { width: 14px; height: 14px; color: var(--blue); flex-shrink: 0; }
.entry-timestamp strong { color: var(--text); font-weight: 600; }

.simple-form-card {
  background: var(--bg-white); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.5rem;
  display: flex; flex-direction: column; gap: 1rem;
  box-shadow: var(--shadow);
}
.form-row {
  display: flex; gap: .85rem; align-items: flex-start; flex-wrap: wrap;
}
.form-row .field.grow { flex: 1; min-width: 160px; }
.form-row .field.w120 { width: 120px; flex-shrink: 0; }
.form-row .field.w140 { width: 140px; flex-shrink: 0; }
.form-row .field.w200 { width: 200px; flex-shrink: 0; }

/* bottom-nav hidden on desktop; shown in mobile.css */
.bottom-nav { display: none; }
