:root {
  --bg: #f4f6fa;
  --card: #fff;
  --text: #101827;
  --muted: #6b7280;
  --border: #e4e9f0;
  --brand: #0ea5e9;
  --brand-dark: #0369a1;
  --danger: #dc2626;
  --ok: #16a34a;
  --warn: #b45309;
  --shadow: 0 2px 8px rgba(15,23,42,.06);
}
* { box-sizing: border-box; }
body { margin: 0; padding: 0; background: var(--bg); color: var(--text);
       font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
                    "Helvetica Neue", Arial, sans-serif; font-size: 14px; line-height: 1.4; }
a { color: var(--brand-dark); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------- Top nav --------------------------------------------------- */
.topnav { background: var(--card); border-bottom: 1px solid var(--border);
          padding: 0 20px; display: flex; align-items: center; gap: 16px;
          height: 56px; box-shadow: var(--shadow); }
.topnav a { color: var(--text); padding: 8px 6px; }
.topnav__brand a { font-weight: 700; font-size: 16px; color: var(--brand-dark); }
.topnav__spacer { flex: 1; }
.topnav__user { color: var(--muted); font-size: 13px; }
.topnav__logout { color: var(--danger); }

/* ---------- Page ------------------------------------------------------ */
.page { max-width: 1100px; margin: 0 auto; padding: 24px 20px 64px; }
h1 { font-size: 22px; margin: 0 0 16px; display: flex; gap: 10px; align-items: center; }
h2 { font-size: 16px; margin: 20px 0 10px; }
h3 { font-size: 14px; margin: 14px 0 6px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.debt  { color: var(--danger); }
.pay   { color: var(--ok); }

/* ---------- Flash ---------------------------------------------------- */
.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px;
         border: 1px solid var(--border); background: var(--card); }
.flash--success { background: #dcfce7; border-color: #86efac; }
.flash--error   { background: #fee2e2; border-color: #fca5a5; }

/* ---------- Auth cards ------------------------------------------------ */
.auth-card { max-width: 420px; margin: 60px auto; background: var(--card);
             padding: 24px; border-radius: 12px; box-shadow: var(--shadow); }
.auth-card label { display: block; margin-bottom: 10px; font-size: 13px; color: var(--muted); }
.auth-card input { display: block; width: 100%; padding: 10px 12px; margin-top: 4px;
                   border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.auth-card .btn { width: 100%; margin-top: 8px; }

/* ---------- Tiles ---------------------------------------------------- */
.tiles { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
         margin-bottom: 24px; }
.tile { background: var(--card); padding: 18px; border-radius: 12px; box-shadow: var(--shadow); }
.tile__val { font-size: 24px; font-weight: 700; }
.tile__lbl { color: var(--muted); margin-top: 4px; }
.tile--accent { background: linear-gradient(135deg, #0ea5e9, #0369a1); color: #fff; }
.tile--accent .tile__lbl { color: rgba(255,255,255,.85); }
.tile--warn { background: #fee2e2; }
.tile--pending { background: linear-gradient(135deg, #f59e0b, #b45309); color: #fff; }
.tile--pending .tile__lbl { color: rgba(255,255,255,.85); }

/* ---------- Filters / chips ------------------------------------------ */
.filters { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 12px; }
.chip { display: inline-block; padding: 4px 10px; border-radius: 999px;
        border: 1px solid var(--border); background: var(--card);
        color: var(--text); font-size: 12px; }
.chip:hover { text-decoration: none; }
.chip--active { border-color: var(--brand); color: var(--brand-dark); }
.chip--new       { background: #dbeafe; }
.chip--confirmed { background: #ede9fe; }
.chip--paid      { background: #dcfce7; }
.chip--debt      { background: #fee2e2; }
.chip--issued    { background: #fef3c7; }
.chip--closed    { background: #e5e7eb; }
.chip--pending   { background: #fde68a; color: #78350f; }

/* Badge для колонки "Видача" в списку замовлень */
.badge { display: inline-block; padding: 2px 8px; border-radius: 6px;
         font-size: 12px; font-weight: 500; white-space: nowrap; }
.badge--issued  { background: #dcfce7; color: #14532d; }
.badge--pending { background: #fde68a; color: #78350f; }
.badge--muted   { background: #f3f4f6; color: var(--muted); }

/* ---------- Table ---------------------------------------------------- */
.tbl { width: 100%; border-collapse: collapse; background: var(--card);
       box-shadow: var(--shadow); border-radius: 10px; overflow: hidden;
       margin-bottom: 16px; }
.tbl th, .tbl td { text-align: left; padding: 10px 12px; font-size: 13px; border-top: 1px solid var(--border); }
.tbl thead th { background: #f9fafb; border-top: 0; color: var(--muted); font-weight: 500; }
.tbl tfoot th { background: #f9fafb; }
.tbl .num, .num { text-align: right; font-variant-numeric: tabular-nums; }
.row-off { opacity: .55; }

/* Клікабельний рядок таблиці: клік по будь-якій клітинці → перехід. */
.tbl tbody tr.row-link { cursor: pointer; transition: background .12s ease; }
.tbl tbody tr.row-link:hover { background: #eff6ff; }
.tbl tbody tr.row-link:active { background: #dbeafe; }
.tbl tbody tr.row-link a { color: inherit; }
.tbl tbody tr.row-link a:hover { text-decoration: underline; }

/* ---------- Cards / forms ------------------------------------------- */
.card { background: var(--card); padding: 16px; border-radius: 12px;
        box-shadow: var(--shadow); margin-bottom: 16px; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
@media (max-width: 800px) { .two-col { grid-template-columns: 1fr; } }
.inline-form { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.inline-form input, .inline-form select {
  padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px;
}
.search-form { display: flex; gap: 6px; margin-bottom: 12px; }
.search-form input, .search-form select {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
.search-form input { flex: 1; }

/* ---------- Buttons -------------------------------------------------- */
.btn { display: inline-block; padding: 8px 14px; border-radius: 8px;
       border: 1px solid var(--border); background: var(--card); color: var(--text);
       font-size: 13px; cursor: pointer; font-family: inherit; }
.btn:hover { text-decoration: none; background: #f3f4f6; }
.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); color: #fff; }
.btn--sm { padding: 4px 8px; font-size: 12px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Live search results ------------------------------------- */
.results { max-height: 280px; overflow-y: auto; margin: 8px 0; }
.results .row { padding: 8px 10px; border-radius: 8px; cursor: pointer;
                display: flex; justify-content: space-between; gap: 8px;
                border: 1px solid transparent; }
.results .row:hover { border-color: var(--border); background: #f9fafb; }
.results .row + .row { margin-top: 4px; }
.results .name { flex: 1; }
.results .meta { color: var(--muted); font-size: 12px; }

.selected { padding: 10px; border-radius: 8px; background: #f0f9ff;
            border: 1px solid #bae6fd; margin-top: 8px; }

/* ---------- Field blocks (форми редагування в картці) ---------------- */
.field-block { margin: 16px 0 20px; padding: 12px; border: 1px solid var(--border);
               border-radius: 10px; background: #fbfcfe; }
.field-block h3 { margin: 0 0 8px; font-size: 13px; font-weight: 600;
                  text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.field-row { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
.field-row input[type="number"], .field-row input[type="text"], .field-row input:not([type]) {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px;
  font-size: 14px; min-width: 100px;
}
.field-row input[type="number"] { width: 100px; }
.field-row .field-suffix { color: var(--muted); font-size: 14px; }
.field-row .btn { padding: 8px 14px; }
.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0;
                   margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; }
