:root {
  color-scheme: light;
  font-family: Arial, Helvetica, sans-serif;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #eef2f6;
  --text: #17202a;
  --muted: #617083;
  --line: #d9e0e7;
  --primary: #1769e0;
  --primary-dark: #1155b4;
  --doctor-1: #8b5cf6;
  --doctor-1-soft: #f3ecff;
  --doctor-1-card: #fbf8ff;
  --doctor-1-border: #eadcff;
  --doctor-2: #14b8a6;
  --doctor-2-soft: #e9fbf7;
  --doctor-2-card: #f4fdfb;
  --doctor-2-border: #cdf4ed;
  --danger: #b42318;
  --warning: #8a5a00;
  --ok: #16794f;
  --radius: 8px;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

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

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 18px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 13px;
}

.panel-subtitle {
  margin: -8px 0 12px;
  color: var(--muted);
  font-size: 13px;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 24px;
}

h2 {
  margin-bottom: 14px;
  font-size: 18px;
}

h3 {
  margin-bottom: 4px;
  font-size: 16px;
}

.topbar-actions,
.dialog-actions,
.dialog-actions-right,
.toolbar,
.segmented,
.view-switch,
.card-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.api-status {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}

.api-status.connected {
  color: var(--ok);
}

body .technical-action,
body.local-mode .technical-action[data-local-only] {
  display: none !important;
}

body.api-enabled .technical-action:not([data-local-only]) {
  display: inline-flex !important;
}

body.auth-required:not(.authenticated) #newAppointmentBtn,
body.auth-required:not(.authenticated) #settingsBtn,
body.auth-required:not(.authenticated) .layout {
  display: none !important;
}

body.official-app .demo-only,
body:not(.official-app) .official-settings {
  display: none !important;
}

.layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 18px;
  padding: 18px;
}

.sidebar,
.content {
  min-width: 0;
}

.panel,
.content {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
  margin-bottom: 14px;
}

.btn.full {
  width: 100%;
}

.content {
  padding: 18px;
  background: #ffffff;
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.stats div {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-2);
}

.stats span {
  display: block;
  font-size: 24px;
  font-weight: 700;
}

.stats small,
.meta,
.notes,
#agendaSubtitle {
  color: var(--muted);
}

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

.work-card {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px;
  text-align: left;
}

.work-card:hover {
  border-color: #b8c7d9;
  background: #f8fafc;
}

.work-card span {
  display: grid;
  gap: 2px;
}

.work-card strong {
  font-size: 14px;
}

.work-card small {
  color: var(--muted);
  font-size: 12px;
}

.work-card b {
  min-width: 30px;
  border-radius: 999px;
  background: var(--surface-2);
  color: #223044;
  font-size: 14px;
  padding: 5px 8px;
  text-align: center;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
}

.doctor-key {
  display: grid;
  gap: 8px;
  margin-bottom: 14px;
  color: #344256;
  font-size: 14px;
}

.doctor-key.compact-key {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  margin: 2px 0 14px;
  padding: 9px 10px;
}

.agenda-tabs {
  display: grid;
  gap: 7px;
}

.agenda-tab {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: #344256;
  cursor: pointer;
  font-weight: 700;
  padding: 9px 10px;
  text-align: left;
}

.agenda-tab:hover {
  border-color: #b8c7d9;
  background: #f8fafc;
}

.agenda-tab.active {
  border-color: var(--primary);
  background: #edf5ff;
  color: var(--primary-dark);
  box-shadow: inset 0 0 0 1px rgba(23, 105, 224, 0.2);
}

.agenda-tab.doctor-1.active {
  border-color: var(--doctor-1);
  background: var(--doctor-1-soft);
  color: #4c1d95;
  box-shadow: inset 0 0 0 1px rgba(139, 92, 246, 0.22);
}

.agenda-tab.doctor-2.active {
  border-color: var(--doctor-2);
  background: var(--doctor-2-soft);
  color: #0f766e;
  box-shadow: inset 0 0 0 1px rgba(20, 184, 166, 0.22);
}

.doctor-key span {
  display: flex;
  align-items: center;
  gap: 8px;
}

.key-dot {
  width: 15px;
  height: 15px;
  border-radius: 50%;
  flex: 0 0 15px;
  display: inline-block;
}

.key-dot.doctor-1 {
  background: var(--doctor-1);
}

.key-dot.doctor-2 {
  background: var(--doctor-2);
}

.field span {
  color: #3d4a5c;
  font-size: 13px;
  font-weight: 700;
}

.panel-section-title {
  border-top: 1px solid var(--line);
  color: #344256;
  font-size: 14px;
  margin: 14px 0 10px;
  padding-top: 14px;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  padding: 10px 11px;
}

textarea {
  resize: vertical;
}

.search {
  margin-bottom: 10px;
}

#newPatientBtn {
  margin-bottom: 10px;
}

.btn {
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  text-align: center;
}

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

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

.btn.secondary {
  background: #fff;
  border-color: var(--line);
  color: var(--text);
}

.btn.danger {
  background: #fff;
  border-color: #f0b8b3;
  color: var(--danger);
}

.btn.small {
  padding: 7px 9px;
  font-size: 13px;
}

.file-btn {
  display: inline-block;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.toolbar {
  justify-content: space-between;
  margin-bottom: 16px;
}

.segmented {
  gap: 0;
}

.segmented button,
.view-switch button {
  border: 1px solid var(--line);
  background: #fff;
  padding: 9px 12px;
  cursor: pointer;
}

.segmented button:first-child,
.view-switch button:first-child {
  border-radius: 6px 0 0 6px;
}

.segmented button:last-child,
.view-switch button:last-child {
  border-radius: 0 6px 6px 0;
}

.view-switch {
  gap: 0;
}

.view-switch button.active {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
}

.appointments-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 12px;
}

.appointments-grid.week-view {
  display: grid;
  grid-template-columns: repeat(5, minmax(210px, 1fr));
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 2px;
}

.week-summary-column {
  min-width: 210px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  overflow: hidden;
}

.week-summary-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
}

.week-summary-header div {
  display: grid;
  gap: 2px;
  min-width: 0;
}

.week-summary-header strong {
  font-size: 13px;
  line-height: 1.2;
}

.week-summary-header span {
  color: var(--muted);
  font-size: 12px;
}

.week-summary-body {
  display: grid;
  gap: 7px;
  padding: 8px;
}

.week-open-day {
  width: calc(100% - 16px);
  margin: 0 8px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--primary-dark);
  cursor: pointer;
  font-size: 12px;
  font-weight: 700;
  padding: 8px;
}

.week-appointment {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  width: 100%;
  border: 1px solid var(--line);
  border-left: 4px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  padding: 7px;
  text-align: left;
  min-height: 62px;
}

.week-appointment:hover {
  box-shadow: 0 6px 14px rgba(15, 23, 42, 0.1);
}

.week-appointment.doctor-1 {
  background: var(--doctor-1-card);
  border-color: var(--doctor-1-border);
}

.week-appointment.doctor-2 {
  background: var(--doctor-2-card);
  border-color: var(--doctor-2-border);
}

.week-appointment.status-confirmed {
  border-left-color: var(--ok);
}

.week-appointment.status-pending {
  border-left-color: var(--primary);
}

.week-appointment.status-change {
  border-left-color: var(--warning);
}

.week-appointment.status-no_response {
  border-left-color: #64748b;
}

.week-appointment.status-cancelled {
  border-left-color: var(--danger);
  opacity: 0.78;
}

.week-time {
  align-self: stretch;
  display: grid;
  align-content: center;
  border-radius: 6px;
  background: var(--surface-2);
  color: var(--text);
  font-size: 12px;
  font-weight: 700;
  padding: 6px 5px;
  text-align: center;
}

.week-time small {
  display: block;
  margin-top: 2px;
  font-size: 10px;
  font-weight: 700;
}

.week-copy {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.week-copy strong,
.week-copy small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.week-copy strong {
  font-size: 13px;
  line-height: 1.2;
}

.week-copy small {
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
}

.week-open-day:hover {
  border-color: var(--primary);
  color: var(--primary-dark);
}

.day-column {
  min-height: 180px;
  border: 1px solid #d8e0e8;
  border-radius: var(--radius);
  background: #ffffff;
  overflow: hidden;
}

.doctor-column.doctor-1 {
  border-top: 4px solid var(--doctor-1);
}

.doctor-column.doctor-2 {
  border-top: 4px solid var(--doctor-2);
}

.doctor-column.doctor-1 .day-column-header {
  background: var(--doctor-1-soft);
}

.doctor-column.doctor-2 .day-column-header {
  background: var(--doctor-2-soft);
}

.day-column-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  background: #f8fafc;
  border-bottom: 1px solid var(--line);
}

.column-header-main {
  display: grid;
  gap: 2px;
  min-width: 0;
}

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

.day-column-header strong {
  font-size: 15px;
}

.column-add-btn {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: #223044;
  cursor: pointer;
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
  padding: 6px 8px;
}

.column-add-btn:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.day-column-body {
  display: grid;
  gap: 7px;
  padding: 10px;
}

.empty {
  padding: 16px;
  color: var(--muted);
  text-align: center;
}

.empty.compact {
  padding: 10px;
}

.appointment-card {
  border: 1px solid var(--line);
  border-left: 5px solid #cbd5e1;
  border-radius: 6px;
  background: #fff;
  display: grid;
  grid-template-rows: auto minmax(18px, auto) minmax(20px, auto) auto;
  min-height: 158px;
  padding: 8px 9px;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}

.appointment-card:hover {
  box-shadow: 0 8px 18px rgba(15, 23, 42, 0.1);
  transform: translateY(-1px);
}

.appointment-card.status-confirmed {
  border-left-color: var(--ok);
}

.appointment-card.status-pending {
  border-left-color: var(--primary);
}

.appointment-card.status-change {
  border-left-color: var(--warning);
}

.appointment-card.status-no_response {
  border-left-color: #64748b;
}

.appointment-card.status-cancelled {
  border-left-color: var(--danger);
  opacity: 0.78;
}

.appointment-card.doctor-1 {
  background: var(--doctor-1-card);
  border-color: var(--doctor-1-border);
}

.appointment-card.doctor-2 {
  background: var(--doctor-2-card);
  border-color: var(--doctor-2-border);
}

.appointment-card.doctor-1.status-confirmed,
.week-appointment.doctor-1.status-confirmed,
.appointment-card.doctor-2.status-confirmed,
.week-appointment.doctor-2.status-confirmed {
  border-left-color: var(--ok);
}

.appointment-card.doctor-1.status-pending,
.week-appointment.doctor-1.status-pending,
.appointment-card.doctor-2.status-pending,
.week-appointment.doctor-2.status-pending {
  border-left-color: var(--primary);
}

.appointment-card.doctor-1.status-change,
.week-appointment.doctor-1.status-change,
.appointment-card.doctor-2.status-change,
.week-appointment.doctor-2.status-change {
  border-left-color: var(--warning);
}

.appointment-card.doctor-1.status-no_response,
.week-appointment.doctor-1.status-no_response,
.appointment-card.doctor-2.status-no_response,
.week-appointment.doctor-2.status-no_response {
  border-left-color: #64748b;
}

.appointment-card.doctor-1.status-cancelled,
.week-appointment.doctor-1.status-cancelled,
.appointment-card.doctor-2.status-cancelled,
.week-appointment.doctor-2.status-cancelled {
  border-left-color: var(--danger);
}

.appointment-main {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  gap: 8px;
}

.time {
  align-self: start;
  min-height: 46px;
  padding: 7px 6px;
  border-radius: 6px;
  background: var(--surface-2);
  font-weight: 700;
  font-size: 13px;
  text-align: center;
}

.time small {
  display: block;
  margin-top: 2px;
  color: inherit;
  font-size: 10px;
  font-weight: 700;
}

.appointment-card.doctor-1 .time {
  background: var(--surface-2);
  color: var(--text);
}

.appointment-card.doctor-2 .time {
  background: var(--surface-2);
  color: var(--text);
}

.appointment-card h3 {
  margin-bottom: 2px;
  font-size: 14px;
}

.appointment-card .meta {
  display: flex;
  align-items: center;
  flex-wrap: nowrap;
  gap: 5px;
  font-size: 12px;
  min-width: 0;
  overflow: hidden;
}

.appointment-card .meta span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.appointment-card .meta span:first-child {
  max-width: 120px;
}

.appointment-card .meta span:nth-child(2) {
  max-width: 80px;
}

.appointment-card .meta span:nth-child(3) {
  max-width: 96px;
}

.notes {
  margin: 7px 0 2px 64px;
  min-width: 0;
  overflow: hidden;
  font-size: 12px;
  line-height: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.next-action {
  margin: 0 0 7px 64px;
  overflow: hidden;
  color: #344256;
  font-size: 12px;
  font-weight: 700;
  line-height: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-pill {
  border-radius: 999px;
  color: #fff;
  display: inline-flex;
  flex: 0 0 auto;
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  justify-self: start;
  min-width: 76px;
  padding: 5px 8px;
  white-space: nowrap;
  justify-content: center;
}

.status-pill.status-pending {
  background: var(--primary);
}

.status-pill.status-confirmed {
  background: var(--ok);
}

.status-pill.status-change {
  background: var(--warning);
  min-width: 92px;
}

.status-pill.status-no_response {
  background: #64748b;
  min-width: 98px;
}

.status-pill.status-cancelled {
  background: var(--danger);
}

.appointment-card .card-actions {
  align-self: end;
  justify-content: flex-end;
}

.appointment-card .status-select {
  max-width: 132px;
  padding: 6px 8px;
  font-size: 12px;
}

.patient-list {
  display: grid;
  gap: 8px;
  max-height: 360px;
  overflow: auto;
}

.patient-item {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 10px;
  cursor: pointer;
}

.patient-item strong {
  display: block;
  margin-bottom: 4px;
}

.patient-item small {
  color: var(--muted);
}

.patient-matches {
  display: grid;
  gap: 6px;
  margin-top: 8px;
}

.patient-matches button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 9px 10px;
  text-align: left;
  cursor: pointer;
}

.patient-matches small {
  color: var(--muted);
  white-space: nowrap;
}

.dialog {
  width: min(760px, calc(100vw - 28px));
  border: 0;
  border-radius: var(--radius);
  box-shadow: 0 24px 72px rgba(15, 23, 42, 0.24);
  padding: 0;
}

.dialog.small-dialog {
  width: min(440px, calc(100vw - 28px));
}

.dialog::backdrop {
  background: rgba(15, 23, 42, 0.42);
}

.dialog form,
.dialog-body {
  padding: 18px;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

.dialog-subtitle {
  margin: 4px 0 0;
  color: var(--muted);
}

.form-error {
  margin: 4px 0 0;
  color: var(--danger);
  font-size: 13px;
  font-weight: 700;
}

.settings-help {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #f8fafc;
  color: var(--muted);
  font-size: 13px;
  padding: 10px 12px;
}

.form-error.success {
  color: var(--ok);
}

#bulkImportData {
  width: 100%;
  min-height: 150px;
  resize: vertical;
}

.settings-section {
  margin: 4px 0 14px;
}

.settings-section h3 {
  margin-bottom: 4px;
}

.duration-settings {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.duration-setting {
  display: grid;
  grid-template-columns: 1fr 110px;
  align-items: center;
  gap: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  padding: 9px 10px;
}

.duration-setting span {
  color: #344256;
  font-size: 13px;
  font-weight: 700;
}

.duration-setting select {
  padding: 7px 8px;
}

.icon-btn {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  cursor: pointer;
}

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

.dialog-actions {
  justify-content: space-between;
  margin-top: 18px;
}

.patient-appointments {
  display: grid;
  gap: 16px;
}

.patient-appointment-group h3 {
  margin: 0 0 8px;
  color: #344256;
  font-size: 15px;
}

.patient-appointment {
  display: grid;
  gap: 4px;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  padding: 11px;
  text-align: left;
}

.patient-appointment span {
  color: var(--muted);
}

.patient-appointment small {
  color: var(--muted);
}

@media (max-width: 900px) {
  .topbar,
  .toolbar,
  .dialog-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .layout {
    display: flex;
    flex-direction: column;
    grid-template-columns: 1fr;
  }

  .content {
    order: -1;
  }

  .sidebar {
    order: 2;
  }

  .topbar-actions,
  .dialog-actions-right {
    flex-wrap: wrap;
  }
}

@media (max-width: 560px) {
  .layout {
    padding: 10px;
  }

  .topbar {
    padding: 14px;
  }

  .form-grid,
  .appointments-grid,
  .duration-settings {
    grid-template-columns: 1fr;
  }

  .duration-setting {
    grid-template-columns: 1fr;
  }

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