:root {
  color-scheme: light;
  --bg: #f4f5f9;
  --sidebar: #eceef6;
  --ink: #282747;
  --muted: #8a8da5;
  --line: #e3e5ec;
  --accent: #1f6f8b;
  --accent-strong: #185b72;
  --accent-soft: #e8f5f8;
  --accent-line: #b8dce4;
  --danger: #b42318;
  --white: #ffffff;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Arial, Helvetica, sans-serif;
}

button,
input,
select {
  font: inherit;
}

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

.login-card {
  width: min(420px, 100%);
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 32px;
  box-shadow: 0 18px 45px rgba(31, 35, 55, 0.09);
}

.brand-kicker,
.eyebrow {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.brand h1,
.topbar h1 {
  margin: 8px 0 0;
}

.login-form {
  display: grid;
  gap: 18px;
  margin-top: 28px;
}

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

.login-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 13px 14px;
  outline: none;
}

.login-form input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(55, 49, 88, 0.12);
}

.login-form button,
.ghost-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.login-form button {
  background: var(--accent);
  color: var(--white);
  font-weight: 700;
  padding: 13px 16px;
}

.alert {
  margin-top: 18px;
  border-radius: 8px;
  padding: 12px 14px;
  font-size: 14px;
}

.alert-error {
  background: #fff1f0;
  color: var(--danger);
}

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

.sidebar {
  background: var(--sidebar);
  border-right: 1px solid var(--line);
  padding: 24px 8px;
}

.sidebar-logo {
  height: 56px;
  padding: 0 16px;
  color: var(--accent);
  font-size: 28px;
  line-height: 1;
}

.logo-small {
  display: block;
  color: #139b8f;
  font-size: 13px;
  font-weight: 700;
}

.sidebar-nav {
  display: grid;
  gap: 22px;
  margin-top: 42px;
}

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

.nav-group-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  padding: 0 14px;
  text-transform: uppercase;
}

.nav-item {
  display: block;
  color: var(--muted);
  text-decoration: none;
  border-radius: 8px;
  padding: 16px 14px;
  font-weight: 700;
}

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
  box-shadow: inset 4px 0 0 var(--accent);
}

.nav-item.disabled {
  cursor: default;
  opacity: 0.65;
}

.workspace {
  min-width: 0;
}

.topbar {
  min-height: 88px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  background: var(--white);
  border-bottom: 1px solid var(--line);
  padding: 18px 26px;
}

.topbar h1,
.panel h2,
.table-header h2 {
  color: var(--ink);
}

.eyebrow {
  margin: 0;
}

.ghost-button {
  background: var(--accent-soft);
  color: var(--accent);
  padding: 10px 14px;
  font-weight: 700;
}

.content {
  padding: 28px 26px;
}

.panel,
.table-panel {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel {
  padding: 24px;
}

.panel h2,
.table-header h2 {
  margin: 0;
}

.panel p {
  margin: 10px 0 0;
  color: var(--muted);
}

.table-panel {
  margin-top: 24px;
  overflow: hidden;
}

.table-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 18px;
  border-bottom: 1px solid var(--line);
}

.table-header span,
.table-row span:nth-child(2),
.table-row span:nth-child(3) {
  color: var(--muted);
}

.placeholder-table {
  display: grid;
}

.table-row {
  display: grid;
  grid-template-columns: 1fr 160px 1.5fr;
  gap: 18px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.table-row:last-child {
  border-bottom: 0;
}

.table-head {
  background: #fafafa;
  font-weight: 700;
}

.toolbar-panel,
.patients-panel {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.toolbar-panel {
  padding: 18px;
}

.filters-form {
  display: grid;
  grid-template-columns: minmax(220px, 1.3fr) minmax(180px, 0.8fr) minmax(120px, 0.5fr) 108px auto;
  gap: 14px;
  align-items: end;
}

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

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

.filters-form input:focus,
.filters-form select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(55, 49, 88, 0.12);
}

.filter-actions,
.patients-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.primary-button,
.secondary-button {
  border-radius: 8px;
  cursor: pointer;
  font-weight: 700;
  padding: 11px 15px;
  text-decoration: none;
}

.primary-button {
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--white);
}

.secondary-button {
  border: 1px solid var(--accent-line);
  background: var(--white);
  color: var(--accent-strong);
}

.patients-panel {
  margin-top: 18px;
  overflow: hidden;
}

.patients-actions {
  min-height: 64px;
  padding: 14px 18px;
}

.patients-actions span {
  color: var(--muted);
  font-weight: 700;
  margin-left: auto;
}

.patients-table-wrap {
  overflow-x: auto;
}

.patients-table {
  width: 100%;
  min-width: 1420px;
  border-collapse: collapse;
  font-size: 14px;
}

.patients-table th {
  background: #f3f7f9;
  color: #687681;
  font-size: 13px;
  text-align: left;
  position: sticky;
  top: 0;
  z-index: 1;
}

.patients-table th,
.patients-table td {
  border-bottom: 1px solid var(--line);
  padding: 14px 10px;
  vertical-align: middle;
}

.patients-table td {
  color: #3f4553;
}

.patients-table tbody tr:hover {
  background: #f8fbfc;
}

.patients-table a {
  color: var(--accent-strong);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.patients-table .num {
  text-align: right;
  white-space: nowrap;
}

.patients-table .technical-id {
  color: var(--muted);
  font-family: Consolas, "Courier New", monospace;
  font-size: 13px;
  white-space: nowrap;
}

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

.empty-state {
  color: var(--muted);
  text-align: center;
}

.doctor-summary-table {
  min-width: 1080px;
}

.doctor-matrix-table {
  min-width: 1380px;
}

.outcome-cell {
  display: grid;
  gap: 3px;
  min-width: 92px;
}

.outcome-cell strong {
  color: var(--ink);
  font-size: 16px;
}

.outcome-cell span,
.outcome-cell small {
  color: var(--muted);
  font-size: 12px;
}

.stats-filter-panel {
  display: flex;
  gap: 18px;
  align-items: center;
  justify-content: space-between;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
}

.quick-periods,
.date-range-form {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.period-button {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  border: 1px solid var(--accent-line);
  border-radius: 8px;
  background: var(--white);
  color: var(--accent-strong);
  font-weight: 700;
  padding: 9px 14px;
  text-decoration: none;
}

.period-button.active {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--white);
}

.period-button.muted-button {
  color: var(--muted);
  cursor: default;
  opacity: 0.8;
}

.date-range-form input {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 9px 12px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.doctor-kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 18px;
  margin-top: 18px;
}

.stat-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  box-shadow: 0 14px 32px rgba(31, 35, 55, 0.06);
}

.stat-card span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
}

.stat-card strong {
  display: block;
  color: var(--ink);
  font-size: 42px;
  line-height: 1;
  margin-top: 12px;
}

.stat-card .money-strong {
  font-size: 28px;
}

.stat-card p {
  color: var(--muted);
  margin: 8px 0 0;
}

.stat-detail-link {
  color: var(--accent-strong);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.stat-divider {
  height: 1px;
  background: var(--line);
  margin: 20px 0;
}

.stat-card dl {
  display: grid;
  gap: 14px;
  margin: 0;
}

.stat-card dl div {
  display: flex;
  gap: 16px;
  align-items: baseline;
  justify-content: space-between;
}

.stat-card dt {
  color: var(--muted);
  font-size: 14px;
}

.stat-card dd {
  color: var(--ink);
  font-size: 18px;
  font-weight: 700;
  margin: 0;
}

.stat-card .muted-metric dt,
.stat-card .muted-metric dd {
  color: var(--muted);
  font-size: 13px;
}

.total-card {
  border-color: var(--accent-line);
}

.discount-card {
  border-color: #d8e5ee;
}

.sync-form {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: end;
}

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

.sync-form input {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  padding: 9px 12px;
}

.sync-result {
  margin-top: 18px;
}

.sync-result pre {
  max-height: 360px;
  overflow: auto;
  background: #f6f8fb;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: #334155;
  padding: 14px;
  white-space: pre-wrap;
}

.sync-ok {
  border-color: var(--accent-line);
}

.sync-error {
  border-color: #f1b7b0;
}

.details-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 16px 18px;
}

.details-period,
.details-count {
  color: var(--muted);
  font-weight: 700;
}

.stat-patients-list {
  display: grid;
  gap: 14px;
  margin-top: 18px;
}

.stat-patient-card {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.stat-patient-header {
  display: flex;
  gap: 18px;
  align-items: flex-start;
  justify-content: space-between;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.stat-patient-header h2 {
  margin: 0;
  color: var(--ink);
  font-size: 20px;
}

.stat-patient-header p {
  margin: 6px 0 0;
  color: var(--muted);
}

.patient-sales {
  min-width: 180px;
  text-align: right;
}

.patient-sales span {
  display: block;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.patient-sales strong {
  display: block;
  color: var(--ink);
  font-size: 22px;
  margin-top: 6px;
}

.patient-sales small {
  display: block;
  color: var(--muted);
  margin-top: 5px;
}

.visit-list {
  display: grid;
}

.visit-line {
  display: flex;
  gap: 18px;
  align-items: center;
  justify-content: space-between;
  padding: 13px 18px;
  border-bottom: 1px solid var(--line);
}

.visit-line:last-child {
  border-bottom: 0;
}

.visit-line strong {
  color: var(--ink);
}

.visit-line span {
  color: var(--muted);
  margin-left: 8px;
}

.visit-sums {
  display: grid;
  gap: 4px;
  min-width: 180px;
  text-align: right;
}

.visit-sums span {
  color: var(--ink);
  font-weight: 700;
}

.visit-sums small {
  color: var(--muted);
}

.empty-details {
  padding: 24px;
  color: var(--muted);
}

.pagination {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  justify-content: flex-end;
  padding: 14px 18px;
  border-top: 1px solid var(--line);
}

.page-link,
.page-gap {
  min-width: 36px;
  border-radius: 8px;
  padding: 8px 11px;
  text-align: center;
}

.page-link {
  border: 1px solid var(--line);
  color: var(--accent-strong);
  font-weight: 700;
  text-decoration: none;
}

.page-link.active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-strong);
}

.page-link.disabled {
  color: var(--muted);
  pointer-events: none;
  opacity: 0.55;
}

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

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

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

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

  .topbar,
  .table-header {
    align-items: flex-start;
    flex-direction: column;
  }

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

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

  .stats-filter-panel,
  .stats-grid,
  .doctor-kpi-grid {
    grid-template-columns: 1fr;
  }

  .stats-filter-panel,
  .date-range-form {
    align-items: stretch;
    flex-direction: column;
  }

  .filter-actions,
  .patients-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .details-toolbar,
  .stat-patient-header,
  .visit-line {
    align-items: stretch;
    flex-direction: column;
  }

  .patient-sales,
  .visit-sums {
    min-width: 0;
    text-align: left;
  }

  .patients-actions span {
    margin-left: 0;
  }
}
