:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --text: #14181f;
  --muted: #6b7280;
  --line: #e5e7eb;
  --red: #c1121f;
  --red-dark: #8d0d17;
  --red-soft: #fdecec;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  --green: #0f766e;
  --green-soft: #e6f4f1;
  --blue: #1d4ed8;
  --blue-soft: #e8efff;
  --radius: 16px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.05), 0 8px 24px rgba(16, 24, 40, 0.05);
}

* {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background:
    radial-gradient(1100px 520px at 88% -12%, #ffe6e6 0%, rgba(255, 230, 230, 0) 62%),
    var(--bg);
}

h1, h2, h3, p {
  margin: 0;
}

button,
input,
select {
  font: inherit;
  color: inherit;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: absolute;
  left: 12px;
  top: -60px;
  z-index: 50;
  padding: 10px 14px;
  background: var(--text);
  color: #fff;
  border-radius: 8px;
  text-decoration: none;
}

.skip-link:focus {
  top: 12px;
}

/* ---------- Top bar ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px 32px;
  background: rgba(255, 255, 255, 0.82);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  font-size: 21px;
  background: var(--red-soft);
  border: 1px solid #f3c6c6;
  border-radius: 12px;
}

.brand h1 {
  font-size: 19px;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.brand p {
  font-size: 12.5px;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* ---------- Layout ---------- */

main {
  display: grid;
  gap: 20px;
  width: 100%;
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px 24px 48px;
}

main > *,
.split > * {
  min-width: 0;
}

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

.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 16px;
}

.panel-head h2 {
  font-size: 15.5px;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.hint {
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------- Stats ---------- */

.stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stat {
  display: grid;
  gap: 2px;
  padding: 16px 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 3px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
}

.stat-ok { border-left-color: var(--green); }
.stat-warn { border-left-color: var(--amber); }
.stat-danger { border-left-color: var(--red); }
.stat-info { border-left-color: var(--blue); }

.stat-label {
  font-size: 12px;
  font-weight: 650;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-value {
  font-size: 30px;
  font-weight: 750;
  line-height: 1.15;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.stat-note {
  font-size: 12.5px;
  color: var(--muted);
}

/* ---------- Split ---------- */

.split {
  display: grid;
  grid-template-columns: 1.35fr 1fr;
  gap: 20px;
  align-items: start;
}

/* ---------- Blood type cards ---------- */

.type-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.type-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  background: #fcfcfd;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.type-card.is-low {
  background: #fffafa;
  border-color: #f3c6c6;
}

.type-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
}

.blood-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 40px;
  padding: 3px 8px;
  font-size: 13px;
  font-weight: 750;
  letter-spacing: 0.01em;
  color: var(--red-dark);
  background: var(--red-soft);
  border: 1px solid #f3c6c6;
  border-radius: 8px;
}

.blood-badge.small {
  min-width: 34px;
  padding: 2px 6px;
  font-size: 11.5px;
}

.type-units {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.type-units strong {
  font-size: 25px;
  font-weight: 750;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}

.type-units span {
  font-size: 12px;
  color: var(--muted);
}

.meter {
  height: 6px;
  overflow: hidden;
  background: #eef0f3;
  border-radius: 999px;
}

.meter span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #e63946, var(--red));
  transition: width 0.35s ease;
}

.type-card.is-low .meter span {
  background: linear-gradient(90deg, #f59e0b, #d97706);
}

.type-card {
  cursor: help;
}

.type-card:focus-visible {
  outline: 3px solid rgba(193, 18, 31, 0.22);
  outline-offset: 2px;
}

.type-tip {
  position: fixed;
  z-index: 80;
  width: 238px;
  padding: 12px 14px;
  color: #f9fafb;
  background: #111827;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  box-shadow: 0 18px 44px rgba(15, 23, 42, 0.3);
  opacity: 0;
  transform: translateY(4px);
  pointer-events: none;
  transition: opacity 0.14s ease, transform 0.14s ease;
}

.type-tip.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.type-tip[hidden] {
  display: none;
}

.tip-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 9px;
  font-size: 12px;
  color: #d1d5db;
}

.tip-head strong {
  font-size: 13px;
  color: #fff;
}

.tip-list {
  display: grid;
  gap: 5px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tip-list li {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  font-size: 12.5px;
  color: #e5e7eb;
}

.tip-list li strong {
  color: #fff;
  font-variant-numeric: tabular-nums;
}

.tip-list li.is-zero,
.tip-list li.is-zero strong {
  color: #6b7280;
}

.tip-foot {
  margin-top: 9px;
  padding-top: 8px;
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  font-size: 11.5px;
  line-height: 1.45;
  color: #9ca3af;
}

.type-target {
  font-size: 11px;
  color: var(--muted);
}

.chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  border-radius: 999px;
  white-space: nowrap;
}

.chip-ok { color: var(--green); background: var(--green-soft); }
.chip-warn { color: var(--amber); background: var(--amber-soft); }
.chip-danger { color: var(--red-dark); background: var(--red-soft); }

/* ---------- Expiry watch ---------- */

.watch-list {
  display: grid;
  gap: 0;
  max-height: 372px;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  list-style: none;
}

.watch-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 2px;
  border-top: 1px solid #f0f1f3;
}

.watch-item:first-child {
  border-top: 0;
  padding-top: 0;
}

.watch-main {
  flex: 1;
  min-width: 0;
}

.watch-main p {
  font-size: 13.5px;
}

.watch-main .muted {
  font-size: 12px;
  color: var(--muted);
}

.empty-state {
  padding: 26px 12px;
  font-size: 13px;
  color: var(--muted);
  text-align: center;
}

/* ---------- Toolbar ---------- */

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 14px;
}

.field-inline {
  display: grid;
  gap: 5px;
  min-width: 150px;
  font-size: 11.5px;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.field-inline.grow {
  flex: 1;
  min-width: 220px;
}

.field-inline select,
.field-inline input {
  padding: 8px 10px;
  font-size: 14px;
  font-weight: 500;
  letter-spacing: normal;
  text-transform: none;
  color: var(--text);
  background: #fff;
  border: 1px solid #d7dbe1;
  border-radius: 9px;
}

/* ---------- Table ---------- */

.table-wrap {
  position: relative;
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 12px;
}

table {
  width: 100%;
  min-width: 780px;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-align: left;
  text-transform: uppercase;
  color: var(--muted);
  background: #fafbfc;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

tbody td {
  padding: 11px 14px;
  vertical-align: middle;
  border-bottom: 1px solid #f0f1f3;
}

tbody tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: #fafbfc;
}

.num {
  font-variant-numeric: tabular-nums;
}

.row-note {
  display: block;
  font-size: 11.5px;
  color: var(--muted);
}

.status {
  display: inline-flex;
  align-items: center;
  padding: 3px 9px;
  font-size: 11.5px;
  font-weight: 650;
  border-radius: 999px;
  white-space: nowrap;
}

.status-ok { color: var(--green); background: var(--green-soft); }
.status-soon { color: var(--amber); background: var(--amber-soft); }
.status-expired { color: var(--red-dark); background: var(--red-soft); }

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

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 9px 14px;
  font-size: 13.5px;
  font-weight: 650;
  line-height: 1.2;
  color: var(--text);
  background: #fff;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease;
}

.btn:focus-visible,
.icon-btn:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(193, 18, 31, 0.22);
  outline-offset: 1px;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.btn-primary {
  color: #fff;
  background: var(--red);
  border-color: var(--red);
}

.btn-primary:hover:not(:disabled) {
  background: var(--red-dark);
  border-color: var(--red-dark);
}

.btn-ghost {
  background: #fff;
  border-color: var(--line);
}

.btn-ghost:hover:not(:disabled) {
  background: #f5f6f8;
}

.btn-small {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 8px;
}

.btn-danger-ghost {
  color: var(--red);
  background: #fff;
  border-color: #f3c6c6;
}

.btn-danger-ghost:hover:not(:disabled) {
  background: var(--red-soft);
}

.icon-btn {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  font-size: 14px;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.icon-btn:hover {
  background: #f2f3f5;
  color: var(--text);
}

/* ---------- Dialogs ---------- */

.dialog {
  width: min(580px, calc(100vw - 32px));
  padding: 0;
  color: var(--text);
  background: #fff;
  border: 0;
  border-radius: var(--radius);
  box-shadow: 0 24px 64px rgba(15, 23, 42, 0.28);
}

.dialog::backdrop {
  background: rgba(15, 23, 42, 0.45);
  backdrop-filter: blur(2px);
}

.dialog form {
  padding: 22px 24px 20px;
}

.dialog-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.dialog-head h2 {
  font-size: 19px;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.dialog-intro {
  margin: -6px 0 16px;
  font-size: 13px;
  color: var(--muted);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px 16px;
}

.form-grid label {
  display: grid;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 650;
  color: #374151;
}

.form-grid .span-2 {
  grid-column: 1 / -1;
}

.form-grid input,
.form-grid select {
  width: 100%;
  padding: 9px 11px;
  font-size: 14px;
  font-weight: 500;
  background: #fff;
  border: 1px solid #d7dbe1;
  border-radius: 9px;
}

.form-grid input:focus,
.form-grid select:focus {
  border-color: #e08a8f;
}

.form-hint {
  margin-top: 12px;
  font-size: 12px;
  color: var(--muted);
}

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

.issue-preview {
  min-height: 76px;
  margin-top: 16px;
  padding: 14px;
  font-size: 13px;
  background: #f8f9fb;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.preview-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

.alloc-list {
  display: grid;
  gap: 0;
  margin: 10px 0 8px;
  padding: 0;
  list-style: none;
}

.alloc-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-top: 1px dashed #e3e6ea;
}

.alloc-main {
  flex: 1;
  min-width: 0;
}

.alloc-main .muted {
  font-size: 12px;
  color: var(--muted);
}

.issue-preview .muted {
  color: var(--muted);
}

.issue-preview .small {
  margin-top: 8px;
  font-size: 11.5px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 100;
  max-width: 360px;
  padding: 12px 16px;
  font-size: 13.5px;
  color: #fff;
  background: #111827;
  border-radius: 10px;
  box-shadow: 0 12px 32px rgba(15, 23, 42, 0.28);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

/* ---------- Responsive ---------- */

@media (max-width: 980px) {
  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .split {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .topbar {
    padding: 14px 16px;
  }

  main {
    padding: 18px 14px 36px;
  }

  .type-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .brand-mark {
    width: 38px;
    height: 38px;
    font-size: 18px;
  }

  .topbar-actions {
    width: 100%;
  }

  .topbar-actions .btn {
    flex: 1;
  }
}

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

  .stats {
    gap: 10px;
  }

  .stat {
    padding: 13px 14px;
  }

  .stat-value {
    font-size: 25px;
  }

  .toast {
    right: 14px;
    bottom: 14px;
    left: 14px;
    max-width: none;
  }
}
