:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e5ea;
  --text: #1c2430;
  --muted: #6b7484;
  --primary: #2f6fed;
  --primary-hover: #275fd0;
  --danger: #d64545;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 30, 50, 0.08);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

/* ---------- Login ---------- */
.login {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login__card {
  width: 100%;
  max-width: 340px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.login__title { margin: 0 0 4px; font-size: 22px; }
.login__hint { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.4; }
.login__error { margin: 0; color: var(--danger); font-size: 14px; }

/* ---------- Fields & buttons ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field__label { font-size: 13px; color: var(--muted); }
.field__input {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
  outline: none;
}
.field__input:focus { border-color: var(--primary); }

.btn {
  padding: 10px 16px;
  border: 1px solid transparent;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  background: var(--surface);
}
.btn:disabled { opacity: 0.6; cursor: default; }
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn--ghost { border-color: var(--border); color: var(--text); }

/* ---------- Shell ---------- */
.topbar {
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
}
.topbar__brand { font-weight: 600; }
.topbar__user { display: flex; align-items: center; gap: 12px; }
.topbar__name { color: var(--muted); font-size: 14px; }

.shell__body { display: flex; min-height: calc(100vh - 56px); }
.sidenav {
  width: 200px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.sidenav__item {
  padding: 10px 12px;
  border-radius: 8px;
  color: var(--text);
  text-decoration: none;
  font-size: 14px;
}
.sidenav__item:hover { background: var(--bg); }
.sidenav__item--active { background: var(--primary); color: #fff; }

.content { flex: 1; padding: 24px; }
.placeholder h2 { margin-top: 0; }
.placeholder p { color: var(--muted); }

/* ---------- Page & common ---------- */
.page { max-width: 900px; }
.page__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.page__title { margin: 8px 0 16px; font-size: 20px; }
.muted { color: var(--muted); font-size: 14px; }
.error { color: var(--danger); font-size: 14px; }
.count { margin-top: 10px; }
.back { color: var(--primary); text-decoration: none; font-size: 14px; }
.back:hover { text-decoration: underline; }
.btn--danger { border-color: var(--danger); color: var(--danger); }
.btn--danger:hover:not(:disabled) { background: var(--danger); color: #fff; }

.search { margin: 12px 0 16px; max-width: 360px; }

.createbar {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
.createbar .field__input { flex: 1; min-width: 140px; }

/* ---------- Table ---------- */
.table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}
.table th, .table td {
  text-align: left;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.table th { background: #fafbfc; color: var(--muted); font-weight: 500; }
.table tbody tr:last-child td { border-bottom: none; }
.row { cursor: pointer; }
.row:hover td { background: #f7f9fc; }
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  background: #eef2fb;
  color: var(--primary);
  font-size: 12px;
}

/* ---------- Cards & forms ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 20px;
}
.form__grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 14px;
}
.field--wide { grid-column: 1 / -1; }
.form__actions { display: flex; gap: 10px; margin-top: 18px; }
.form__subhead { margin: 20px 0 4px; font-size: 15px; }
.section__head {
  display: flex; align-items: center; justify-content: space-between;
  margin: 8px 0 12px;
}
.section__head h3 { margin: 0; font-size: 16px; }

@media (max-width: 640px) {
  .form__grid { grid-template-columns: 1fr; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  background: #2b3648;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
}
.toast--show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast--error { background: var(--danger); }

/* ---------- Documents ---------- */
.filters { display: flex; gap: 10px; margin: 12px 0 16px; flex-wrap: wrap; }
.filters .search { margin: 0; }
.filters select { max-width: 180px; }
.num { text-align: right; }

.table--positions td, .table--positions th { padding: 6px 8px; }
.cell {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 14px;
}
.cell--num { text-align: right; }
.table--positions .num { width: 110px; }
.line-total { white-space: nowrap; font-variant-numeric: tabular-nums; }
.rm {
  border: none;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font-size: 15px;
  padding: 4px 6px;
}
.rm:hover { color: var(--danger); }

.totals {
  margin: 16px 0 4px;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  font-size: 14px;
}
.totals span { color: var(--muted); margin-right: 8px; }
.totals__grand { font-size: 16px; }
.totals__grand b { color: var(--primary); }

/* ---------- Payer picker ---------- */
.picker { position: relative; }
.picker__results {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 20;
  max-height: 260px;
  overflow-y: auto;
}
.picker__item { padding: 9px 12px; cursor: pointer; font-size: 14px; }
.picker__item:hover { background: var(--bg); }
.picker__empty { padding: 9px 12px; color: var(--muted); font-size: 14px; }
