/**
 * Settings screen styles — (v5-mini-app-7-2)
 * iOS Settings-style grouped sections.
 * Uses CSS variables provided by app.css / Telegram theme.
 */

/* ── Screen container ─────────────────────────────────────────────────────── */

.settings-screen {
  padding: 0 0 80px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  height: 100%;
  box-sizing: border-box;
}

/* ── Skeleton (AC11) ──────────────────────────────────────────────────────── */

.settings-skeleton {
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.skel-section {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.skel-header {
  height: 10px;
  width: 120px;
  border-radius: 5px;
  background: var(--cl-border);
  animation: skel-pulse 1.4s ease-in-out infinite;
}

.skel-card {
  height: 52px;
  border-radius: 12px;
  background: var(--cl-border);
  animation: skel-pulse 1.4s ease-in-out infinite;
}

.skel-card--tall {
  height: 120px;
}

@keyframes skel-pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: 0.45; }
}

/* ── Error banner ─────────────────────────────────────────────────────────── */

.settings-error {
  margin: 16px;
  padding: 12px 14px;
  background: rgba(239, 68, 68, 0.1);
  border: 1px solid var(--cl-error, #ef4444);
  border-radius: var(--cl-radius, 10px);
  color: var(--cl-error, #ef4444);
  font-size: 14px;
}

/* ── iOS Settings sections (T2) ───────────────────────────────────────────── */

/**
 * Each group consists of:
 *   .settings-group-header  — small uppercase label above the card
 *   .settings-card          — rounded container with background
 */

.settings-group-header {
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--cl-hint, var(--cl-text-secondary));
  padding: 16px 16px 4px;
  margin: 0;
}

.settings-card {
  margin: 0 16px 4px;
  background: var(--cl-secondary-bg, var(--cl-card));
  border-radius: 12px;
  overflow: hidden;
}

/* ── Settings rows ────────────────────────────────────────────────────────── */

.settings-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  min-height: 44px; /* T1d */
  border-bottom: 1px solid var(--cl-divider, rgba(128, 128, 128, 0.12));
}

.settings-row:last-child {
  border-bottom: none;
}

.settings-row--button {
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.settings-row__label {
  flex: 1;
  font-size: 15px;
  color: var(--cl-text);
}

.settings-row__value {
  font-size: 15px;
  color: var(--cl-text-secondary);
  max-width: 50%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-align: right;
}

.settings-row__sub {
  font-size: 12px;
  color: var(--cl-text-secondary);
  margin-top: 2px;
}

.settings-row__chevron {
  font-size: 12px;
  color: var(--cl-text-secondary);
  flex-shrink: 0;
}

/* ── Toggle switch (T5a, T6a) ─────────────────────────────────────────────── */

.toggle-switch {
  position: relative;
  width: 51px;
  height: 31px;
  flex-shrink: 0;
}

.toggle-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle-track {
  position: absolute;
  inset: 0;
  border-radius: 15px;
  background: var(--cl-border);
  transition: background 0.2s;
  cursor: pointer;
}

.toggle-switch input:checked + .toggle-track {
  background: var(--cl-success, #10b981);
}

.toggle-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s;
  pointer-events: none;
}

.toggle-switch input:checked ~ .toggle-thumb {
  transform: translateX(20px);
}

/* ── Select dropdowns (T4a, T4b, T5b) ────────────────────────────────────── */

.settings-select {
  -webkit-appearance: none;
  appearance: none;
  background: transparent;
  border: none;
  color: var(--cl-text-secondary);
  font-size: 15px;
  padding-right: 16px;
  text-align: right;
  cursor: pointer;
  outline: none;
  max-width: 160px;
  /* Chevron via background svg */
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23999'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 2px center;
}

/* ── Template row ─────────────────────────────────────────────────────────── */

.template-row__icon {
  font-size: 22px;
  width: 28px;
  text-align: center;
  flex-shrink: 0;
}

.template-row__name {
  flex: 1;
  font-size: 15px;
  color: var(--cl-text);
}

.template-row__change {
  font-size: 14px;
  color: var(--cl-link);
  cursor: pointer;
  padding: 4px 0 4px 8px;
  -webkit-tap-highlight-color: transparent;
  flex-shrink: 0;
}

.template-row__discover {
  display: block;
  width: calc(100% - 28px);
  margin: 0 14px 12px;
  padding: 10px;
  background: transparent;
  color: var(--cl-link);
  border: 1px solid var(--cl-link);
  border-radius: var(--cl-radius, 8px);
  font-size: 13px;
  text-align: center;
  cursor: pointer;
  min-height: 44px; /* T1d */
  -webkit-tap-highlight-color: transparent;
}

/* ── Non-admin read-only view (T9) ────────────────────────────────────────── */

.settings-readonly {
  padding: 24px 16px;
}

.settings-readonly__title {
  font-size: 20px;
  font-weight: 700;
  color: var(--cl-text);
  margin: 0 0 4px;
}

.settings-readonly__subtitle {
  font-size: 14px;
  color: var(--cl-text-secondary);
  margin: 0 0 20px;
}

.readonly-card {
  background: var(--cl-secondary-bg, var(--cl-card));
  border-radius: 12px;
  overflow: hidden;
}

.readonly-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--cl-divider, rgba(128, 128, 128, 0.12));
  font-size: 15px;
}

.readonly-row:last-child { border-bottom: none; }

.readonly-row__label  { color: var(--cl-text-secondary); }
.readonly-row__value  { color: var(--cl-text); font-weight: 500; text-align: right; }

/* ── Danger Zone section (T7) ─────────────────────────────────────────────── */

.settings-group-header--danger {
  color: var(--cl-error, #ef4444);
}

.settings-card--danger {
  background: rgba(239, 68, 68, 0.06);
  border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-danger {
  width: 100%;
  padding: 13px 14px;
  background: transparent;
  color: var(--cl-error, #ef4444);
  border: none;
  font-size: 15px;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  min-height: 44px; /* T1d */
  -webkit-tap-highlight-color: transparent;
}

/* ── Undo toast (T8c) ─────────────────────────────────────────────────────── */

.undo-toast {
  position: fixed;
  bottom: 80px; /* above Telegram safe area */
  left: 16px;
  right: 16px;
  z-index: 100;
  background: var(--cl-card);
  border-radius: var(--cl-radius, 10px);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  gap: 10px;
}

.undo-toast__message {
  font-size: 14px;
  color: var(--cl-text);
  flex: 1;
}

.btn-undo {
  background: none;
  border: none;
  color: var(--cl-link);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 0;
  min-height: 44px; /* T1d */
  -webkit-tap-highlight-color: transparent;
}

/* ── Save error ───────────────────────────────────────────────────────────── */

.settings-save-error {
  margin: 4px 16px 0;
  font-size: 12px;
  color: var(--cl-error, #ef4444);
}

/* ── Dialog overlay ───────────────────────────────────────────────────────── */

.dialog-overlay {
  position: fixed;
  inset: 0;
  z-index: 150;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: flex-end;
  justify-content: center;
}

.dialog-sheet {
  background: var(--cl-bg);
  border-radius: 16px 16px 0 0;
  padding: 20px 20px 36px;
  width: 100%;
  max-height: 70vh;
  overflow-y: auto;
}

.dialog-sheet__title {
  font-size: 17px;
  font-weight: 700;
  color: var(--cl-text);
  margin: 0 0 8px;
}

.dialog-sheet__body {
  font-size: 14px;
  color: var(--cl-text-secondary);
  margin: 0 0 20px;
  line-height: 1.5;
}

.dialog-sheet__input {
  display: block;
  width: 100%;
  padding: 12px;
  background: var(--cl-card);
  color: var(--cl-text);
  border: 1px solid var(--cl-border);
  border-radius: var(--cl-radius, 8px);
  font-size: 15px;
  outline: none;
  box-sizing: border-box;
  margin-bottom: 12px;
}

.dialog-sheet__input:focus {
  border-color: var(--cl-link);
}

.dialog-sheet__error {
  font-size: 12px;
  color: var(--cl-error, #ef4444);
  margin: 0 0 12px;
}

.btn-dialog-confirm {
  display: block;
  width: 100%;
  padding: 13px;
  background: var(--cl-error, #ef4444);
  color: #fff;
  border: none;
  border-radius: var(--cl-radius, 8px);
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px; /* T1d */
  -webkit-tap-highlight-color: transparent;
  margin-bottom: 10px;
}

.btn-dialog-cancel {
  display: block;
  width: 100%;
  padding: 13px;
  background: var(--cl-card);
  color: var(--cl-link);
  border: none;
  border-radius: var(--cl-radius, 8px);
  font-size: 16px;
  cursor: pointer;
  min-height: 44px; /* T1d */
  -webkit-tap-highlight-color: transparent;
}

/* ── Catalog overlay ──────────────────────────────────────────────────────── */

/* M1 fix: position:fixed escapes overflow-y:auto clipping in WebKit scroll containers */
.catalog-panel {
  position: fixed;
  inset: 0;
  background: var(--cl-bg);
  z-index: 120;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.catalog-panel__header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--cl-border);
  flex-shrink: 0;
}

.catalog-panel__back {
  background: none;
  border: none;
  color: var(--cl-link);
  font-size: 15px;
  cursor: pointer;
  padding: 8px;
  min-height: 44px; /* T1d */
  -webkit-tap-highlight-color: transparent;
}

.catalog-panel__title {
  font-size: 16px;
  font-weight: 600;
  color: var(--cl-text);
  margin: 0;
}

.catalog-panel__list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.catalog-template-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 14px;
  background: var(--cl-card);
  border-radius: var(--cl-radius, 8px);
  cursor: pointer;
  min-height: 44px; /* T1d */
  -webkit-tap-highlight-color: transparent;
}

.catalog-template-item__icon { font-size: 22px; flex-shrink: 0; }

.catalog-template-item__info { flex: 1; min-width: 0; }

.catalog-template-item__name {
  font-size: 15px;
  font-weight: 500;
  color: var(--cl-text);
}

.catalog-template-item__cat {
  font-size: 12px;
  color: var(--cl-text-secondary);
  text-transform: capitalize;
}
