:root {
  color-scheme: only light;
  --bg: #f6f7fb;
  --surface: #ffffff;
  --surface-2: #f9fafb;
  --ink: #111827;
  --muted: #6b7280;
  --green: #111827;
  --green-2: #2563eb;
  --primary: #2563eb;
  --gold: #2563eb;
  --red: #dc2626;
  --blue: #2563eb;
  --primary-soft: #dbeafe;
  --green-soft: #dcfce7;
  --red-soft: #fee2e2;
  --yellow: #ca8a04;
  --yellow-soft: #fef3c7;
  --line: #e5e7eb;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  --radius: 16px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Pretendard, sans-serif;
  line-height: 1.5;
}

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

button {
  cursor: pointer;
}

.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;
}

.app-shell {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: 100svh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100svh;
  padding: 24px 18px;
  background: #111827;
  color: white;
  display: flex;
  flex-direction: column;
  gap: 28px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  color: inherit;
  text-decoration: none;
}

.brand img {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
}

.brand strong,
.brand small {
  display: block;
}

.brand small {
  color: #9ca3af;
  margin-top: 3px;
}

.side-nav {
  display: grid;
  gap: 8px;
}

.side-nav button {
  border: 0;
  border-radius: 12px;
  background: transparent;
  color: #d1d5db;
  padding: 12px 14px;
  text-align: left;
  font-weight: 700;
}

.side-nav button:hover,
.side-nav button.is-active {
  background: rgba(255, 255, 255, 0.1);
  color: white;
}

.connection-card {
  margin-top: auto;
  border: 1px solid rgba(255, 255, 255, 0.16);
  border-radius: 16px;
  padding: 14px;
  background: rgba(255, 255, 255, 0.08);
}

.connection-card span,
.connection-card strong {
  display: block;
}

.connection-card span {
  color: #9ca3af;
  font-size: 12px;
}

.workspace {
  padding: 28px;
  min-width: 0;
}

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

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

h1,
h2 {
  margin: 0;
  color: var(--green);
}

h1 {
  font-size: 28px;
  font-weight: 900;
}

h2 {
  font-size: 20px;
  font-weight: 900;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.search input {
  width: min(360px, 34vw);
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  padding: 10px 12px;
  min-height: 42px;
}

textarea {
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
  outline: 3px solid rgba(37, 99, 235, 0.18);
  border-color: var(--primary);
}

.button,
.icon-button {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--ink);
  padding: 10px 14px;
  font-weight: 800;
  min-height: 42px;
}

.button:hover,
.icon-button:hover {
  box-shadow: var(--shadow);
}

.button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.icon-button {
  width: 40px;
  height: 40px;
  padding: 0;
  font-size: 26px;
  line-height: 1;
}

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

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

.metric {
  padding: 18px;
}

.metric span,
.panel-head span,
.settings-note,
.prescription-head span {
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  color: var(--ink);
  font-size: 26px;
  font-weight: 900;
}

.metric.is-warning strong {
  color: var(--red);
}

.view-panel {
  overflow: hidden;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.table-wrap {
  overflow: auto;
  border-radius: 0 0 16px 16px;
}

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

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 13px 16px;
  text-align: left;
  vertical-align: middle;
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  background: #f9fafb;
}

tr[data-patient-id] {
  cursor: pointer;
}

tr[data-patient-id]:hover {
  background: var(--surface-2);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 3px 9px;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 12px;
  font-weight: 800;
}

.pill.warning {
  background: var(--red-soft);
  color: var(--red);
}

.inventory-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(230px, 1fr));
  gap: 12px;
  padding: 16px;
}

.product-card {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 18px;
  background: #fff;
  box-shadow: var(--shadow);
}

.product-card header {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}

.stock-bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #eef2ff;
}

.stock-bar span {
  display: block;
  height: 100%;
  max-width: 100%;
  background: var(--primary);
}

.product-card.is-low .stock-bar span {
  background: var(--red);
}

.settings-panel {
  max-width: 760px;
}

.settings-form,
.chart-form {
  display: grid;
  gap: 16px;
  padding: 18px;
}

.settings-form label,
.chart-form label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.profile-grid {
  display: grid;
  grid-template-columns: 1.4fr 1fr 0.78fr 0.78fr 1fr;
  gap: 12px;
  align-items: end;
}

.profile-grid input,
.profile-grid select {
  min-height: 40px;
  padding: 8px 10px;
}

.readonly-field,
.progress-field {
  min-height: 68px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f9fafb;
  padding: 9px 11px;
}

.readonly-field span,
.progress-field-head span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.readonly-field strong,
.progress-field-head strong {
  display: block;
  margin-top: 5px;
  color: var(--ink);
  font-size: 18px;
  font-weight: 900;
}

.program-start-field {
  grid-column: 1 / 2;
}

.program-field {
  grid-column: 2 / 4;
}

.program-field select {
  background: #fff;
}

.program-field option.featured-program-option {
  background: #eff6ff;
  color: #1d4ed8;
  font-weight: 900;
}

.progress-field {
  grid-column: 4 / 6;
}

.progress-field-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.progress-field-head strong {
  margin-top: 0;
  color: var(--primary);
}

.progress-bar {
  height: 9px;
  overflow: hidden;
  border-radius: 999px;
  background: #e5e7eb;
  margin-top: 9px;
}

.progress-bar span {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #2563eb, #16a34a);
  transition: width 180ms ease;
}

.chart-link-field,
.memo-field {
  grid-column: 1 / -1;
}

.linked-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
}

.linked-input .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 66px;
  text-decoration: none;
}

.linked-input .button.is-disabled {
  color: var(--muted);
  pointer-events: none;
  background: #f9fafb;
}

.settings-note {
  margin: 0;
  padding: 0 18px 18px;
}

.form-actions,
.drawer-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.drawer[hidden] {
  display: none;
}

.drawer {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  justify-items: end;
}

.drawer-backdrop {
  position: absolute;
  inset: 0;
  border: 0;
  background: rgba(15, 23, 42, 0.46);
}

.drawer-panel {
  position: relative;
  width: min(980px, 100%);
  height: 100svh;
  overflow: auto;
  background: var(--surface);
  box-shadow: 0 24px 80px rgba(15, 23, 42, 0.24);
}

.drawer-panel-small {
  width: min(680px, 100%);
}

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

.tabs {
  display: flex;
  gap: 8px;
  padding: 14px 18px 0;
}

.tabs button {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  color: var(--muted);
  padding: 9px 12px;
  font-weight: 800;
}

.tabs button.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

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

.form-grid .wide,
.wide {
  grid-column: 1 / -1;
}

.prescription-head {
  display: flex;
  justify-content: space-between;
  align-items: end;
  gap: 14px;
}

.product-picker {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 10px;
}

.product-input {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 12px;
  background: #fff;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}

.product-input span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.history-list {
  display: grid;
  gap: 10px;
}

.history-item {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #fff;
  padding: 12px;
  box-shadow: 0 4px 14px rgba(15, 23, 42, 0.04);
}

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
  }

  .topbar,
  .topbar-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .search input {
    width: 100%;
  }

  .metric-grid,
  .form-grid {
    grid-template-columns: 1fr;
  }

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

  .profile-grid .program-start-field,
  .profile-grid .program-field,
  .profile-grid .progress-field,
  .profile-grid .chart-link-field,
  .profile-grid .memo-field {
    grid-column: 1 / -1;
  }
}

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

  .linked-input {
    grid-template-columns: 1fr;
  }
}
