:root {
  --bg: #F3F4F7;
  --surface: #FFFFFF;
  --surface-2: #F6F7FA;
  --border: #E4E7EC;
  --ink: #14181F;
  --ink-muted: #66707E;
  --primary: #12192B;
  --primary-2: #1D2740;
  --sidebar-grad: linear-gradient(180deg, #12192B 0%, #1A2340 100%);
  --accent: #0FB5AD;
  --accent-2: #0EA6A3;
  --accent-ink: #06413F;
  --accent-soft: #E3F8F6;
  --indigo: #6366F1;
  --indigo-soft: #EEF0FE;
  --amber: #F0A93E;
  --amber-bg: #FDF2E1;
  --amber-ink: #8A5A16;
  --red: #EF4B4B;
  --red-bg: #FCEAEA;
  --green: #16A870;
  --green-bg: #E4F7EE;
  --gray-bg: #EDEFF2;
  --gray-ink: #4B5768;
  --notif-unread-bg: #F3FAFA;
  --green-row-tint: #D3F5E5;
  --amber-row-tint: #FCE3AD;
  --red-row-tint: #F9CFCF;
  --radius: 12px;
  --mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --sans: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; overflow-x: hidden; height: 100%; overflow-y: hidden; }
input, textarea, select { color: var(--ink); font-family: inherit; }

[data-theme="dark"] {
  --bg: #141B29;
  --surface: #1C2434;
  --surface-2: #242D40;
  --border: #37415A;
  --ink: #EDF1F7;
  --ink-muted: #9DA8BC;
  --primary: #6366F1;
  --primary-2: #7B7EF5;
  --sidebar-grad: linear-gradient(180deg, #101623 0%, #182034 100%);
  --accent-soft: #15423D;
  --accent-ink: #7FE8E2;
  --indigo-soft: #2A2B52;
  --amber-bg: #45330F;
  --amber-ink: #F5CE8C;
  --red-bg: #45201F;
  --green-bg: #163A28;
  --gray-bg: #2A3346;
  --gray-ink: #CBD5E4;
  --notif-unread-bg: #1B2836;
  --green-row-tint: #123C27;
  --amber-row-tint: #45330F;
  --red-row-tint: #45201F;
}
[data-theme="dark"] .btn { background: var(--surface); color: var(--ink); }
[data-theme="dark"] .btn.ghost:hover { background: var(--surface-2); }
[data-theme="dark"] .toast { color: #0E1420; background: #E8ECF3; }
[data-theme="dark"] .toast.error { background: var(--red); color: #fff; }
[data-theme="dark"] .toast.success { background: var(--green); color: #fff; }
[data-theme="dark"] .modal-backdrop { background: rgba(4,7,12,0.66); }
body {
  font-family: var(--sans);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; }
a { color: var(--accent-ink); text-decoration: none; }

/* ---------- Layout ---------- */
#app { display: flex; height: 100%; }

.sidebar {
  width: 232px;
  flex-shrink: 0;
  background: var(--sidebar-grad);
  color: #E7ECF0;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  height: 100%;
  overflow-y: auto;
}
.sidebar-brand {
  padding: 4px 8px 20px;
  line-height: 1.3;
}
.sidebar-brand-name {
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.01em;
  background: linear-gradient(90deg, var(--accent) 0%, #7FE8E2 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.sidebar-brand-sub {
  font-size: 11.5px;
  font-weight: 600;
  color: #9AA7B2;
  margin-top: 2px;
}

.nav-group { margin-bottom: 4px; }
.nav-label {
  font-size: 10.5px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #7C8A98;
  padding: 14px 10px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 8px;
  color: #C7D1DA;
  cursor: pointer;
  font-size: 13.5px;
  font-weight: 500;
  transition: background .12s ease, color .12s ease;
}
.nav-item:hover { background: rgba(255,255,255,0.06); color: #fff; }
.nav-item.active {
  background: linear-gradient(90deg, var(--accent) 0%, #14C4BB 100%);
  color: #06231F;
  font-weight: 700;
  box-shadow: 0 4px 12px rgba(15,181,173,0.35);
}
.nav-item .ic { width: 19px; display: flex; align-items: center; justify-content: center; opacity: .85; flex-shrink: 0; }
.nav-item.active .ic { opacity: 1; }

.sidebar-footer {
  margin-top: auto;
  padding: 10px 8px;
  border-top: 1px solid rgba(255,255,255,0.1);
  font-size: 12px;
  color: #9AA7B2;
}
.sidebar::-webkit-scrollbar { width: 7px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.16); border-radius: 10px; }
.sidebar::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.28); }
.sidebar { scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.2) transparent; }

.main {
  flex: 1;
  min-width: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
}
.topbar {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  padding: 0 20px;
  position: sticky;
  top: 0;
  z-index: 5;
  box-shadow: 0 1px 3px rgba(20,30,40,0.03);
}
.topbar-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 0 12px;
}
.topbar-brand img { max-height: 64px; max-width: 260px; width: auto; height: auto; object-fit: contain; display: block; }
.topbar h1 { font-size: 16px; margin: 0; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; justify-self: start; }
.topbar-actions { display: flex; align-items: center; gap: 14px; justify-self: end; }
@media (max-width: 560px) { .topbar-brand { display: none; } .topbar { grid-template-columns: 1fr auto; } }
.bell {
  position: relative;
  cursor: pointer;
  color: var(--ink-muted);
  display: flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px;
  transition: background .12s ease, color .12s ease;
}
.bell:hover { background: var(--surface-2); color: var(--ink); }
.bell .dot {
  position: absolute; top: -3px; right: -6px;
  background: var(--red); color: #fff;
  font-size: 10px; font-weight: 700;
  border-radius: 8px; padding: 0 4px; line-height: 14px;
}
.user-chip { display: flex; align-items: center; gap: 8px; font-size: 13px; color: var(--ink-muted); }
.user-chip b { color: var(--ink); }
.logout-btn { color: var(--ink-muted); cursor: pointer; font-size: 13px; display: flex; align-items: center; gap: 6px; }
.logout-btn:hover { color: var(--red); }

.content { padding: 12px 20px 20px; flex: 1; min-width: 0; min-height: 0; overflow-y: auto; }

/* ---------- Cards / grid ---------- */
.grid { display: grid; gap: 14px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2,1fr); } .grid-3 { grid-template-columns: repeat(2,1fr);} }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 2px rgba(20,30,40,0.04);
  transition: box-shadow .15s ease;
}
.stat-card { position: relative; overflow: hidden; }
.stat-icon {
  width: 34px; height: 34px; border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 12px;
}
.stat-icon.teal { background: var(--accent-soft); color: var(--accent-ink); }
.stat-icon.amber { background: var(--amber-bg); color: var(--amber-ink); }
.stat-icon.indigo { background: var(--indigo-soft); color: var(--indigo); }
.stat-icon.green { background: var(--green-bg); color: var(--green); }
.stat-icon.red { background: var(--red-bg); color: var(--red); }
.stat-card .stat-label { font-size: 12px; color: var(--ink-muted); margin-bottom: 8px; font-weight: 600; letter-spacing: .01em; }
.stat-card .stat-value { font-size: 26px; font-weight: 800; font-family: var(--mono); letter-spacing: -0.01em; }
.stat-card .stat-sub { font-size: 12px; color: var(--ink-muted); margin-top: 5px; }
.stat-card.accent { border-left: 3px solid var(--accent); }
.stat-card.warn { border-left: 3px solid var(--amber); }
.stat-card.danger { border-left: 3px solid var(--red); }

.section-title {
  font-size: 14px;
  font-weight: 700;
  margin: 22px 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

/* ---------- Table ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow-x: auto; overflow-y: hidden; box-shadow: 0 1px 2px rgba(20,30,40,0.04); max-width: 100%; }

/* Click-to-expand table cell — compact single-line ellipsis by default; clicking toggles to a
   fully wrapped, full-text view, and clicking again collapses it back. Used for long product
   name lists in table rows (Purchases/Sales lists, Reports) so the row stays compact until the
   person actually wants to read the full text. */
.expandable-cell {
  max-width: 240px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  cursor: pointer; position: relative; padding-right: 18px !important;
}
.expandable-cell::after {
  content: "⤢"; position: absolute; right: 4px; top: 50%; transform: translateY(-50%);
  font-size: 10px; color: var(--ink-muted); opacity: .6;
}
.expandable-cell.expanded {
  max-width: 340px; white-space: normal; overflow: visible; text-overflow: clip; word-break: break-word;
}
.expandable-cell.expanded::after { content: "×"; font-size: 13px; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-muted);
  background: var(--surface-2);
  padding: 11px 12px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-weight: 700;
}
tbody td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--surface-2); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.muted { color: var(--ink-muted); }
.empty-row td { text-align: center; padding: 30px; color: var(--ink-muted); }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center;
  font-size: 11px; font-weight: 600;
  padding: 2px 8px; border-radius: 20px;
  white-space: nowrap;
}
.badge.gray { background: var(--gray-bg); color: var(--gray-ink); }
.badge.green { background: var(--green-bg); color: var(--green); }
.badge.amber { background: var(--amber-bg); color: var(--amber-ink); }
.badge.red { background: var(--red-bg); color: var(--red); }
.badge.accent { background: var(--accent-soft); color: var(--accent-ink); }
.badge.indigo { background: var(--indigo-soft); color: var(--indigo); }

/* ---------- Buttons / forms ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  padding: 8px 14px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all .12s ease;
}
.btn:hover { border-color: #C9D0D8; transform: translateY(-1px); box-shadow: 0 2px 6px rgba(20,30,40,0.06); }
.btn.primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn.primary:hover { background: var(--primary-2); box-shadow: 0 4px 10px rgba(20,30,40,0.18); }
.btn.accent { background: var(--accent); color: #06231F; border-color: var(--accent); }
.btn.accent:hover { box-shadow: 0 4px 10px rgba(14,166,163,0.28); }
.btn.danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn.ghost { background: transparent; border-color: transparent; padding: 6px 8px; }
.btn.ghost:hover { transform: none; box-shadow: none; background: var(--surface-2); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; transform: none; box-shadow: none; }

/* "+" add/create buttons — visually distinct from primary confirm actions (e.g. "შენახვა")
   and from secondary/ghost buttons, so the "start something new" action always stands out
   the same way everywhere in the app. */
.btn.add {
  background: var(--accent-bg, #E4F7F6);
  color: var(--accent-2);
  border: 1px dashed var(--accent);
  font-weight: 700;
}
[data-theme="dark"] .btn.add { background: rgba(14,166,163,0.16); color: #7FE8E2; border-color: rgba(14,166,163,0.5); }
.btn.add:hover { background: var(--accent); color: #06231F; border-style: solid; box-shadow: 0 4px 10px rgba(14,166,163,0.28); }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--ink-muted); margin-bottom: 5px; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
  color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus, button:focus-visible, .btn:focus-visible, .nav-item:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.field.mono input { font-family: var(--mono); }
.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.toolbar {
  display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: nowrap;
  position: sticky; top: 0; z-index: 4;
  background: var(--bg); padding: 10px 0 10px;
  overflow-x: auto;
}
.toolbar .search { flex: 1; min-width: 180px; }
.toolbar.hidden-filters { display: none; }
.toolbar > * { flex-shrink: 0; }
.toolbar .search { flex-shrink: 1; }
.toolbar input, .toolbar select, .toolbar .btn {
  height: 34px;
  box-sizing: border-box;
}
.toolbar input, .toolbar select { padding-top: 0; padding-bottom: 0; }
.toolbar .field { display: flex; flex-direction: column; justify-content: center; }
.toolbar .field label { margin-bottom: 2px; }
.search input { padding: 7px 12px; border: 1px solid var(--border); border-radius: 8px; width: 100%; max-width: 340px; background: var(--surface); color: var(--ink); font-size: 13px; }

/* Toolbar/filter dropdowns (category, brand, supplier, etc.) — styled to match the rest of the UI
   instead of falling back to the browser's plain native <select> box. */
select, .toolbar select, .pill-tabs select, .field select {
  appearance: none;
  -webkit-appearance: none;
  padding: 7px 30px 7px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background-color: var(--surface);
  color: var(--ink);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2366707E' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-repeat: no-repeat;
  background-position: right 8px center;
  transition: border-color .12s ease;
}
.toolbar select, .pill-tabs select { width: auto; max-width: 190px; }
select:hover, .toolbar select:hover, .pill-tabs select:hover, .field select:hover { border-color: #C9D0D8; }
select:focus, .toolbar select:focus, .pill-tabs select:focus, .field select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,22,28,0.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; z-index: 50;
}
.modal {
  background: var(--surface);
  border-radius: 12px;
  width: 100%; max-width: 560px;
  padding: 22px;
}
.modal h2 { margin: 0; font-size: 16px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
.modal-close-x {
  background: transparent; border: none; cursor: pointer;
  width: 28px; height: 28px; border-radius: 8px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; line-height: 1; color: var(--ink-muted);
  transition: background .12s ease, color .12s ease;
}
.modal-close-x:hover { background: var(--surface-2); color: var(--ink); }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.modal.wide { max-width: 780px; }

/* ---------- Login ---------- */
.login-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: var(--sidebar-grad);
}
.login-box {
  background: var(--surface); border-radius: 14px; padding: 40px 34px 34px;
  width: 100%; max-width: 380px;
}
.login-brand { text-align: center; margin-bottom: 28px; }
.login-brand-icon {
  width: 54px; height: 54px; margin: 0 auto 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, var(--accent-2) 0%, var(--indigo) 100%);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  box-shadow: 0 8px 20px rgba(99,102,241,0.25);
}
.login-brand-name {
  font-size: 21px; font-weight: 800; letter-spacing: -0.01em;
  background: linear-gradient(90deg, var(--accent-2) 0%, var(--indigo) 100%);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.login-brand-sub { font-size: 13px; font-weight: 600; color: var(--ink-muted); margin-top: 3px; }
.login-error { color: var(--red); font-size: 13px; margin-top: 10px; min-height: 16px; }

/* ---------- Product search combobox ---------- */
.combo { position: relative; }
.combo input[type="text"] {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface); color: var(--ink);
}
.combo-dropdown {
  position: absolute; top: calc(100% + 4px); left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  max-height: 260px; overflow-y: auto; z-index: 30;
  box-shadow: 0 10px 24px rgba(20,30,40,0.14);
}
.combo-item {
  padding: 8px 12px; cursor: pointer; font-size: 13px;
  display: flex; justify-content: space-between; gap: 10px; align-items: center;
  border-bottom: 1px solid var(--border);
}
.combo-item:last-child { border-bottom: none; }
.combo-item:hover, .combo-item.active { background: var(--surface-2); }
.combo-item .meta { color: var(--ink-muted); font-size: 11.5px; white-space: nowrap; }

/* ---------- Misc ---------- */
.sticky-page-header {
  position: sticky; top: 0; z-index: 4;
  background: var(--bg);
  padding-top: 2px;
  margin-bottom: 4px;
}

.pill-tabs {
  display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: nowrap; overflow-x: auto;
  position: sticky; top: 0; z-index: 4;
  background: var(--bg); padding: 4px 0 10px;
}
/* When a toolbar directly follows pill-tabs (the common page layout), it needs to stick
   below them instead of at the same top:0 — otherwise the two sticky headers would overlap. */
.pill-tabs + .toolbar { top: 44px; }
.pill-tabs ~ #rep-body .toolbar { top: 44px; }
.pill-tabs ~ #stock-body .toolbar { top: 88px; }
.pill-tabs ~ #sales-body .toolbar { top: 44px; }
.pill-tabs ~ #acq-toolbar .toolbar { top: 44px; }
.pill-tab {
  padding: 6px 13px; border-radius: 20px; font-size: 12.5px; font-weight: 600;
  background: var(--surface-2); color: var(--ink-muted); cursor: pointer; border: 1px solid var(--border);
}
.pill-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.notif-panel {
  position: absolute; top: 52px; right: 20px; width: 340px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 12px 30px rgba(20,30,40,0.15);
  max-height: 420px; overflow-y: auto; z-index: 30;
}
.notif-item { padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 12.5px; }
.notif-item:last-child { border-bottom: none; }
.notif-item.unread { background: var(--notif-unread-bg); }
.notif-item .t { color: var(--ink-muted); font-size: 11px; margin-top: 3px; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--ink-muted); }
.empty-state .big { font-size: 28px; margin-bottom: 8px; }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; font-size: 13px; }
.kv .k { color: var(--ink-muted); }

.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }
.link-btn { color: var(--accent-ink); font-weight: 600; cursor: pointer; }
.link-btn:hover { text-decoration: underline; }

.toast-wrap { position: fixed; bottom: 20px; right: 20px; z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast {
  background: var(--ink); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 13px;
  box-shadow: 0 8px 20px rgba(0,0,0,0.2);
}
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }
