:root {
  color-scheme: light;
  --bg: #f6f7f9;
  --panel: #ffffff;
  --ink: #18202a;
  --muted: #657282;
  --line: #d8dee7;
  --accent: #4055f6;
  --accent-dark: #2638c8;
  --accent-soft: #e7eaff;
  --warn: #9a4f18;
  --danger: #d12c2c;
}

* {
  box-sizing: border-box;
}

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

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(246, 247, 249, 0.96);
}

.login-screen[hidden] {
  display: none;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(24, 32, 42, 0.12);
}

.shell {
  width: min(1180px, calc(100vw - 32px));
  margin: 32px auto;
}

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

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

.eyebrow {
  margin: 0 0 6px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 3.4rem);
  line-height: 1;
}

.status {
  min-width: 120px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

.toolbar {
  display: flex;
  align-items: end;
  gap: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  margin-bottom: 16px;
}

.tabs {
  display: flex;
  gap: 6px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.tab {
  min-height: 42px;
  padding: 0 16px;
  border: 0;
  border-bottom: 3px solid transparent;
  border-radius: 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 800;
}

.tab:hover,
.tab.is-active {
  background: transparent;
  border-bottom-color: var(--accent);
  color: var(--accent-dark);
}

.tab-panel[hidden] {
  display: none;
}

.notification-fab {
  position: fixed;
  right: 24px;
  bottom: 24px;
  z-index: 12;
  width: 54px;
  min-height: 54px;
  border-radius: 50%;
  padding: 0;
  box-shadow: 0 14px 34px rgba(24, 32, 42, 0.2);
}

.notification-fab span:first-child {
  position: relative;
  display: grid;
  place-items: center;
  width: 26px;
  height: 22px;
  margin: 0 auto;
  border: 2px solid currentColor;
  border-radius: 8px;
  font-weight: 900;
  line-height: 1;
}

.notification-fab span:first-child::after {
  content: "";
  position: absolute;
  right: 4px;
  bottom: -6px;
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  background: var(--accent);
  transform: rotate(45deg);
}

.notification-dot {
  position: absolute;
  top: 3px;
  right: 4px;
  width: 14px;
  height: 14px;
  border: 2px solid var(--panel);
  border-radius: 50%;
  background: var(--danger);
}

.notification-panel {
  position: fixed;
  right: 24px;
  bottom: 88px;
  z-index: 11;
  width: min(390px, calc(100vw - 32px));
  max-height: min(620px, calc(100vh - 120px));
  display: grid;
  grid-template-rows: auto 1fr;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 55px rgba(24, 32, 42, 0.18);
  overflow: hidden;
}

.notification-panel[hidden] {
  display: none;
}

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

.notification-head h2 {
  font-size: 1rem;
}

.notification-list {
  display: grid;
  gap: 10px;
  padding: 12px;
  overflow: auto;
}

.notification-item {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  background: #fbfcfe;
}

.notification-item-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
}

.notification-clear-button {
  width: 28px;
  height: 28px;
  min-height: 28px;
  border-radius: 50%;
  color: var(--muted);
  font-size: 0.85rem;
  line-height: 1;
  text-transform: uppercase;
}

.notification-clear-button:hover {
  color: var(--danger);
  border-color: rgba(226, 75, 75, 0.35);
}

.notification-item.is-warning {
  border-left-color: var(--warn);
}

.notification-item.is-error {
  border-left-color: var(--danger);
}

.notification-item strong {
  font-size: 0.92rem;
}

.notification-item p {
  margin: 0;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.4;
}

.wide-control {
  flex: 1 1 280px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

select,
input,
button,
textarea {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
}

select,
input,
textarea {
  background: #fff;
  color: var(--ink);
  padding: 0 10px;
}

textarea {
  width: 100%;
  min-height: 180px;
  padding: 12px;
  line-height: 1.45;
  resize: vertical;
}

.placeholder-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.token-button {
  min-height: 32px;
  padding: 0 10px;
  border-color: var(--accent-soft);
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 0.82rem;
}

.token-button:hover {
  background: #d7ddff;
}

select {
  min-width: min(380px, 54vw);
}

input {
  width: 96px;
}

input[type="search"] {
  width: 100%;
}

button {
  padding: 0 16px;
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  cursor: pointer;
  font-weight: 700;
}

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

button:disabled {
  cursor: wait;
  opacity: 0.65;
}

.secondary-button {
  background: #fff;
  color: var(--accent-dark);
  border-color: var(--line);
}

.secondary-button:hover {
  background: var(--accent-soft);
}

.data-region {
  min-height: 360px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  overflow: hidden;
}

.empty {
  padding: 48px 20px;
  color: var(--muted);
  text-align: center;
}

.table-wrap {
  width: 100%;
  overflow: auto;
}

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

th,
td {
  max-width: 360px;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

th {
  position: sticky;
  top: 0;
  background: #edf2f5;
  color: #26323f;
  font-size: 0.82rem;
}

.filter-row th {
  top: 42px;
  background: #f8fafb;
  padding: 7px 8px;
}

.filter-row input {
  width: 100%;
  min-height: 32px;
  font-size: 0.82rem;
}

.sort-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
  min-height: 28px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: inherit;
  text-align: left;
}

.sort-button:hover {
  background: transparent;
  color: var(--accent-dark);
}

.sort-button::after {
  content: "";
  color: var(--muted);
  font-size: 0.72rem;
}

.sort-button[data-direction="asc"]::after {
  content: "ASC";
}

.sort-button[data-direction="desc"]::after {
  content: "DESC";
}

td {
  color: #2b3642;
  font-size: 0.9rem;
}

.select-column {
  width: 92px;
  min-width: 92px;
  text-align: center;
}

.select-column input {
  width: 18px;
  min-height: 18px;
}

.checkbox-cell {
  text-align: center;
}

.checkbox-cell input {
  width: 18px;
  min-height: 18px;
}

.clickable-row {
  cursor: pointer;
}

.clickable-row:hover td {
  background: var(--accent-soft);
}

.editable-cell {
  cursor: text;
  outline: 0;
}

.editable-cell:hover,
.editable-cell:focus {
  background: #fffef2;
  box-shadow: inset 0 0 0 2px var(--accent);
}

.editable-cell.is-saving {
  opacity: 0.7;
}

.editable-cell.is-error-cell {
  background: #fff5ef;
  box-shadow: inset 0 0 0 2px var(--warn);
}

.is-error {
  color: var(--warn);
}

.placeholder-panel {
  min-height: 280px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  font-weight: 700;
}

.upload-panel {
  min-height: 420px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 24px;
}

.upload-dropzone {
  width: min(680px, 100%);
  min-height: 260px;
  display: grid;
  place-items: center;
  align-content: center;
  gap: 14px;
  border: 2px dashed #a9b3c6;
  border-radius: 8px;
  background: #f8fafb;
  color: var(--muted);
  text-align: center;
  padding: 28px;
}

.upload-tag-control {
  width: min(680px, 100%);
}

.upload-tag-control input {
  width: 100%;
}

.upload-dropzone.is-dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.upload-dropzone p {
  margin: 0;
  color: var(--ink);
  font-size: 1.05rem;
  font-weight: 800;
}

.upload-dropzone span {
  font-size: 0.9rem;
  font-weight: 700;
}

.upload-status {
  min-height: 22px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
  text-align: center;
}

.sms-grid {
  display: grid;
  grid-template-columns: minmax(280px, 0.95fr) minmax(320px, 1.05fr);
  gap: 16px;
  align-items: start;
}

.sms-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  padding: 16px;
}

.preview {
  grid-column: 1 / -1;
}

.history-section {
  grid-column: 1 / -1;
}

.compact-table-wrap table {
  min-width: 820px;
}

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

.section-kicker {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 0.74rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

h2 {
  margin: 0;
  font-size: 1.15rem;
}

.selection-count {
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 0.82rem;
  font-weight: 800;
  white-space: nowrap;
}

.picker-controls {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
  margin-bottom: 12px;
}

.picker-controls label {
  flex: 0 1 170px;
}

.picker-controls label:first-child {
  flex-basis: 240px;
}

.picker-controls label:nth-child(2),
.picker-controls label:nth-child(3) {
  flex-basis: 190px;
}

.picker-controls label:nth-child(5) {
  flex: 1 1 280px;
}

.picker-controls label:nth-child(6) {
  flex-basis: 180px;
}

.picker-controls button {
  flex: 0 0 150px;
}

.patient-list {
  display: grid;
  gap: 8px;
  max-height: 420px;
  overflow: auto;
  padding-right: 4px;
}

.patient-option {
  display: grid;
  grid-template-columns: 18px 1fr;
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 600;
}

.patient-option input {
  width: 18px;
  min-height: 18px;
  margin-top: 2px;
}

.patient-option span {
  display: grid;
  gap: 3px;
}

.patient-option small {
  color: var(--muted);
  font-weight: 600;
}

.picker-empty {
  padding: 22px;
  color: var(--muted);
  text-align: center;
}

.form-control {
  margin-top: 14px;
}

.form-select-row {
  display: grid;
  grid-template-columns: 1fr 42px;
  gap: 8px;
}

.form-select-row select {
  min-width: 0;
  width: 100%;
}

.icon-button {
  display: grid;
  place-items: center;
  padding: 0;
  font-size: 0.82rem;
}

.preview-card {
  min-height: 150px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafb;
}

.preview-card p {
  margin: 0 0 14px;
  color: var(--ink);
  line-height: 1.45;
  white-space: pre-wrap;
}

.preview-card a {
  color: var(--accent-dark);
  font-weight: 800;
}

.selected-patients {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 12px;
}

.selected-patient {
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  color: var(--ink);
  font-size: 0.84rem;
  font-weight: 700;
}

.muted-chip {
  color: var(--muted);
}

.draft-actions {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 16px;
}

.draft-status {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 700;
}

.detail-panel {
  margin-top: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 16px;
}

.detail-meta span {
  padding: 6px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafb;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.answer-list {
  display: grid;
  grid-template-columns: minmax(180px, 0.34fr) minmax(0, 0.66fr);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  margin: 0;
}

.answer-list dt,
.answer-list dd {
  min-width: 0;
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
}

.answer-list dt {
  background: #f8fafb;
  color: var(--ink);
  font-weight: 800;
  overflow-wrap: anywhere;
}

.answer-list dd {
  margin: 0;
  color: #2b3642;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.answer-list dt:last-of-type,
.answer-list dd:last-of-type {
  border-bottom: 0;
}

.empty-detail {
  grid-column: 1 / -1;
  margin: 0;
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 720px) {
  .shell {
    width: min(100vw - 20px, 1180px);
    margin: 18px auto;
  }

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

  select,
  input,
  button,
  textarea {
    width: 100%;
  }

  .sms-grid,
  .picker-controls,
  .draft-actions {
    grid-template-columns: 1fr;
    align-items: stretch;
    flex-direction: column;
  }

  .answer-list {
    grid-template-columns: 1fr;
  }

  .answer-list dt {
    border-bottom: 0;
  }
}
