:root {
  --bg: #F3F5EE;
  --surface: #FFFFFF;
  --ink: #1B241D;
  --ink-muted: #5E6B5F;
  --primary: #1E3B2E;
  --primary-light: #2E5641;
  --accent: #C68A2E;
  --accent-soft: #F0DDAA;
  --danger: #A6402B;
  --danger-soft: #F3DAD2;
  --border: #E2E6DA;
  --ring-filled: #3F7A54;
  --ring-empty: #D8CBA0;
  --radius: 10px;
  --shadow-sm: 0 1px 2px rgba(27, 36, 29, 0.06);
  --shadow-md: 0 6px 20px rgba(27, 36, 29, 0.08);
  --font-display: "Fraunces", serif;
  --font-body: "Inter", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
}

h1, h2 {
  font-family: var(--font-display);
  font-weight: 600;
  margin: 0;
  letter-spacing: -0.01em;
}

.app {
  display: grid;
  grid-template-columns: 248px 1fr;
  min-height: 100vh;
}

/* ---------- Sidebar ---------- */
.sidebar {
  background: var(--primary);
  color: #EAF0EA;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 6px;
}

.brand-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  line-height: 1.2;
}

.brand-sub {
  font-size: 11.5px;
  color: #AFC4B2;
  letter-spacing: 0.02em;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #D7E4D8;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.nav-item.active {
  background: var(--primary-light);
  color: #FFFFFF;
}

.nav-item.disabled {
  opacity: 0.45;
  cursor: default;
}

.nav-item svg { flex-shrink: 0; opacity: 0.9; }

.nav-subitem {
  padding: 8px 12px 8px 34px;
  font-size: 13px;
}

.nav-submenu {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.nav-submenu[hidden] { display: none; }

.api-link {
  margin-top: auto;
  display: flex;
  align-items: center;
  gap: 8px;
  color: #AFC4B2;
  text-decoration: none;
  font-size: 12.5px;
  padding: 10px 12px;
  border-top: 1px solid rgba(255,255,255,0.12);
}

.api-link:hover { color: #FFFFFF; }

/* ---------- Main ---------- */
.main {
  padding: 32px 40px 60px;
  max-width: 1180px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  margin-bottom: 22px;
  gap: 16px;
  flex-wrap: wrap;
}

.topbar h1 { font-size: 26px; margin-top: 6px; }

.year-switcher {
  display: flex;
  align-items: center;
  gap: 8px;
}

.year-switcher label {
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
}

.year-switcher select {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
  color: var(--primary);
  background: var(--accent-soft);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 5px 10px;
  cursor: pointer;
}

.year-switcher select:focus {
  outline: 2px solid var(--primary-light);
  outline-offset: 1px;
}

.subtitle {
  color: var(--ink-muted);
  margin: 4px 0 0;
  font-size: 13.5px;
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-family: var(--font-body);
  font-weight: 600;
  font-size: 13.5px;
  cursor: pointer;
  transition: background 0.15s ease, transform 0.05s ease;
}
.btn:active { transform: translateY(1px); }

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-light); }

.btn-accent { background: var(--accent); color: #2A1C05; }
.btn-accent:hover { filter: brightness(1.05); }

.btn-ghost { background: transparent; color: var(--ink-muted); }
.btn-ghost:hover { background: var(--bg); color: var(--ink); }

.btn-icon {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 6px 8px;
  cursor: pointer;
  color: var(--ink-muted);
}
.btn-icon:hover { background: var(--bg); color: var(--ink); }
.btn-icon.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- Stats ---------- */
.stats-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 22px;
}

.stats-row-narrow {
  grid-template-columns: repeat(2, minmax(160px, 220px));
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}

.stat-value {
  font-family: var(--font-display);
  font-size: 28px;
  font-weight: 600;
}

.stat-label {
  font-size: 12.5px;
  color: var(--ink-muted);
  margin-top: 2px;
}

.stat-good .stat-value { color: var(--ring-filled); }
.stat-warn .stat-value { color: var(--accent); }

/* ---------- Filter bar ---------- */
.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: flex-end;
  padding: 16px 18px;
  border-bottom: 1px solid var(--border);
  background: #FAFBF6;
}

.filter-field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  min-width: 130px;
}

.filter-field label {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--ink-muted);
}

.filter-field input,
.filter-field select {
  font-family: var(--font-body);
  font-size: 13.5px;
  padding: 7px 9px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #FFFFFF;
  color: var(--ink);
}

.filter-field input:focus,
.filter-field select:focus {
  outline: 2px solid var(--primary-light);
  outline-offset: 1px;
}

.filter-field input[type="date"] { width: 140px; }

.filter-range-inputs { display: flex; gap: 6px; }
.filter-range-inputs input { width: 74px; }

/* ---------- Table ---------- */
.table-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.table-scroll { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-muted);
  padding: 12px 18px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 13px 18px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #FAFBF6; }

.col-actions { text-align: right; }
td.col-actions { text-align: right; white-space: nowrap; }

.row-clickable { cursor: pointer; }

.cell-name { font-weight: 600; }
.cell-sub { color: var(--ink-muted); font-size: 12.5px; }

.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--ink-muted);
}
.empty-state .btn { margin-top: 12px; }

/* ---------- Rendezhető fejlécek ---------- */
thead th.sortable {
  cursor: pointer;
  user-select: none;
}
thead th.sortable:hover { color: var(--ink); }

.sort-icon {
  display: inline-block;
  margin-left: 4px;
  font-size: 9px;
  opacity: 0.3;
  transform: translateY(-1px);
}
.sort-icon::after { content: "▲"; }

thead th.sort-active .sort-icon { opacity: 1; color: var(--primary); }
thead th.sort-desc .sort-icon::after { content: "▼"; }

/* ---------- Lapozás ---------- */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  padding: 14px 18px;
  border-top: 1px solid var(--border);
  background: #FAFBF6;
}
.pagination-bar[hidden] { display: none; }

.pagination-info {
  font-size: 12.5px;
  color: var(--ink-muted);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pagination-page {
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
  min-width: 56px;
  text-align: center;
}

.page-size-group { display: flex; gap: 4px; }

.page-size-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 7px;
  padding: 5px 10px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
}
.page-size-btn:hover { background: var(--bg); color: var(--ink); }
.page-size-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }

.btn-icon:disabled {
  opacity: 0.35;
  cursor: default;
  pointer-events: none;
}

/* ---------- Dialogs ---------- */
dialog.dialog {
  border: none;
  border-radius: 14px;
  padding: 0;
  width: 480px;
  max-width: calc(100vw - 32px);
  box-shadow: var(--shadow-md);
}

dialog.dialog-wide { width: 760px; }

dialog.dialog::backdrop {
  background: rgba(27, 36, 29, 0.45);
}

.dialog-form {
  padding: 26px 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.dialog-form h2 { margin-bottom: 4px; }

.dialog-form label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.optional { font-weight: 400; color: var(--ink-muted); }

.form-field-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}

.optional-label { display: block; }

.assignment-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 6px; }
.assignment-list:empty { display: none; }
.assignment-row {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--accent-soft); border-radius: 7px; padding: 6px 10px; font-size: 13px;
  font-weight: 400;
}
.assignment-add-row { display: flex; gap: 8px; align-items: center; }
.assignment-add-row select { flex: 1; }

.dialog-form input,
.dialog-form select,
.dialog-form textarea {
  font-family: var(--font-body);
  font-size: 14px;
  padding: 9px 11px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: #FCFDFA;
  color: var(--ink);
}

.dialog-form input:focus,
.dialog-form select:focus,
.dialog-form textarea:focus {
  outline: 2px solid var(--primary-light);
  outline-offset: 1px;
}

.dialog-form textarea { resize: vertical; font-family: var(--font-body); }

.hint {
  font-weight: 400;
  font-size: 11.5px;
  color: var(--ink-muted);
}

.form-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 7px;
  padding: 8px 12px;
  font-size: 13px;
  margin: 0;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 6px;
}

.detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.detail-header-actions {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.detail-actions {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 10px;
}

.stock-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 14px;
}

.stock-summary:empty { display: none; }

.stock-badge {
  display: inline-flex;
  align-items: baseline;
  gap: 5px;
  background: var(--accent-soft);
  color: var(--primary);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 12.5px;
  font-weight: 600;
}

.stock-badge .stock-badge-count {
  font-family: var(--font-display);
  font-size: 14px;
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  bottom: 26px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff;
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 13.5px;
  box-shadow: var(--shadow-md);
  z-index: 50;
}

.toast.error { background: var(--danger); }

/* ---------- Responsive ---------- */
@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; align-items: center; padding: 14px 18px; }
  .nav { flex-direction: row; }
  .api-link { display: none; }
  .main { padding: 22px; }
  .stats-row { grid-template-columns: repeat(2, 1fr); }
}

/* ---------- Bejelentkező oldal (login.html) ---------- */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 32px 36px;
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.login-card .dialog-form { padding: 0; }

/* ---------- Sidebar: bejelentkezett felhasználó ---------- */
.sidebar-user {
  border-top: 1px solid rgba(234, 240, 234, 0.15);
  padding-top: 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sidebar-user-name {
  font-size: 13px;
  font-weight: 600;
  color: #EAF0EA;
}

.btn-logout { width: 100%; justify-content: center; }

/* ---------- Checkbox mező (pl. Felhasználó "Aktív" mezője) ---------- */
.checkbox-label {
  flex-direction: row !important;
  align-items: center;
  gap: 8px !important;
}
