:root {
  --bg: #f4f7f6;
  --surface: #ffffff;
  --surface-soft: #eef5f2;
  --border: #d8e1df;
  --text: #17211f;
  --muted: #66736f;
  --primary: #0f766e;
  --primary-strong: #0b5f59;
  --primary-soft: #dff3ef;
  --accent: #7c3aed;
  --warning: #b7791f;
  --warning-soft: #fff4d8;
  --danger: #b42318;
  --danger-soft: #ffe4df;
  --success: #147d4f;
  --success-soft: #def7e8;
  --shadow: 0 18px 45px rgba(23, 33, 31, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  font-family:
    Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  color: var(--text);
  background:
    linear-gradient(180deg, rgba(223, 243, 239, 0.7), rgba(244, 247, 246, 0) 280px),
    var(--bg);
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
}

dialog {
  margin: auto;
}

.app-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 40px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  min-width: 0;
}

.brand__mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  flex: 0 0 48px;
  border-radius: 8px;
  color: #ffffff;
  background: var(--primary);
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
}

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

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

h1 {
  margin-bottom: 0;
  font-size: 34px;
  line-height: 1.1;
  letter-spacing: 0;
}

.topbar__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 16px;
  border-radius: 8px;
  font-weight: 750;
  text-align: center;
  cursor: pointer;
  transition:
    transform 160ms ease,
    background 160ms ease,
    box-shadow 160ms ease,
    color 160ms ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.72;
}

.button--primary {
  color: #ffffff;
  background: var(--primary);
  box-shadow: 0 10px 24px rgba(15, 118, 110, 0.22);
}

.button--primary:hover:not(:disabled) {
  background: var(--primary-strong);
}

.button--secondary {
  color: var(--primary-strong);
  background: var(--primary-soft);
}

.button--secondary:hover:not(:disabled) {
  background: #cbece5;
}

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

.button--danger:hover:not(:disabled) {
  background: #8f1c14;
}

.button--file {
  width: 100%;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.icon-button {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  flex: 0 0 38px;
  border-radius: 8px;
  color: var(--muted);
  background: var(--surface-soft);
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
}

.icon-button:hover {
  color: var(--text);
  background: var(--primary-soft);
}

.page-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 18px;
}

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

.metric,
.workspace,
.details {
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
}

.metric__label {
  display: block;
  min-height: 18px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 650;
}

.metric__value {
  display: block;
  margin-top: 8px;
  font-size: 32px;
  line-height: 1;
}

.workspace,
.details {
  padding: 18px;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(240px, 1.4fr) repeat(3, minmax(150px, 0.8fr));
  gap: 12px;
  align-items: end;
}

.field {
  display: grid;
  gap: 7px;
  min-width: 0;
}

.field__label {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.field__hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

input,
select {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  outline: none;
}

input {
  padding: 0 13px;
}

input[type="file"] {
  display: flex;
  align-items: center;
  padding: 9px 12px;
}

select {
  padding: 0 34px 0 12px;
}

input:focus,
select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.16);
}

input:disabled,
select:disabled {
  opacity: 0.75;
}

.status {
  min-height: 22px;
  margin: 14px 0;
  color: var(--muted);
  font-size: 14px;
  font-weight: 650;
}

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

.patient-card {
  min-width: 0;
}

.patient-card__button {
  display: grid;
  width: 100%;
  grid-template-columns: 46px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
  min-height: 88px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: inherit;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.patient-card__button:hover,
.patient-card__button.is-active {
  border-color: rgba(15, 118, 110, 0.55);
  background: var(--surface-soft);
}

.patient-card__button:hover {
  transform: translateY(-1px);
}

.avatar {
  display: grid;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 8px;
  background-color: var(--surface-soft);
  background-repeat: no-repeat;
  box-shadow: inset 0 0 0 1px rgba(23, 33, 31, 0.08);
  overflow: hidden;
}

.patient-card__content {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.patient-card__header,
.patient-card__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.patient-card__name {
  overflow: hidden;
  min-width: 0;
  font-size: 16px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.patient-card__meta,
.patient-card__date {
  overflow: hidden;
  color: var(--muted);
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge,
.risk {
  display: inline-flex;
  min-height: 24px;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.badge--paid {
  color: var(--success);
  background: var(--success-soft);
}

.badge--unpaid {
  color: var(--danger);
  background: var(--danger-soft);
}

.risk--low {
  color: var(--success);
  background: var(--success-soft);
}

.risk--medium {
  color: var(--warning);
  background: var(--warning-soft);
}

.risk--high {
  color: var(--danger);
  background: var(--danger-soft);
}

.empty-state {
  display: grid;
  min-height: 220px;
  place-items: center;
  align-content: center;
  gap: 8px;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: var(--surface);
  text-align: center;
}

.empty-state h2 {
  margin: 0;
  font-size: 20px;
}

.empty-state p {
  margin: 0;
  color: var(--muted);
}

.details {
  align-self: start;
  position: sticky;
  top: 18px;
}

.details h2 {
  margin-bottom: 8px;
  font-size: 24px;
  line-height: 1.2;
}

.details-photo {
  width: 100%;
  aspect-ratio: 1 / 1;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background-color: var(--surface-soft);
  background-repeat: no-repeat;
  box-shadow: inset 0 0 0 1px rgba(23, 33, 31, 0.04);
}

.details__note {
  min-height: 22px;
  margin-bottom: 18px;
  color: var(--muted);
  line-height: 1.5;
}

.details-list {
  display: grid;
  grid-template-columns: 120px minmax(0, 1fr);
  gap: 12px 14px;
  margin: 0;
}

.details-list dt {
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

.details-list dd {
  min-width: 0;
  margin: 0;
  font-weight: 700;
  overflow-wrap: anywhere;
}

.details-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 9px;
  margin-top: 18px;
}

.modal {
  width: min(760px, calc(100% - 24px));
  max-height: min(760px, calc(100vh - 24px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
  overflow: auto;
  box-shadow: 0 28px 80px rgba(23, 33, 31, 0.26);
}

.modal::backdrop {
  background: rgba(23, 33, 31, 0.42);
}

.patient-form {
  display: grid;
  gap: 18px;
  padding: 22px;
}

.modal__header,
.modal__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.modal__header h2 {
  margin: 0;
  font-size: 25px;
  line-height: 1.2;
}

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

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

.form-error {
  min-height: 20px;
  margin: 0;
  color: var(--danger);
  font-size: 14px;
  font-weight: 750;
}

.modal__footer {
  justify-content: flex-end;
}

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

  .details {
    position: static;
  }

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

  .field--wide {
    grid-column: 1 / -1;
  }
}

@media (max-width: 720px) {
  .app-shell {
    width: min(100% - 20px, 1180px);
    padding-top: 18px;
  }

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

  .topbar__actions {
    justify-content: stretch;
  }

  .button {
    flex: 1 1 150px;
  }

  h1 {
    font-size: 27px;
  }

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

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

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

  .patient-card__header,
  .patient-card__footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .patient-card__name,
  .patient-card__meta,
  .patient-card__date {
    white-space: normal;
  }
}

@media (max-width: 480px) {
  .brand__mark {
    width: 42px;
    height: 42px;
    flex-basis: 42px;
    font-size: 26px;
  }

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

  .metric {
    padding: 14px;
  }

  .patient-card__button {
    grid-template-columns: 40px minmax(0, 1fr);
  }

  .avatar {
    width: 40px;
    height: 40px;
  }

  .details-list {
    grid-template-columns: 1fr;
    gap: 5px;
  }
}
