*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --sidebar: #1a1d23;
  --sidebar-hover: #252932;
  --sidebar-active: #2d3340;
  --text: #1a1d23;
  --text-muted: #6b7280;
  --border: #e5e7eb;
  --primary: #e85d04;
  --primary-hover: #d45303;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --orange: #ea580c;
  --orange-bg: #ffedd5;
  --blue: #2563eb;
  --blue-bg: #dbeafe;
  --yellow: #ca8a04;
  --yellow-bg: #fef9c3;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.04);
  --shadow-lg: 0 8px 30px rgba(0,0,0,.12);
}

html {
  height: 100%;
  -webkit-text-size-adjust: 100%;
}
body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
button, a, .nav-item, .dash-kpi, .dash-spot, .exp-cat-card {
  touch-action: manipulation;
}

.app {
  display: flex;
  min-height: 100vh;
}

/* Sidebar */
.sidebar {
  width: 260px;
  background: linear-gradient(180deg, #171a21 0%, #1d212a 100%);
  color: #fff;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 12px;
  left: 12px;
  bottom: 12px;
  border-radius: 18px;
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
  overflow: hidden;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 20px 18px;
}

.brand-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  font-size: 1.4rem;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--primary), #f59e0b);
  box-shadow: 0 6px 16px rgba(232,93,4,.35);
}

.brand h1 {
  font-size: 1.1rem;
  font-weight: 700;
  letter-spacing: -.01em;
}

.brand p {
  font-size: .72rem;
  color: rgba(255,255,255,.45);
}

.nav {
  flex: 1;
  padding: 6px 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow-y: auto;
  scrollbar-width: thin;
  scrollbar-color: rgba(255,255,255,.15) transparent;
}

.nav-section {
  margin: 16px 12px 6px;
  font-size: .66rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255,255,255,.35);
}

.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 8px 10px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,.68);
  font-size: .875rem;
  font-family: inherit;
  border-radius: 10px;
  cursor: pointer;
  text-align: left;
  transition: background .15s, color .15s;
}

.nav-icon {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  flex-shrink: 0;
  font-size: 1rem;
  border-radius: 8px;
  background: rgba(255,255,255,.05);
  transition: background .15s;
}

.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item:hover .nav-icon { background: rgba(255,255,255,.1); }

.nav-item.active {
  background: rgba(232,93,4,.14);
  color: #fff;
  font-weight: 600;
}
.nav-item.active .nav-icon { background: var(--primary); }
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -12px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--primary);
}

.sidebar-footer {
  padding: 12px;
  margin: 0 12px 12px;
  border-radius: 12px;
  background: rgba(255,255,255,.04);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.sidebar-action {
  padding: 8px 10px;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: 8px;
  background: transparent;
  color: rgba(255,255,255,.75);
  font-size: .78rem;
  font-family: inherit;
  cursor: pointer;
  transition: background .15s, color .15s;
}
.sidebar-action:hover { background: rgba(255,255,255,.08); color: #fff; }
.sidebar-logout { grid-column: 1 / -1; }
.sidebar-install {
  grid-column: 1 / -1;
  border-color: rgba(232,93,4,.5);
  background: rgba(232,93,4,.16);
  color: #fff;
  font-weight: 600;
}
.sidebar-install:hover { background: var(--primary); }
.sidebar-action[hidden] { display: none; }

.brand-icon-img {
  display: block;
  padding: 0;
  object-fit: cover;
}

.install-banner {
  display: none;
  position: fixed;
  left: 10px;
  right: 10px;
  bottom: calc(74px + env(safe-area-inset-bottom));
  z-index: 140;
  align-items: center;
  gap: 10px;
  padding: 10px 10px 10px 12px;
  border-radius: 14px;
  background: var(--surface);
  box-shadow: 0 10px 30px rgba(0,0,0,.18);
  border: 1px solid var(--border);
}
.install-banner:not([hidden]) { display: flex; }
body.auth-locked .install-banner { display: none; }
.install-banner-icon { width: 40px; height: 40px; border-radius: 10px; flex-shrink: 0; }
.install-banner-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.install-banner-text strong { font-size: .88rem; }
.install-banner-text span { font-size: .72rem; color: var(--text-muted); }
.install-banner-close {
  border: none;
  background: none;
  font-size: 1.4rem;
  line-height: 1;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 4px;
}
.install-steps { padding-left: 20px; line-height: 1.9; font-size: .92rem; }
.install-ico { font-size: 1rem; }

.cloud-info {
  grid-column: 1 / -1;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 2px 4px;
  min-width: 0;
}
.cloud-user {
  font-size: .78rem;
  color: rgba(255,255,255,.8);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.cloud-status {
  font-size: .7rem;
  color: rgba(255,255,255,.45);
}
.cloud-status::before {
  content: '';
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 6px;
  border-radius: 50%;
  background: currentColor;
  vertical-align: middle;
}
.cloud-status:empty::before { display: none; }
.cloud-status[data-state="saved"] { color: #4ade80; }
.cloud-status[data-state="saving"] { color: #fbbf24; }
.cloud-status[data-state="error"] { color: #f87171; }
.cloud-status[data-state="offline"] { color: #93c5fd; }

.login-screen {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 1000;
  place-items: center;
  padding: max(20px, env(safe-area-inset-top)) 20px max(20px, env(safe-area-inset-bottom));
  background: linear-gradient(135deg, #171a21 0%, #2a2f3a 100%);
}
body.auth-locked .login-screen { display: grid; }
body.auth-locked .app { display: none; }

.login-card {
  width: 100%;
  max-width: 380px;
  padding: 28px;
  background: var(--surface);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
}
.login-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
}
.login-brand h1 { font-size: 1.2rem; }
.login-brand p { font-size: .82rem; color: var(--text-muted); }
.login-error {
  margin-bottom: 12px;
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--red-bg);
  color: var(--red);
  font-size: .82rem;
}
.login-submit { width: 100%; justify-content: center; }

/* Main */
.main {
  flex: 1;
  margin-left: 284px;
  padding: 0 32px 32px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 24px 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 24px;
}

.topbar h2 { font-size: 1.5rem; font-weight: 700; }
.topbar p { color: var(--text-muted); font-size: .875rem; }

.topbar-title-row {
  display: flex;
  align-items: center;
  gap: 18px;
  min-width: 0;
}

.promet-top-summary {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  background: var(--green-bg);
  border-radius: 10px;
  white-space: nowrap;
}
.promet-top-summary[hidden] { display: none !important; }
.promet-top-icon { font-size: 1.05rem; }
.promet-top-label {
  display: block;
  font-size: .7rem;
  color: var(--text-muted);
  line-height: 1.2;
}
.promet-top-summary strong {
  display: block;
  font-size: 1rem;
  line-height: 1.25;
  color: var(--text);
}
.promet-top-sub {
  display: block;
  font-size: .7rem;
  color: var(--text-muted);
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.search-box input {
  padding: 9px 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .875rem;
  width: 220px;
  font-family: inherit;
}

.search-box input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(232,93,4,.15);
}

.date-display {
  font-size: .875rem;
  color: var(--text-muted);
  white-space: nowrap;
}

/* Pages */
.page { display: none; }
.page.active { display: block; }

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 20px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  gap: 16px;
  align-items: flex-start;
  box-shadow: var(--shadow);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.stat-icon.red { background: var(--red-bg); }
.stat-icon.green { background: var(--green-bg); }
.stat-icon.blue { background: var(--blue-bg); }
.stat-icon.orange { background: var(--orange-bg); }
.stat-icon.purple { background: #f3e8ff; }
.stat-icon.teal { background: #ccfbf1; }

.stats-grid-6 { grid-template-columns: repeat(3, 1fr); }
.stats-grid-4 { grid-template-columns: repeat(4, 1fr); }
.stats-grid-1 { grid-template-columns: 1fr; max-width: 420px; }

.dashboard-grid-3 { grid-template-columns: repeat(3, 1fr); }
.dashboard-grid-2 { grid-template-columns: 1fr 1fr; }

/* Modern dashboard */
.dash-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 20px;
  margin-bottom: 18px;
  padding: 22px 24px;
  border-radius: 18px;
  background:
    radial-gradient(circle at 100% 0%, rgba(232,93,4,.28), transparent 42%),
    linear-gradient(135deg, #171a21 0%, #2a303b 100%);
  color: #fff;
  box-shadow: 0 12px 28px rgba(23,26,33,.18);
}
.dash-hero-kicker {
  margin: 0 0 4px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: rgba(255,255,255,.5);
}
.dash-hero-title {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 700;
  letter-spacing: -.02em;
  text-transform: capitalize;
}
.dash-hero-sub {
  margin: 6px 0 0;
  font-size: .88rem;
  color: rgba(255,255,255,.55);
}
.dash-hero-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 10px;
}
.dash-month-picker {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: .72rem;
  color: rgba(255,255,255,.55);
}
.dash-month-picker input {
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 10px;
  background: rgba(255,255,255,.08);
  color: #fff;
  font-family: inherit;
  font-size: .9rem;
  color-scheme: dark;
}
.dash-quick { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.dash-quick-btn {
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 999px;
  background: rgba(255,255,255,.08);
  color: #fff;
  font-family: inherit;
  font-size: .78rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s;
}
.dash-quick-btn:hover {
  background: var(--primary);
  border-color: var(--primary);
}

.dash-spotlight {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 18px;
}
.dash-spot {
  --spot: #14b8a6;
  --spot-bg: rgba(20,184,166,.10);
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  padding: 20px 22px;
  border: 1px solid rgba(0,0,0,.04);
  border-radius: 18px;
  background:
    radial-gradient(circle at 100% 0%, var(--spot-bg), transparent 55%),
    var(--surface);
  box-shadow: var(--shadow);
  font: inherit;
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.dash-spot:hover {
  transform: translateY(-2px);
  box-shadow: 0 12px 26px rgba(0,0,0,.08);
  border-color: var(--spot-bg);
}
.dash-spot-out {
  --spot: #f59e0b;
  --spot-bg: rgba(245,158,11,.12);
}
.dash-spot-total {
  --spot: #6366f1;
  --spot-bg: rgba(99,102,241,.10);
}
.dash-spot-icon {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--spot-bg);
  font-size: 1.5rem;
}
.dash-spot-body { min-width: 0; }
.dash-spot-label {
  display: block;
  margin-bottom: 4px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--spot);
}
.dash-spot strong {
  display: block;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -.02em;
  line-height: 1.15;
}
.dash-spot-meta {
  display: block;
  margin-top: 4px;
  font-size: .78rem;
  color: var(--text-muted);
}

.dash-kpi {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  cursor: pointer;
  font: inherit;
  color: inherit;
  transition: transform .15s, box-shadow .15s, border-color .15s;
}
.dash-kpi:hover {
  transform: translateY(-2px);
  box-shadow: 0 10px 24px rgba(0,0,0,.08);
  border-color: rgba(232,93,4,.25);
}
.dash-kpi-body { min-width: 0; }
.dash-kpi .stat-value { font-size: 1.45rem; }

.dash-panel {
  display: flex;
  flex-direction: column;
  border: 1px solid rgba(0,0,0,.04);
}
.dash-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  background: linear-gradient(180deg, #fcfcfd 0%, #fff 100%);
}
.dash-panel-header h3 { margin: 0; }
.dash-panel-header p {
  margin: 4px 0 0;
  font-size: .78rem;
  color: var(--text-muted);
}
.dash-panel-count {
  min-width: 28px;
  height: 28px;
  padding: 0 8px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--red-bg);
  color: var(--red);
  font-size: .8rem;
  font-weight: 700;
}
.dash-panel-count.warn {
  background: var(--orange-bg);
  color: var(--orange);
}
.dash-panel .card-body { flex: 1; }
.dash-panel-link {
  width: 100%;
  padding: 12px 20px;
  border: none;
  border-top: 1px solid var(--border);
  background: transparent;
  color: var(--primary);
  font-family: inherit;
  font-size: .82rem;
  font-weight: 600;
  text-align: left;
  cursor: pointer;
}
.dash-panel-link:hover { background: #fff7ed; }
.dash-list-item { gap: 12px; }
.dash-list-amount { font-weight: 700; white-space: nowrap; }
.dash-empty {
  padding: 28px 12px;
  text-align: center;
  color: var(--text-muted);
  font-size: .85rem;
  background:
    radial-gradient(circle at 50% 0%, rgba(232,93,4,.06), transparent 55%);
  border-radius: 12px;
}

.period-filter {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 20px;
  font-size: .875rem;
  color: var(--text-muted);
}

.period-filter input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-family: inherit;
}

.badge-warning { background: var(--yellow-bg); color: var(--yellow); }
.badge-active { background: var(--green-bg); color: var(--green); }
.badge-inactive { background: #f3f4f6; color: var(--text-muted); }

/* Availability */
.availability-summary {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 20px;
}

.avail-stat {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  border-left: 4px solid var(--border);
}

.avail-stat.low { border-left-color: var(--orange); }
.avail-stat.warning { border-left-color: var(--yellow); }
.avail-stat.ok { border-left-color: var(--green); }

.avail-stat strong { font-size: 1.5rem; display: block; }
.avail-stat span { font-size: .8rem; color: var(--text-muted); }

.availability-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.avail-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  border-top: 3px solid var(--border);
}

.avail-card.low { border-top-color: var(--orange); }
.avail-card.warning { border-top-color: var(--yellow); }
.avail-card.ok { border-top-color: var(--green); }

.avail-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}

.avail-card-header h4 { font-size: .95rem; margin-bottom: 2px; }
.avail-card-header code { font-size: .75rem; color: var(--text-muted); }

.stock-bar-wrap { margin: 12px 0; }
.stock-bar-label {
  display: flex;
  justify-content: space-between;
  font-size: .75rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

.stock-bar {
  height: 8px;
  background: #e5e7eb;
  border-radius: 4px;
  overflow: hidden;
}

.stock-bar-fill {
  height: 100%;
  border-radius: 4px;
  transition: width .3s;
}

.stock-bar-fill.low { background: var(--orange); }
.stock-bar-fill.warning { background: var(--yellow); }
.stock-bar-fill.ok { background: var(--green); }

.avail-card-meta {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  font-size: .78rem;
  color: var(--text-muted);
  margin-top: 10px;
}

.avail-card-meta strong { color: var(--text); display: block; }

/* Expense category cards */
.expense-categories {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.exp-cat-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 14px;
  text-align: center;
  box-shadow: var(--shadow);
  cursor: pointer;
  transition: all .15s;
  border: 2px solid transparent;
}

.exp-cat-card:hover { border-color: var(--primary); }
.exp-cat-card.active { border-color: var(--primary); background: #fff7ed; }
.exp-cat-card .icon { font-size: 1.5rem; margin-bottom: 6px; }
.exp-cat-card .name { font-size: .78rem; font-weight: 600; }
.exp-cat-card .amount { font-size: .75rem; color: var(--text-muted); margin-top: 4px; }
.exp-cat-card .exp-cat-sub {
  margin-top: 2px;
  font-size: .68rem;
  color: var(--text-muted);
}
.exp-cat-card.has-unpaid .amount { color: var(--red); font-weight: 700; }
.exp-cat-total {
  border-color: rgba(220,38,38,.25);
  background: #fff7f7;
}
.exp-cat-total .amount { color: var(--red); font-weight: 700; font-size: .9rem; }

.bar-fill-green { background: linear-gradient(90deg, #16a34a, #22c55e); }

.promet-entry-wrap { margin-top: 8px; box-shadow: none; }
.promet-entry-table input[type="number"] {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 1rem;
}
.promet-entry-table .promet-total-cell {
  vertical-align: middle;
  font-size: 1.1rem;
  color: var(--primary);
  white-space: nowrap;
}

.promet-calc-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 12px 14px;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: .9rem;
  color: var(--text-muted);
}
.promet-calc-bar strong { color: var(--text); }
.promet-ostanato-bar {
  margin-top: 14px;
  background: var(--green-bg);
  border-color: transparent;
}
.promet-ostanato-bar #prOstanato {
  font-size: 1.15rem;
  color: var(--green);
}
.promet-ostanato-hint {
  margin-top: 6px;
  font-size: .75rem;
  color: var(--text-muted);
}
.day-name-hint {
  display: block;
  margin-top: 4px;
  font-size: .8rem;
  color: var(--text-muted);
  text-transform: capitalize;
}
.field-warn {
  display: none;
  color: var(--red);
  font-size: .75rem;
  margin-top: 4px;
}
.dnevnici-worker-card { margin-bottom: 20px; }
.dnevnici-worker-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.dnevnici-worker-header h3 { font-size: 1.05rem; }
.dnevnici-owed {
  margin-top: 6px;
  font-size: .85rem;
  color: var(--text-muted);
}
.dnevnici-owed.has-debt {
  color: var(--red);
  font-weight: 500;
}
.dnevnici-owed.has-debt strong { color: var(--red); }
.dnevnici-owed span { font-weight: 400; opacity: .85; margin-left: 4px; }
.dnevnici-worker-meta {
  margin-top: 4px;
  font-size: .82rem;
  color: var(--text-muted);
}
.dnevnica-day-row {
  display: grid;
  grid-template-columns: 1fr 110px auto 110px 40px;
  gap: 8px;
  align-items: center;
  margin-bottom: 8px;
}
.dnevnica-day-row input[type="date"],
.dnevnica-day-row input[type="number"] {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .9rem;
}
.dnevnica-day-name {
  font-size: .82rem;
  color: var(--text-muted);
  text-transform: capitalize;
}
.dnevnica-paid-check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .85rem;
  white-space: nowrap;
}
@media (max-width: 768px) {
  .dnevnici-worker-header { flex-direction: column; }
  .dnevnica-day-row {
    grid-template-columns: 1fr;
    gap: 4px;
  }
}
.promet-expense-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 8px;
}
.promet-expense-row {
  display: grid;
  grid-template-columns: 88px 1fr 120px;
  gap: 8px;
  align-items: center;
}
.promet-expense-label {
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
}
.promet-expense-row input[type="text"],
.promet-expense-row input[type="number"] {
  width: 100%;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .9rem;
}
.promet-exp-line {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: .82rem;
  white-space: nowrap;
}

.supplier-products-hint {
  margin: -2px 0 10px;
  font-size: .8rem;
  color: var(--text-muted);
}
.supplier-product-head,
.supplier-product-row {
  display: grid;
  grid-template-columns: 1fr 110px 120px 40px;
  gap: 8px;
  align-items: center;
}
.supplier-product-head {
  margin-bottom: 6px;
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .03em;
}
.supplier-product-row { margin-bottom: 8px; }
.form-group .supplier-product-row input,
.form-group .supplier-product-row select { width: 100%; }
.text-muted { color: var(--text-muted); }
.supplier-products-cell {
  display: inline-block;
  max-width: 260px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: middle;
  font-size: .85rem;
}

.invoice-items-wrap { box-shadow: none; margin-top: 8px; }
.invoice-items-table select,
.invoice-items-table input[type="number"] {
  width: 100%;
  min-width: 70px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: .9rem;
}
.invoice-items-table .invoice-line-total {
  white-space: nowrap;
  font-weight: 600;
  vertical-align: middle;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 20px;
  border-bottom: 2px solid var(--border);
}

.tab {
  padding: 10px 20px;
  border: none;
  background: none;
  font-family: inherit;
  font-size: .875rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: all .15s;
}

.tab:hover { color: var(--text); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Reports */
.report-filters { margin-bottom: 24px; }

.form-row-4 { grid-template-columns: repeat(4, 1fr); }

.report-actions {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}
.report-actions #generateReportBtn { flex: 1; }
.report-period {
  margin-top: 4px;
  font-size: .85rem;
  font-weight: 600;
  color: var(--text-muted);
}
.report-grid-gap { margin-top: 20px; }
#reportStats .stat-value { font-size: 1.35rem; }

.category-bar-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  font-size: .875rem;
}
.category-bar-item .bar-label {
  width: 170px;
  flex-shrink: 0;
  min-width: 0;
}
.category-bar-item .bar-label small {
  display: block;
  font-size: .72rem;
  color: var(--text-muted);
}
.category-bar-item .bar-fill-blue { background: linear-gradient(90deg, #2563eb, #60a5fa); }
.category-bar-item .bar-fill-green { background: linear-gradient(90deg, #16a34a, #22c55e); }

.category-bar-item .bar-wrap {
  flex: 1;
  height: 6px;
  background: #e5e7eb;
  border-radius: 3px;
  overflow: hidden;
}

.category-bar-item .bar-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
}

.category-bar-item .amount {
  min-width: 80px;
  text-align: right;
  font-weight: 600;
  font-size: .8rem;
}

.modal-lg { max-width: 640px; }

.journal-type {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: .72rem;
  font-weight: 600;
}

.journal-invoice { background: var(--blue-bg); color: var(--blue); }
.journal-expense { background: var(--orange-bg); color: var(--orange); }
.journal-salary { background: #f3e8ff; color: #7c3aed; }
.journal-promet { background: var(--green-bg); color: var(--green); }

.row-overdue { background: #fef2f2 !important; }
.row-overdue:hover { background: #fee2e2 !important; }
.row-expiring { background: #fffbeb !important; }

.due-badge {
  display: inline-block;
  font-size: .7rem;
  color: var(--red);
  font-weight: 600;
  margin-left: 6px;
}

.net-preview {
  padding: 10px 14px;
  background: #f0fdf4;
  border-radius: 8px;
  font-size: .875rem;
  margin-top: 8px;
}
.net-preview strong { color: var(--green); font-size: 1.1rem; }

@media print {
  .sidebar, .topbar-actions, .report-filters, .nav, .sidebar-footer,
  .toolbar, .btn, .modal-overlay, .toast-container { display: none !important; }
  .main { margin-left: 0 !important; padding: 0 !important; }
  .page { display: none !important; }
  #page-reports { display: block !important; }
  .card, .stat-card { box-shadow: none !important; break-inside: avoid; }
  body { background: #fff; }
}

/* Responsive additions */
@media (max-width: 1100px) {
  .stats-grid-6 { grid-template-columns: repeat(2, 1fr); }
  .stats-grid-4 { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid-3 { grid-template-columns: 1fr; }
  .availability-summary { grid-template-columns: repeat(2, 1fr); }
  .form-row-4 { grid-template-columns: 1fr 1fr; }
  .dash-spotlight { grid-template-columns: 1fr 1fr; }
  .dash-spot-out { grid-column: 1 / -1; }
  .dash-hero { flex-direction: column; align-items: stretch; }
  .dash-hero-side { align-items: stretch; }
  .dash-quick { justify-content: flex-start; }
}

@media (max-width: 768px) {
  .stats-grid-6, .stats-grid-4 { grid-template-columns: 1fr 1fr; }
  .availability-summary { grid-template-columns: 1fr; }
  .form-row-4 { grid-template-columns: 1fr; }
  .dashboard-grid-2 { grid-template-columns: 1fr; }
  .promet-expense-row {
    grid-template-columns: 1fr 110px;
    gap: 6px;
  }
  .promet-expense-label { grid-column: 1 / -1; }
  .dash-hero { padding: 18px 16px; border-radius: 14px; }
  .dash-hero-title { font-size: 1.25rem; }
  .dash-spotlight { grid-template-columns: 1fr; gap: 10px; }
  .category-bar-item { flex-wrap: wrap; gap: 6px 10px; }
  .category-bar-item .bar-label { width: auto; flex: 1 1 60%; }
  .category-bar-item .bar-wrap { flex-basis: 100%; order: 3; }
  .report-actions { flex-wrap: wrap; }
  .dash-spot { padding: 14px 16px; gap: 12px; }
  .dash-spot-icon { width: 42px; height: 42px; font-size: 1.2rem; border-radius: 12px; }
  .dash-spot strong { font-size: 1.3rem; }
  .dash-spot:hover { transform: none; }
  .dash-quick-btn { flex: 1 1 auto; text-align: center; }
}

.stat-label { font-size: .8rem; color: var(--text-muted); margin-bottom: 4px; }
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1.2; }
.stat-sub { font-size: .8rem; color: var(--text-muted); margin-top: 2px; }

.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}

/* Cards */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.card-header h3 { font-size: .95rem; font-weight: 600; }
.card-body { padding: 12px 20px 16px; }

.list-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: .875rem;
}

.list-item:last-child { border-bottom: none; }

.list-item-info strong { display: block; }
.list-item-info span { color: var(--text-muted); font-size: .8rem; }

.empty-state {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: .875rem;
}

/* Toolbar */
.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 12px;
}

.toolbar-info { color: var(--text-muted); font-size: .875rem; }

.filters {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.filters select,
.filters input {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .875rem;
  font-family: inherit;
  background: var(--surface);
}

/* Buttons */
.btn {
  padding: 9px 18px;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all .15s;
  white-space: nowrap;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--bg); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-success { background: var(--green); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-sm { padding: 7px 12px; font-size: .8rem; }
.btn-icon { padding: 6px 10px; font-size: .85rem; }

.btn-group { display: flex; gap: 6px; }

/* Table */
.table-wrap {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

.data-table th {
  text-align: left;
  padding: 12px 16px;
  background: #f9fafb;
  font-weight: 600;
  font-size: .8rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .03em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr:hover { background: #fafafa; }
.data-table tbody tr:last-child td { border-bottom: none; }

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: .75rem;
  font-weight: 600;
}

.badge-paid { background: var(--green-bg); color: var(--green); }
.badge-unpaid { background: var(--red-bg); color: var(--red); }
.badge-partial { background: var(--yellow-bg); color: var(--yellow); }
.badge-low { background: var(--orange-bg); color: var(--orange); }
.badge-ok { background: var(--green-bg); color: var(--green); }

/* Summary bar */
.summary-bar {
  margin-top: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-radius: var(--radius);
  font-size: .875rem;
  color: var(--text-muted);
  box-shadow: var(--shadow);
}

.summary-bar strong { color: var(--text); }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 18px 24px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 { font-size: 1.1rem; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.5rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

.modal-body { padding: 20px 24px; }
.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Form */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: .8rem;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text-muted);
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: .875rem;
  font-family: inherit;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(232,93,4,.15);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: 8px;
  color: #fff;
  font-size: .875rem;
  box-shadow: var(--shadow-lg);
  animation: slideIn .3s ease;
}

.toast-success { background: var(--green); }
.toast-error { background: var(--red); }
.toast-info { background: var(--blue); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Responsive */
@media (max-width: 1100px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
}

/* Mobile */
.menu-toggle,
.mobile-nav,
.sidebar-backdrop { display: none; }

@media (max-width: 768px) {
  body { padding-bottom: calc(72px + env(safe-area-inset-bottom)); }

  /* Drawer menu */
  .sidebar {
    top: 0;
    left: 0;
    bottom: 0;
    width: min(86vw, 320px);
    max-width: 320px;
    padding-top: env(safe-area-inset-top);
    border-radius: 0 18px 18px 0;
    transform: translateX(-105%);
    transition: transform .25s ease;
    z-index: 260;
  }
  body.nav-open .sidebar { transform: none; }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 250;
    background: rgba(0,0,0,.45);
    opacity: 0;
    pointer-events: none;
    transition: opacity .25s;
  }
  body.nav-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  body.nav-open { overflow: hidden; }
  .nav-item { padding: 12px 10px; font-size: .95rem; min-height: 44px; }

  .menu-toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 4px;
    width: 44px;
    height: 44px;
    padding: 0 12px;
    flex-shrink: 0;
    border: 1px solid var(--border);
    border-radius: 10px;
    background: var(--surface);
    cursor: pointer;
  }
  .menu-toggle span {
    display: block;
    height: 2px;
    border-radius: 2px;
    background: var(--text);
  }

  /* Layout */
  .main { margin-left: 0; padding: 0 14px 20px; min-width: 0; }
  .topbar {
    position: sticky;
    top: 0;
    z-index: 100;
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
    margin: 0 -14px 16px;
    padding: calc(10px + env(safe-area-inset-top)) 14px 10px;
    background: var(--bg);
    box-shadow: 0 1px 0 var(--border);
    border-bottom: none;
  }
  .topbar-title-row { flex-wrap: wrap; gap: 10px; }
  .topbar-title { flex: 1; min-width: 0; }
  .topbar h2 { font-size: 1.15rem; line-height: 1.2; }
  .topbar p {
    font-size: .75rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  .promet-top-summary { width: 100%; }
  .topbar-actions { width: 100%; }
  .search-box { flex: 1; }
  .search-box input { width: 100%; min-height: 44px; }
  .date-display { display: none; }

  /* Inputs: 16px prevents iOS zoom on focus */
  input, select, textarea,
  .filters select, .filters input,
  .period-filter input,
  .search-box input,
  .form-group input,
  .form-group select,
  .form-group textarea { font-size: 16px !important; min-height: 44px; }
  textarea { min-height: 88px; }

  .btn { min-height: 44px; padding: 11px 16px; }
  .btn-icon { min-width: 44px; min-height: 44px; padding: 8px; }

  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar > .btn,
  .toolbar > div > .btn { width: 100%; justify-content: center; }
  .toolbar > div:not(.filters) { display: flex; flex-wrap: wrap; gap: 8px; }
  .toolbar > div:not(.filters) > .btn { flex: 1 1 140px; }
  .filters { width: 100%; }
  .filters > select,
  .filters > input,
  .filters > label { flex: 1 1 140px; min-width: 0; }
  .period-filter { flex-wrap: wrap; }
  .period-filter input { flex: 1; }

  /* Stats: compact 2-column cards */
  .stats-grid,
  .stats-grid-6,
  .stats-grid-4 { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
  .stats-grid-1 { grid-template-columns: 1fr; max-width: none; }
  .stat-card { flex-direction: column; gap: 8px; padding: 14px; }
  .stat-icon { width: 36px; height: 36px; font-size: 1.1rem; border-radius: 10px; }
  .stat-value { font-size: 1.25rem; }
  .stat-label, .stat-sub { font-size: .72rem; }
  .dashboard-grid { gap: 14px; }
  .dash-kpi:hover { transform: none; }
  .dash-panels { grid-template-columns: 1fr; }
  .card-header { padding: 12px 14px; }
  .card-body { padding: 10px 14px 14px; }
  .form-row { grid-template-columns: 1fr; }
  .expense-categories { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .exp-cat-card { padding: 12px 8px; min-height: 88px; }

  /* Tables become cards */
  .main .data-table thead { display: none; }
  .main .data-table,
  .main .data-table tbody,
  .main .data-table tr,
  .main .data-table td { display: block; width: 100%; }
  .main .data-table tbody tr {
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
  }
  .main .data-table tbody tr:last-child { border-bottom: none; }
  .main .data-table tbody tr:hover { background: none; }
  .main .data-table td {
    display: flow-root;
    padding: 5px 0;
    border: none;
    text-align: right;
    word-break: break-word;
    line-height: 1.5;
  }
  .main .data-table td::before {
    content: attr(data-label);
    float: left;
    max-width: 45%;
    margin-right: 12px;
    line-height: 1.9;
    font-size: .7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--text-muted);
    text-align: left;
  }
  .main .data-table td[data-label=""]::before { display: none; }
  .main .data-table td:first-child {
    font-size: .95rem;
    font-weight: 600;
    padding-bottom: 8px;
  }
  .main .data-table td.empty-state { display: block; text-align: center; }
  .main .data-table td .btn-group { display: inline-flex; justify-content: flex-end; flex-wrap: wrap; }
  .main .data-table td .btn-icon { width: 44px; height: 44px; }
  .table-wrap { overflow-x: visible; }
  .summary-bar { font-size: .82rem; line-height: 1.7; }
  .supplier-products-cell { max-width: 52vw; }

  /* Modals become bottom sheets */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal,
  .modal-lg {
    max-width: 100%;
    max-height: min(94dvh, 94vh);
    border-radius: 18px 18px 0 0;
    display: flex;
    flex-direction: column;
  }
  .modal-header { padding: 14px 16px; position: sticky; top: 0; background: var(--surface); z-index: 1; }
  .modal-body { padding: 16px; flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .modal-footer {
    position: sticky;
    bottom: 0;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    background: var(--surface);
  }
  .modal-footer .btn { flex: 1; justify-content: center; }
  .modal-close { font-size: 1.8rem; padding: 4px 8px; min-width: 44px; min-height: 44px; }

  .invoice-items-wrap { overflow: visible; }
  .invoice-items-table { min-width: 0; width: 100%; }
  .invoice-items-table thead { display: none; }
  .invoice-items-table,
  .invoice-items-table tbody,
  .invoice-items-table tr,
  .invoice-items-table td { display: block; width: 100%; }
  .invoice-items-table tbody tr {
    padding: 10px 0 12px;
    margin-bottom: 8px;
    border-bottom: 1px dashed var(--border);
  }
  .invoice-items-table td { padding: 4px 0; }
  .invoice-items-table td:nth-child(1)::before,
  .invoice-items-table td:nth-child(2)::before,
  .invoice-items-table td:nth-child(3)::before,
  .invoice-items-table td:nth-child(4)::before {
    display: block;
    font-size: .7rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 4px;
  }
  .invoice-items-table td:nth-child(1)::before { content: 'Артикл'; }
  .invoice-items-table td:nth-child(2)::before { content: 'Количина'; }
  .invoice-items-table td:nth-child(3)::before { content: 'Цена/ед.'; }
  .invoice-items-table td:nth-child(4)::before { content: 'Вкупно'; }
  .invoice-items-table td:last-child { text-align: right; }

  .supplier-product-head { display: none; }
  .supplier-product-row {
    grid-template-columns: 1fr 1fr 44px;
    padding-bottom: 8px;
    border-bottom: 1px dashed var(--border);
  }
  .supplier-product-row input[type="text"] { grid-column: 1 / -1; }

  .toast-container {
    left: 12px;
    right: 12px;
    bottom: calc(80px + env(safe-area-inset-bottom));
  }

  /* Bottom navigation */
  .mobile-nav {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 150;
    padding: 6px 6px calc(8px + env(safe-area-inset-bottom));
    background: #171a21;
    box-shadow: 0 -6px 20px rgba(0,0,0,.15);
  }
  .mobile-nav-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-height: 48px;
    padding: 6px 2px;
    border: none;
    border-radius: 10px;
    background: transparent;
    color: rgba(255,255,255,.6);
    font-family: inherit;
    font-size: .68rem;
    font-weight: 500;
    cursor: pointer;
  }
  .mobile-nav-item span { font-size: 1.15rem; line-height: 1.2; }
  .mobile-nav-item.active { color: #fff; background: rgba(232,93,4,.22); }
  body.auth-locked .mobile-nav { display: none; }
  body.auth-locked { padding-bottom: 0; }
  body.has-install-banner { padding-bottom: calc(138px + env(safe-area-inset-bottom)); }

  .login-card { padding: 22px 18px; }
}

@media print {
  .mobile-nav, .menu-toggle, .sidebar-backdrop, .install-banner { display: none !important; }
}

@media (display-mode: standalone) {
  .topbar { padding-top: calc(12px + env(safe-area-inset-top)); }
}
