/* ============================================================
   Пералня v2 — дизайн система (светъл „Портал" стил)
   Източник на истината за вида: одобрен макет Подход 2.
   ============================================================ */

* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg: #f4f6f8;
  --card: #ffffff;
  --border: #e5e7eb;
  --line: #f1f5f9;
  --shadow: 0 1px 3px rgba(15,23,42,.06);
  --shadow-md: 0 6px 20px rgba(15,23,42,.08);
  --ink: #0f172a;
  --body: #334155;
  --muted: #64748b;
  --faint: #94a3b8;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eff4ff;
  --good: #059669;
  --good-soft: #ecfdf5;
  --bad: #dc2626;
  --bad-soft: #fef2f2;
  --warn: #b45309;
  --warn-soft: #fffbeb;
  --radius: 16px;
  --radius-sm: 10px;
}

html, body { height: 100%; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--body);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  line-height: 1.5;
  font-size: 14px;
}
a { text-decoration: none; color: inherit; }
input, button, select, textarea { font-family: inherit; }

.layout { display: flex; min-height: 100vh; }

/* ---------- SIDEBAR ---------- */
.sidebar {
  width: 256px; flex-shrink: 0;
  background: var(--card);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand { padding: 22px 24px; border-bottom: 1px solid var(--border); }
.brand .logo { display: flex; align-items: center; gap: 11px; }
.brand .logo i { font-size: 22px; color: var(--accent); }
.brand .logo .title { font-size: 14px; font-weight: 700; color: var(--ink); line-height: 1.3; }
.brand .logo .sub { font-size: 12px; color: var(--muted); font-weight: 500; }

.nav { flex: 1; padding: 18px 14px; overflow-y: auto; }
.nav-group { margin-bottom: 22px; }
.nav-group-label {
  font-size: 11px; font-weight: 700; letter-spacing: .07em;
  color: var(--muted); text-transform: uppercase; padding: 0 12px 9px;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px;
  color: var(--body); font-size: 14px; font-weight: 500;
  margin-bottom: 2px; transition: background .12s, color .12s;
}
.nav-item i { font-size: 17px; color: var(--muted); width: 20px; text-align: center; }
.nav-item:hover { background: #f8fafc; color: var(--ink); }
.nav-item.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav-item.active i { color: var(--accent); }
.nav-item .badge-count {
  margin-left: auto; font-size: 11px; font-weight: 700;
  background: var(--bad-soft); color: var(--bad);
  border-radius: 999px; padding: 1px 7px;
}

.lang-switch { display: flex; gap: 6px; padding: 12px 18px 0; }
.lang-switch button { flex: 1; height: 32px; border: 1px solid var(--border); background: #fff; border-radius: 8px; font-size: 12.5px; font-weight: 700; color: var(--muted); cursor: pointer; transition: background .12s, color .12s; }
.lang-switch button:hover { background: #f8fafc; color: var(--ink); }
.lang-switch button.active { background: var(--accent-soft); color: var(--accent); border-color: #dbe7ff; }

.nav-user { padding: 16px 18px; border-top: 1px solid var(--border); display: flex; align-items: center; gap: 12px; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 14px; flex-shrink: 0;
}
.nav-user .name { font-size: 14px; font-weight: 600; color: var(--ink); }
.nav-user .role { font-size: 12px; color: var(--muted); }

/* ---------- MAIN ---------- */
.main { flex: 1; min-width: 0; padding: 40px 48px 64px; }
.content { max-width: 880px; margin: 0 auto; }
.content.wide { max-width: 1100px; }

/* ---------- PAGE HEADER ---------- */
.page-head { margin-bottom: 32px; display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; }
.page-head h1 { font-size: 34px; font-weight: 800; color: var(--ink); letter-spacing: -0.02em; line-height: 1.1; }
.page-head .date, .page-head .subtitle {
  margin-top: 8px; font-size: 15px; color: var(--muted); font-weight: 500;
  display: flex; align-items: center; gap: 8px;
}
.page-head .date i { color: var(--accent); font-size: 16px; }
.head-actions { display: flex; gap: 10px; flex-shrink: 0; }

/* ---------- STATUS BAND ---------- */
.status-band {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 28px 32px; display: flex; align-items: stretch; margin-bottom: 36px;
}
.stat { flex: 1; padding: 4px 8px; }
.stat-label { font-size: 13px; font-weight: 600; color: var(--muted); display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.stat-label i { font-size: 15px; }
.stat-value { font-size: 34px; font-weight: 800; color: var(--ink); letter-spacing: -0.02em; line-height: 1; }
.stat-value .unit { font-size: 16px; font-weight: 600; color: var(--muted); margin-left: 4px; }
.stat-sub { margin-top: 8px; font-size: 13px; color: var(--muted); font-weight: 500; }
.stat.good .stat-label i { color: var(--good); }
.stat.accent .stat-label i { color: var(--accent); }
.stat.bad .stat-value { color: var(--bad); }
.stat.bad .stat-label i { color: var(--bad); }
.stat.warn .stat-label i { color: var(--warn); }
.stat.warn .stat-value { color: var(--warn); }
.stat-divider { width: 1px; background: var(--border); margin: 4px 12px; }

/* receipt photo control (под таблицата за получаване) */
.receipt-photo-row { display: flex; align-items: center; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.receipt-photo-row .note a { color: var(--accent); font-weight: 600; }
.doc-thumb { display: inline-block; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; }
.doc-thumb img { display: block; max-width: 100%; height: auto; }

/* ---------- SECTION ---------- */
.section { margin-bottom: 36px; }
.section-head { display: flex; align-items: center; gap: 14px; margin-bottom: 18px; }
.section-num {
  width: 38px; height: 38px; border-radius: 11px;
  background: var(--accent-soft); color: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 800; flex-shrink: 0;
}
.section-head .titles h2 { font-size: 22px; font-weight: 700; color: var(--ink); letter-spacing: -0.01em; line-height: 1.2; }
.section-head .titles p { font-size: 14px; color: var(--muted); margin-top: 2px; }

/* ---------- CARD ---------- */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px 28px 28px; }
.card.pad-sm { padding: 18px 20px; }
.card-title { font-size: 16px; font-weight: 700; color: var(--ink); margin-bottom: 16px; }

/* ---------- TABLE ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table.t { width: 100%; border-collapse: collapse; }
table.t thead th {
  font-size: 12px; font-weight: 700; letter-spacing: .04em; text-transform: uppercase;
  color: var(--muted); text-align: left; padding: 0 14px 14px; border-bottom: 1px solid var(--border);
}
table.t thead th.num { text-align: center; }
table.t thead th.right { text-align: right; }
table.t tbody td { padding: 16px 14px; border-bottom: 1px solid var(--line); font-size: 15px; vertical-align: middle; }
table.t tbody tr:last-child td { border-bottom: none; }
table.t tbody tr.clickable { cursor: pointer; }
table.t tbody tr.clickable:hover { background: #f8fafc; }
table.t tfoot td { padding: 16px 14px; font-size: 15px; font-weight: 700; color: var(--ink); border-top: 2px solid var(--border); }
td.item { font-weight: 600; color: var(--ink); }
td.item i { color: var(--muted); font-size: 16px; margin-right: 9px; }
td.num, th.num { text-align: center; }
td.right, th.right { text-align: right; }
td.expected { text-align: center; color: var(--body); font-weight: 500; width: 130px; }
td.count { width: 140px; text-align: center; }
td.diff { width: 130px; text-align: center; }

/* compact table variant for dense lists (Дневник, Справки) */
table.t.compact tbody td { padding: 12px 14px; font-size: 14px; }

/* ---------- INPUTS ---------- */
.count-input, .send-input, .input {
  height: 44px; border: 1px solid var(--border); border-radius: 10px; background: #fff;
  font-size: 16px; font-weight: 600; color: var(--ink);
  transition: border-color .12s, box-shadow .12s;
}
.count-input { width: 100px; text-align: center; margin: 0 auto; display: block; }
.count-cell { display: flex; align-items: center; justify-content: center; gap: 6px; }
.count-cell .count-input { margin: 0; }
.fill-exp { width: 34px; height: 34px; flex-shrink: 0; border: 1px solid var(--border); background: #fff; border-radius: 8px; color: var(--good); cursor: pointer; display: flex; align-items: center; justify-content: center; font-size: 15px; transition: background .12s, border-color .12s; }
.fill-exp:hover { background: var(--good-soft); border-color: #a7f3d0; }
.fill-exp:active { transform: translateY(1px); }
.send-input { width: 110px; text-align: center; }
.input { width: 100%; padding: 0 14px; font-weight: 500; font-size: 15px; }
.input::placeholder, .send-input::placeholder { color: #cbd5e1; font-weight: 500; }
.count-input:focus, .send-input:focus, .input:focus, select.input:focus {
  outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
textarea.input { height: auto; padding: 12px 14px; resize: vertical; min-height: 80px; line-height: 1.5; }
select.input { cursor: pointer; }
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--body); margin-bottom: 7px; }
.field-row { display: flex; gap: 14px; }
.field-row .field { flex: 1; }
.date-input { max-width: 150px; }

/* Поле за дата с писане + календар */
.dtfield { display: inline-flex; align-items: stretch; width: 176px; max-width: 100%; vertical-align: top; }
.dtfield .dt-text { flex: 1; min-width: 0; border-top-right-radius: 0; border-bottom-right-radius: 0; border-right: none; }
.dt-cal-wrap { position: relative; flex: 0 0 42px; display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--border); border-top-right-radius: 10px; border-bottom-right-radius: 10px; background: #fff; color: var(--muted); cursor: pointer; font-size: 16px; transition: background .12s, color .12s; }
.dt-cal-wrap:hover { background: #f8fafc; color: var(--accent); }
.dt-iso { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0; cursor: pointer; padding: 0; margin: 0; border: 0; min-width: 0; }

/* stepper (+/-) */
.stepper { display: inline-flex; align-items: center; gap: 8px; }
.stepper button {
  width: 40px; height: 40px; border: 1px solid var(--border); background: #fff; border-radius: 10px;
  color: var(--body); font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: background .12s, border-color .12s;
}
.stepper button:hover { background: #f8fafc; border-color: #cbd5e1; }
.stepper input { width: 84px; height: 40px; text-align: center; border: 1px solid var(--border); border-radius: 10px; font-size: 16px; font-weight: 700; color: var(--ink); }
.stepper input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }

/* ---------- DIFF PILLS / BADGES ---------- */
.diff-pill, .badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 6px 13px; border-radius: 999px; font-size: 14px; font-weight: 700;
}
.diff-pill.zero, .badge.good { background: var(--good-soft); color: var(--good); }
.diff-pill.minus, .badge.bad { background: var(--bad-soft); color: var(--bad); }
.diff-pill.plus, .badge.accent { background: var(--accent-soft); color: var(--accent); }
.badge.muted { background: #f1f5f9; color: var(--muted); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.sm { padding: 3px 9px; font-size: 12px; }

/* ---------- BUTTONS ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  height: 44px; padding: 0 22px; border: 1px solid transparent; border-radius: 11px;
  font-size: 15px; font-weight: 600; cursor: pointer; transition: background .12s, transform .05s, border-color .12s;
  white-space: nowrap;
}
.btn i { font-size: 17px; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: translateY(1px); }
.btn-good { background: var(--good); color: #fff; }
.btn-good:hover { background: #047857; }
.btn-ghost { background: #fff; color: var(--body); border-color: var(--border); }
.btn-ghost:hover { background: #f8fafc; border-color: #cbd5e1; color: var(--ink); }
.btn-danger { background: #fff; color: var(--bad); border-color: #fecaca; }
.btn-danger:hover { background: var(--bad-soft); }
.btn-sm { height: 36px; padding: 0 14px; font-size: 13.5px; border-radius: 9px; }
.btn-lg { height: 50px; padding: 0 26px; font-size: 16px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: 9px; }

.section-actions { display: flex; justify-content: flex-end; gap: 12px; margin-top: 24px; padding-top: 22px; border-top: 1px solid var(--border); }
.section-actions.between { justify-content: space-between; align-items: center; }
.section-actions .note { font-size: 13px; color: var(--muted); }

/* ---------- SEND LIST ---------- */
.send-list { display: flex; flex-direction: column; }
.send-row { display: flex; align-items: center; justify-content: space-between; padding: 14px 4px; border-bottom: 1px solid var(--line); }
.send-row:last-child { border-bottom: none; }
.send-row .label { display: flex; align-items: center; gap: 12px; font-size: 15px; font-weight: 600; color: var(--ink); }
.send-row .label i { color: var(--muted); font-size: 18px; }
.send-row .sub { font-size: 12.5px; color: var(--muted); font-weight: 500; margin-top: 2px; }

/* ---------- ACTIVITY ---------- */
.activity { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px 24px; }
.activity-title { font-size: 12px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--muted); margin-bottom: 14px; }
.activity-row { display: flex; align-items: center; gap: 13px; padding: 9px 0; font-size: 14px; color: var(--body); }
.activity-row + .activity-row { border-top: 1px solid var(--line); }
.activity-row .dot { width: 30px; height: 30px; border-radius: 9px; display: flex; align-items: center; justify-content: center; flex-shrink: 0; font-size: 15px; }
.dot.in { background: var(--accent-soft); color: var(--accent); }
.dot.out { background: var(--good-soft); color: var(--good); }
.dot.miss { background: var(--bad-soft); color: var(--bad); }
.activity-row .txt { flex: 1; }
.activity-row .txt strong { color: var(--ink); font-weight: 600; }
.activity-row .time { font-size: 13px; color: var(--muted); white-space: nowrap; }

/* ---------- INFO / HINT ---------- */
.hint { display: flex; align-items: flex-start; gap: 10px; background: var(--accent-soft); border: 1px solid #dbe7ff; color: #1e3a8a; border-radius: 12px; padding: 14px 16px; font-size: 14px; margin-bottom: 22px; }
.hint i { color: var(--accent); font-size: 17px; margin-top: 1px; }

/* ---------- EMPTY STATE ---------- */
.empty { text-align: center; padding: 56px 20px; color: var(--muted); }
.empty i { font-size: 40px; color: var(--faint); display: block; margin-bottom: 14px; }
.empty .t { font-size: 16px; font-weight: 600; color: var(--body); margin-bottom: 5px; }
.empty .s { font-size: 14px; }

/* ---------- TABS ---------- */
.tabs { display: flex; gap: 6px; border-bottom: 1px solid var(--border); margin-bottom: 24px; }
.tab { padding: 10px 16px; font-size: 14px; font-weight: 600; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px; }
.tab:hover { color: var(--ink); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* segmented filter (etажи/крила, периоди) */
.segmented { display: inline-flex; flex-wrap: wrap; gap: 6px; }
.segmented button {
  height: 36px; padding: 0 14px; border: 1px solid var(--border); background: #fff; border-radius: 9px;
  font-size: 13.5px; font-weight: 600; color: var(--body); cursor: pointer;
}
.segmented button:hover { background: #f8fafc; }
.segmented button.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ---------- MODAL ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: flex; align-items: center; justify-content: center; z-index: 100; padding: 24px; opacity: 0; pointer-events: none; transition: opacity .15s; }
.modal-overlay.open { opacity: 1; pointer-events: auto; }
.modal { background: var(--card); border-radius: var(--radius); box-shadow: 0 20px 60px rgba(15,23,42,.25); width: 100%; max-width: 560px; max-height: 88vh; display: flex; flex-direction: column; transform: translateY(8px); transition: transform .15s; }
.modal-overlay.open .modal { transform: translateY(0); }
.modal.lg { max-width: 760px; }
.modal-head { padding: 22px 26px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-head h3 { font-size: 19px; font-weight: 700; color: var(--ink); }
.modal-close { width: 34px; height: 34px; border: none; background: #f1f5f9; border-radius: 9px; color: var(--muted); font-size: 18px; cursor: pointer; display: flex; align-items: center; justify-content: center; }
.modal-close:hover { background: #e2e8f0; color: var(--ink); }
.modal-body { padding: 24px 26px; overflow-y: auto; }
.modal-foot { padding: 18px 26px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 12px; }

/* confirm dialog */
.confirm-box { display: flex; gap: 14px; align-items: flex-start; }
.confirm-icon { width: 44px; height: 44px; border-radius: 12px; background: var(--bad-soft); color: var(--bad); display: flex; align-items: center; justify-content: center; font-size: 22px; flex-shrink: 0; }
.confirm-msg { font-size: 15px; color: var(--body); line-height: 1.5; padding-top: 6px; }

/* ---------- TOAST ---------- */
.toast-wrap { position: fixed; bottom: 28px; left: 50%; transform: translateX(-50%); z-index: 200; display: flex; flex-direction: column; gap: 10px; align-items: center; }
.toast {
  background: var(--ink); color: #fff; padding: 13px 20px; border-radius: 11px; font-size: 14.5px; font-weight: 500;
  box-shadow: 0 10px 30px rgba(15,23,42,.3); display: flex; align-items: center; gap: 10px;
  animation: toastIn .2s ease; max-width: 460px;
}
.toast.err { background: var(--bad); }
.toast i { font-size: 17px; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- UTIL ---------- */
.spinner { display: inline-block; width: 18px; height: 18px; border: 2px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.loading-center { text-align: center; padding: 48px; }
.muted { color: var(--muted); }
.text-good { color: var(--good); }
.text-bad { color: var(--bad); }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.row-between { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
