:root {
  --bg: #f5f7fa;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --border: #e5e7eb;
  --primary: #1976d2;
  --primary-dark: #1259a8;
  --green: #22c55e;
  --green-bg: #dcfce7;
  --yellow: #eab308;
  --yellow-bg: #fef9c3;
  --red: #ef4444;
  --red-bg: #fee2e2;
  --error: #b91c1c;
  --ok: #15803d;
  --shadow: 0 1px 3px rgba(0,0,0,0.08), 0 2px 8px rgba(0,0,0,0.04);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.container {
  max-width: 560px;
  margin: 0 auto;
  padding: 16px;
}
.container.admin { max-width: 760px; }

.header { text-align: center; margin-bottom: 16px; }
.header h1 { margin: 0; font-size: 1.5rem; }
.subtitle { color: var(--muted); margin: 4px 0 0; font-size: 0.95rem; }

.step {
  background: var(--card);
  border-radius: 12px;
  padding: 16px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}

.hidden { display: none !important; }

h2 { font-size: 1.15rem; margin: 0 0 12px; }
h3 { font-size: 1rem; margin: 16px 0 8px; }

/* Legend */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 12px;
  font-size: 0.85rem;
  color: var(--muted);
}
.dot {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}
.dot.green { background: var(--green); }
.dot.yellow { background: var(--yellow); }
.dot.red { background: var(--red); }

/* Calendar */
.cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}
.cal-title { font-weight: 600; font-size: 1.1rem; color: #404040; }
/* Month arrows — big, spread to the edges, like the mobile app */
.icon-btn {
  background: transparent;
  border: none;
  border-radius: 50%;
  width: 48px; height: 48px;
  font-size: 1.75rem;
  font-weight: 700;
  cursor: pointer;
  color: #404040;
  display: flex; align-items: center; justify-content: center;
}
.icon-btn:hover { background: rgba(0,0,0,0.06); }

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  font-size: 0.8rem;
  color: #919191;
  text-align: center;
  margin-bottom: 6px;
}

.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.cal-cell {
  aspect-ratio: 1 / 1;
  border: 1px solid transparent;
  border-radius: 4px;
  background: #ffffff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  font-weight: 800;
  padding: 0;
  color: #000000;
  position: relative;
  transition: transform 0.12s, box-shadow 0.12s;
}
/* current-month day with no status yet — white with thin grey border */
.cal-cell:not(.empty):not(.past):not(.s-green):not(.s-yellow):not(.s-red):not(.closed):not(.beyond) {
  border-color: #d9d9d9;
}
.cal-cell.empty { border: none; background: transparent; cursor: default; }
.cal-cell.past {
  color: #919191;
  font-weight: 400;
  background: #d9d9d9;
  border-color: transparent;
  cursor: not-allowed;
}
/* solid status fills with black digits — same as the app */
.cal-cell.s-green  { background: #34A853; border-color: transparent; color: #000; }
.cal-cell.s-yellow { background: #FBBC04; border-color: transparent; color: #000; }
.cal-cell.s-red    { background: #EA4335; border-color: transparent; color: #000; }
/* today — thick black frame */
.cal-cell.today { border: 3px solid #000; }
/* selected — floats up with a shadow + black frame */
.cal-cell.selected {
  border: 2px solid #000;
  transform: scale(1.18);
  box-shadow: 0 6px 14px rgba(0,0,0,0.35);
  z-index: 2;
}
.cal-cell.today.selected { border-width: 3px; }
.cal-cell:not([disabled]):not(.selected):hover { transform: scale(1.06); }
.cal-cell[disabled] { cursor: not-allowed; }

.slots-section {
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.slots-section h2 { margin-bottom: 12px; }

/* Slots */
.slots {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
}
.slot {
  padding: 12px 8px;
  border: 1px solid var(--primary);
  border-radius: 8px;
  background: white;
  color: var(--primary);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
.slot:hover:not(:disabled) { background: var(--primary); color: white; }
.slot.taken {
  border-color: var(--border);
  background: #f3f4f6;
  color: #9ca3af;
  cursor: not-allowed;
  text-decoration: line-through;
}

.back-btn {
  background: transparent;
  border: none;
  color: var(--primary);
  cursor: pointer;
  padding: 0 0 12px;
  font-size: 0.95rem;
}

/* Form */
form label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.9rem;
  color: var(--muted);
}
input[type="text"], input[type="tel"], input[type="password"], input[type="time"], select {
  display: block;
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--text);
  margin-top: 4px;
}
input:focus, select:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }

button.primary, button.secondary, .tg-btn {
  display: inline-block;
  width: 100%;
  padding: 14px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 8px;
  cursor: pointer;
  border: none;
  margin-top: 4px;
  text-align: center;
  text-decoration: none;
}
button.primary { background: var(--primary); color: white; }
button.primary:hover:not(:disabled) { background: var(--primary-dark); }
button.primary:disabled { opacity: 0.6; cursor: not-allowed; }
button.secondary { background: white; color: var(--primary); border: 1px solid var(--primary); }
button.secondary:hover { background: var(--bg); }
button.small { width: auto; padding: 8px 14px; font-size: 0.9rem; margin: 0; }

.selected { color: var(--muted); }
.selected strong { color: var(--text); }

.error { color: var(--error); margin-top: 8px; font-size: 0.9rem; min-height: 1.2em; }
.muted { color: var(--muted); }
.msg { margin-top: 8px; font-size: 0.9rem; min-height: 1.2em; }
.msg.ok { color: var(--ok); }
.msg.error { color: var(--error); }

/* Done */
.done { text-align: center; padding: 16px 0; }
.done-icon { font-size: 3rem; margin-bottom: 8px; }
.tg-block {
  margin: 16px 0;
  padding: 16px;
  background: #e3f2fd;
  border-radius: 8px;
}
.tg-btn { background: #0088cc; color: white; }
.tg-btn:hover { background: #006da3; }

/* Admin */
.tabs {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
  align-items: center;
}
.tab, .tab-right {
  background: transparent;
  border: none;
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.95rem;
  color: var(--muted);
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }
.tab-right { margin-left: auto; color: var(--error); }
.tab-right:hover { text-decoration: underline; }

.tab-content { margin-top: 8px; }

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

.day-title {
  margin: 16px 0 8px;
  padding: 6px 10px;
  background: var(--bg);
  border-radius: 6px;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 600;
}
.day-title:first-child { margin-top: 0; }

.booking {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  background: white;
}
.booking.confirmed { background: #f0fdf4; border-color: var(--green); }
.b-time { font-size: 1.1rem; font-weight: 700; color: var(--primary); min-width: 56px; }
.b-name { font-weight: 500; }
.b-phone { color: var(--text); text-decoration: none; font-size: 0.9rem; }
.b-phone:hover { text-decoration: underline; }
.b-car { font-size: 0.85rem; color: var(--muted); margin-top: 2px; }
.b-car strong { color: var(--text); font-weight: 600; }
.b-actions { display: flex; gap: 8px; align-items: center; }

/* Green call button — square with rounded corners, white phone icon */
.call-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  background: #22c55e;
  color: white;
  border-radius: 10px;
  text-decoration: none;
  box-shadow: 0 2px 6px rgba(34,197,94,0.4);
  transition: transform 0.1s, box-shadow 0.1s, background 0.1s;
  flex-shrink: 0;
}
.call-btn:hover, .call-btn:active {
  background: #16a34a;
  transform: scale(1.05);
  box-shadow: 0 3px 10px rgba(34,197,94,0.5);
}
.call-btn svg { display: block; width: 22px; height: 22px; fill: white; }
.c-actions { display: flex; align-items: center; }

/* Clients */
.client {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 8px;
  background: white;
}
.c-name { font-weight: 600; font-size: 1rem; }
.c-phone { color: var(--text); text-decoration: none; font-size: 0.9rem; }
.c-phone:hover { text-decoration: underline; }
.c-car { font-size: 0.85rem; color: var(--muted); margin-top: 2px; }
.c-car strong { color: var(--text); font-weight: 600; }
.c-stats {
  display: flex;
  gap: 16px;
  align-items: center;
  font-size: 0.85rem;
}
.c-stats > div { text-align: center; min-width: 60px; }
.c-num { display: block; font-weight: 700; font-size: 1.2rem; color: var(--primary); }
.c-lbl { color: var(--muted); font-size: 0.75rem; }
.c-last { color: var(--muted); font-size: 0.75rem; min-width: 110px; text-align: right; }

@media (max-width: 480px) {
  .client { grid-template-columns: 1fr; }
  .c-stats { justify-content: flex-start; flex-wrap: wrap; }
  .c-last { text-align: left; }
}

/* Row actions */
.row-actions { display: flex; gap: 8px; align-items: center; }

/* Tags extra */
.tag.dur { background: var(--muted); color: white; margin-left: 4px; }
.tag.closed { background: var(--red); color: white; }
.tag.open { background: var(--green); color: white; }

/* Checkbox row */
.checkbox-row {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  cursor: pointer;
  color: var(--text) !important;
  font-size: 0.95rem !important;
}
.checkbox-row input[type="checkbox"] {
  width: 18px; height: 18px;
  margin: 0;
}

/* Textarea */
textarea {
  display: block;
  width: 100%;
  padding: 12px;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: white;
  color: var(--text);
  margin-top: 4px;
  resize: vertical;
}
textarea:focus { outline: 2px solid var(--primary); outline-offset: -1px; border-color: var(--primary); }

/* Schedule editor */
.schedule {
  background: var(--bg);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
}
.sched-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
}
.sched-row .checkbox-row { margin: 0; min-width: 140px; }
.sched-day { font-size: 0.9rem; }
.sched-sep { color: var(--muted); }
.sched-row input[type="time"] { padding: 6px 8px; font-size: 0.9rem; margin: 0; width: auto; }
.sched-row input[type="time"]:disabled { opacity: 0.4; background: #fafafa; }

/* Overrides */
.overrides {
  background: var(--bg);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 12px;
  min-height: 40px;
}
.override-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.override-row:last-child { border-bottom: none; }
.ov-date { font-weight: 600; min-width: 100px; }

/* "Add override" inline form */
#tab-settings .row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
#tab-settings .row input[type="date"],
#tab-settings .row input[type="time"],
#tab-settings .row select { margin: 0; padding: 8px; font-size: 0.9rem; width: auto; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.5);
}
.modal-body {
  position: relative;
  background: white;
  border-radius: 12px;
  max-width: 500px;
  width: calc(100% - 32px);
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 24px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.25);
}
.modal-close {
  position: absolute;
  top: 12px; right: 12px;
  background: transparent;
  border: none;
  font-size: 1.3rem;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
}
.modal-close:hover { color: var(--text); }
.modal-body h2 { margin-top: 0; }
.modal-body input[disabled] { opacity: 0.6; background: #fafafa; }

/* Phone autocomplete dropdown */
.suggest {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 4px;
  max-height: 200px;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.sug-item {
  padding: 10px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}
.sug-item:last-child { border-bottom: none; }
.sug-item:hover { background: var(--bg); }

/* Required asterisk in form labels */
.req { color: var(--error); font-weight: 700; }

/* Info box (admin settings) */
.info-box {
  background: #dcfce7;
  border: 1px solid var(--green);
  border-radius: 8px;
  padding: 12px 16px;
  margin: 12px 0;
  color: #14532d;
  font-size: 0.9rem;
  line-height: 1.5;
}
.info-box a { color: var(--primary); font-weight: 600; }
details summary {
  cursor: pointer;
  padding: 8px 0;
  font-weight: 600;
  color: var(--primary);
  user-select: none;
}
details summary:hover { text-decoration: underline; }
details[open] summary { margin-bottom: 8px; }

/* Form editor (admin "Форма" tab) */
.fields-editor { margin-bottom: 16px; }
.field-row {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: 12px;
  padding: 12px;
  background: var(--bg);
  border-radius: 8px;
  margin-bottom: 8px;
  border: 1px solid var(--border);
}
.field-move { display: flex; flex-direction: column; gap: 2px; align-items: center; }
.field-move .link { padding: 2px 6px; line-height: 1; color: var(--muted); }
.field-move .link:hover { color: var(--primary); }
.link-empty { color: transparent; padding: 2px 6px; }
.field-main { min-width: 0; }
.field-label-inp {
  display: block;
  width: 100%;
  padding: 6px 8px;
  font-size: 0.95rem;
  font-weight: 600;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: white;
  margin: 0 0 6px;
}
.field-label-inp[readonly] { background: #f3f4f6; cursor: default; }
.field-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  font-size: 0.8rem;
}
.inline-cb {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin: 0;
  cursor: pointer;
  color: var(--text) !important;
  font-size: 0.8rem !important;
}
.inline-cb input[type="checkbox"] { width: 14px; height: 14px; margin: 0; }
.tag.type { background: #e0e7ff; color: #3730a3; }
.tag.locked { background: #fef3c7; color: #92400e; }
.field-opts { margin-top: 4px; }

.grid-add-field {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 8px;
  margin: 8px 0;
}
.grid-add-field input,
.grid-add-field select { margin: 0; padding: 8px; font-size: 0.9rem; width: auto; }
#new-field-options { width: 100%; padding: 8px; margin: 0 0 12px; font-size: 0.9rem; }

@media (max-width: 480px) {
  .grid-add-field { grid-template-columns: 1fr; }
  .field-meta { font-size: 0.75rem; }
}

/* Notification banner + flash (admin) */
.alert-banner {
  position: fixed;
  top: 0; left: 0; right: 0;
  z-index: 2000;
  background: #ef4444;
  color: white;
  padding: 16px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-weight: 600;
  font-size: 1rem;
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  animation: alert-slide-in 0.3s ease-out;
}
@keyframes alert-slide-in {
  from { transform: translateY(-100%); }
  to { transform: translateY(0); }
}
.alert-text { flex: 1; }
.alert-dismiss {
  background: white;
  color: #ef4444;
  border: none;
  padding: 8px 18px;
  border-radius: 6px;
  font-weight: 700;
  cursor: pointer;
  font-size: 0.95rem;
}
.alert-dismiss:hover { background: #fee2e2; }

/* Body bg flash (pulses while banner is up) */
body.alert-flash {
  animation: bg-pulse 1s ease-in-out infinite;
}
@keyframes bg-pulse {
  0%, 100% { background: var(--bg); }
  50% { background: #fee2e2; }
}

/* Pause banner (client side) */
.pause-banner {
  background: #fef3c7;
  border: 1px solid #f59e0b;
  border-radius: 12px;
  padding: 24px;
  text-align: center;
  margin: 16px;
}
.pause-banner h2 { margin: 0 0 8px; color: #92400e; }
.pause-banner p { margin: 0; color: #78350f; white-space: pre-wrap; }

/* Beyond max_booking_days cells */
.cal-cell.beyond,
.cal-cell.closed {
  background: #ffffff;
  color: #c4c4c4;
  font-weight: 400;
  cursor: not-allowed;
  border-color: #d9d9d9;
}

.tag {
  display: inline-block;
  padding: 2px 6px;
  font-size: 0.7rem;
  border-radius: 4px;
  margin-left: 4px;
  vertical-align: middle;
  font-weight: 600;
}
.tag.tg { background: #0088cc; color: white; }
.tag.ok { background: var(--green); color: white; }

.link {
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 1.1rem;
  padding: 4px 8px;
}
.link.danger:hover { color: var(--error); }

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

/* Avatar editor (admin settings) */
.avatar-editor {
  display: flex;
  align-items: center;
  gap: 14px;
  margin: 12px 0;
}
.avatar-preview {
  width: 72px; height: 72px;
  border-radius: 50%;
  object-fit: cover;
  background: #e5e7eb;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.avatar-preview.empty { background: #e5e7eb url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="40" height="40" viewBox="0 0 24 24" fill="none" stroke="%239ca3af" stroke-width="1.5"><circle cx="12" cy="8" r="4"/><path d="M4 20c0-4 4-6 8-6s8 2 8 6"/></svg>') center/40px no-repeat; }
.avatar-controls { display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }

/* Address line on client page */
.biz-address {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-top: 6px;
  color: var(--primary);
  text-decoration: none;
  font-size: 0.95rem;
}
.biz-address:hover { text-decoration: underline; }
.biz-avatar {
  width: 84px; height: 84px;
  border-radius: 50%;
  object-fit: cover;
  margin: 0 auto 8px;
  display: block;
  border: 2px solid var(--card);
  box-shadow: var(--shadow);
}

@media (max-width: 480px) {
  .grid-2 { grid-template-columns: 1fr; }
  .cal-cell { font-size: 1rem; }
  .booking { grid-template-columns: auto 1fr; }
  .b-actions { grid-column: 1 / -1; justify-content: flex-end; }
}
