:root {
  --color-bg: #f4f6f8;
  --color-surface: #ffffff;
  --color-border: #dde2e7;
  --color-text: #1f2937;
  --color-text-muted: #667085;
  --color-primary: #2563a8;
  --color-primary-dark: #1c4d80;
  --color-success: #1b7a43;
  --color-success-bg: #e4f5ea;
  --color-danger: #b3261e;
  --color-danger-bg: #fbe9e7;
  --color-warning: #a15c00;
  --color-warning-bg: #fff2df;
  --color-muted-bg: #eceff2;
  --radius: 8px;
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 15px;
  line-height: 1.45;
}

a { color: var(--color-primary); text-decoration: none; }
a:hover { text-decoration: underline; }

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

/* ---------- Topbar ---------- */

.topbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 0 20px;
  height: 58px;
  display: flex;
  align-items: center;
  gap: 24px;
}

.brand {
  font-weight: 700;
  font-size: 17px;
  color: var(--color-text);
  white-space: nowrap;
}
.brand:hover { text-decoration: none; }

.main-nav {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
}

.main-nav a {
  padding: 8px 12px;
  border-radius: var(--radius);
  color: var(--color-text-muted);
  font-weight: 500;
  font-size: 14px;
  background: none;
  border: none;
  cursor: pointer;
  font-family: inherit;
}

.main-nav a:hover { background: var(--color-muted-bg); text-decoration: none; }
.main-nav a.active { color: var(--color-primary); background: #eaf1fa; }

.user-menu {
  display: flex;
  align-items: center;
  gap: 12px;
  white-space: nowrap;
}
.user-name { font-size: 14px; color: var(--color-text-muted); }
.btn-link { font-size: 14px; }

/* ---------- Flash messages ---------- */

.flash-stack { margin-bottom: 18px; display: flex; flex-direction: column; gap: 8px; }
.flash {
  padding: 10px 14px;
  border-radius: var(--radius);
  font-size: 14px;
  border: 1px solid transparent;
}
.flash-success { background: var(--color-success-bg); color: var(--color-success); border-color: #bfe4cd; }
.flash-danger { background: var(--color-danger-bg); color: var(--color-danger); border-color: #f1c3bd; }
.flash-warning { background: var(--color-warning-bg); color: var(--color-warning); border-color: #f3ddb0; }

/* ---------- Layout helpers ---------- */

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}
.page-header h1 { margin: 0; font-size: 22px; }
.page-header-actions { display: flex; gap: 8px; }
.section-title { font-size: 17px; margin: 28px 0 12px; }
.chart-toggle-row {
  display: flex;
  margin: 28px 0 12px;
}
.back-link { font-size: 13px; color: var(--color-text-muted); }
.hint-text { color: var(--color-text-muted); font-size: 14px; margin-top: -8px; }

.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  margin-bottom: 18px;
}

/* ---------- Forms ---------- */

label {
  display: flex;
  flex-direction: column;
  gap: 5px;
  font-size: 13px;
  font-weight: 600;
  color: var(--color-text-muted);
  margin-bottom: 14px;
}

input[type=text], input[type=password], input[type=number], input[type=email],
select, textarea {
  font-family: inherit;
  font-size: 14px;
  font-weight: 400;
  color: var(--color-text);
  padding: 9px 11px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  background: var(--color-surface);
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 168, 0.15);
}
textarea { resize: vertical; font-weight: 400; }

.checkbox-label {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-weight: 500;
  color: var(--color-text);
}
.checkbox-label input { margin: 0; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 4px 16px;
}
.form-hint { color: var(--color-text-muted); font-size: 13px; }
.form-error {
  background: var(--color-danger-bg);
  color: var(--color-danger);
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 10px;
}
.inline-form { display: inline; }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--color-primary); color: #fff; }
.btn-primary:hover { background: var(--color-primary-dark); }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border); }
.btn-secondary:hover { background: var(--color-muted-bg); }
.btn-danger { background: var(--color-surface); color: var(--color-danger); border-color: #f1c3bd; }
.btn-danger:hover { background: var(--color-danger-bg); }
.btn-danger:disabled { color: var(--color-text-muted); border-color: var(--color-border); cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 13px; }
.btn-block { width: 100%; }

/* ---------- Search ---------- */

.search-card { padding: 16px 20px; }
.search-row { display: flex; gap: 10px; flex-wrap: wrap; }
.search-input { flex: 1; min-width: 220px; }
.search-row select { min-width: 180px; }
.search-filters {
  display: flex;
  align-items: center;
  gap: 20px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--color-text-muted);
}
.result-count { margin-left: auto; }

/* ---------- Shranjeni pogledi (Navision-style) ---------- */

.view-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.view-select {
  min-width: 200px;
  padding: 8px 10px;
  font-size: 13px;
}

.views-list { display: flex; flex-direction: column; gap: 8px; max-height: 300px; overflow-y: auto; }
.view-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: 6px;
}
.view-row-name { font-size: 14px; font-weight: 600; }
.view-row-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* ---------- Stolpci tabele (dodajanje/skrivanje polj) ---------- */

.table-toolbar {
  display: flex;
  justify-content: flex-end;
  padding: 10px 16px;
  border-bottom: 1px solid var(--color-border);
  background: #fafbfc;
}
.columns-modal-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  margin: 4px 0 18px;
}

/* ---------- Tables ---------- */

.table-card { padding: 0; overflow: hidden; }
.table-scroll { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th, .data-table td {
  padding: 11px 16px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}
.data-table th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
  background: #fafbfc;
}
.data-table tbody tr:hover { background: #fafbfc; }
.data-table td.num, .data-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.actions-col { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }
th.actions-col { text-align: right; }
.empty-state { text-align: center; color: var(--color-text-muted); padding: 30px; }

.filter-row td {
  padding: 4px 8px;
  background: #f6f8fa;
  border-bottom: 2px solid var(--color-border);
}
.filter-cell {
  display: flex;
  align-items: stretch;
  gap: 3px;
}
.col-filter {
  width: 100%;
  min-width: 0;
  padding: 4px 6px;
  font-size: 12px;
  font-weight: 400;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: var(--color-surface);
  box-sizing: border-box;
}
.col-filter:disabled {
  background: #eceff2;
  color: var(--color-text-muted);
  cursor: pointer;
}
.col-filter::placeholder { color: #b2bac2; }
.filter-caret {
  flex-shrink: 0;
  width: 18px;
  padding: 0;
  border: 1px solid var(--color-border);
  border-radius: 4px;
  background: var(--color-surface);
  color: var(--color-text-muted);
  font-size: 9px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.filter-caret:hover { background: var(--color-muted-bg); }
.filter-caret.active {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: #fff;
}
.data-table td.num.filter-row,
.filter-row td.num .col-filter { text-align: right; }
.data-table th[hidden],
.data-table td[hidden] { display: none !important; }
.archived-row { opacity: 0.55; }
.low-stock-row td[data-col="quantity"] { color: var(--color-warning); font-weight: 600; }

/* ---------- Vlečenje stolpcev (drag & drop) ---------- */

.data-table th[draggable="true"] { cursor: grab; user-select: none; }
.data-table th[draggable="true"]:active { cursor: grabbing; }
.data-table th.dragging { opacity: 0.4; }
.data-table th.drag-over-left { box-shadow: inset 3px 0 0 0 var(--color-primary); }
.data-table th.drag-over-right { box-shadow: inset -3px 0 0 0 var(--color-primary); }

/* ---------- Pojavno okno za več filtrov pod enim stolpcem ---------- */

.filter-popover {
  position: fixed;
  z-index: 200;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.18);
  padding: 14px;
  width: 300px;
  max-width: calc(100vw - 24px);
}
.filter-popover[hidden] { display: none; }
.filter-popover-header {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--color-text-muted);
  margin-bottom: 10px;
}
.filter-popover-rows {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 10px;
  max-height: 260px;
  overflow-y: auto;
}
.filter-popover-row { display: flex; gap: 6px; align-items: center; }
.filter-popover-row select { flex-shrink: 0; width: auto; padding: 6px; font-size: 12px; }
.filter-popover-row input { flex: 1; min-width: 0; padding: 6px 8px; font-size: 13px; margin: 0; }
.filter-popover-row-remove {
  flex-shrink: 0;
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 15px;
  padding: 2px 6px;
}
.filter-popover-row-remove:hover { color: var(--color-danger); }
.filter-popover-add { width: 100%; justify-content: center; }
.filter-popover-actions { display: flex; justify-content: space-between; gap: 8px; margin-top: 10px; }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: 6px;
  vertical-align: middle;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}
.badge-success { background: var(--color-success-bg); color: var(--color-success); }
.badge-danger { background: var(--color-danger-bg); color: var(--color-danger); }
.badge-warning { background: var(--color-warning-bg); color: var(--color-warning); }
.badge-muted { background: var(--color-muted-bg); color: var(--color-text-muted); }

/* ---------- Item detail ---------- */

.details-card dl.details-grid {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 10px 16px;
  margin: 0;
}
.details-grid dt { color: var(--color-text-muted); font-size: 13px; font-weight: 600; }
.details-grid dd { margin: 0; }
.text-warning { color: var(--color-warning); font-weight: 700; }

/* ---------- Receiving table ---------- */

.receiving-table input, .receiving-table select {
  width: 100%;
  padding: 7px 8px;
  font-size: 13px;
}
.receiving-actions { justify-content: space-between; }
.btn-remove-row {
  background: none;
  border: none;
  color: var(--color-text-muted);
  cursor: pointer;
  font-size: 16px;
  padding: 4px 8px;
}
.btn-remove-row:hover { color: var(--color-danger); }
.row-stock-hint { font-size: 11px; color: var(--color-text-muted); margin-top: 2px; }

/* ---------- Login ---------- */

.login-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 80vh;
}
.login-card { width: 100%; max-width: 360px; }
.login-title { margin: 0 0 4px; font-size: 20px; text-align: center; }
.login-subtitle { margin: 0 0 18px; text-align: center; color: var(--color-text-muted); font-size: 13px; }

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-backdrop[hidden] { display: none; }
.modal {
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.modal h2 { margin: 0 0 4px; font-size: 18px; }
.modal-subtitle { margin: 0 0 16px; color: var(--color-text-muted); font-size: 13px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

.error-card { text-align: center; padding: 60px 20px; }
.error-card h1 { font-size: 48px; margin: 0; color: var(--color-text-muted); }

/* ---------- Hitri +/- stepper za zalogo ---------- */

.qty-stepper {
  display: inline-flex;
  border: 1px solid var(--color-border);
  border-radius: 6px;
  overflow: hidden;
}
.btn-step {
  background: var(--color-surface);
  border: none;
  color: var(--color-text);
  width: 26px;
  height: 26px;
  font-size: 15px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.btn-step:hover { background: var(--color-muted-bg); }
.btn-step-minus { border-right: 1px solid var(--color-border); }
.btn-step-minus:hover { color: var(--color-danger); }
.btn-step-plus:hover { color: var(--color-success); }

.qty-stepper-inline {
  display: inline-flex;
  vertical-align: middle;
  margin-left: 10px;
}
.qty-stepper-inline .btn-step { width: 28px; height: 28px; font-size: 16px; }

/* ---------- Graf gibanja zaloge ---------- */

.chart-card { padding: 20px; }
.chart-legend {
  display: flex;
  gap: 18px;
  font-size: 12px;
  color: var(--color-text-muted);
  margin-bottom: 10px;
}
.chart-legend span { display: inline-flex; align-items: center; gap: 6px; }
.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
}
.legend-dot-line { background: var(--color-primary); }
.legend-dot-success { background: var(--color-success); }
.legend-dot-danger { background: var(--color-danger); }
#chart-container { width: 100%; overflow-x: auto; }
#chart-container svg { display: block; width: 100%; height: auto; }
.chart-empty { color: var(--color-text-muted); font-size: 13px; padding: 20px 0; text-align: center; }
.chart-axis-label { font-size: 10px; fill: var(--color-text-muted); }
.chart-grid-line { stroke: var(--color-border); stroke-width: 1; }
.chart-value-line { fill: none; stroke: var(--color-primary); stroke-width: 2; }
.chart-marker { cursor: pointer; transition: r 0.1s ease; }
.chart-marker:hover { r: 6; }
.chart-marker-success { fill: var(--color-success); }
.chart-marker-danger { fill: var(--color-danger); }

.chart-tooltip {
  position: fixed;
  z-index: 1000;
  background: #1f2937;
  color: #fff;
  padding: 9px 12px;
  border-radius: 8px;
  font-size: 12px;
  line-height: 1.5;
  box-shadow: 0 8px 20px rgba(0,0,0,0.25);
  pointer-events: none;
  max-width: 260px;
  white-space: normal;
}
.chart-tooltip[hidden] { display: none; }
.chart-tooltip .tt-title { font-weight: 700; margin-bottom: 3px; font-size: 13px; }
.chart-tooltip .tt-title-success { color: #7ee2a8; }
.chart-tooltip .tt-title-danger { color: #f5a397; }
.chart-tooltip .tt-row { opacity: 0.92; }
.chart-tooltip .tt-note {
  margin-top: 5px;
  padding-top: 5px;
  border-top: 1px solid rgba(255,255,255,0.18);
  font-style: italic;
  opacity: 0.9;
}

@media (max-width: 720px) {
  .topbar-inner { flex-wrap: wrap; height: auto; padding: 10px 16px; }
  .main-nav { order: 3; width: 100%; flex-wrap: wrap; }
  .details-card dl.details-grid { grid-template-columns: 1fr; }
  .actions-col { flex-wrap: wrap; }
}
