:root {
  --bg: #f4f8fb;
  --panel: #ffffff;
  --text: #10202d;
  --muted: #667789;
  --line: #dce7ef;
  --primary: #087f8c;
  --primary-dark: #05616a;
  --accent: #2563eb;
  --danger: #b42318;
  --warning: #b54708;
  --success: #067647;
  --shadow: 0 10px 25px rgba(16, 32, 45, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Arial, Helvetica, sans-serif;
}

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

.app-header {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: center;
  padding: 24px clamp(16px, 4vw, 42px);
  background: #ffffff;
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--primary);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  margin-bottom: 6px;
  font-size: clamp(24px, 3vw, 36px);
}

h2 {
  margin-bottom: 14px;
  font-size: 22px;
}

h3 {
  margin-bottom: 14px;
  font-size: 18px;
}

.subhead,
.muted {
  color: var(--muted);
}

.subhead {
  margin-bottom: 0;
}

.header-actions,
.action-row,
.form-actions,
.dashboard-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  align-items: center;
}

.tab-button,
.ghost-button,
.primary-button,
.secondary-button,
.danger-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
  min-height: 42px;
  padding: 10px 16px;
  font-weight: 700;
}

.tab-button,
.ghost-button,
.secondary-button {
  background: #eef5f8;
  color: var(--text);
}

.tab-button.active,
.primary-button {
  background: var(--primary);
  color: #ffffff;
}

.primary-button:hover {
  background: var(--primary-dark);
}

.danger-button {
  background: #fee4e2;
  color: var(--danger);
}

main {
  padding: 24px clamp(16px, 4vw, 42px) 48px;
}

.notice {
  max-width: 1300px;
  margin: 0 auto 18px;
  padding: 14px 16px;
  border: 1px solid #fedf89;
  border-left: 5px solid var(--warning);
  border-radius: 8px;
  background: #fffbeb;
}

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
  gap: 18px;
  max-width: 1300px;
  margin: 0 auto;
  align-items: start;
}

.panel,
.kpi-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 18px;
}

.narrow-panel {
  max-width: 460px;
  margin: 0 auto;
}

.panel-heading,
.dashboard-actions {
  justify-content: space-between;
}

label {
  display: grid;
  gap: 7px;
  margin-bottom: 14px;
  color: #33485b;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid #c8d6e2;
  border-radius: 8px;
  padding: 11px 12px;
  background: #ffffff;
  color: var(--text);
}

textarea {
  resize: vertical;
}

.field-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.results-panel {
  display: grid;
  gap: 18px;
}

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

.kpi-card {
  padding: 16px;
}

.kpi-card span {
  display: block;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.kpi-card strong {
  font-size: 24px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 4px 10px;
  border-radius: 999px;
  background: #e0f2fe;
  color: #075985;
  font-weight: 700;
  font-size: 12px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  background: #f8fbfd;
  color: #33485b;
  font-size: 13px;
  text-transform: uppercase;
}

.dose-amount {
  font-weight: 800;
  color: var(--primary-dark);
}

.small-text {
  color: var(--muted);
  font-size: 12px;
}

.empty {
  color: var(--muted);
  text-align: center;
}

.hidden {
  display: none !important;
}

.filter-panel {
  display: grid;
  grid-template-columns: 2fr 1fr 1fr;
  gap: 12px;
  margin: 18px 0;
}

.filter-panel label {
  margin-bottom: 0;
}

.chart-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 18px;
  margin-bottom: 18px;
}

.admin-kpis {
  margin-top: 18px;
}

.setup-list {
  margin: 0;
  padding-left: 22px;
}

.setup-list li {
  margin-bottom: 10px;
}

code {
  padding: 2px 5px;
  border-radius: 4px;
  background: #eef5f8;
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px;
}

.drug-form {
  display: grid;
  gap: 14px;
  margin-bottom: 18px;
}

.library-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fbfdff;
}

.library-card strong {
  display: block;
  margin-bottom: 6px;
}

.card-actions {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.card-actions button {
  padding: 8px 10px;
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: min(420px, calc(100vw - 36px));
  padding: 14px 16px;
  border-radius: 8px;
  background: #10202d;
  color: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

.toast.success {
  background: var(--success);
}

.toast.error {
  background: var(--danger);
}

@media (max-width: 980px) {
  .app-header,
  .dashboard-actions {
    align-items: flex-start;
    flex-direction: column;
  }

  .layout-grid,
  .chart-grid {
    grid-template-columns: 1fr;
  }

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

  .filter-panel {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 620px) {
  .field-row,
  .kpi-grid {
    grid-template-columns: 1fr;
  }

  .header-actions,
  .form-actions,
  .action-row {
    width: 100%;
  }

  .tab-button,
  .primary-button,
  .secondary-button,
  .ghost-button {
    flex: 1;
  }
}

@media print {
  body {
    background: #ffffff;
  }

  .app-header,
  .notice,
  .header-actions,
  .form-actions,
  .dashboard-actions,
  .filter-panel,
  .toast,
  .ghost-button,
  .secondary-button,
  .danger-button {
    display: none !important;
  }

  main {
    padding: 0;
  }

  .tab-panel {
    display: block;
  }

  .tab-panel:not(.active) {
    display: none;
  }

  .layout-grid {
    display: block;
  }

  .panel,
  .kpi-card {
    box-shadow: none;
    border-color: #b8c7d3;
    break-inside: avoid;
  }

  table {
    min-width: 0;
    font-size: 11px;
  }
}
