:root {
  color-scheme: light;
  --ink: #191816;
  --soft-ink: #3f3c37;
  --muted: #746f66;
  --line: #ded8cc;
  --paper: #f7f4ee;
  --panel: #fffdf8;
  --charcoal: #25221d;
  --gold: #b88a38;
  --gold-dark: #8f6827;
  --emerald: #16685d;
  --blue: #315f8c;
  --rose: #b5534d;
  --green: #238161;
  --shadow: 0 18px 42px rgba(36, 30, 21, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Inter, Segoe UI, Arial, sans-serif;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(184, 138, 56, 0.11), transparent 34%),
    linear-gradient(315deg, rgba(22, 104, 93, 0.1), transparent 28%),
    var(--paper);
}

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

button {
  cursor: pointer;
}

.login-screen {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px;
}

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

.login-card {
  display: grid;
  gap: 18px;
  width: min(440px, 100%);
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(255, 253, 248, 0.96);
  box-shadow: var(--shadow);
}

.login-logo {
  width: 100%;
  max-width: 280px;
  height: 128px;
  object-fit: contain;
  justify-self: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff8ec;
}

.login-card h1 {
  margin-top: 6px;
  font-size: 28px;
}

.login-help {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

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

.app-shell.locked {
  display: none;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding: 24px 18px;
  color: #f6efe1;
  background: linear-gradient(180deg, #24211d, #171615);
  border-right: 1px solid rgba(255, 255, 255, 0.08);
}

.brand {
  display: flex;
  align-items: flex-start;
  flex-direction: column;
  gap: 10px;
  min-height: 132px;
}

.brand-logo {
  width: 100%;
  max-width: 220px;
  height: 96px;
  object-fit: contain;
  border: 1px solid rgba(250, 231, 184, 0.45);
  border-radius: 8px;
  background: #fff8ec;
}

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

.brand span {
  color: #cfc2a8;
  font-size: 13px;
}

.nav {
  display: grid;
  gap: 7px;
}

.nav-item,
.ghost-button,
.secondary-button,
.primary-button,
.danger-button,
.text-button,
.icon-button {
  border: 0;
  border-radius: 8px;
  min-height: 42px;
  padding: 0 14px;
  font-weight: 800;
}

.nav-item {
  position: relative;
  text-align: left;
  color: #ded2bd;
  background: transparent;
}

.nav-item.active,
.nav-item:hover {
  color: #fff8eb;
  background: rgba(255, 255, 255, 0.1);
}

.nav-item.active::before {
  position: absolute;
  left: 0;
  top: 10px;
  width: 3px;
  height: 22px;
  content: "";
  border-radius: 999px;
  background: var(--gold);
}

.sidebar-actions {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

.user-pill {
  display: grid;
  gap: 3px;
  padding: 11px 12px;
  border: 1px solid rgba(250, 231, 184, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.user-pill span,
.user-pill small {
  display: block;
}

.user-pill span {
  color: #fff8eb;
  font-weight: 900;
}

.user-pill small {
  color: #cfc2a8;
}

.auth-error {
  padding: 10px 12px;
  border-radius: 8px;
  color: #fff;
  background: var(--rose);
  font-size: 13px;
  font-weight: 800;
}

.file-label {
  display: grid;
  place-items: center;
}

#importData {
  display: none;
}

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

.topbar,
.topbar-actions,
.panel-header,
.toolbar,
.modal-header,
.modal-actions,
.item-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar {
  margin-bottom: 22px;
}

h1,
h2,
p {
  margin: 0;
}

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

h2 {
  font-size: 18px;
  letter-spacing: 0;
}

.eyebrow,
.metric span,
.metric small,
.empty,
.item-meta,
.token-grid span {
  color: var(--muted);
  font-size: 13px;
}

.primary-button {
  color: #fffdf6;
  background: linear-gradient(135deg, var(--gold), var(--gold-dark));
}

.secondary-button,
.ghost-button {
  color: var(--charcoal);
  background: #ece5d8;
}

.ghost-button {
  color: #fff4db;
  background: rgba(255, 255, 255, 0.1);
}

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

.text-button {
  padding: 0;
  color: var(--gold-dark);
  background: transparent;
}

.icon-button {
  width: 38px;
  padding: 0;
  color: var(--charcoal);
  background: #efe8da;
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  text-decoration: none;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.executive-band {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 136px;
  margin-bottom: 18px;
  padding: 24px;
  color: #fff8eb;
  background:
    linear-gradient(90deg, rgba(37, 34, 29, 0.92), rgba(37, 34, 29, 0.72)),
    url("https://images.unsplash.com/photo-1629909613654-28e377c37b09?auto=format&fit=crop&w=1400&q=80");
  background-position: center;
  background-size: cover;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.executive-band .eyebrow {
  color: #dec995;
}

.executive-band h2 {
  margin-top: 6px;
  font-size: 28px;
}

.mini-stat {
  min-width: 132px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.22);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.mini-stat span,
.mini-stat strong {
  display: block;
}

.mini-stat span {
  color: #dec995;
  font-size: 13px;
}

.mini-stat strong {
  margin-top: 8px;
  font-size: 30px;
}

.metrics-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metrics-grid.compact {
  grid-template-columns: repeat(4, minmax(130px, 1fr));
}

.metric,
.panel,
.patient-card,
.pipeline-column {
  background: rgba(255, 253, 248, 0.94);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric {
  padding: 18px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
}

.metric small {
  display: block;
  margin-top: 3px;
}

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

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

.panel {
  padding: 18px;
}

.stack-list,
.checklist {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.list-item {
  display: grid;
  gap: 9px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf9;
}

.item-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
}

.item-title {
  font-weight: 900;
}

.item-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
  background: #eee7da;
}

.badge.scheduled,
.badge.due,
.badge.Consultation {
  color: var(--blue);
  background: #e8eff6;
}

.badge.completed,
.badge.done,
.badge.Completed,
.badge.Post-op,
.badge.Post-op-care {
  color: var(--green);
  background: #e7f2ec;
}

.badge.cancelled,
.badge.overdue {
  color: var(--rose);
  background: #f5e8e6;
}

.badge.pending,
.badge.Plan-proposed,
.badge.Surgery-confirmed,
.badge.High,
.badge.VIP,
.badge.Urgent,
.badge.Sent,
.badge.Needs-review {
  color: var(--gold-dark);
  background: #f5ecd8;
}

.badge.Lead {
  color: var(--soft-ink);
  background: #ede7dc;
}

.badge.Signed {
  color: var(--green);
  background: #e7f2ec;
}

.badge.Not-sent {
  color: var(--rose);
  background: #f5e8e6;
}

.toolbar {
  margin-bottom: 14px;
}

.toolbar input,
.toolbar select,
.form-grid input,
.form-grid select,
.form-grid textarea,
.modal-card input,
.modal-card select,
.modal-card textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--ink);
  background: #fffdf9;
}

.toolbar input {
  max-width: 420px;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffdf9;
  box-shadow: var(--shadow);
}

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

th,
td {
  padding: 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 13px;
  background: #f1eadc;
}

.patient-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
  gap: 14px;
}

.patient-card {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.patient-card strong {
  font-size: 18px;
}

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

.patient-meta-grid span {
  padding: 9px;
  border-radius: 8px;
  color: var(--muted);
  background: #f5efe4;
  font-size: 12px;
  font-weight: 800;
}

.photo-record {
  display: grid;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fffaf1;
}

.photo-upload-row {
  display: grid;
  grid-template-columns: minmax(180px, 240px) 1fr;
  gap: 14px;
  align-items: end;
}

.photo-picker input {
  padding: 8px;
}

.photo-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px;
}

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

.photo-card img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  background: #efe8da;
}

.photo-card-body {
  display: grid;
  gap: 7px;
  padding: 9px;
}

.photo-card strong {
  font-size: 12px;
}

.photo-card button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 12px;
}

.pipeline {
  display: grid;
  grid-template-columns: repeat(6, minmax(220px, 1fr));
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 10px;
}

.pipeline-column {
  min-height: 420px;
  padding: 14px;
}

.pipeline-column h2 {
  margin-bottom: 12px;
}

.token-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 16px;
}

.token-grid span {
  padding: 10px;
  border-radius: 8px;
  background: #f3eadc;
  font-weight: 900;
}

dialog {
  width: min(820px, calc(100vw - 28px));
  padding: 0;
  border: 0;
  border-radius: 10px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.25);
}

dialog::backdrop {
  background: rgba(24, 21, 17, 0.5);
}

.modal-card {
  display: grid;
  gap: 16px;
  max-height: min(86vh, 820px);
  overflow: auto;
  padding: 20px;
  background: #fffdf8;
}

.print-preview-shell {
  display: grid;
  gap: 16px;
  max-height: min(88vh, 900px);
  overflow: auto;
  padding: 18px;
  background: #f7f4ee;
}

#printPreview {
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.form-grid {
  display: grid;
  gap: 14px;
}

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

label {
  display: grid;
  gap: 7px;
  color: var(--soft-ink);
  font-size: 13px;
  font-weight: 900;
}

textarea {
  resize: vertical;
}

.modal-actions {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
}

.toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  transform: translateY(18px);
  opacity: 0;
  pointer-events: none;
  padding: 12px 14px;
  border-radius: 8px;
  color: #fff;
  background: var(--charcoal);
  transition: 180ms ease;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

#printArea {
  display: none;
}

.print-document {
  color: #191816;
  background: #fff;
  font-family: Segoe UI, Arial, sans-serif;
}

.print-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 18px;
  border-bottom: 2px solid #b88a38;
}

.print-logo {
  width: 190px;
  height: auto;
}

.print-title {
  text-align: right;
}

.print-title h1 {
  font-size: 24px;
}

.print-section {
  margin-top: 22px;
}

.print-section h2 {
  margin-bottom: 10px;
  color: #8f6827;
  font-size: 16px;
}

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

.print-field {
  padding: 9px 0;
  border-bottom: 1px solid #e7dfd1;
}

.print-field strong {
  display: block;
  color: #746f66;
  font-size: 12px;
}

.print-table {
  width: 100%;
  min-width: 0;
  border-collapse: collapse;
}

.print-table th,
.print-table td {
  padding: 10px;
  border: 1px solid #ded8cc;
}

.print-total {
  display: grid;
  gap: 8px;
  max-width: 320px;
  margin-left: auto;
  margin-top: 16px;
}

.print-total div {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid #ded8cc;
}

.print-total .grand {
  color: #8f6827;
  font-size: 18px;
  font-weight: 900;
}

.print-photo-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.print-photo {
  break-inside: avoid;
  border: 1px solid #ded8cc;
}

.print-photo img {
  display: block;
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
}

.print-photo strong,
.print-photo span {
  display: block;
  padding: 6px 8px;
}

.print-photo span {
  color: #746f66;
  font-size: 12px;
}

@media print {
  body {
    background: #fff;
  }

  .app-shell,
  .toast,
  #printDialog {
    display: none !important;
  }

  #printArea {
    display: block;
    padding: 28px;
  }
}

@media (max-width: 1100px) {
  .pipeline {
    grid-template-columns: repeat(6, 240px);
  }
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    gap: 14px;
    padding: 14px;
  }

  .nav {
    grid-template-columns: repeat(9, minmax(112px, 1fr));
    overflow-x: auto;
  }

  .sidebar-actions {
    display: none;
  }

  .workspace {
    padding: 18px;
  }

  .topbar,
  .toolbar,
  .executive-band {
    align-items: stretch;
    flex-direction: column;
  }

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

  .metrics-grid,
  .content-grid,
  .crm-grid,
  .form-grid.two,
  .photo-upload-row {
    grid-template-columns: 1fr;
  }
}
