/*
 * Sculeprime Gestiune — design system stylesheet.
 * Single file, CSS custom properties, mobile-first. Light theme is the
 * default; @media (prefers-color-scheme: dark) overrides the tokens.
 * No external fonts, no build step, no external requests.
 */

/* ---------------------------------------------------------------------- */
/* Tokens                                                                  */
/* ---------------------------------------------------------------------- */

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --ink: #16181d;
  --muted: #5b6370;
  --line: #e3e6ea;
  --brand: #2f6df6;
  --brand-ink: #ffffff;
  --brand-hover: #2559d1;

  --good: #1a8f4c;
  --good-bg: #e6f6ec;
  --warn: #c77700;
  --warn-bg: #fdf1de;
  --bad: #d23b3b;
  --bad-bg: #fbe9e9;
  --info: #5b6370;
  --info-bg: #eef0f3;
  --head: #1f2a44;
  --head-ink: #eaf0ff;

  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 2px rgba(16, 18, 22, 0.06), 0 1px 8px rgba(16, 18, 22, 0.04);

  --sidebar-width: 240px;
  --header-height: 60px;
  --bottom-nav-height: 64px;
  --content-max-width: 1100px;

  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14161a;
    --surface: #1c1f25;
    --surface-2: #23262d;
    --ink: #eef0f3;
    --muted: #9aa3b0;
    --line: #2c3038;
    --brand: #5b8bff;
    --brand-ink: #0c1220;
    --brand-hover: #7ba0ff;

    --good: #38c07a;
    --good-bg: #113222;
    --warn: #e0a13a;
    --warn-bg: #3a2c10;
    --bad: #ea6565;
    --bad-bg: #3a1414;
    --info: #9aa3b0;
    --info-bg: #23262d;
    --head: #0b1220;
    --head-ink: #cdd9f0;

    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 8px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --bg: #14161a;
  --surface: #1c1f25;
  --surface-2: #23262d;
  --ink: #eef0f3;
  --muted: #9aa3b0;
  --line: #2c3038;
  --brand: #5b8bff;
  --brand-ink: #0c1220;
  --brand-hover: #7ba0ff;
  --good: #38c07a;
  --good-bg: #113222;
  --warn: #e0a13a;
  --warn-bg: #3a2c10;
  --bad: #ea6565;
  --bad-bg: #3a1414;
  --info: #9aa3b0;
  --info-bg: #23262d;
  --head: #0b1220;
  --head-ink: #cdd9f0;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 1px 8px rgba(0, 0, 0, 0.25);
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #eef0f3;
  --ink: #16181d;
  --muted: #5b6370;
  --line: #e3e6ea;
  --brand: #2f6df6;
  --brand-ink: #ffffff;
  --brand-hover: #2559d1;
  --good: #1a8f4c;
  --good-bg: #e6f6ec;
  --warn: #c77700;
  --warn-bg: #fdf1de;
  --bad: #d23b3b;
  --bad-bg: #fbe9e9;
  --info: #5b6370;
  --info-bg: #eef0f3;
  --head: #1f2a44;
  --head-ink: #eaf0ff;
  color-scheme: light;
}

/* ---------------------------------------------------------------------- */
/* Reset & base                                                            */
/* ---------------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  /* Defensive: the page itself never scrolls sideways — wide content must
     scroll inside its own container (.table-wrap). Belt-and-suspenders behind
     the minmax(0,1fr) grid fix on .app. */
  overflow-x: hidden;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
    Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji";
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  margin: 0 0 0.5em;
  line-height: 1.25;
  font-weight: 700;
}

h1 { font-size: 1.75rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.125rem; }

p { margin: 0 0 1em; }

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

img { max-width: 100%; }

.tabular-nums,
.stat__value,
td.num,
th.num {
  font-variant-numeric: tabular-nums;
}

/* ---------------------------------------------------------------------- */
/* App shell / layout                                                      */
/* ---------------------------------------------------------------------- */

.app {
  min-height: 100vh;
  display: grid;
  /* minmax(0, 1fr) — NOT plain 1fr — so the column can shrink below the
     min-content width of its children (a wide header row, a wide table).
     With plain 1fr the header's intrinsic width stretched the whole app and
     the page scrolled sideways on mobile. */
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 1fr;
}

.app__header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  height: var(--header-height);
  padding: 0 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.app__brand {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--ink);
}

.app__brand small {
  font-weight: 400;
  color: var(--muted);
  font-size: 0.85rem;
}

.app__header-actions {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.app__user {
  color: var(--muted);
  font-size: 0.88rem;
  white-space: nowrap;
}

.app__logout-form {
  display: inline-flex;
}

.app__header-link {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
}

.app__header-link:hover {
  background: var(--surface-2);
  text-decoration: none;
  color: var(--ink);
}

/* Mobile: keep the top header within the viewport. The full header row
   (brand + company + user·role + logout + settings) is too wide for a phone
   and used to force the whole app to ~691px and scroll sideways. Drop the
   company name, the user identity, and the "Beállítások" label (icon stays);
   the bottom nav carries navigation. */
@media (max-width: 767px) {
  .app__header { gap: 0.5rem; }
  .app__brand { min-width: 0; }
  .app__brand small { display: none; }
  .app__user { display: none; }
  .app__header-actions { gap: 0.4rem; min-width: 0; }
  .app__header-link-text { display: none; }
}

.app__header-link.is-active {
  background: var(--brand);
  color: var(--brand-ink);
}

.app__body {
  display: flex;
  min-width: 0;
}

.app__sidebar {
  display: none;
}

.app__main {
  flex: 1;
  min-width: 0;
  padding: 1rem;
  padding-bottom: calc(var(--bottom-nav-height) + 1rem);
}

.app__content {
  max-width: var(--content-max-width);
  margin: 0 auto;
}

@media (min-width: 768px) {
  .app__sidebar {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    width: var(--sidebar-width);
    flex-shrink: 0;
    padding: 1rem 0.75rem;
    background: var(--surface);
    border-right: 1px solid var(--line);
    position: sticky;
    top: var(--header-height);
    height: calc(100vh - var(--header-height));
  }

  .app__main {
    padding: 1.5rem 2rem;
    padding-bottom: 1.5rem;
  }

  .bottom-nav {
    display: none;
  }
}

/* Nav (shared link styles for sidebar + bottom bar) */

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.6rem 0.75rem;
  border-radius: var(--radius-sm);
  color: var(--muted);
  font-size: 0.95rem;
  font-weight: 500;
}

.nav-link:hover {
  background: var(--surface-2);
  text-decoration: none;
  color: var(--ink);
}

.nav-link.is-active {
  background: var(--brand);
  color: var(--brand-ink);
}

.nav-link__icon {
  font-size: 1.1rem;
  line-height: 1;
  width: 1.3em;
  text-align: center;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  height: var(--bottom-nav-height);
  background: var(--surface);
  border-top: 1px solid var(--line);
  /* Many sections → more tabs than fit on a phone. Scroll the bar horizontally
     (inside itself, never the page) so every tab stays reachable. */
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.bottom-nav::-webkit-scrollbar { display: none; }

.bottom-nav .nav-link {
  flex: 0 0 auto;
  min-width: 4.5rem;
  flex-direction: column;
  gap: 0.15rem;
  border-radius: 0;
  padding: 0.4rem 0.25rem;
  font-size: 0.7rem;
  text-align: center;
}

.bottom-nav .nav-link.is-active {
  background: transparent;
  color: var(--brand);
}

.bottom-nav .nav-link__icon {
  font-size: 1.25rem;
  width: auto;
}

/* Desktop: the sidebar carries navigation, so hide the bottom bar. This must
   come AFTER the base .bottom-nav{display:flex} to win on source order. */
@media (min-width: 768px) {
  .bottom-nav { display: none; }
}

/* ---------------------------------------------------------------------- */
/* Page header                                                             */
/* ---------------------------------------------------------------------- */

.page-header {
  position: sticky;
  top: var(--header-height);
  z-index: 10;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin: -1rem -1rem 1rem;
  padding: 1rem;
  background: var(--bg);
}

@media (min-width: 768px) {
  .page-header {
    margin: -1.5rem -2rem 1.5rem;
    padding: 1.5rem 2rem 1rem;
    top: var(--header-height);
  }
}

.page-header h1 {
  margin: 0;
}

.page-header__actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

/* ---------------------------------------------------------------------- */
/* Card / stat / grid                                                      */
/* ---------------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.25rem;
}

.card > h2, .card > h3 {
  margin-top: 0;
}

.card--danger {
  border-color: var(--bad);
  border-left-width: 4px;
  background: var(--bad-bg);
}

/* Clickable report/tile cards. */
.card--link {
  display: block;
  text-decoration: none;
  color: inherit;
  transition: border-color .12s ease, box-shadow .12s ease, transform .12s ease;
}
.card--link:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}
.card--link .card__icon { font-size: 1.6rem; }
.card--link .card__title { font-weight: 600; margin: .35rem 0 .25rem; }
.card--link p { margin: 0; color: var(--muted); font-size: .85rem; }

/* Inline filter bar (period pickers + export buttons). */
.filter-bar {
  display: flex;
  align-items: flex-end;
  gap: .75rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.filter-bar .field { margin: 0; }

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

a.stat {
  text-decoration: none;
  color: inherit;
  transition: border-color .12s ease, transform .12s ease;
}
a.stat:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
}

.stat__label {
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.stat__value {
  font-size: 1.9rem;
  font-weight: 700;
  line-height: 1.1;
}

.stat__sub {
  color: var(--muted);
  font-size: 0.85rem;
}

.stat--good .stat__value { color: var(--good); }
.stat--warn .stat__value { color: var(--warn); }
.stat--bad .stat__value { color: var(--bad); }

.link-card {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.25rem;
  color: var(--ink);
  font-weight: 600;
  transition: border-color 0.15s ease;
}

.link-card:hover {
  border-color: var(--brand);
  text-decoration: none;
}

.link-card__icon {
  font-size: 1.5rem;
  line-height: 1;
}

.link-card__label small {
  display: block;
  font-weight: 400;
  color: var(--muted);
  font-size: 0.8rem;
}

/* ---------------------------------------------------------------------- */
/* Table (responsive: real table desktop, stacked cards mobile)            */
/* ---------------------------------------------------------------------- */

.table-wrap {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  /* A wide table scrolls INSIDE its own card (never the page). On mobile the
     .table switches to the stacked layout below, so this rarely engages there. */
  overflow-x: auto;
}

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

.table th,
.table td {
  padding: 0.65rem 0.9rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}

.table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  background: var(--surface-2);
}

.table tbody tr:last-child td {
  border-bottom: none;
}

.table tbody tr:hover {
  background: var(--surface-2);
}

.table td.num,
.table th.num {
  text-align: right;
}

@media (max-width: 767px) {
  .table thead {
    display: none;
  }

  .table, .table tbody, .table tr, .table td {
    display: block;
    width: 100%;
  }

  .table tr {
    border-bottom: 1px solid var(--line);
    padding: 0.75rem 0.9rem;
  }

  .table tbody tr:last-child {
    border-bottom: none;
  }

  .table td {
    border-bottom: none;
    padding: 0.2rem 0;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
  }

  .table td[data-label]::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 600;
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.02em;
    flex-shrink: 0;
  }

  .table td.num {
    text-align: right;
  }

  /* Wide, data-dense analytics tables opt OUT of the stacked layout: on mobile
     they stay a real table and scroll horizontally INSIDE their .table-wrap
     card (headers preserved), which reads far better than 15 label-less values
     stacked per row. */
  .table--scroll {
    display: table;
    width: max-content;
    min-width: 100%;
    white-space: nowrap;
  }
  .table--scroll thead { display: table-header-group; }
  .table--scroll tbody { display: table-row-group; }
  .table--scroll tfoot { display: table-footer-group; }
  .table--scroll tr { display: table-row; padding: 0; }
  .table--scroll td, .table--scroll th {
    display: table-cell;
    width: auto;
    border-bottom: 1px solid var(--line);
  }
  .table--scroll td::before { content: none; }
}

/* ---------------------------------------------------------------------- */
/* List-page card (filter bar + polished table + footer)                  */
/*                                                                        */
/* Scoped, additive classes for the 5 main list pages (Számlák, Partnerek,*/
/* Készlet, Bejövő, Pénzügy) — layered ALONGSIDE the existing .table-wrap/*/
/* .table so unrelated tables (detail pages, settings, invoice lines)     */
/* stay untouched.                                                        */
/* ---------------------------------------------------------------------- */

.list-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.list-card .table-wrap {
  border: 0;
  box-shadow: none;
  border-radius: 0;
}

.list-filters {
  display: flex;
  gap: 0.6rem;
  flex-wrap: wrap;
  align-items: flex-end;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}

.table--list thead th {
  background: var(--head);
  color: var(--head-ink);
}

.table--list td.num,
.table--list th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.list-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.9rem;
}

/* ---------------------------------------------------------------------- */
/* Badge                                                                   */
/* ---------------------------------------------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--info-bg);
  color: var(--info);
  white-space: nowrap;
}

.badge::before {
  content: "";
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.9;
}

.badge--good { background: var(--good-bg); color: var(--good); }
.badge--warn { background: var(--warn-bg); color: var(--warn); }
.badge--bad  { background: var(--bad-bg);  color: var(--bad); }
.badge--info { background: var(--info-bg); color: var(--info); }

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 600;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  line-height: 1.2;
  transition: background 0.12s ease, border-color 0.12s ease, opacity 0.12s ease;
}

.btn:hover {
  background: var(--surface-2);
  text-decoration: none;
}

.btn--primary {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
}

.btn--primary:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
}

.btn--ghost {
  background: transparent;
  border-color: transparent;
  color: var(--brand);
}

.btn--ghost:hover {
  background: var(--surface-2);
}

.btn--danger {
  background: var(--bad);
  border-color: var(--bad);
  color: #ffffff;
}

.btn--danger:hover {
  opacity: 0.9;
}

.btn--sm {
  padding: 0.32rem 0.7rem;
  font-size: 0.82rem;
}

.btn:disabled,
.btn[disabled] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

.btn-row {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

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

.form-row {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-bottom: 1rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  flex: 1;
  min-width: 180px;
}

.field label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--muted);
}

.input,
.select,
textarea.input {
  font: inherit;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--ink);
  width: 100%;
}

.input:focus,
.select:focus,
textarea.input:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
  border-color: var(--brand);
}

.field--error .input,
.field--error .select {
  border-color: var(--bad);
}

.field__error {
  color: var(--bad);
  font-size: 0.82rem;
}

.field__hint {
  color: var(--muted);
  font-size: 0.8rem;
}

/* ---------------------------------------------------------------------- */
/* Flash / empty state / pills                                             */
/* ---------------------------------------------------------------------- */

.flash {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  margin-bottom: 1rem;
  font-size: 0.92rem;
}

.flash--success {
  background: var(--good-bg);
  border-color: var(--good);
  color: var(--good);
}

.flash--error {
  background: var(--bad-bg);
  border-color: var(--bad);
  color: var(--bad);
}

.flash--warning {
  background: var(--warn-bg);
  border-color: var(--warn);
  color: var(--warn);
}

.empty {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--muted);
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.empty__icon {
  font-size: 2.2rem;
  margin-bottom: 0.5rem;
}

.empty__title {
  color: var(--ink);
  font-weight: 700;
  font-size: 1.05rem;
  margin-bottom: 0.25rem;
}

.pill-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
}

.pill:hover {
  border-color: var(--brand);
  color: var(--ink);
  text-decoration: none;
}

.pill.is-active {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
}

/* Checkbox-backed filter pill (e.g. Árazás warning toggles): the input is
   visually hidden but stays in the accessibility tree and in normal form
   submission, so it works with hx-include like any other field. */
.pill-toggle {
  position: relative;
}

.pill-toggle input {
  position: absolute;
  inset: 0;
  opacity: 0;
  margin: 0;
  cursor: pointer;
}

.pill-toggle:has(input:checked) {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--brand-ink);
}

/* Stock overlay popped next to a line's quantity cell (hover/focus). */
.stock-pop {
  position: absolute;
  z-index: 50;
  min-width: 220px;
  max-width: 320px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 6px 24px rgba(16,32,44,.18);
  padding: 10px 12px;
  font-size: .82rem;
  pointer-events: none;
}
.stock-pop .sp-title {
  font-size: .7rem; text-transform: uppercase; letter-spacing: .05em;
  color: var(--muted); font-weight: 700; margin: 2px 0 5px;
}
.stock-pop .sp-title + .sp-title, .stock-pop .sp-total + .sp-title { margin-top: 10px; }
.stock-pop .sp-row { display: flex; justify-content: space-between; gap: 14px; padding: 2px 0; }
.stock-pop .sp-row .tnum { font-variant-numeric: tabular-nums; white-space: nowrap; }
.stock-pop .sp-muted { color: var(--muted); }
.stock-pop .sp-total { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 5px; font-weight: 700; }
.stock-pop .sp-empty { color: var(--muted); }

/* Input paired with an inline action button (e.g. CIF + ANAF fetch). */
.input-with-btn {
  display: flex;
  gap: 0.4rem;
  align-items: stretch;
}

.input-with-btn .input {
  flex: 1;
  min-width: 0;
}

.input-with-btn .btn {
  flex: none;
  white-space: nowrap;
}

/* ---------------------------------------------------------------------- */
/* Invoice line rows + stock toggle                                        */
/* ---------------------------------------------------------------------- */

/* NOTE: `.line-row` is a table `<tr>` in the invoice line table — it must NOT
   be a flex container (that collapsed every cell into one vertical column).
   The row is targeted in JS by the `data-line-row` attribute, not this class. */

.field--narrow {
  flex: 0 1 8rem;
  min-width: 6rem;
}

.btn-row--tight {
  margin: 0.25rem 0 1rem;
}

/* Per-line stock coupling. The DEFAULT (checked) state is deliberately calm —
   deducting stock is the normal case. Unchecking is the exception (fără
   scădere), so it flips to a loud amber warning that stands out. */
.stock-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.2rem 0;
  line-height: 1.15;
  white-space: normal;
}

.stock-toggle__box {
  width: 0.9rem;
  height: 0.9rem;
  flex: none;
  accent-color: var(--good);
  cursor: pointer;
}

.stock-toggle__on {
  color: var(--good);
}

.stock-toggle__off {
  display: none;
  color: var(--warn);
}

/* Unchecked -> hide the calm "deduct" label, reveal the amber warning. */
.stock-toggle:has(.stock-toggle__box:not(:checked)) .stock-toggle__on {
  display: none;
}

.stock-toggle:has(.stock-toggle__box:not(:checked)) .stock-toggle__off {
  display: inline;
}

.stock-toggle:has(.stock-toggle__box:not(:checked)) .stock-toggle__box {
  accent-color: var(--warn);
}

/* Per-line "the entered price is gross (ÁFÁ-s)" toggle, sitting under the
   price input in the price cell. */
.gross-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  cursor: pointer;
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--muted);
  margin-top: 0.2rem;
  white-space: nowrap;
}

.gross-toggle__box {
  width: 0.85rem;
  height: 0.85rem;
  flex: none;
  cursor: pointer;
}

.gross-toggle:has(.gross-toggle__box:checked) {
  color: var(--accent);
}

/* ---------------------------------------------------------------------- */
/* Invoice line TABLE (inline-editable spreadsheet-style tétel table) +    */
/* live totals card.                                                       */
/* ---------------------------------------------------------------------- */

.table--lines th,
.table--lines td {
  padding: 0.4rem 0.5rem;
  vertical-align: middle;
  white-space: nowrap;
}

.table--lines .lines-idx {
  width: 2rem;
  text-align: center;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.table--lines .lines-col-prod {
  min-width: 14rem;
  white-space: normal;
}

.table--lines .lines-col-qty { width: 6rem; }
.table--lines .lines-col-um { width: 6rem; }
.table--lines .lines-col-vat { width: 8.5rem; }
.table--lines .lines-col-price { width: 6rem; }
.table--lines .lines-col-val { width: 6.5rem; }
.table--lines .lines-col-tva { width: 6rem; }
.table--lines .lines-col-mgmt { width: 7rem; }
.table--lines .lines-col-stk { width: 7.5rem; white-space: normal; }
.table--lines .lines-col-del { width: 2rem; text-align: center; }

.table--lines td.num,
.table--lines th.num {
  font-variant-numeric: tabular-nums;
}

/* A borderless input/select that only reveals its outline on hover/focus —
   the table itself supplies the visual grid, so each cell doesn't need its
   own boxed control (see szamla-vazlat.html prototype). */
.cell-input {
  border: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.5rem;
  width: 100%;
  min-width: 0;
}

.cell-input:hover {
  border-color: var(--brand);
}

.cell-input:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
  border-color: var(--brand);
  background: var(--surface);
}

.line-remove-btn {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.1rem;
  line-height: 1;
  padding: 0.2rem 0.45rem;
  border-radius: var(--radius-sm);
}

.line-remove-btn:hover {
  color: var(--bad);
  background: var(--bad-bg);
}

/* Custom product combobox (replaces the native <datalist>): one shared menu,
   repositioned under whichever product cell is active. Each option shows the
   SKU, name, and the product's stock (per gestiune + a total badge). */
.combo-menu {
  position: absolute;
  z-index: 60;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: 0 10px 30px rgba(16, 32, 44, .22);
  max-height: 300px;
  overflow-y: auto;
  min-width: 20rem;
  padding: 0.25rem;
  display: none;
}
.combo-menu.is-open { display: block; }
.combo-opt {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 0.6rem;
  border-radius: 7px;
  cursor: pointer;
}
.combo-opt:hover,
.combo-opt.is-hl { background: var(--surface-2); }
.combo-opt__main { min-width: 0; }
.combo-opt__sku { font-family: var(--font-mono, ui-monospace, monospace); font-weight: 600; font-size: 0.86rem; }
.combo-opt__name { color: var(--muted); font-size: 0.82rem; }
.combo-opt__sub { color: var(--muted); font-size: 0.75rem; margin-top: 1px; }
.combo-badge {
  flex: none;
  font-size: 0.76rem;
  font-weight: 700;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.combo-badge--in { background: var(--good-bg); color: var(--good); }
.combo-badge--low { background: var(--warn-bg); color: var(--warn); }
.combo-badge--none { background: var(--surface-2); color: var(--muted); }
.combo-empty { padding: 0.75rem 0.6rem; color: var(--muted); font-size: 0.88rem; }

.below-lines {
  display: flex;
  justify-content: flex-end;
  margin: 1rem 0;
}

.totals-card {
  min-width: 20rem;
  max-width: 26rem;
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 1.1rem;
  font-variant-numeric: tabular-nums;
}

.totals-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.25rem 0;
}

.totals-vat-lines {
  border-top: 1px dashed var(--line);
  border-bottom: 1px dashed var(--line);
  margin: 0.4rem 0;
  padding: 0.4rem 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.totals-vat-lines:empty {
  border-color: transparent;
  margin: 0;
  padding: 0;
}

.totals-row--grand {
  border-top: 1px solid var(--line);
  margin-top: 0.4rem;
  padding-top: 0.5rem;
  font-weight: 700;
  font-size: 1.05rem;
}

.totals-row--grand span:last-child {
  color: var(--brand);
}

/* NIR supplier-total countdown (SOFT — a display aid, never blocks submit):
   0,00 remaining -> "egyezik" (green); positive remaining -> the neutral
   grand-total brand color above; negative (overshoot) -> a red warning. */
.totals-row--grand.remain-ok,
.totals-row--grand.remain-ok span:last-child {
  color: var(--good);
}

.totals-row--grand.remain-over,
.totals-row--grand.remain-over span:last-child {
  color: var(--bad);
}

kbd {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 5px;
  padding: 0.05rem 0.4rem;
  font-size: 0.8rem;
}

@media (max-width: 767px) {
  /* The generic `.table` mobile rule below turns every table into stacked
     label/value cards — wrong for a spreadsheet-style editable line table
     (there's nowhere to put a per-column label next to an <input>/<select>).
     Override back to a real table and let it scroll horizontally instead,
     same idea as the prototype's `.tbl-scroll`. */
  .table-wrap:has(.table--lines) {
    overflow-x: auto;
  }

  .table--lines {
    display: table;
    min-width: 860px;
    width: auto;
  }

  .table--lines thead { display: table-header-group; }
  .table--lines tbody { display: table-row-group; }
  .table--lines tr { display: table-row; }
  .table--lines td,
  .table--lines th {
    display: table-cell;
    width: auto;
  }
}

/* ---------------------------------------------------------------------- */
/* Utilities                                                               */
/* ---------------------------------------------------------------------- */

.text-muted { color: var(--muted); }
.text-good { color: var(--good); }
.text-warn { color: var(--warn); }
.text-bad { color: var(--bad); }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.section { margin-bottom: 2rem; }

/* ---------------------------------------------------------------------- */
/* NIMINOM pricing-decision overlay (modal, htmx-swapped)                  */
/* ---------------------------------------------------------------------- */
.modal-backdrop{position:fixed;inset:0;z-index:60;background:rgba(15,23,42,.5);
  display:flex;align-items:flex-start;justify-content:center;padding:4vh 12px;overflow-y:auto;}
.modal-card{background:var(--surface);border:1px solid var(--line);border-radius:16px;
  box-shadow:0 20px 60px rgba(0,0,0,.35);width:100%;max-width:960px;overflow:hidden;}
.niminom-ov .ov-head{display:flex;align-items:center;justify-content:space-between;gap:12px;
  padding:16px 20px;border-bottom:1px solid var(--line);background:var(--surface-2);}
.niminom-ov .ov-sku{font-family:ui-monospace,SFMono-Regular,Menlo,monospace;color:var(--muted);font-size:.82rem;}
.niminom-ov .ov-name{font-weight:800;font-size:1.1rem;}
.niminom-ov .x{width:30px;height:30px;border-radius:8px;border:1px solid var(--line);
  background:var(--surface);color:var(--muted);cursor:pointer;font-size:1rem;}
.niminom-ov .ov-empty{padding:26px 22px;color:var(--muted);}
.niminom-ov .ov-grid{display:grid;grid-template-columns:.95fr 1.2fr 1.1fr;}
.niminom-ov .ov-col{padding:16px 20px;border-right:1px solid var(--line);}
.niminom-ov .ov-col:last-child{border-right:none;}
.niminom-ov .ov-col h3{margin:0 0 10px;font-size:.72rem;letter-spacing:.05em;text-transform:uppercase;color:var(--muted);}
.niminom-ov .ov-big{font-size:1.7rem;font-weight:800;letter-spacing:-.02em;line-height:1.15;}
.niminom-ov .ov-sub{color:var(--muted);font-size:.82rem;}
.niminom-ov .ov-kv{display:flex;justify-content:space-between;gap:10px;padding:5px 0;border-bottom:1px dashed var(--line);font-size:.9rem;}
.niminom-ov .ov-kv:last-child{border-bottom:none;}
.niminom-ov .ov-kv span:last-child{font-weight:700;}
.niminom-ov .ladder{display:flex;flex-direction:column;gap:6px;}
.niminom-ov .rung{display:flex;align-items:center;justify-content:space-between;gap:10px;
  padding:7px 10px;border-radius:9px;background:var(--surface-2);border:1px solid var(--line);font-size:.88rem;}
.niminom-ov .rung.you{background:var(--info-bg);border-color:transparent;}
.niminom-ov .rung.below-floor{opacity:.7;}
.niminom-ov .rung .who{display:flex;align-items:center;gap:8px;min-width:0;}
.niminom-ov .rung .cname{white-space:nowrap;overflow:hidden;text-overflow:ellipsis;}
.niminom-ov .rung .pr{font-weight:800;font-variant-numeric:tabular-nums;}
.niminom-ov .dot{width:8px;height:8px;border-radius:50%;flex-shrink:0;}
.niminom-ov .dot.good{background:var(--good);} .niminom-ov .dot.bad{background:var(--bad);}
.niminom-ov .tag{font-size:.64rem;font-weight:700;padding:1px 6px;border-radius:6px;text-transform:uppercase;letter-spacing:.03em;}
.niminom-ov .tag.floor{background:var(--bad-bg);color:var(--bad);}
.niminom-ov .tag.you{background:var(--accent);color:#fff;}
.niminom-ov .tag.oos{background:var(--warn-bg);color:var(--warn);}
.niminom-ov .rec-box{background:var(--good-bg);border-radius:11px;padding:12px 14px;margin-bottom:12px;}
.niminom-ov .rec-lbl{font-size:.7rem;text-transform:uppercase;letter-spacing:.05em;color:var(--good);font-weight:700;}
.niminom-ov .guard{display:flex;justify-content:space-between;gap:8px;font-size:.85rem;padding:4px 0;}
.niminom-ov .g-ok{color:var(--good);font-weight:700;} .niminom-ov .g-bad{color:var(--bad);font-weight:700;}
.niminom-ov .price-form{margin-top:12px;}
.niminom-ov .price-input{display:flex;gap:8px;margin:4px 0 6px;}
.niminom-ov .price-input .input{flex:1;font-weight:700;}
.niminom-ov .ov-manage{border-top:1px solid var(--line);padding:14px 20px;background:var(--surface-2);}
.niminom-ov .ov-manage h3{margin:0 0 8px;font-size:.72rem;letter-spacing:.05em;text-transform:uppercase;color:var(--muted);}
.niminom-ov .url-form{display:flex;gap:8px;flex-wrap:wrap;align-items:center;}
.niminom-ov .note{color:var(--muted);font-size:.85rem;}
@media (max-width:767px){
  .niminom-ov .ov-grid{grid-template-columns:1fr;}
  .niminom-ov .ov-col{border-right:none;border-bottom:1px solid var(--line);}
}
