/* ============================================================
   Settings page (STEP 4.9)
   Ported from _design/zain-os/project/Settings - B.html
   Six-section layout with sticky TOC + save bar.
   ============================================================ */

.st-wrap { max-width: 1180px; margin: 0 auto; }

.st-page-hd { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 12px; }
.st-page-hd h1 { font-size: 22px; font-weight: 500; letter-spacing: -0.01em; line-height: 1; margin: 0; color: var(--text); }
.st-page-hd .sub { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

/* Profile header */
.st-profile-hdr { display: flex; align-items: center; gap: 16px; padding: 16px 20px; background: var(--card); border: 1px solid var(--border-light); border-radius: var(--r-sm); margin-bottom: 16px; }
.st-profile-hdr .av { width: 44px; height: 44px; border-radius: 50%; background: var(--brand); color: #fff; display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 18px; }
.st-profile-hdr .info { line-height: 1.3; }
.st-profile-hdr .n { font-size: 15px; font-weight: 500; color: var(--text); letter-spacing: -0.005em; }
.st-profile-hdr .e { font-size: 12px; color: var(--text-secondary); }
.st-profile-hdr .sp { flex: 1; }
.st-profile-hdr .kv { display: grid; grid-template-columns: auto auto; gap: 4px 16px; font-size: 11px; }
.st-profile-hdr .kv .k { color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.06em; font-family: var(--font-mono); font-size: 9.5px; }
.st-profile-hdr .kv .v { color: var(--text); font-family: var(--font-mono); font-size: 11px; }

/* TOC */
.st-toc { display: flex; gap: 18px; padding: 10px 0; border-bottom: 1px solid var(--border-light); position: sticky; top: 0; background: var(--bg); z-index: 5; margin-bottom: 28px; flex-wrap: wrap; }
.st-toc a { font-size: 12.5px; color: var(--text-secondary); text-decoration: none; padding: 4px 0; border-bottom: 1px solid transparent; font-weight: 500; cursor: pointer; }
.st-toc a.is-on { color: var(--brand); border-bottom-color: var(--brand); }
.st-toc a:hover { color: var(--text); }
.st-toc .sp { flex: 1; }
.st-toc .st-search { display: flex; align-items: center; gap: 6px; background: var(--card); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 4px 10px; }
.st-toc .st-search input { border: 0; background: transparent; outline: none; font-family: inherit; font-size: 12px; color: var(--text); width: 180px; }
.st-toc .st-search svg { width: 12px; height: 12px; color: var(--text-tertiary); }

/* Sections */
.st-section { margin-bottom: 56px; scroll-margin-top: 80px; }
.st-section-hd { display: flex; align-items: baseline; gap: 14px; margin-bottom: 6px; }
.st-section-hd .num { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: 0.1em; }
.st-section-hd h2 { font-size: 20px; font-weight: 500; letter-spacing: -0.01em; margin: 0; color: var(--text); }
.st-section-hd .spacer { flex: 1; }
.st-section-desc { font-size: 13px; color: var(--text-secondary); max-width: 640px; margin-bottom: 22px; line-height: 1.55; }

/* Cards */
.st-card { background: var(--card); border: 1px solid var(--border-light); border-radius: var(--r-sm); padding: 18px 22px; }
.st-section > .st-card + .st-card { margin-top: 12px; }
.st-card-hd { display: flex; align-items: baseline; gap: 10px; margin-bottom: 14px; padding-bottom: 12px; border-bottom: 1px solid var(--border-light); }
.st-card-hd h3 { font-size: 13.5px; font-weight: 500; margin: 0; letter-spacing: -0.005em; color: var(--text); }
.st-card-hd .desc { font-size: 11.5px; color: var(--text-secondary); }
.st-card-hd .sp { flex: 1; }
.st-card-hd .status { font-size: 10px; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.08em; color: #6A8A70; }

/* Inline setting row */
.st-irow { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 20px; align-items: center; padding: 14px 0; border-top: 1px solid var(--border-light); min-height: 56px; box-sizing: border-box; }
.st-irow:first-child { border-top: 0; padding-top: 0; }
.st-irow:last-child { padding-bottom: 0; }
.st-irow .name { font-size: 13px; color: var(--text); font-weight: 500; }
.st-irow .desc { font-size: 11.5px; color: var(--text-secondary); margin-top: 2px; line-height: 1.45; }
.st-irow .ctrl { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }

.st-card input[type="text"], .st-card input[type="number"], .st-card input[type="tel"], .st-card input[type="time"], .st-card select {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 6px 11px;
  color: var(--text); font-family: inherit; font-size: 12.5px; outline: none;
}
.st-card input:focus, .st-card select:focus { border-color: var(--brand); }
.st-card input[type="number"], .st-card .mono-in { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.st-w-80 { width: 80px; } .st-w-100 { width: 100px; } .st-w-140 { width: 140px; } .st-w-200 { width: 200px; } .st-w-240 { width: 240px; }
.st-unit { font-size: 11.5px; color: var(--text-secondary); }

.st-switch { position: relative; width: 36px; height: 20px; border-radius: 10px; background: var(--brand); cursor: pointer; flex-shrink: 0; border: 0; padding: 0; }
.st-switch::after { content: ''; position: absolute; top: 2px; right: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: right var(--dur-default) var(--ease); }
.st-switch.off { background: var(--border); }
.st-switch.off::after { right: 18px; }

.st-seg { display: inline-flex; padding: 2px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-sm); }
.st-seg button { padding: 5px 10px; background: transparent; border: 0; border-radius: 4px; color: var(--text-secondary); font-family: inherit; font-size: 11.5px; cursor: pointer; }
.st-seg button.is-on { background: var(--brand-soft); color: var(--brand); font-weight: 500; }

.st-btn { height: 28px; padding: 0 12px; border-radius: var(--r-sm); font-family: inherit; font-size: 12px; font-weight: 500; cursor: pointer; border: 1px solid var(--border); background: transparent; color: var(--text); }
.st-btn:hover { border-color: var(--brand-dim); color: var(--brand); }
.st-btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.st-btn.primary:hover { background: var(--brand-hover); }
.st-btn.danger { color: var(--danger); border-color: rgba(161,63,40,0.4); }
.st-btn.danger:hover { background: rgba(161,63,40,0.12); }

/* Alert grid */
.st-alert-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 2px; background: var(--border-light); border-radius: var(--r-sm); overflow: hidden; }
.st-alert-cell { background: var(--card); padding: 12px 14px; display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.st-alert-cell .lbl { font-size: 12.5px; color: var(--text); font-weight: 500; }
.st-alert-cell .d { font-size: 11px; color: var(--text-secondary); margin-top: 2px; line-height: 1.45; }

/* Dual layout — cards stretch so Display + Financials end at the same height */
.st-dual { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: stretch; }
.st-dual > * { min-width: 0; display: flex; flex-direction: column; }
.st-dual > .st-card { height: 100%; }
@media (max-width: 900px) { .st-dual { grid-template-columns: 1fr; } }

/* Archive table */
.st-arch-wrap { background: var(--card); border: 1px solid var(--border-light); border-radius: var(--r-sm); overflow: hidden; }
.st-arch-hd { display: flex; align-items: center; padding: 12px 18px; border-bottom: 1px solid var(--border-light); gap: 10px; }
.st-arch-hd h4 { font-size: 12.5px; font-weight: 500; margin: 0; color: var(--text); }
.st-arch-hd .n { font-size: 10.5px; color: var(--text-tertiary); font-family: var(--font-mono); }
.st-arch-hd .sp { flex: 1; }
.st-arch-hd .st-search { display: flex; align-items: center; gap: 6px; background: var(--bg); border: 1px solid var(--border); border-radius: var(--r-sm); padding: 3px 10px; }
.st-arch-hd .st-search input { border: 0; background: transparent; outline: none; font-family: inherit; font-size: 12px; color: var(--text); width: 160px; }
.st-arch-wrap table { width: 100%; border-collapse: collapse; font-size: 12px; }
.st-arch-wrap th { text-align: left; padding: 8px 18px; background: var(--hover); color: var(--text-secondary); font-weight: 500; font-size: 10px; text-transform: uppercase; letter-spacing: 0.06em; font-family: var(--font-mono); border-bottom: 1px solid var(--border-light); }
.st-arch-wrap td { padding: 9px 18px; border-bottom: 1px solid var(--border-light); color: var(--text); }
.st-arch-wrap tr:last-child td { border-bottom: 0; }
.st-arch-wrap tr:hover { background: var(--hover); }
.st-arch-wrap .sec { color: var(--text-secondary); font-size: 11px; }
.st-arch-wrap .ts { font-family: var(--font-mono); font-size: 10.5px; color: var(--text-tertiary); }
.st-arch-wrap .actions { display: flex; gap: 6px; justify-content: flex-end; }
.st-arch-wrap .actions button { font-size: 11px; color: var(--text-secondary); background: transparent; border: 0; cursor: pointer; font-family: inherit; padding: 2px 4px; }
.st-arch-wrap .actions button:hover { color: var(--brand); }
.st-arch-wrap .actions button.x:hover { color: var(--danger); }

/* Services */
.st-svc-list { display: grid; grid-template-columns: 1fr 1fr; gap: 0 20px; }
@media (max-width: 900px) { .st-svc-list { grid-template-columns: 1fr; } }
.st-svc-row { display: grid; grid-template-columns: 8px 1fr auto auto; gap: 12px; align-items: center; padding: 10px 0; border-top: 1px solid var(--border-light); font-size: 12px; }
.st-svc-row:nth-child(-n+2) { border-top: 0; }
.st-svc-row .dot { width: 7px; height: 7px; border-radius: 50%; background: #6A8A70; }
.st-svc-row .dot.warn { background: #C99A52; }
.st-svc-row .dot.red { background: var(--danger); }
.st-svc-row .lbl { color: var(--text); }
.st-svc-row .sub { font-size: 10.5px; color: var(--text-tertiary); margin-top: 1px; }
.st-svc-row .val { color: var(--text-secondary); font-family: var(--font-mono); font-size: 10.5px; }
.st-svc-row .run { font-size: 10.5px; color: var(--brand); cursor: pointer; background: transparent; border: 0; padding: 0; font-family: inherit; }
.st-svc-row .run:hover { text-decoration: underline; }

/* Danger zone */
.st-danger-zone { border: 1px solid rgba(161,63,40,0.3); border-radius: var(--r-sm); background: rgba(161,63,40,0.04); overflow: hidden; }
.st-danger-zone .dz-hd { padding: 12px 20px; border-bottom: 1px solid rgba(161,63,40,0.2); color: var(--danger); font-size: 10.5px; font-weight: 500; font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.08em; }
.st-danger-zone .dz-row { display: grid; grid-template-columns: 1fr auto; gap: 16px; align-items: center; padding: 14px 20px; border-top: 1px solid rgba(161,63,40,0.14); }
.st-danger-zone .dz-row:first-of-type { border-top: 0; }
.st-danger-zone .dz-row .dz-name { font-size: 13px; font-weight: 500; color: var(--text); }
.st-danger-zone .dz-row .dz-desc { font-size: 11.5px; color: var(--text-secondary); margin-top: 2px; line-height: 1.45; }
.st-danger-zone .dz-row .dz-desc code { font-family: var(--font-mono); font-size: 10.5px; padding: 1px 5px; background: rgba(232,97,58,0.08); border-radius: 3px; color: var(--brand); }

/* Sticky save bar */
.st-save-bar { position: sticky; bottom: 20px; margin: 32px 0 0; display: flex; align-items: center; gap: 12px; padding: 10px 14px; background: var(--card); border: 1px solid var(--border); border-radius: var(--r-sm); box-shadow: 0 12px 28px rgba(0,0,0,0.45); z-index: 10; }
.st-save-bar .msg { font-size: 12.5px; color: var(--text-secondary); }
.st-save-bar .dot { width: 6px; height: 6px; border-radius: 50%; background: #C99A52; display: inline-block; margin-right: 6px; }
.st-save-bar .sp { flex: 1; }
.st-save-bar.is-hidden { display: none; }

/* ============================================================
   Responsive (additive only — desktop unchanged above)
   ============================================================ */

@media (max-width: 1024px) {
  .st-dual { grid-template-columns: 1fr; }
  .st-svc-list { grid-template-columns: 1fr; }
  .st-svc-row:nth-child(2) { border-top: 1px solid var(--border-light); }
  .st-svc-row:first-child { border-top: 0; }

  /* Profile header wraps */
  .st-profile-hdr { flex-wrap: wrap; }
  .st-profile-hdr .sp { display: none; }
  .st-profile-hdr .kv { width: 100%; padding-top: 8px; border-top: 1px solid var(--border-light); }
}

@media (max-width: 640px) {
  .st-wrap { max-width: 100%; }

  /* Section headings */
  .st-section { margin-bottom: 40px; }
  .st-section-hd h2 { font-size: 17px; }

  /* Cards: tighter padding */
  .st-card { padding: 14px 14px; }
  .st-card-hd { flex-wrap: wrap; gap: 6px; }

  /* Inline setting rows stack: name above ctrl */
  .st-irow { grid-template-columns: 1fr; gap: 8px; padding: 12px 0; min-height: 0; }
  .st-irow .ctrl { justify-content: flex-start; }

  /* Profile header */
  .st-profile-hdr { padding: 12px 14px; gap: 12px; }
  .st-profile-hdr .av { width: 36px; height: 36px; font-size: 14px; }
  .st-profile-hdr .kv { grid-template-columns: 1fr auto; gap: 2px 12px; }

  /* TOC scrolls horizontally on phones */
  .st-toc { gap: 12px; overflow-x: auto; -webkit-overflow-scrolling: touch; flex-wrap: nowrap; }
  .st-toc a { flex-shrink: 0; }
  .st-toc .sp, .st-toc .st-search { display: none; }

  /* Alert grid: 1 col */
  .st-alert-grid { grid-template-columns: 1fr; }

  /* Archive table: horizontal scroll */
  .st-arch-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .st-arch-wrap table { min-width: 640px; }
  .st-arch-hd { flex-wrap: wrap; gap: 8px; }
  .st-arch-hd .sp { display: none; }
  .st-arch-hd .st-search input { width: 100%; }

  /* Danger zone rows stack */
  .st-danger-zone .dz-row { grid-template-columns: 1fr; gap: 8px; }

  /* Save bar */
  .st-save-bar { flex-wrap: wrap; padding: 10px 12px; bottom: 8px; }
  .st-save-bar .sp { width: 100%; height: 0; flex: 0 0 100%; }

  /* iOS zoom prevention */
  .st-card input[type="text"],
  .st-card input[type="number"],
  .st-card input[type="tel"],
  .st-card input[type="time"],
  .st-card select,
  .st-arch-hd .st-search input,
  .st-toc .st-search input { font-size: 16px; }
}

@media (hover: none) and (pointer: coarse) {
  .st-btn { min-height: 36px; padding: 0 14px; }
  .st-seg button { min-height: 32px; padding: 6px 12px; }
  .st-svc-row .run { min-height: 32px; padding: 4px 8px; }
  .st-arch-wrap .actions button { min-width: 32px; min-height: 32px; }
  .st-toc a { padding: 8px 0; min-height: 36px; }
  /* Switch tap target — keep visual size but expand the hit area
     to ~36px high using padding via the parent */
  .st-switch { min-width: 36px; }
  /* Card inputs need a comfortable touch height */
  .st-card input[type="text"],
  .st-card input[type="number"],
  .st-card input[type="tel"],
  .st-card input[type="time"],
  .st-card select { min-height: 36px; }
}

/* ============================================================
   Responsive — gap fixes (additive only)
   Page header + section header wrap, irow ctrl widths grow,
   fixed-width inputs become responsive on phone, profile
   header KV grid wraps, archive table preview gets card view
   only at very narrow widths via existing horizontal scroll.
   ============================================================ */

@media (max-width: 1024px) {
  /* Page header: title + sub stack if needed */
  .st-page-hd { flex-wrap: wrap; }

  /* Section header: action button (e.g. "Send test alert") wraps below */
  .st-section-hd { flex-wrap: wrap; row-gap: 8px; }
  .st-section-hd .spacer { flex: 1 1 auto; }

  /* Card header: description can wrap to next line */
  .st-card-hd { flex-wrap: wrap; row-gap: 6px; }

  /* Profile header info shrinks gracefully */
  .st-profile-hdr .info { min-width: 0; flex: 1 1 auto; }
  .st-profile-hdr .n,
  .st-profile-hdr .e { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }

  /* TOC search input width caps to its container */
  .st-toc .st-search input { width: 140px; max-width: 100%; }

  /* Inline setting row name + desc can wrap freely */
  .st-irow .name,
  .st-irow .desc { word-break: break-word; }
}

@media (max-width: 640px) {
  /* Page title smaller on phone */
  .st-page-hd h1 { font-size: 18px; }

  /* Section descriptions / headers tighter */
  .st-section-desc { font-size: 12.5px; }

  /* Irow ctrl: stretch full width when stacking under name; let buttons wrap */
  .st-irow .ctrl { width: 100%; }

  /* Fixed-width inputs become responsive — keep min but let them grow */
  .st-card .st-w-80,
  .st-card .st-w-100,
  .st-card .st-w-140,
  .st-card .st-w-200,
  .st-card .st-w-240 { width: auto; min-width: 80px; max-width: 100%; flex: 0 1 auto; }
  .st-card input[type="text"].st-w-240,
  .st-card input[type="tel"].st-w-240 { flex: 1 1 100%; }

  /* Buttons inside ctrl wrap to a new row */
  .st-irow .ctrl .st-btn { flex: 0 0 auto; }

  /* Profile header: stack avatar, info, KV */
  .st-profile-hdr { align-items: flex-start; }
  .st-profile-hdr .info { flex: 1 1 100%; }
  .st-profile-hdr .kv { width: 100%; }

  /* Card header description on its own line if needed */
  .st-card-hd h3 { flex: 0 1 auto; }
  .st-card-hd .desc,
  .st-card-hd .status { flex: 0 0 100%; }

  /* Service rows: tighten gap, allow value/label to share */
  .st-svc-row { grid-template-columns: 8px 1fr auto; gap: 8px; }
  .st-svc-row .run { grid-column: 1 / -1; justify-self: end; }

  /* Archive header: search input full width */
  .st-arch-hd { flex-direction: column; align-items: stretch; }
  .st-arch-hd h4 { flex: 0 0 auto; }
  .st-arch-hd .st-search { width: 100%; }
  .st-arch-hd .st-search input { width: 100%; }

  /* Save bar: stack buttons full-width-friendly */
  .st-save-bar .st-btn { flex: 1 1 auto; }
  .st-save-bar .msg { flex: 1 1 100%; }

  /* Danger zone: ensure code/inline elements wrap */
  .st-danger-zone .dz-row .dz-desc { word-break: break-word; }
  .st-danger-zone .dz-row .dz-name { word-break: break-word; }

  /* Alert grid cell: stack label and switch */
  .st-alert-cell { flex-wrap: wrap; }
}
