:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef3f8;
  --text: #172033;
  --muted: #6b7280;
  --primary: #155eef;
  --primary-dark: #0b46be;
  --success: #138a5b;
  --danger: #c2413b;
  --warning: #b7791f;
  --border: #dce3ec;
  --shadow: 0 18px 45px rgba(28, 45, 75, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; text-decoration: none; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 28px;
  background: rgba(255,255,255,.92);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(14px);
}
.brand { display: flex; align-items: center; gap: 12px; font-weight: 800; }
.brand-mark {
  width: 38px; height: 38px; border-radius: 13px;
  display: grid; place-items: center; color: white;
  background: linear-gradient(145deg, #1f74ff, #0ea5a8);
  box-shadow: 0 10px 24px rgba(21,94,239,.25);
}
.brand small { display:block; color:var(--muted); font-weight:600; font-size:11px; }
.top-actions { display:flex; align-items:center; gap:10px; flex-wrap:wrap; }

.layout { display:grid; grid-template-columns: 250px 1fr; min-height: calc(100vh - 67px); }
.sidebar {
  padding: 24px 16px;
  border-right: 1px solid var(--border);
  background: #fbfcfe;
}
.nav-group { margin-bottom: 24px; }
.nav-title { padding: 0 12px 8px; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .12em; font-weight: 800; }
.nav-button {
  width: 100%; border: 0; background: transparent; text-align:left;
  padding: 11px 12px; border-radius: 12px; margin: 3px 0; color: #39445a;
}
.nav-button:hover, .nav-button.active { background: #eaf1ff; color: var(--primary); font-weight: 700; }
.main { padding: 28px; min-width: 0; }
.view { display:none; }
.view.active { display:block; animation: fade .18s ease; }
@keyframes fade { from { opacity:.2; transform:translateY(3px); } to { opacity:1; transform:none; } }

.hero {
  display:grid; grid-template-columns: 1.4fr .8fr; gap: 22px;
  padding: 30px; border-radius: 26px; color:white;
  background: radial-gradient(circle at top right, rgba(255,255,255,.22), transparent 40%), linear-gradient(135deg,#155eef,#0b8d91);
  box-shadow: var(--shadow);
}
.hero h1 { font-size: clamp(30px, 4vw, 54px); line-height:1.03; margin:0 0 14px; }
.hero p { max-width: 720px; color:rgba(255,255,255,.84); font-size:17px; }
.hero-panel { background:rgba(255,255,255,.14); border:1px solid rgba(255,255,255,.22); border-radius:20px; padding:20px; }

.grid { display:grid; gap:18px; }
.grid-2 { grid-template-columns: repeat(2,minmax(0,1fr)); }
.grid-3 { grid-template-columns: repeat(3,minmax(0,1fr)); }
.grid-4 { grid-template-columns: repeat(4,minmax(0,1fr)); }
.card {
  background: var(--surface); border:1px solid var(--border); border-radius:var(--radius);
  padding:20px; box-shadow: 0 8px 26px rgba(28,45,75,.045); min-width:0;
}
.card h2, .card h3 { margin-top:0; }
.section-head { display:flex; justify-content:space-between; align-items:center; gap:16px; margin-bottom:18px; }
.section-head h1, .section-head h2 { margin:0; }
.muted { color:var(--muted); }
.metric { font-size:30px; font-weight:850; margin-top:7px; }

.form-grid { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:14px; }
.form-grid .full { grid-column:1/-1; }
label { display:grid; gap:6px; font-size:13px; color:#4b5568; font-weight:650; }
input, textarea, select {
  width:100%; border:1px solid var(--border); background:white; color:var(--text);
  border-radius:11px; padding:11px 12px; outline:none;
}
input:focus, textarea:focus, select:focus { border-color:#78a7ff; box-shadow:0 0 0 3px rgba(21,94,239,.11); }
textarea { min-height:92px; resize:vertical; }

.btn {
  border:0; border-radius:11px; padding:10px 15px; font-weight:750;
  display:inline-flex; align-items:center; justify-content:center; gap:7px;
}
.btn-primary { color:white; background:var(--primary); }
.btn-primary:hover { background:var(--primary-dark); }
.btn-secondary { color:#334155; background:var(--surface-2); }
.btn-danger { color:white; background:var(--danger); }
.btn-success { color:white; background:var(--success); }
.btn-ghost { background:transparent; border:1px solid var(--border); }
.btn-sm { padding:7px 10px; font-size:12px; }
.actions { display:flex; gap:8px; flex-wrap:wrap; align-items:center; }

.table-wrap { overflow:auto; border:1px solid var(--border); border-radius:14px; }
table { width:100%; border-collapse:collapse; min-width:700px; background:white; }
th, td { padding:12px 14px; border-bottom:1px solid var(--border); text-align:left; vertical-align:top; font-size:13px; }
th { background:#f8fafc; color:#586174; font-size:11px; text-transform:uppercase; letter-spacing:.05em; }
tr:last-child td { border-bottom:0; }
.code { font-family: ui-monospace,SFMono-Regular,Menlo,monospace; font-size:12px; word-break:break-all; }
.badge { display:inline-flex; align-items:center; padding:4px 8px; border-radius:999px; background:#eaf1ff; color:var(--primary); font-size:11px; font-weight:800; }
.badge.success { color:var(--success); background:#e8f7f1; }
.badge.danger { color:var(--danger); background:#fdeceb; }
.badge.warning { color:var(--warning); background:#fff5dd; }

.toast-container {
  position: fixed;
  top: 86px;
  right: 18px;
  z-index: 1100;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 10px;
  width: min(380px, calc(100vw - 36px));
  max-height: calc(100vh - 104px);
  overflow-y: auto;
  pointer-events: none;
}
.toast {
  flex: 0 0 auto;
  background: #172033;
  color: white;
  padding: 14px 16px;
  border-radius: 13px;
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  pointer-events: auto;
}
.toast.error { background:#8f2f2b; }
.toast.success { background:#126846; }
.hidden { display:none !important; }
.empty { padding:28px; text-align:center; color:var(--muted); }
.status-line { padding:10px 12px; border-radius:10px; background:#f1f5f9; color:#475569; font-size:13px; }
.login-shell { min-height:100vh; display:grid; place-items:center; padding:24px; background:linear-gradient(140deg,#eff5ff,#eefaf8); }
.login-card { width:min(520px,100%); }
pre.output { max-height:360px; overflow:auto; background:#111827; color:#d1fae5; padding:14px; border-radius:12px; white-space:pre-wrap; }

@media (max-width: 1050px) {
  .layout { grid-template-columns:1fr; }
  .sidebar { position:sticky; top:67px; z-index:20; display:flex; gap:8px; overflow:auto; border-right:0; border-bottom:1px solid var(--border); padding:10px; }
  .nav-group { display:flex; margin:0; }
  .nav-title { display:none; }
  .nav-button { white-space:nowrap; width:auto; }
  .hero, .grid-3, .grid-4 { grid-template-columns:1fr 1fr; }
}
@media (max-width: 700px) {
  .topbar { padding:12px 16px; }
  .main { padding:16px; }
  .hero, .grid-2, .grid-3, .grid-4, .form-grid { grid-template-columns:1fr; }
  .form-grid .full { grid-column:auto; }
  .hero { padding:22px; }
}

/* Access-controlled sections */
[data-access].hidden,
[data-admin-only].hidden {
  display: none !important;
}

.link-button {
  appearance: none;
  border: 0;
  padding: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.link-button:hover {
  color: var(--primary, #2563eb);
  text-decoration: underline;
}

.clickable-card {
  cursor: pointer;
  transition: transform .15s ease, box-shadow .15s ease;
}

.clickable-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 35px rgba(15, 23, 42, .12);
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 24px;
}

.modal.hidden {
  display: none;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 42, .58);
  backdrop-filter: blur(3px);
}

.modal-dialog {
  position: relative;
  width: min(760px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 24px 80px rgba(15, 23, 42, .3);
}

.modal-head,
.modal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid #e5e7eb;
}

.modal-head h2 {
  margin: 0;
}

.modal-body {
  padding: 20px;
}

.modal-actions {
  justify-content: flex-end;
  border-top: 1px solid #e5e7eb;
  border-bottom: 0;
}

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

.detail-item {
  padding: 12px;
  border-radius: 12px;
  background: #f8fafc;
}

.detail-item.full {
  grid-column: 1 / -1;
}

.detail-label {
  display: block;
  margin-bottom: 4px;
  color: #64748b;
  font-size: 12px;
}

@media (max-width: 700px) {
  .detail-grid { grid-template-columns: 1fr; }
}


.appointment-group {
  margin-bottom: 14px;
  border: 1px solid #e5e7eb;
  border-radius: 16px;
  background: #fff;
  overflow: hidden;
}

.appointment-group > summary {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  cursor: pointer;
  font-weight: 700;
  list-style: none;
  user-select: none;
}

.appointment-group > summary::-webkit-details-marker {
  display: none;
}

.appointment-group > summary::after {
  content: '▾';
  margin-left: auto;
  transition: transform .18s ease;
}

.appointment-group:not([open]) > summary::after {
  transform: rotate(-90deg);
}

.appointment-group-content {
  padding: 0 14px 14px;
}

.appointment-group-content .table-wrap {
  margin: 0;
}

.role-manager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.role-manager select {
  min-width: 170px;
}


.working-hours-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 6px;
}

.working-hours-day-row {
  display: grid;
  grid-template-columns: minmax(125px, 160px) 1fr;
  gap: 12px;
  align-items: start;
}

.working-hours-day-name {
  padding-top: 6px;
  font-weight: 700;
  text-transform: none;
}

.working-hours-intervals {
  display: flex;
  flex-direction: column;
  gap: 7px;
}

.working-hours-interval-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 7px;
}

.working-hours-interval {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 6px 11px;
  border: 1px solid #dbe4f0;
  border-radius: 999px;
  background: #fff;
  font-weight: 600;
  white-space: nowrap;
}

.schedule-management-list {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid #e5e7eb;
}

@media (max-width: 700px) {
  .working-hours-day-row {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  .working-hours-day-name {
    padding-top: 0;
  }
}

/* Phone input with optional region code. The backend still receives digits only. */
.phone-input-group {
  display: grid;
  grid-template-columns: minmax(105px, auto) minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  width: 100%;
}

.phone-input-group .phone-country-select {
  min-width: 105px;
  width: 100%;
}

.phone-input-group input[name="phone"] {
  min-width: 0;
  width: 100%;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.02em;
}

@media (max-width: 560px) {
  .phone-input-group {
    grid-template-columns: 1fr;
  }
}

.doctor-user-link-panel {
  display: grid;
  gap: 16px;
}

.doctor-user-results {
  display: grid;
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
}

.doctor-user-result {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 16px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: var(--surface);
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.doctor-user-result:hover {
  border-color: var(--primary);
  background: var(--surface-2);
}

.doctor-user-result-main {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.doctor-user-result-main span,
.doctor-user-result-phone {
  color: var(--muted);
  overflow-wrap: anywhere;
}

@media (max-width: 640px) {
  .doctor-user-result {
    align-items: flex-start;
    flex-direction: column;
  }
}

.service-status-group {
  grid-column: 1 / -1;
}

.service-status-group > .appointment-group-content.grid {
  padding-top: 4px;
}


/* Doctor avatars */
.doctor-avatar { width:84px; height:84px; border-radius:50%; object-fit:cover; flex:0 0 auto; background:var(--surface-2); border:1px solid var(--border); }
.doctor-avatar-small { width:38px; height:38px; }
.doctor-avatar-large { width:128px; height:128px; }
.doctor-avatar-preview { width:96px; height:96px; }
.doctor-card-layout, .doctor-profile-head, .doctor-table-person, .avatar-picker-row { display:flex; align-items:center; gap:16px; }
.doctor-card-content { min-width:0; flex:1; }
.doctor-profile-head { margin-bottom:18px; }
.doctor-profile-head h3 { margin:0 0 4px; }
.doctor-table-person { gap:10px; }
.avatar-picker { display:grid; gap:8px; font-size:13px; color:#4b5568; font-weight:650; }
.avatar-upload-control { display:inline-flex; align-items:center; justify-content:center; width:auto; padding:10px 14px; border:1px dashed #78a7ff; border-radius:11px; color:var(--primary); background:#f5f8ff; cursor:pointer; }
.avatar-upload-control input { display:none; }
@media (max-width: 640px) { .doctor-card-layout, .doctor-profile-head { align-items:flex-start; } .doctor-avatar-large { width:96px; height:96px; } }

.doctor-card-schedule {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.5;
}

.doctor-card-schedule-icon {
  flex: 0 0 auto;
  margin-top: 1px;
  font-size: 18px;
  color: #7f8ca3;
}

.doctor-card-schedule-day strong {
  color: var(--text);
  text-transform: lowercase;
}

.doctor-card-schedule-separator {
  white-space: normal;
}

.doctor-card-arrow {
  align-self: center;
  margin-left: auto;
  padding-left: 12px;
  color: #526078;
  font-size: 42px;
  font-weight: 300;
  line-height: 1;
}

.public-doctor-card .doctor-card-layout {
  width: 100%;
}

@media (max-width: 640px) {
  .doctor-card-arrow {
    display: none;
  }

  .doctor-card-schedule {
    font-size: 14px;
  }
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  filter: saturate(0.65);
}


/* Responsive doctor catalogue: cards use all available width without cramped columns. */
#publicDoctors {
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 520px), 1fr));
  align-items: stretch;
}

.public-doctor-card {
  width: 100%;
  min-width: 0;
}

.doctor-card-schedule-content {
  display: grid;
  gap: 3px;
  min-width: 0;
}

.doctor-card-schedule-content > strong {
  display: block;
  margin-bottom: 2px;
}

.doctor-card-schedule-day {
  display: block;
  white-space: nowrap;
}

.doctor-card-schedule-separator {
  display: none;
}

.field-label-title {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  width: fit-content;
  min-width: 0;
}

.required-mark {
  display: inline;
  color: #d43f3a;
  font-weight: 800;
  line-height: 1;
  white-space: nowrap;
}

@media (max-width: 640px) {
  #publicDoctors {
    grid-template-columns: 1fr;
  }

  .public-doctor-card .doctor-card-layout {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: start;
  }

  .public-doctor-card .doctor-card-arrow {
    display: none;
  }

  .doctor-card-schedule-day {
    font-size: 13px;
  }
}


/* Изменённые пользователем поля профиля */
#profileForm .field-changed {
  border-color: #2563eb;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
  background: #f8fbff;
}

#profileForm .phone-input-group:has(input.field-changed) {
  border-radius: 12px;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.14);
}

#saveProfile:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}
