:root {
  color-scheme: light;
  --ink: #172126;
  --muted: #66717a;
  --line: #dde4e8;
  --panel: #ffffff;
  --page: #f4f7f6;
  --side: #203035;
  --side-ink: #edf7f4;
  --teal: #118c7e;
  --teal-dark: #0c6f65;
  --green: #2f7d4f;
  --amber: #a66614;
  --red: #b83232;
  --lavender: #6656a5;
  --shadow: 0 12px 26px rgba(22, 32, 36, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  background: var(--page);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
}

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

button {
  cursor: pointer;
}

button:disabled,
.btn:disabled {
  cursor: progress;
  opacity: 0.62;
  filter: grayscale(0.12);
}

form.is-busy {
  position: relative;
}

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

.sidebar {
  background: var(--side);
  color: var(--side-ink);
  padding: 20px 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 46px;
  margin-bottom: 26px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #e7f7f0;
  color: var(--teal-dark);
  font-weight: 800;
}

.brand-title {
  font-size: 18px;
  font-weight: 760;
}

.brand-subtitle {
  color: #b7c7c3;
  font-size: 12px;
  margin-top: 2px;
}

.build-marker {
  color: #9eb0ac;
  font-size: 11px;
  margin: -14px 0 20px 54px;
}

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

.nav-button {
  width: 100%;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 12px;
  background: transparent;
  color: #d7e2df;
  text-align: left;
  display: flex;
  align-items: center;
  gap: 10px;
}

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

.nav-glyph {
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 12px;
  font-weight: 800;
}

.main {
  min-width: 0;
}

.topbar {
  min-height: 72px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(12px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  position: sticky;
  top: 0;
  z-index: 5;
}

.page-title {
  font-size: 22px;
  font-weight: 760;
  margin: 0;
}

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

.user-chip {
  display: grid;
  gap: 2px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  min-width: 180px;
}

.user-chip strong {
  font-size: 13px;
}

.user-chip span {
  color: var(--muted);
  font-size: 12px;
}

.content {
  padding: 24px 28px 44px;
}

.login-page {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(320px, 440px) minmax(0, 1fr);
  background:
    linear-gradient(120deg, rgba(17, 140, 126, 0.12), rgba(47, 125, 79, 0.06)),
    var(--page);
}

.login-panel {
  background: var(--panel);
  padding: 48px;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.login-visual {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(135deg, rgba(17, 140, 126, 0.9), rgba(32, 48, 53, 0.94)),
    repeating-linear-gradient(90deg, transparent 0 52px, rgba(255, 255, 255, 0.08) 52px 53px);
}

.login-visual::before,
.login-visual::after {
  content: "";
  position: absolute;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.08);
}

.login-visual::before {
  width: min(520px, 66vw);
  height: 320px;
  right: 9%;
  top: 18%;
}

.login-visual::after {
  width: min(420px, 58vw);
  height: 180px;
  right: 16%;
  top: 56%;
}

.login-title {
  margin: 22px 0 8px;
  font-size: 30px;
}

.login-copy {
  margin: 0 0 28px;
  color: var(--muted);
  line-height: 1.5;
}

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

.form-row {
  display: grid;
  gap: 6px;
}

.form-row label {
  color: #3c4b51;
  font-size: 13px;
  font-weight: 680;
}

.field,
input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid #cbd7dc;
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  padding: 10px 12px;
  outline: none;
}

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

.multi-select {
  min-height: 112px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(17, 140, 126, 0.12);
}

.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  color: #3c4b51;
  font-size: 13px;
}

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

.button-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.toolbar-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) auto auto;
  gap: 8px;
  margin-bottom: 12px;
}

.section-copy {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.table-actions {
  gap: 6px;
}

.table-actions .btn {
  min-height: 32px;
  padding: 6px 10px;
  font-size: 12px;
}

.invoice-lines {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
  overflow-x: auto;
}

.invoice-lines-head,
.invoice-line-summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.invoice-lines-head h4 {
  margin: 0;
  font-size: 16px;
}

.invoice-line-head,
.invoice-line-row {
  display: grid;
  grid-template-columns: minmax(120px, 0.85fr) minmax(145px, 1fr) minmax(180px, 1.25fr) 68px 90px 76px 92px 88px 76px;
  gap: 8px;
  align-items: center;
  min-width: 1040px;
}

.invoice-line-head {
  color: var(--muted);
  font-size: 12px;
  font-weight: 720;
}

.invoice-line-row input,
.invoice-line-row select {
  min-height: 38px;
  padding: 8px 10px;
}

.invoice-line-row output {
  min-height: 38px;
  display: flex;
  align-items: center;
  font-weight: 720;
}

.invoice-line-remove {
  min-height: 38px;
  padding-inline: 8px;
}

.invoice-line-summary {
  padding-top: 8px;
  border-top: 1px solid var(--line);
  color: var(--muted);
}

.invoice-line-summary strong {
  color: var(--ink);
  font-size: 16px;
}

.btn {
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 9px 14px;
  font-weight: 720;
  background: #edf3f1;
  color: #223135;
}

.btn:hover {
  filter: brightness(0.98);
}

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

.btn.primary:hover {
  background: var(--teal-dark);
}

.btn.warning {
  background: #fff4df;
  color: #74450b;
  border-color: #efd39e;
}

.btn.ghost {
  background: transparent;
  border-color: var(--line);
}

.btn.danger {
  background: #fff1f1;
  color: var(--red);
  border-color: #f1c4c4;
}

.section {
  margin-bottom: 24px;
}

.app-page-stack {
  display: grid;
  gap: 18px;
}

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

.section-title {
  margin: 0;
  font-size: 18px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(130px, 1fr));
  gap: 14px;
}

.metric-card,
.panel,
.record-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.metric-card {
  min-height: 118px;
  padding: 16px;
  display: grid;
  align-content: space-between;
}

.metric-label {
  color: var(--muted);
  font-size: 13px;
}

.metric-value {
  font-size: 30px;
  font-weight: 820;
}

.metric-card.teal {
  border-top: 4px solid var(--teal);
}

.metric-card.green {
  border-top: 4px solid var(--green);
}

.metric-card.amber {
  border-top: 4px solid var(--amber);
}

.metric-card.lavender {
  border-top: 4px solid var(--lavender);
}

.metric-card.red {
  border-top: 4px solid var(--red);
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(320px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.billing-page .panel,
.whatsapp-page .panel {
  box-shadow: 0 10px 24px rgba(22, 32, 36, 0.06);
}

.billing-composer > .section-head {
  align-items: flex-start;
}

.billing-meta-grid,
.settings-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
}

.automation-box {
  display: grid;
  grid-template-columns: repeat(2, minmax(220px, 1fr));
  gap: 12px 18px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
}

.automation-box .inline-section-head {
  grid-column: 1 / -1;
  margin-bottom: 0;
}

.status-metrics .metric-value {
  font-size: 26px;
}

.whatsapp-ops-grid {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.whatsapp-logs-grid {
  display: grid;
  grid-template-columns: minmax(300px, 420px) minmax(0, 1fr);
  gap: 18px;
  align-items: start;
}

.document-table table {
  min-width: 860px;
}

.visit-grid {
  grid-template-columns: minmax(340px, 520px) minmax(0, 1fr);
}

.setup-grid {
  margin-top: 18px;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
}

.panel {
  padding: 18px;
}

.physio-panel {
  display: grid;
  gap: 14px;
  padding: 14px;
  border: 1px solid #d6e4df;
  border-radius: 8px;
  background: #f7fbf9;
}

.physio-panel .section-head {
  margin-bottom: 0;
}

.panel h3 {
  margin: 0 0 14px;
  font-size: 16px;
}

.table-wrap {
  width: 100%;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

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

.compact-table table {
  min-width: 520px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  color: #3c4b51;
  background: #f0f5f3;
  font-weight: 780;
}

tr:last-child td {
  border-bottom: 0;
}

tr.is-pending-row td {
  background: #fbf8ef;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  background: #edf3f1;
  color: #334349;
  font-size: 12px;
  font-weight: 720;
}

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

.badge.amber {
  background: #fff4df;
  color: var(--amber);
}

.badge.red {
  background: #fff1f1;
  color: var(--red);
}

.badge.teal {
  background: #e2f4f1;
  color: var(--teal-dark);
}

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

.empty {
  min-height: 160px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed #c4d1d4;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.65);
  text-align: center;
  padding: 20px;
}

.empty.subtle {
  min-height: auto;
  place-items: start;
  justify-items: start;
  text-align: left;
  padding: 10px 12px;
  font-size: 13px;
}

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

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

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

.stacked-panels {
  display: grid;
  gap: 18px;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #203035;
  color: #ffffff;
  box-shadow: 0 18px 30px rgba(0, 0, 0, 0.22);
  opacity: 0;
  transform: translateY(12px);
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
  z-index: 30;
}

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

.error-box {
  border: 1px solid #f0b7b7;
  border-radius: 8px;
  color: var(--red);
  background: #fff6f6;
  padding: 10px 12px;
  font-size: 13px;
}

.loading {
  min-height: 320px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.mobile-top {
  display: none;
}

@media (max-width: 1080px) {
  .metrics {
    grid-template-columns: repeat(2, minmax(130px, 1fr));
  }

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

  .billing-meta-grid,
  .settings-grid,
  .automation-box,
  .whatsapp-ops-grid,
  .whatsapp-logs-grid {
    grid-template-columns: 1fr;
  }

  .invoice-line-head {
    display: none;
  }

  .invoice-line-row {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    min-width: 0;
    padding-top: 10px;
    border-top: 1px solid var(--line);
  }
}

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

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 10;
    padding: 12px;
  }

  .brand {
    margin-bottom: 12px;
  }

  .nav {
    grid-template-columns: repeat(3, 1fr);
  }

  .nav-button {
    justify-content: center;
    padding: 0 8px;
    font-size: 12px;
  }

  .nav-glyph {
    display: none;
  }

  .topbar {
    padding: 14px 16px;
    align-items: flex-start;
    gap: 12px;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: space-between;
  }

  .user-chip {
    min-width: 0;
    flex: 1;
  }

  .content {
    padding: 18px 16px 32px;
  }

  .login-page {
    grid-template-columns: 1fr;
  }

  .login-panel {
    min-height: 100vh;
    padding: 28px 20px;
    border-right: 0;
  }

  .login-visual {
    display: none;
  }

  .metrics,
  .two-col,
  .three-col,
  .toolbar-row {
    grid-template-columns: 1fr;
  }

  .invoice-lines-head,
  .invoice-line-summary {
    align-items: stretch;
    flex-direction: column;
  }

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