:root {
  --bg: #f7faf8;
  --panel: #ffffff;
  --line: #dfe8e3;
  --text: #173126;
  --muted: #63746c;
  --primary: #087443;
  --primary-dark: #075c36;
  --primary-soft: #edf8f1;
  --ok: #087443;
  --danger: #b42318;
  --shadow: 0 16px 40px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Segoe UI", Tahoma, Verdana, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden {
  display: none !important;
}

.container {
  max-width: 1200px;
  margin: 18px auto;
  padding: 0 14px;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 20px;
  background: #fff;
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  box-shadow: var(--shadow);
}

.login-card h1 {
  margin: 0;
  font-size: 30px;
  letter-spacing: 0;
}

.app-title {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: end;
  margin-bottom: 14px;
}

.app-title h1,
.section-heading h2 {
  margin: 0;
  letter-spacing: 0;
}

.app-title h1 {
  font-size: 30px;
  color: #0d3f29;
}

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

.title-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.header {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  box-shadow: var(--shadow);
}

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

.patient-summary {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 14px;
}

.patient-summary span {
  color: var(--muted);
}

.patient-switcher {
  margin-top: 12px;
  max-width: 360px;
}

.status-group {
  display: grid;
  gap: 8px;
  justify-items: end;
}

.status {
  background: #ecfdf3;
  color: var(--ok);
  border: 1px solid #b8e6cb;
  padding: 6px 10px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 12px;
}

.persist-status {
  color: var(--muted);
  font-size: 12px;
}

.quick-create {
  margin-top: 12px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.section-heading {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
  margin-bottom: 12px;
}

.section-heading h2 {
  font-size: 18px;
}

.section-heading span {
  color: var(--muted);
  font-size: 13px;
}

.patient-form,
.encounter-form {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr)) auto;
  gap: 10px;
  align-items: end;
}

.seed-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.form-error {
  margin: 0;
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
}

.encounter-form {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  background: #fff;
  border: 1px solid #d8eadf;
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}

.patients-toolbar {
  max-width: 520px;
  margin-bottom: 12px;
}

.patients-list {
  display: grid;
  gap: 8px;
}

.patient-row {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--text);
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  text-align: left;
  cursor: pointer;
}

.patient-row:hover {
  border-color: var(--primary);
  box-shadow: 0 8px 22px rgba(8, 116, 67, 0.08);
}

.patient-row-main,
.patient-row-meta {
  display: grid;
  gap: 4px;
}

.patient-row-main span,
.patient-row-meta span {
  color: var(--muted);
  font-size: 13px;
}

.patient-row-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
}

.delete-patient {
  border: 1px solid #f1b8b4;
  border-radius: 6px;
  color: var(--danger);
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 600;
}

.delete-patient:hover,
.delete-patient:focus {
  background: #fff5f5;
  outline: none;
}

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

.tab-btn {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--text);
  border-radius: 6px;
  padding: 8px 12px;
  font-size: 14px;
  cursor: pointer;
}

.tab-btn.active {
  border-color: var(--primary);
  background: var(--primary-soft);
  color: var(--primary);
  font-weight: 600;
}

.panel {
  display: none;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  margin-top: 12px;
  padding: 14px;
  box-shadow: var(--shadow);
}

.panel.active {
  display: block;
}

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

.stack {
  display: grid;
  gap: 10px;
}

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

.card h3 {
  margin: 0 0 8px;
  font-size: 15px;
  color: var(--primary);
}

.item-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  border-top: 1px solid #edf1f6;
  padding: 8px 0;
  font-size: 14px;
}

.item-row:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.item-row span:last-child {
  white-space: pre-line;
}

.vital-row {
  display: grid;
  grid-template-columns: 150px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  border-top: 1px solid #edf1f6;
  padding: 8px 0;
}

.vital-row:first-of-type {
  border-top: 0;
  padding-top: 0;
}

.vital-row label {
  margin-bottom: 0;
}

.unit-input,
.compound-input {
  display: flex;
  align-items: center;
  gap: 6px;
}

.unit-input {
  max-width: 180px;
}

.compound-input {
  max-width: 240px;
}

.unit-input input,
.compound-input input {
  width: auto;
  min-width: 0;
}

.unit-input input {
  flex: 0 1 110px;
}

.compound-input input {
  flex: 0 1 72px;
}

.unit-input span,
.compound-input span {
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
}

.vital-row input[readonly] {
  max-width: 110px;
  background: #f8fafc;
  color: var(--muted);
}

.vitals-actions {
  align-items: center;
}

.save-status {
  color: var(--muted);
  font-size: 13px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: pre;
}

.encounter-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.encounter-card summary {
  list-style: none;
  cursor: pointer;
  padding: 12px;
}

.encounter-card summary::-webkit-details-marker {
  display: none;
}

.encounter-summary {
  display: grid;
  grid-template-columns: 130px 1fr 1fr;
  gap: 10px;
  align-items: center;
  font-size: 14px;
}

.encounter-date {
  font-weight: 700;
  color: var(--primary);
}

.encounter-complaint,
.encounter-diagnosis {
  color: var(--text);
}

.encounter-detail {
  border-top: 1px solid #edf1f6;
  padding: 0 12px 12px;
}

.encounter-detail-actions {
  margin: 10px 0;
}

.encounter-edit-form {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding-top: 12px;
}

.encounter-edit-form textarea {
  min-height: 76px;
}

label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 6px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 10px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(8, 116, 67, 0.14);
  outline: none;
}

textarea {
  min-height: 90px;
  resize: vertical;
}

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

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

.note-format {
  background: #fff;
  border: 1px dashed var(--line);
  padding: 10px;
  border-radius: 8px;
  margin-top: 10px;
  font-size: 14px;
}

.plan-sections {
  display: grid;
  gap: 12px;
}

.plan-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  background: #fff;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  align-items: start;
}

.inline-input {
  display: flex;
  gap: 8px;
}

.inline-input .btn {
  flex-shrink: 0;
}

.med-meta {
  margin-top: 8px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.selected-list {
  margin: 0;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  min-height: 44px;
  list-style: none;
  display: grid;
  gap: 6px;
  background: #fff;
}

.selected-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  border: 1px solid #cfe4d7;
  border-radius: 6px;
  padding: 6px 8px;
  background: #fff;
  font-size: 14px;
}

.remove-item {
  border: 1px solid #b9d8c5;
  background: #eff9f3;
  color: #24563b;
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 12px;
  cursor: pointer;
}

.selected-empty {
  color: var(--muted);
  font-size: 13px;
}

.actions {
  margin-top: 14px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.btn {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 9px 14px;
  font-size: 14px;
  background: #fff;
  cursor: pointer;
}

.btn:hover {
  border-color: var(--primary);
  color: var(--primary-dark);
}

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

.btn.primary:hover {
  background: var(--primary-dark);
  color: #fff;
}

.btn.danger {
  border-color: #f1b8b4;
  color: var(--danger);
}

.empty-state {
  border: 1px dashed var(--line);
  border-radius: 8px;
  padding: 18px;
  color: var(--muted);
  background: #fff;
  text-align: center;
}

@media (max-width: 900px) {
  .app-title,
  .header,
  .grid,
  .form-grid,
  .patient-form,
  .encounter-form,
  .patient-row {
    grid-template-columns: 1fr;
  }

  .title-actions,
  .status-group {
    justify-content: flex-start;
    justify-items: start;
  }

  .plan-row {
    grid-template-columns: 1fr;
  }

  .encounter-edit-form {
    grid-template-columns: 1fr;
  }

  .med-meta {
    grid-template-columns: 1fr;
  }

  .encounter-summary {
    grid-template-columns: 1fr;
  }

  .vital-row {
    grid-template-columns: 1fr;
    gap: 6px;
  }

  .unit-input,
  .compound-input {
    max-width: none;
  }
}
