:root {
  --bg: #eef6f4;
  --surface: #ffffff;
  --surface-2: #f7faf9;
  --ink: #000000;
  --muted: #66737f;
  --line: #d9e5e2;
  --primary: #0f766e;
  --primary-2: #115e59;
  --accent: #b42318;
  --amber: #a16207;
  --green: #15803d;
  --shadow: 0 10px 28px rgba(20, 52, 48, 0.13);
  --radius: 8px;
  --base-font-size: 24px;
}

button,
input,
textarea,
select {
  font-size: var(--base-font-size);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, "Segoe UI", sans-serif;
  letter-spacing: 0;
  overscroll-behavior-y: none;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(180deg, #dcefeb 0, #eef6f4 220px),
    var(--bg);
  overscroll-behavior-y: none;
}

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

button {
  cursor: pointer;
}

.hidden {
  display: none !important;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px 14px;
  background:
    linear-gradient(180deg, #dcefeb 0, #eef6f4 240px),
    var(--bg);
}

.login-panel {
  width: 100%;
  max-width: 420px;
  display: grid;
  gap: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px 14px;
  box-shadow: var(--shadow);
}

.login-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

.brand-logo {
  width: 100%;
  height: auto;
  object-fit: contain;
  display: block;
}

.brand-logo-small {
  flex: 0 0 auto;
  width: 40px;
  height: 40px;
  object-fit: contain;
  border-radius: 6px;
}

.brand-logo-topbar {
  width: 100%;
  height: auto;
  object-fit: contain;
  display: block;
}

.login-brand h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.15;
}

.login-brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 15px;
}

.wide-btn {
  width: 100%;
}

.login-message {
  min-height: 18px;
  margin: 0;
  color: var(--accent);
  font-size: 13px;
}

.device-pending {
  display: grid;
  gap: 10px;
  padding: 12px;
  background: #fff7ed;
  border: 1px solid #fed7aa;
  border-radius: var(--radius);
  color: #9a3412;
}

.device-pending p {
  margin: 0;
  font-size: 13px;
  line-height: 1.4;
}

.device-actions {
  display: grid;
  grid-template-columns: 1fr;
  gap: 8px;
}

.hint-text {
  margin: -6px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.35;
}

.hint-text.wide {
  grid-column: 1 / -1;
}

.app-shell {
  width: 100%;
  max-width: 520px;
  min-height: 100vh;
  margin: 0 auto;
  background: var(--bg);
  position: relative;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 8px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 12px;
  background: rgba(238, 246, 244, 0.94);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid rgba(15, 118, 110, 0.12);
}

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

.brand-mark {
  flex: 0 0 36px;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--primary);
  color: #fff;
  font-size: 13px;
  font-weight: 800;
}

.topbar h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--surface);
  color: var(--primary-2);
  display: grid;
  place-items: center;
  box-shadow: 0 2px 8px rgba(15, 118, 110, 0.07);
}

.icon-btn.contained {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.back-btn {
  visibility: hidden;
}

.back-btn.visible {
  visibility: visible;
}

.content {
  padding: 14px 14px calc(28px + env(safe-area-inset-bottom));
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.search-panel {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
}

.search-box {
  min-height: 54px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.search-box svg {
  color: var(--primary);
  flex: 0 0 auto;
}

.search-box input {
  width: 100%;
  min-width: 0;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--ink);
  font-size: 19px;
}

.primary-btn,
.ghost-btn,
.danger-btn,
.quick-btn {
  min-height: 44px;
  border-radius: var(--radius);
  border: 1px solid transparent;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 700;
  text-decoration: none;
}

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

.ghost-btn {
  background: var(--surface);
  color: var(--primary-2);
  border-color: var(--line);
}

.danger-btn {
  background: #fff1f2;
  color: var(--accent);
  border-color: #fecdd3;
}

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
  color: var(--muted);
  font-size: 15px;
  margin: 6px 2px 12px;
}

.dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--amber);
}

.dot.ok {
  background: var(--green);
}

.dot.bad {
  background: var(--accent);
}

.account-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
  min-height: 32px;
  margin: -4px 2px 12px;
  color: var(--muted);
  font-size: 12px;
}

.account-line>div {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  flex: 0 0 auto;
}

.link-btn {
  border: 0;
  background: transparent;
  color: var(--primary-2);
  font-size: 12px;
  font-weight: 800;
  padding: 4px 0;
}

.danger-link {
  color: var(--accent);
}

.patient-list,
.treatment-list {
  display: grid;
  gap: 10px;
}

.patient-card,
.treatment-card,
.patient-profile,
.field {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 4px 18px rgba(20, 52, 48, 0.07);
}

.patient-card {
  padding: 14px;
  text-align: left;
  width: 100%;
  color: inherit;
}

.patient-card:active,
.quick-btn:active,
.primary-btn:active,
.ghost-btn:active,
.icon-btn:active {
  transform: translateY(1px);
}

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
}

.patient-card h3 {
  margin: 0;
  font-size: 19px;
  line-height: 1.25;
}

.chip {
  flex: 0 0 auto;
  padding: 4px 8px;
  border-radius: 999px;
  background: #e0f2f1;
  color: var(--primary-2);
  font-size: 14px;
  font-weight: 800;
}

.meta {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 15px;
  line-height: 1.35;
}

.empty {
  padding: 28px 14px;
  text-align: center;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.55);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}

.patient-profile {
  padding: 16px;
}

.profile-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-start;
}

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

.profile-head h2 {
  margin: 0;
  font-size: 22px;
}

.patient-profile h3 {
  margin: 14px 0 0;
  font-size: 24px;
  line-height: 1.2;
}

.quick-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 16px;
}

.quick-btn {
  background: #f8fafc;
  color: var(--primary-2);
  border-color: var(--line);
}

.quick-btn.accent {
  background: #fff7ed;
  color: #9a3412;
  border-color: #fed7aa;
}

.finance-strip {
  margin: 12px 0;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.finance-strip div {
  background: #0f2f2d;
  color: #d7fffb;
  padding: 11px 8px;
  border-radius: var(--radius);
  min-width: 0;
}

.finance-strip span {
  display: block;
  font-size: 11px;
  opacity: 0.75;
  margin-bottom: 4px;
}

.finance-strip strong {
  display: block;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  padding: 3px;
  background: #dbeae7;
  border-radius: var(--radius);
  margin: 12px 0;
}

.segment {
  height: 40px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--primary-2);
  font-weight: 800;
}

.segment.active {
  background: var(--surface);
  color: var(--ink);
  box-shadow: 0 2px 8px rgba(20, 52, 48, 0.09);
}

.pane {
  display: none;
}

.pane.active {
  display: block;
}

.view-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
  margin: 0 0 10px;
}

.view-switch-btn {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--primary-2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  font-weight: 800;
}

.view-switch-btn svg {
  width: 18px;
  height: 18px;
}

.view-switch-btn.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: 0 4px 14px rgba(15, 118, 110, 0.18);
}

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

.field {
  padding: 8px;
  min-width: 0;
}

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

.field span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 4px;
  font-weight: 800;
  text-transform: uppercase;
}

.field strong {
  display: block;
  font-size: 17px;
  line-height: 1.35;
  overflow-wrap: anywhere;
}

.treatment-card {
  padding: 12px;
  border-left: 4px solid var(--primary);
}

.treatment-card.unpaid {
  border-left-color: var(--amber);
}

.treatment-card.locked {
  opacity: 0.78;
}

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

.treatment-date {
  font-weight: 800;
  color: var(--primary-2);
}

.treatment-tags {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 5px;
}

.tooth-pill,
.recall-pill {
  padding: 3px 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 800;
}

.tooth-pill {
  background: #f1f5f9;
  color: var(--muted);
}

.recall-pill {
  background: #fff7ed;
  color: #9a3412;
}

.treatment-desc {
  margin: 9px 0;
  font-size: 17px;
  line-height: 1.42;
  overflow-wrap: anywhere;
}

.treatment-foot {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 15px;
  border-top: 1px solid #edf2f1;
  padding-top: 8px;
}

.money-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

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

.small-btn {
  min-height: 34px;
  padding: 0 10px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--primary-2);
  font-weight: 800;
}

.treatment-table-wrap {
  width: 100%;
  max-height: 68vh;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  background: var(--surface);
  border: 1px solid #b9c9c6;
  border-radius: var(--radius);
  box-shadow: 0 4px 18px rgba(20, 52, 48, 0.07);
}

.treatment-table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 12px;
  line-height: 1.3;
}

.treatment-table th,
.treatment-table td {
  border: 1px solid #cbd8d5;
  padding: 7px 8px;
  vertical-align: top;
  background: #fff;
  color: var(--ink);
}

.treatment-table th {
  position: sticky;
  top: 0;
  z-index: 2;
  background: #e7f1ee;
  color: #123c38;
  font-weight: 900;
  text-align: left;
  white-space: nowrap;
}

.treatment-table tbody tr:nth-child(even) td {
  background: #fbfdfd;
}

.treatment-table tbody tr.unpaid td {
  background: #fff8e6;
}

.treatment-table tbody tr.locked td {
  color: #718096;
}

.treatment-table .col-index,
.treatment-table .number-cell {
  text-align: center;
  width: 42px;
}

.treatment-table .text-cell {
  width: 260px;
  overflow-wrap: anywhere;
}

.treatment-table .money-cell {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.treatment-table .action-cell {
  text-align: center;
}

.treatment-table .action-cell .small-btn {
  min-height: 30px;
  padding: 0 8px;
  font-size: 12px;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: none;
  align-items: flex-end;
  justify-content: center;
  padding: 0 0 env(safe-area-inset-bottom);
  background: rgba(15, 23, 42, 0.38);
}

.sheet.open {
  display: flex;
}

.sheet-panel {
  width: 100%;
  max-width: 520px;
  max-height: 92vh;
  overflow: auto;
  background: var(--surface);
  border-radius: 8px 8px 0 0;
  padding: 16px 14px 18px;
  box-shadow: 0 -18px 42px rgba(10, 24, 22, 0.2);
}

.sheet-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.sheet-header h2 {
  margin: 0;
  font-size: 20px;
}

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

.input {
  display: grid;
  gap: 6px;
}

.input.wide,
.sheet-actions.wide {
  grid-column: 1 / -1;
}

.input span,
.check-row span {
  color: var(--muted);
  font-size: 14px;
  font-weight: 800;
}

.input input,
.input textarea,
.input select {
  width: 100%;
  min-width: 0;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fbfdfd;
  color: var(--ink);
  padding: 6px 8px;
  outline: none;
}

.input textarea {
  resize: vertical;
  line-height: 1.4;
}

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

.select-action-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 44px;
  gap: 8px;
  align-items: stretch;
}

.select-action-row .icon-btn {
  width: 44px;
  height: 44px;
}

.dentist-manage-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 18px 0 8px;
}

.dentist-manage-head h3 {
  margin: 0;
  font-size: 15px;
}

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

.dentist-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  align-items: center;
  gap: 8px;
  min-height: 58px;
  padding: 9px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.dentist-row.inactive {
  background: #f1f5f9;
  color: #64748b;
}

.dentist-row-main {
  min-width: 0;
  display: grid;
  gap: 3px;
}

.dentist-row-main strong,
.dentist-row-main span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dentist-row-main span {
  color: var(--muted);
  font-size: 12px;
}

.dentist-status {
  min-width: 62px;
  padding: 5px 7px;
  border-radius: 999px;
  text-align: center;
  font-size: 12px;
  font-weight: 800;
}

.dentist-status.active {
  background: #dcfce7;
  color: #166534;
}

.dentist-status.off {
  background: #fee2e2;
  color: #991b1b;
}

.dentist-status-btn {
  min-width: 56px;
  min-height: 34px;
  padding: 0 10px;
}

.device-approval-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

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

.device-approval-row {
  display: grid;
  gap: 10px;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.device-approval-main {
  min-width: 0;
  display: grid;
  gap: 5px;
}

.device-approval-main strong,
.device-approval-main span,
.device-approval-main small {
  min-width: 0;
  overflow-wrap: anywhere;
}

.device-approval-main span,
.device-approval-main small {
  color: var(--muted);
}

.device-approval-main code {
  width: fit-content;
  max-width: 100%;
  padding: 6px 8px;
  border: 1px dashed #94a3b8;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font-size: 15px;
  font-weight: 800;
  overflow-wrap: anywhere;
}

.device-approval-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.device-approval-actions .primary-btn,
.device-approval-actions .danger-btn {
  min-height: 38px;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding-top: 18px;
}

.check-row input {
  width: 20px;
  height: 20px;
  accent-color: var(--primary);
}

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

.split-actions {
  justify-content: space-between;
}

.split-actions>div {
  display: flex;
  gap: 8px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(20px);
  width: min(92vw, 480px);
  padding: 12px 14px;
  background: #102a27;
  color: #fff;
  border-radius: var(--radius);
  opacity: 0;
  pointer-events: none;
  transition: 0.18s ease;
  z-index: 50;
  box-shadow: var(--shadow);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (min-width: 720px) {
  .app-shell {
    margin-top: 18px;
    min-height: calc(100vh - 36px);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: var(--shadow);
  }

  .topbar {
    border-radius: 8px 8px 0 0;
  }
}

@media (max-width: 360px) {
  .finance-strip strong {
    font-size: 13px;
  }

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

  .input.wide,
  .sheet-actions.wide {
    grid-column: auto;
  }

  .dentist-row {
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .dentist-status {
    display: none;
  }
}