:root {
  --blue-900: #063c8f;
  --blue-700: #075ed7;
  --blue-100: #e8f1ff;
  --green-600: #10a164;
  --orange-600: #f28b20;
  --red-600: #e84c3d;
  --ink: #132238;
  --muted: #64748b;
  --line: #dce5f2;
  --surface: #ffffff;
  --page: #f5f8fc;
  --shadow: 0 10px 30px rgba(17, 47, 89, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, #edf5ff 0%, #f8fbff 38%, #f5f8fc 100%);
  overflow-x: hidden;
}

[hidden] {
  display: none !important;
}

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

button {
  cursor: pointer;
}

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

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 22px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 8px 22px;
}

.mobile-nav-head {
  display: contents;
}

.menu-toggle {
  display: none;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-direction: column;
}

.menu-toggle span {
  width: 19px;
  height: 2px;
  border-radius: 999px;
  background: var(--ink);
  transition: transform 0.18s ease, opacity 0.18s ease;
}

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

.login-stack {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  align-items: stretch;
}

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

.login-stack .login-card {
  width: 100%;
}

.login-brand {
  padding: 0 0 8px;
}

.login-card h1 {
  margin: 0 0 6px;
  font-size: 24px;
}

.login-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
}

.login-card input {
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
}

.login-error {
  min-height: 20px;
  color: var(--red-600);
  margin: 0;
  font-size: 13px;
}

.customer-portal {
  min-height: 100vh;
  padding: 22px;
}

.customer-head {
  max-width: 980px;
  margin: 0 auto 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}

.customer-view {
  max-width: 980px;
  margin: 0 auto;
  display: grid;
  gap: 14px;
}

.customer-summary,
.customer-report {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  padding: 18px;
}

.customer-summary h1,
.customer-report h2 {
  margin: 0 0 8px;
}

.customer-report {
  display: grid;
  gap: 10px;
}

.customer-report-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

@media (max-width: 780px) {
  .login-stack {
    grid-template-columns: 1fr;
  }

  .customer-head {
    align-items: flex-start;
    flex-direction: column;
  }

  .modal-backdrop {
    align-items: start;
    padding: 12px;
  }

  .modal-panel {
    max-height: calc(100vh - 24px);
  }
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 2px solid var(--blue-700);
  color: var(--blue-700);
  font-weight: 900;
  transform: skew(-8deg);
}

.brand-mark.has-logo {
  border: 0;
  transform: none;
  overflow: hidden;
}

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

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

.brand span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

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

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

.nav button.active {
  background: var(--blue-700);
  color: white;
  box-shadow: 0 8px 18px rgba(7, 94, 215, 0.22);
}

.nav .nav-icon {
  width: 22px;
  text-align: center;
  font-size: 15px;
}

.main {
  min-width: 0;
  padding: 20px 28px 36px;
}

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

.search {
  flex: 1;
  max-width: 520px;
  height: 42px;
  display: flex;
  align-items: center;
  gap: 8px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
}

.search input {
  width: 100%;
  border: 0;
  outline: 0;
  color: var(--ink);
}

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

.icon-button {
  width: 36px;
  height: 36px;
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
}

.profile {
  display: flex;
  align-items: center;
  gap: 9px;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  min-width: 0;
}

.profile span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.view {
  display: grid;
  gap: 18px;
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.page-head h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0;
}

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

.bulk-panel {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  box-shadow: var(--shadow);
}

.bulk-panel strong {
  margin-right: 6px;
  white-space: nowrap;
}

.field,
.select {
  height: 40px;
  min-width: 180px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  padding: 0 12px;
  color: var(--ink);
}

.button {
  min-height: 40px;
  border: 0;
  border-radius: 8px;
  padding: 0 14px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  color: white;
  background: var(--blue-700);
  box-shadow: 0 8px 18px rgba(7, 94, 215, 0.18);
}

.button.secondary {
  color: var(--blue-700);
  background: var(--blue-100);
  box-shadow: none;
}

.button.green {
  background: var(--green-600);
}

.button.red {
  background: var(--red-600);
}

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

.stat-card,
.panel,
.table-wrap,
.patient-card,
.modal-panel {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stat-card {
  padding: 18px;
  min-height: 118px;
  display: grid;
  gap: 8px;
}

.stat-top {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
}

.stat-value {
  font-size: 25px;
  font-weight: 800;
}

.stat-change {
  color: var(--green-600);
  font-size: 12px;
}

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

.panel {
  padding: 18px;
}

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

.chart {
  height: 210px;
  display: flex;
  align-items: end;
  gap: 18px;
  padding: 10px 4px 0;
  border-bottom: 1px solid var(--line);
}

.line-chart {
  position: relative;
  height: 210px;
  background:
    linear-gradient(to bottom, transparent 24%, var(--line) 25%, transparent 26%),
    linear-gradient(to bottom, transparent 49%, var(--line) 50%, transparent 51%),
    linear-gradient(to bottom, transparent 74%, var(--line) 75%, transparent 76%);
}

.line-chart svg {
  width: 100%;
  height: 100%;
}

.bar-pair {
  flex: 1;
  min-width: 28px;
  height: 100%;
  display: flex;
  align-items: end;
  justify-content: center;
  gap: 5px;
}

.bar {
  width: 18px;
  border-radius: 5px 5px 0 0;
  background: var(--blue-700);
}

.bar.light {
  background: #b9d4ff;
}

.table-wrap {
  overflow: hidden;
  max-width: 100%;
}

table {
  width: 100%;
  border-collapse: collapse;
  background: white;
}

th,
td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
  white-space: nowrap;
}

.check-cell {
  width: 46px;
  text-align: center;
}

th {
  color: var(--muted);
  background: #f9fbff;
  font-size: 12px;
  font-weight: 700;
}

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

.status {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 700;
}

.status.paid,
.status.done {
  color: #08784a;
  background: #e8f8f1;
}

.status.waiting {
  color: #b96100;
  background: #fff1de;
}

.status.partial {
  color: #075ed7;
  background: var(--blue-100);
}

.status.cancel {
  color: #ba3026;
  background: #ffe8e6;
}

.row-actions {
  display: flex;
  gap: 6px;
}

.mini {
  width: 32px;
  height: 32px;
  border: 1px solid var(--line);
  background: white;
  border-radius: 8px;
}

.mini svg {
  width: 18px;
  height: 18px;
  display: block;
  margin: auto;
  fill: currentColor;
}

.whatsapp-mini {
  border-color: #13a85b;
  background: #16a765;
  color: white;
}

.whatsapp-mini:hover {
  background: #118a53;
}

.patient-layout {
  display: grid;
  grid-template-columns: 270px minmax(0, 1fr);
  gap: 16px;
}

.patient-card {
  padding: 18px;
}

.patient-initial {
  width: 82px;
  height: 82px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  margin-bottom: 14px;
  background: var(--blue-100);
  color: var(--blue-700);
  font-size: 34px;
  font-weight: 800;
}

.patient-card h2 {
  margin: 0 0 14px;
  font-size: 18px;
}

.info-list {
  display: grid;
  gap: 10px;
  margin: 0;
}

.info-list div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.info-list strong {
  color: var(--ink);
  text-align: right;
}

.tabs {
  display: flex;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
}

.tabs button {
  height: 40px;
  border: 0;
  background: transparent;
  color: var(--muted);
  padding: 0 10px;
}

.tabs button.active {
  color: var(--blue-700);
  border-bottom: 2px solid var(--blue-700);
}

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

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

.metric-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.detail-item span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.calendar {
  background: white;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow-x: auto;
  box-shadow: var(--shadow);
}

.calendar-grid {
  display: grid;
  grid-template-columns: 80px repeat(7, minmax(110px, 1fr));
}

.cal-cell,
.cal-head,
.time-cell {
  min-height: 68px;
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  padding: 8px;
}

.cal-head {
  min-height: 42px;
  font-weight: 700;
  background: #f9fbff;
  text-align: center;
}

.time-cell {
  color: var(--muted);
  font-size: 12px;
  background: #fbfdff;
}

.event {
  border-radius: 8px;
  padding: 8px;
  font-size: 12px;
  line-height: 1.35;
  color: #123;
}

.event.blue {
  background: #dcecff;
}

.event.green {
  background: #dff7eb;
}

.event.orange {
  background: #fff0d7;
}

.event.purple {
  background: #ebe5ff;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.34);
  display: grid;
  place-items: center;
  padding: 20px;
  overflow: auto;
  z-index: 30;
}

.modal-panel {
  width: min(560px, 100%);
  max-height: min(90vh, 860px);
  overflow-y: auto;
  padding: 20px;
  overscroll-behavior: contain;
}

.modal-panel.wide {
  width: min(980px, 100%);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.modal-head h2 {
  margin: 0;
  font-size: 18px;
}

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

.form-grid label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

.form-grid label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
}

.form-grid input,
.form-grid textarea,
.form-grid select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 12px;
  color: var(--ink);
  background: white;
}

.bulk-grid {
  display: grid;
  grid-template-columns: minmax(150px, 1.2fr) minmax(150px, 1.2fr) minmax(120px, 1fr) 90px 76px 90px 110px;
  gap: 8px;
  align-items: center;
}

.bulk-grid + .bulk-grid,
#earningRows .bulk-grid {
  margin-top: 8px;
}

.bulk-grid-head {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.bulk-grid input,
.bulk-grid select {
  min-width: 0;
  width: 100%;
}

.form-grid textarea {
  min-height: 120px;
  resize: vertical;
}

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

.toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 20;
  background: #0f172a;
  color: white;
  border-radius: 8px;
  padding: 12px 14px;
  box-shadow: 0 14px 32px rgba(15, 23, 42, 0.22);
}

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

  .sidebar {
    position: sticky;
    height: auto;
    top: 0;
    z-index: 12;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 12px 14px;
  }

  .mobile-nav-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
  }

  .menu-toggle {
    display: inline-flex;
    flex: 0 0 auto;
  }

  .app-shell.menu-open .menu-toggle span:nth-child(1) {
    transform: translateY(6px) rotate(45deg);
  }

  .app-shell.menu-open .menu-toggle span:nth-child(2) {
    opacity: 0;
  }

  .app-shell.menu-open .menu-toggle span:nth-child(3) {
    transform: translateY(-6px) rotate(-45deg);
  }

  .brand {
    padding: 0;
  }

  .nav {
    display: none;
    gap: 6px;
    margin-top: 12px;
    max-height: calc(100dvh - 82px);
    overflow-y: auto;
    padding: 0 2px 4px;
  }

  .app-shell.menu-open .nav {
    display: grid;
  }

  .nav button {
    width: 100%;
    min-width: 0;
  }

  .stats-grid,
  .grid-2,
  .patient-layout,
  .detail-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
    height: auto;
    flex-direction: column;
    gap: 12px;
  }

  .search {
    max-width: none;
    width: 100%;
  }

  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table {
    min-width: 760px;
  }

  .calendar-grid {
    min-width: 850px;
  }

  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .tabs button {
    flex: 0 0 auto;
    white-space: nowrap;
  }

  .chart {
    overflow-x: auto;
  }

  .bar-pair {
    min-width: 44px;
  }

  .bulk-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfdff;
  }

  .bulk-grid-head {
    display: none;
  }

  .bulk-grid .mini {
    width: 100%;
  }

  .modal-panel.wide {
    width: min(720px, 100%);
  }
}

@media (max-width: 620px) {
  body {
    background: #f5f8fc;
  }

  .login-screen {
    align-items: start;
    padding: 18px 12px;
  }

  .login-card {
    padding: 20px;
  }

  .login-card h1 {
    font-size: 22px;
  }

  .customer-portal {
    padding: 14px 12px 28px;
  }

  .customer-head {
    gap: 12px;
    margin-bottom: 14px;
  }

  .customer-summary,
  .customer-report {
    padding: 14px;
  }

  .customer-summary h1 {
    font-size: 22px;
    overflow-wrap: anywhere;
  }

  .customer-report h2 {
    font-size: 18px;
    overflow-wrap: anywhere;
  }

  .customer-report .button {
    width: 100%;
  }

  .app-shell {
    min-height: 100dvh;
  }

  .sidebar {
    padding: 10px 10px 8px;
  }

  .brand {
    gap: 8px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

  .brand strong {
    font-size: 14px;
  }

  .brand span {
    font-size: 11px;
  }

  .nav button {
    height: 38px;
    padding: 0 10px;
    font-size: 13px;
  }

  .nav .nav-icon {
    width: 18px;
  }

  .main {
    padding: 14px 12px 28px;
  }

  .topbar {
    margin-bottom: 14px;
  }

  .search {
    height: 44px;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 42px 42px minmax(0, 1fr) auto;
    gap: 8px;
  }

  .icon-button {
    width: 42px;
    height: 42px;
  }

  .profile {
    height: 42px;
    padding: 0 10px;
  }

  .top-actions .button {
    width: auto;
    min-width: 0;
    padding: 0 12px;
  }

  .page-head {
    align-items: stretch;
    flex-direction: column;
    gap: 12px;
  }

  .page-head h1 {
    font-size: 22px;
  }

  .toolbar,
  .top-actions {
    width: 100%;
  }

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

  .bulk-panel {
    display: grid;
    grid-template-columns: 1fr;
  }

  .field,
  .select,
  .button {
    width: 100%;
  }

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

  .stat-card,
  .panel,
  .patient-card {
    padding: 14px;
  }

  .stat-card {
    min-height: 96px;
  }

  .stat-value {
    font-size: 22px;
  }

  .panel h2 {
    font-size: 15px;
  }

  th,
  td {
    padding: 11px 12px;
    font-size: 13px;
  }

  .row-actions {
    gap: 8px;
  }

  .mini {
    width: 38px;
    height: 38px;
  }

  .patient-initial {
    width: 68px;
    height: 68px;
    font-size: 28px;
  }

  .info-list div {
    align-items: flex-start;
    flex-direction: column;
    gap: 3px;
  }

  .info-list strong {
    text-align: left;
    overflow-wrap: anywhere;
  }

  .tabs {
    margin: 0 -2px 14px;
  }

  .tabs button {
    height: 38px;
    padding: 0 9px;
  }

  .detail-grid {
    gap: 10px;
  }

  .detail-item {
    padding: 10px;
  }

  .calendar-grid {
    grid-template-columns: 64px repeat(7, minmax(104px, 1fr));
    min-width: 792px;
  }

  .cal-cell,
  .cal-head,
  .time-cell {
    min-height: 62px;
    padding: 7px;
  }

  .event {
    padding: 7px;
  }

  .modal-backdrop {
    align-items: start;
    padding: 8px;
  }

  .modal-panel,
  .modal-panel.wide {
    width: 100%;
    max-height: calc(100dvh - 16px);
    padding: 16px;
  }

  .modal-head {
    position: sticky;
    top: -16px;
    z-index: 2;
    margin: -16px -16px 14px;
    padding: 14px 16px;
    background: white;
    border-bottom: 1px solid var(--line);
  }

  .modal-head h2 {
    font-size: 17px;
  }

  .form-grid {
    gap: 10px;
  }

  .form-grid input,
  .form-grid textarea,
  .form-grid select {
    min-height: 44px;
    font-size: 16px;
  }

  .bulk-grid {
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 10px;
  }

  .empty {
    padding: 20px 14px;
  }

  .toast {
    left: 12px;
    right: 12px;
    bottom: 12px;
    text-align: center;
  }
}

@media (max-width: 420px) {
  .top-actions {
    grid-template-columns: 40px 40px minmax(0, 1fr);
  }

  .top-actions .button {
    grid-column: 1 / -1;
  }

  .page-head h1 {
    font-size: 20px;
  }

  .button {
    padding: 0 12px;
  }
}
