/* components.css — buttons, cards, tables, modals, toasts */

/* ---- Buttons ---- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1px;
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--text-primary);
  border: 1px solid var(--border);
  transition: background 0.18s ease, color 0.18s ease, transform 0.10s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  white-space: nowrap;
  user-select: none;
  position: relative;
}

.btn:hover {
  background: var(--bg-soft);
  border-color: var(--border-strong);
  transform: translateY(-1px);
  box-shadow: var(--shadow-sm);
}
.btn:active { transform: translateY(0); }

.btn:focus-visible {
  outline: 2px solid var(--accent-soft);
  outline-offset: 2px;
}

.btn-primary {
  background: var(--accent-strong);
  color: var(--accent-ink);
  border-color: transparent;
}
.btn-primary:hover {
  background: var(--accent);
  color: var(--accent-ink);
  box-shadow: 0 6px 18px rgba(180,150,50,0.35);
}

.btn-danger {
  background: var(--danger);
  color: #fff;
  border-color: transparent;
}
.btn-danger:hover {
  background: #991B1B;
  box-shadow: 0 6px 18px rgba(185,28,28,0.3);
}

.btn-ghost {
  background: transparent;
  border-color: transparent;
}
.btn-ghost:hover {
  background: var(--bg-soft);
  border-color: var(--border);
}

.btn-icon {
  /* 44px is the minimum comfortable tap target on a phone; a 36px square
     icon button is a miss-and-retry on the theme toggle at 390px. Keep the
     drawn box at 36px so the toolbar rhythm does not change, and let padding
     carry the extra 8px of touchable area. */
  width: 44px; height: 44px;
  padding: 4px;
}

.btn-lg {
  padding: 12px 18px;
  font-size: 14px;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12px;
  border-radius: 8px;
}

.btn-spinner {
  display: none;
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}
.btn.loading .btn-spinner { display: inline-block; }
.btn.loading .btn-label  { opacity: 0.7; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Forms ---- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  letter-spacing: 0.2px;
}

.field-input,
.field-select,
.field-textarea {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 14px;
  transition: border-color 0.15s ease, background 0.15s ease, box-shadow 0.15s ease;
  width: 100%;
  outline: none;
}

.field-textarea {
  resize: vertical;
  min-height: 88px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px;
  line-height: 1.55;
}

.field-input:focus,
.field-select:focus,
.field-textarea:focus {
  border-color: var(--accent);
  background: var(--bg-elev);
  box-shadow: 0 0 0 3px rgba(212,175,55,0.18);
}

/* Was an inline style on the textarea; moved here so the phone rule at the
   bottom of this file can override it (an inline min-height cannot be). */
.knowledge-editor {
  width: 100%;
  min-height: 480px;
}

.field-error {
  font-size: 12px;
  color: var(--danger);
  margin-top: 2px;
}

.login-error {
  display: none;
  background: var(--danger-soft);
  color: var(--danger);
  font-size: 13px;
  padding: 10px 12px;
  border-radius: var(--radius);
  margin: 0 0 12px;
  border: 1px solid color-mix(in srgb, var(--danger) 26%, transparent);
}
.login-error.visible { display: block; }

.login-submit {
  width: 100%;
  margin-top: 6px;
}

/* ---- Cards ---- */

.card {
  background: var(--bg-elev);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
  padding: 18px;
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.18s ease, transform 0.12s ease;
}

.card-padded { padding: 22px 24px; }

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
  gap: 12px;
}

.card-head h3 {
  font-family: var(--font-display);
  font-size: 17px;
  font-weight: 600;
}

/* Stat card */
.stat-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  position: relative;
  overflow: hidden;
  transition: transform 0.16s ease, box-shadow 0.16s ease, border-color 0.16s ease;
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}
.stat-card .stat-icon {
  width: 36px; height: 36px;
  display: inline-flex;
  align-items: center; justify-content: center;
  background: var(--bg-soft);
  border-radius: 10px;
  color: var(--accent-strong);
}
.stat-card .stat-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.2px;
  color: var(--text-secondary);
  font-weight: 600;
}
.stat-card .stat-value {
  font-family: var(--font-display);
  font-size: 30px;
  font-weight: 700;
  line-height: 1;
  color: var(--text-primary);
}
.stat-card .stat-foot {
  font-size: 12px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  gap: 6px;
}
.stat-card.wa .stat-icon { background: color-mix(in srgb, var(--whatsapp) 14%, transparent); color: var(--whatsapp); }
.stat-card.ig .stat-icon { background: color-mix(in srgb, var(--instagram) 14%, transparent); color: var(--instagram); }
.stat-card.accent .stat-icon { background: color-mix(in srgb, var(--accent) 16%, transparent); color: var(--accent-strong); }

/* ---- Tables ---- */

.table-wrap {
  overflow: auto;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elev);
}

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

.data-table th {
  text-align: left;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  color: var(--text-secondary);
  background: var(--bg-soft);
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background 0.12s ease, transform 0.12s ease;
  cursor: default;
}

.data-table tbody tr:hover {
  background: var(--table-row-hov);
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.row-actions {
  display: inline-flex;
  gap: 6px;
  align-items: center;
}

.empty-state {
  padding: 36px 20px;
  text-align: center;
  color: var(--text-secondary);
}
.empty-state .emoji { font-size: 30px; display: block; margin-bottom: 6px; }

/* ---- Channel chips ---- */

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px 4px 6px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 500;
  background: var(--bg-soft);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.chip .chip-emoji { font-size: 14px; }
.chip.chip-wa {
  background: color-mix(in srgb, var(--whatsapp) 12%, transparent);
  color: var(--whatsapp-deep);
  border-color: color-mix(in srgb, var(--whatsapp) 22%, transparent);
}
.chip.chip-ig {
  background: color-mix(in srgb, var(--instagram) 12%, transparent);
  color: var(--instagram);
  border-color: color-mix(in srgb, var(--instagram) 22%, transparent);
}
[data-theme="dark"] .chip.chip-wa { color: color-mix(in srgb, var(--whatsapp) 80%, black 0%); }
[data-theme="dark"] .chip.chip-ig { color: color-mix(in srgb, var(--instagram) 80%, white 10%); }

.chip-reminder-on {
  background: color-mix(in srgb, var(--success) 14%, transparent);
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 25%, transparent);
}
.chip-reminder-off {
  background: var(--bg-soft);
  color: var(--text-secondary);
}

/* ---- Date picker / navigator ---- */

.date-picker {
  display: inline-flex;
  align-items: center;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
  box-shadow: var(--shadow-sm);
}

.dp-arrow {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  transition: background 0.15s ease, color 0.15s ease;
  border: 0;
  background: transparent;
  cursor: pointer;
}
.dp-arrow:hover { background: var(--bg-soft); color: var(--text-primary); }
.dp-arrow:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 2px; }

.dp-current {
  padding: 6px 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  background: var(--accent-strong);
  color: var(--accent-ink);
  border: 0;
}
.dp-current:hover { background: var(--accent); }
.dp-current:focus-visible { outline: 2px solid var(--accent-soft); outline-offset: 2px; }

.dp-date-display {
  font-family: var(--font-display);
  font-size: 18px;
  font-weight: 600;
  color: var(--text-primary);
}

/* ---- Modal ---- */

.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(20,18,12,0.45);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center; justify-content: center;
  z-index: 100;
  padding: 20px;
}
.modal-backdrop.visible { display: flex; }

.modal {
  background: var(--bg-elev);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  max-width: 540px;
  width: 100%;
  max-height: 90vh;
  overflow: auto;
  border: 1px solid var(--border);
  animation: modalIn 0.22s cubic-bezier(.2,.8,.2,1);
}

.modal-head {
  padding: 22px 24px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--border);
}

.modal-head h2 {
  font-family: var(--font-display);
  font-size: 22px;
  font-weight: 600;
}

.modal-body { padding: 18px 24px; }
.modal-foot {
  padding: 14px 24px 22px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  border-top: 1px solid var(--border);
}

.modal-close {
  /* Same 44px tap-target floor as .btn-icon. This one matters more: it is the
     only way out of the customer detail sheet on a phone. */
  width: 44px; height: 44px;
  border-radius: 50%;
  display: inline-flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  background: transparent;
  border: 0;
  cursor: pointer;
  transition: background 0.15s ease;
}
.modal-close:hover { background: var(--bg-soft); color: var(--text-primary); }

@keyframes modalIn {
  from { opacity: 0; transform: translateY(8px) scale(0.99); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---- Login foot elements ---- */

.login-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-top: 22px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-secondary);
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  border-radius: 999px;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s ease, transform 0.12s ease;
  user-select: none;
}
.theme-toggle:hover { background: var(--bg-sunken); transform: translateY(-1px); }
.theme-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent);
  display: inline-block;
}

.backend-status {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--text-muted);
}
.status-dot.ok { background: var(--success); box-shadow: 0 0 8px color-mix(in srgb, var(--success) 50%, transparent); }
.status-dot.warn { background: var(--warning); }
.status-dot.off { background: var(--danger); }

/* ---- Toast ---- */

.toast-stack {
  position: fixed;
  bottom: 22px; right: 22px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 200;
  max-width: 360px;
}

.toast {
  padding: 14px 16px;
  border-radius: var(--radius);
  background: var(--bg-elev);
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  font-size: 13px;
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: toastIn 0.25s cubic-bezier(.2,.8,.2,1);
  border-left: 3px solid var(--accent);
}
.toast.success { border-left-color: var(--success); }
.toast.danger { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--warning); }
.toast .toast-title { font-weight: 600; margin-bottom: 2px; }
.toast .toast-body { color: var(--text-secondary); font-size: 12px; }

@keyframes toastIn {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ---- Toolbar above tables ---- */

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

.toolbar .search {
  flex: 1 1 240px;
  position: relative;
  min-width: 200px;
}
.toolbar .search input {
  width: 100%;
  padding: 9px 14px 9px 36px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  font-size: 14px;
  outline: none;
  transition: border 0.15s ease, box-shadow 0.15s ease;
}
.toolbar .search input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(212,175,55,0.18);
}
.toolbar .search .search-icon {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
}

.filter-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: 999px;
  background: var(--bg-elev);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 12px;
  border: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease, border-color 0.15s ease;
  user-select: none;
}
.filter-pill:hover { background: var(--bg-soft); color: var(--text-primary); }
.filter-pill.active {
  background: var(--accent-strong);
  color: var(--accent-ink);
  border-color: transparent;
}

/* time column subtle mono style */
.time-cell {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text-primary);
  font-weight: 600;
}

/* Avatar circle for customers */
.avatar-circle {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 12px;
  background: linear-gradient(135deg, var(--accent-soft), var(--accent-strong));
  color: #1C1917;
  letter-spacing: 0.5px;
  flex: 0 0 auto;
}

.customer-row {
  display: flex;
  align-items: center;
  gap: 12px;
}

.customer-meta { display: flex; flex-direction: column; gap: 2px; }
.customer-meta .name { font-weight: 600; color: var(--text-primary); }
.customer-meta .sub { font-size: 12px; color: var(--text-secondary); }

/* loader shimmer */
.skeleton {
  background: linear-gradient(90deg,
    var(--bg-soft) 0%,
    color-mix(in srgb, var(--bg-soft) 60%, var(--bg-elev)) 50%,
    var(--bg-soft) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.4s linear infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }

.skel-card {
  background: var(--bg-elev);
  border-radius: var(--radius-lg);
  padding: 18px;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.skel-card .skel-line { height: 14px; width: 100%; }
.skel-card .skel-line.short { width: 50%; }
.skel-card .skel-line.big  { height: 30px; width: 70%; }

/* customers list page specific */
.kv-grid {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 8px 18px;
  align-items: center;
  font-size: 14px;
}
.kv-grid dt { color: var(--text-secondary); font-size: 12px; }
.kv-grid dd { margin: 0; font-weight: 500; color: var(--text-primary); }


/* ---- Tables on phones ----
   A 4-column table at 390px wraps the patient name to five lines. Below 600px
   each row becomes a stacked block instead; the header row is then noise, so
   it is hidden. Nothing is dropped — .hide-sm already removes the columns that
   do not matter on a phone. */
@media (max-width: 600px) {
  .table-wrap { overflow-x: auto; }

  .data-table thead { display: none; }

  .data-table,
  .data-table tbody,
  .data-table tr,
  .data-table td {
    display: block;
    width: 100%;
  }

  .data-table tr {
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
  }

  .data-table td {
    padding: 2px 0;
    border-bottom: 0;
  }

  .data-table td.time-cell {
    font-size: 15px;
    font-weight: 700;
    letter-spacing: 0.4px;
  }

  .data-table td.right {
    text-align: left;
    margin-top: 8px;
  }

  /* stacked rows put every cell on its own line, so the two chip cells that
     .hide-sm removes from the desktop table share one line instead */
  .data-table td.hide-sm {
    display: inline-block;
    width: auto;
    margin-right: 6px;
  }

  /* the agenda's patient cell repeats "service · location", which the service
     cell right below already says */
  [data-agenda-table-wrap] .customer-meta .sub { display: none; }

  /* thead is hidden on phones, so a bare "1" says nothing. */
  td[data-label]::before { content: attr(data-label) ": "; color: var(--text-muted); }

  /* the loading / empty placeholder is a single full-width cell */
  .data-table td .empty-state { padding: 24px 8px; }
}


/* ---- Touch targets ----
   Measured on a 390px viewport: day arrows 32px, filter pills 31px, the row
   "Iptal" button 27px. A finger needs ~44px, and Iptal is destructive — a
   misfire cancels a customer's appointment. */
@media (max-width: 600px) {
  .btn,
  .filter-pill,
  .dp-arrow,
  .dp-current {
    min-height: 44px;
  }

  .btn-sm {
    min-height: 40px;
    padding-left: 16px;
    padding-right: 16px;
  }

  .dp-arrow { min-width: 44px; }

  /* the customers search box measured 38px */
  .toolbar .search input { min-height: 44px; }
}


/* ---- Forms on phones ----
   Two fields per line is fine on a laptop; at 390px the selects truncate
   ("Glow Estetik Nişa…"). Also: iOS Safari zooms the whole page when a focused
   input is under 16px, and every field here was 14px. */
.field-pair {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 600px) {
  .field-pair { grid-template-columns: 1fr; }

  .field-input,
  .field-select,
  .field-textarea,
  .toolbar .search input,
  input,
  select,
  textarea {
    font-size: 16px;
  }

  /* single-line flex rows push the page sideways at 390px */
  .card-head,
  .row-8,
  .toolbar { flex-wrap: wrap; }

  .modal { max-height: 92vh; overflow-y: auto; }

  /* The knowledge editor asks for 480px of height. On an 844px phone screen
     that plus the card head buried "Kaydet"/"Geri al" below a full screen of
     scrolling — the operator could not see that their edit had a save button.
     min-height, not max-height: min beats max when the two conflict, so a
     max-height here would be ignored. */
  /* min-height:0 first — min beats max in CSS, so leaving the 480px floor in
     place would make the max-height below a no-op. rows="22" still sets the
     element height; max-height clips it and the textarea scrolls itself. */
  .knowledge-editor { min-height: 0; max-height: 40vh; }
}

/* ---- Staff alerts ----
   Escalations (human handoff, unhandled message, channel down) used to exist
   only as a Telegram push; with no bot configured they reached nobody. This is
   their only surface, so unread ones must read as urgent, not decorative. */
/* .chip sets display:inline-flex, which outranks the [hidden] UA rule. */
.chip[hidden] { display: none; }

.chip-danger {
  background: color-mix(in srgb, var(--danger) 14%, transparent);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 25%, transparent);
}

.alert-row {
  display: flex;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.alert-row:last-child { border-bottom: 0; }
.alert-row.is-read { opacity: 0.55; }
.alert-row .alert-dot {
  width: 8px; height: 8px; border-radius: 999px; margin-top: 6px;
  flex: 0 0 8px; background: var(--text-muted);
}
.alert-row.level-danger  .alert-dot { background: var(--danger); }
.alert-row.level-warning .alert-dot { background: var(--warning); }
.alert-row.level-info    .alert-dot { background: var(--success); }
.alert-row .alert-text { white-space: pre-line; word-break: break-word; }
.alert-row .alert-time { color: var(--text-muted); font-size: 12px; margin-top: 2px; }
