/* SandOS — UI components. */

/* ---- Sidebar navigation ---- */
.sidebar__brand {
  display: flex; align-items: center; gap: var(--s3);
  height: var(--header-h); padding: 0 var(--s5);
  border-bottom: 1px solid var(--border);
  background: linear-gradient(to bottom, rgba(91,155,213,.06), transparent);
  flex: none;
}
.sidebar__logo {
  display: grid; place-items: center; color: var(--accent);
  width: 34px; height: 34px; border-radius: var(--radius-sm);
  background: var(--blue-bg); border: 1px solid rgba(91,155,213,.2);
  box-shadow: 0 0 12px rgba(91,155,213,.15);
  flex: none;
}
.sidebar__logo svg { width: 18px; height: 18px; }
.sidebar__name {
  font-weight: 700; font-size: var(--fs-sm); letter-spacing: .01em;
  color: var(--text);
}
.nav { flex: 1; overflow-y: auto; padding: var(--s3); display: flex; flex-direction: column; gap: 2px; }
.nav-item {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s2) var(--s3); min-height: 40px;
  border-radius: var(--radius-sm); color: var(--text-muted);
  font-size: var(--fs-sm); font-weight: 500; text-align: left; width: 100%;
  position: relative; overflow: hidden;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-item svg { width: 18px; height: 18px; flex: none; transition: color var(--dur) var(--ease); }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.is-active {
  background: linear-gradient(to right, rgba(91,155,213,.18), rgba(91,155,213,.06));
  color: var(--text);
}
.nav-item.is-active::before {
  content: ''; position: absolute; left: 0; top: 6px; bottom: 6px;
  width: 3px; background: var(--accent); border-radius: 0 3px 3px 0;
}
.nav-item.is-active svg { color: var(--accent); }
.nav-item__badge {
  margin-left: auto; font-size: var(--fs-xs); font-family: var(--font-mono);
  background: var(--surface-3); color: var(--text-muted);
  padding: 0 6px; border-radius: 999px;
}
.sidebar__foot { padding: var(--s3); border-top: 1px solid var(--border); }

/* ---- Buttons — compact, modest radius, not pills ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 38px; padding: 0 var(--s4);
  font-size: var(--fs-sm); font-weight: 600; white-space: nowrap;
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--text);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              opacity var(--dur) var(--ease);
}
.btn svg { width: 16px; height: 16px; }
.btn:hover { background: var(--surface-3); border-color: var(--border-strong); }
.btn:active { background: var(--surface); }
.btn--primary {
  background: linear-gradient(to bottom, color-mix(in srgb, var(--accent) 90%, white 10%), var(--accent));
  border-color: var(--accent); color: var(--text-invert);
}
.btn--primary:hover {
  background: linear-gradient(to bottom, var(--accent-hover), color-mix(in srgb, var(--accent-hover) 85%, var(--blue)));
  border-color: var(--accent-hover);
  box-shadow: var(--shadow-accent);
}
.btn--primary:active { background: var(--accent); box-shadow: none; }
.btn--danger {
  background: transparent; border-color: color-mix(in srgb, var(--danger) 55%, var(--border));
  color: var(--danger);
}
.btn--danger:hover { background: var(--red-bg); }
.btn--ghost { background: transparent; border-color: transparent; }
.btn--ghost:hover { background: var(--surface-2); }
.btn--sm { min-height: 32px; padding: 0 var(--s3); font-size: var(--fs-xs); }
.btn--block { width: 100%; }
.btn[disabled], .btn.is-loading { opacity: .55; pointer-events: none; }
.btn.is-loading { position: relative; color: transparent; }
.btn.is-loading::after {
  content: ""; position: absolute; width: 15px; height: 15px;
  border: 2px solid currentColor; border-top-color: transparent;
  border-radius: 50%; animation: spin .7s linear infinite;
  color: var(--text);
}
.btn--primary.is-loading::after { color: var(--text-invert); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; flex: none;
  border-radius: var(--radius-sm); color: var(--text-muted);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn svg { width: 20px; height: 20px; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---- Cards ---- */
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-1);
  position: relative; overflow: hidden;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(to right, transparent, rgba(91,155,213,.4), transparent);
  opacity: 0; transition: opacity var(--dur) var(--ease);
}
.card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-2); }
.card:hover::before { opacity: 1; }
.card__header {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border);
}
.card__title { font-size: var(--fs-md); font-weight: 600; }
.card__header .row { margin-left: auto; }
.card__body { padding: var(--s5); }
.card__body--flush { padding: 0; }

/* ---- Devices page: collapsible node/device/user groups ---- */
.peer-group__chevron { transition: transform var(--dur) var(--ease); flex-shrink: 0; }
details[open] > summary .peer-group__chevron { transform: rotate(90deg); }

/* ---- Page header ---- */
.page-head {
  display: flex; align-items: flex-start; gap: var(--s4);
  flex-wrap: wrap; margin-bottom: var(--s6);
}
.page-head__text { flex: 1; min-width: 200px; }
.page-head h2 { font-size: var(--fs-xl); }
.page-head p { color: var(--text-muted); font-size: var(--fs-sm); margin-top: 2px; }
.page-head__actions { display: flex; gap: var(--s2); flex-wrap: wrap; }

.section-title {
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-faint); margin-bottom: var(--s3);
}

/* ---- Stat tiles ---- */
.stat {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: var(--s4) var(--s5);
  position: relative; overflow: hidden;
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.stat:hover { border-color: var(--border-strong); box-shadow: var(--shadow-2); }
.stat__label {
  display: flex; align-items: center; gap: var(--s2);
  font-size: var(--fs-xs); font-weight: 600; letter-spacing: .04em;
  text-transform: uppercase; color: var(--text-faint);
}
.stat__label svg { width: 15px; height: 15px; }
.stat__value {
  margin-top: var(--s3); font-size: var(--fs-2xl); font-weight: 650;
  font-variant-numeric: tabular-nums; letter-spacing: -.02em; line-height: 1;
}
.stat__value small { font-size: var(--fs-md); color: var(--text-muted); font-weight: 500; }
.stat__meta { margin-top: var(--s2); font-size: var(--fs-xs); color: var(--text-muted); }

/* ---- Meter bar ---- */
.meter { height: 5px; border-radius: 999px; background: var(--surface-3); overflow: hidden; margin-top: var(--s3); }
.meter__fill {
  height: 100%; border-radius: 999px;
  background: linear-gradient(to right, var(--accent), color-mix(in srgb, var(--accent) 65%, var(--cyan)));
  transition: width var(--dur-slow) var(--ease-out);
}
.meter__fill.is-warn   { background: linear-gradient(to right, var(--warn), color-mix(in srgb, var(--warn) 70%, var(--red))); }
.meter__fill.is-danger { background: linear-gradient(to right, color-mix(in srgb, var(--danger) 70%, var(--amber)), var(--danger)); }

/* ---- Badges & status dots ---- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px var(--s2); font-size: var(--fs-xs); font-weight: 600;
  border-radius: var(--radius-xs);
  background: var(--neutral-bg); color: var(--text-muted);
  border: 1px solid rgba(154,166,180,.12);
  white-space: nowrap;
}
.badge svg { width: 13px; height: 13px; }
.badge--ok      { background: var(--green-bg);  color: var(--green);  border-color: rgba(69,185,138,.2); }
.badge--info    { background: var(--blue-bg);   color: var(--blue);   border-color: rgba(91,155,213,.2); }
.badge--vpn     { background: var(--purple-bg); color: var(--purple); border-color: rgba(155,135,212,.2); }
.badge--dns     { background: var(--cyan-bg);   color: var(--cyan);   border-color: rgba(79,182,201,.2); }
.badge--warn    { background: var(--amber-bg);  color: var(--amber);  border-color: rgba(211,164,78,.2); }
.badge--danger  { background: var(--red-bg);    color: var(--red);    border-color: rgba(216,113,111,.2); }

.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--text-faint); }
.dot--ok {
  background: var(--green); box-shadow: 0 0 0 3px var(--green-bg);
  animation: dot-pulse 2.4s var(--ease-out) infinite;
}
.dot--warn   { background: var(--amber); box-shadow: 0 0 0 3px var(--amber-bg); }
.dot--danger { background: var(--red);   box-shadow: 0 0 0 3px var(--red-bg); }
.dot--idle   { background: var(--text-faint); }
@keyframes dot-pulse {
  0%, 100% { box-shadow: 0 0 0 3px var(--green-bg); }
  50%       { box-shadow: 0 0 0 6px rgba(69,185,138,0); }
}

.status-pill {
  display: inline-flex; align-items: center; gap: var(--s2);
  padding: var(--s1) var(--s3); font-size: var(--fs-xs); font-weight: 600;
  border: 1px solid var(--border); border-radius: 999px; color: var(--text-muted);
}

/* ---- Tables ---- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.table th {
  text-align: left; font-size: var(--fs-xs); font-weight: 600;
  letter-spacing: .04em; text-transform: uppercase; color: var(--text-faint);
  padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.table td {
  padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background var(--dur) var(--ease); }
.table tbody tr:hover { background: var(--surface-2); }
.table .col-actions { text-align: right; white-space: nowrap; }

/* ---- Forms ---- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field + .field { margin-top: var(--s4); }
.label { font-size: var(--fs-sm); font-weight: 600; }
.label .req { color: var(--danger); }
.input, .select, .textarea {
  width: 100%; min-height: 42px; padding: 0 var(--s3);
  font-size: var(--fs-md); /* 16px — avoids iOS focus zoom */
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  transition: border-color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.textarea { padding: var(--s3); min-height: 96px; resize: vertical;
  font-family: var(--font-mono); font-size: var(--fs-sm); line-height: 1.5; }
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent); background: var(--surface);
}
.input::placeholder { color: var(--text-faint); }
.input[aria-invalid="true"], .textarea[aria-invalid="true"] { border-color: var(--danger); }
.help { font-size: var(--fs-xs); color: var(--text-muted); }
.field-error { font-size: var(--fs-xs); color: var(--danger); display: flex; align-items: center; gap: 4px; }
.field-error svg { width: 13px; height: 13px; }
.input-group { display: flex; gap: var(--s2); }
.input-group .input { flex: 1; }

/* ---- Toggle switch ---- */
.toggle { position: relative; display: inline-flex; align-items: center; gap: var(--s3); cursor: pointer; }
.toggle input { position: absolute; opacity: 0; width: 44px; height: 26px; margin: 0; cursor: pointer; }
.toggle__track {
  width: 44px; height: 26px; flex: none; border-radius: 999px;
  background: var(--surface-3); border: 1px solid var(--border-strong);
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease);
}
.toggle__track::after {
  content: ""; display: block; width: 20px; height: 20px; margin: 2px;
  border-radius: 50%; background: var(--text-muted);
  box-shadow: 0 1px 3px rgba(0,0,0,.4);
  transition: transform var(--dur) var(--ease), background var(--dur) var(--ease);
}
.toggle input:checked + .toggle__track {
  background: rgba(69,185,138,.22); border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(69,185,138,.1);
}
.toggle input:checked + .toggle__track::after { transform: translateX(18px); background: var(--green); }
.toggle input:focus-visible + .toggle__track { outline: 2px solid var(--focus-ring); outline-offset: 2px; }
.toggle__label { font-size: var(--fs-sm); }

/* ---- Segmented control ---- */
.segmented { display: inline-flex; padding: 3px; gap: 2px;
  background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.segmented button {
  padding: 6px var(--s3); font-size: var(--fs-xs); font-weight: 600;
  border-radius: var(--radius-xs); color: var(--text-muted); white-space: nowrap;
}
.segmented button.is-active { background: var(--surface-3); color: var(--text); }

/* ---- Empty & callout ---- */
.empty {
  display: grid; place-items: center; gap: var(--s3);
  padding: var(--s10) var(--s5); text-align: center; color: var(--text-muted);
}
.empty__icon {
  display: grid; place-items: center; width: 56px; height: 56px;
  border-radius: var(--radius-lg); background: var(--surface-2);
  border: 1px solid var(--border); color: var(--text-faint);
  box-shadow: 0 0 0 6px rgba(154,166,180,.05);
}
.empty__icon svg { width: 26px; height: 26px; }
.empty h3 { font-size: var(--fs-md); font-weight: 600; color: var(--text); }
.empty p { font-size: var(--fs-sm); max-width: 42ch; line-height: 1.6; }

.callout {
  display: flex; gap: var(--s3); padding: var(--s3) var(--s4);
  border-radius: var(--radius-sm); border: 1px solid var(--border);
  background: var(--surface-2); font-size: var(--fs-sm);
}
.callout svg { width: 18px; height: 18px; flex: none; margin-top: 1px; }
.callout--warn   { background: var(--amber-bg); border-color: color-mix(in srgb, var(--amber) 40%, transparent); color: var(--text); }
.callout--warn svg { color: var(--amber); }
.callout--danger { background: var(--red-bg); border-color: color-mix(in srgb, var(--red) 40%, transparent); }
.callout--danger svg { color: var(--danger); }
.callout--info svg { color: var(--accent); }

/* ---- Spinner & skeleton ---- */
.spinner {
  width: 18px; height: 18px; border-radius: 50%;
  border: 2px solid var(--border-strong); border-top-color: var(--accent);
  animation: spin .75s cubic-bezier(.4, 0, .6, 1) infinite;
  filter: drop-shadow(0 0 4px rgba(91,155,213,.4));
}
.spinner--lg { width: 30px; height: 30px; border-width: 3px; }
.spinner--sm { width: 12px; height: 12px; border-width: 1.5px; display: inline-block; vertical-align: -2px; margin-right: 4px; }
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%; border-radius: var(--radius-xs);
  animation: shimmer 1.4s ease-in-out infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- Modal ---- */
.modal {
  position: fixed; inset: 0; z-index: var(--z-modal);
  display: grid; place-items: center; padding: var(--s4);
  background: rgba(0, 0, 0, .65);
  backdrop-filter: blur(4px);
  animation: fade var(--dur) var(--ease);
}
.modal__panel {
  width: 100%; max-width: 460px; max-height: 90dvh; overflow-y: auto; overflow-x: hidden;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-pop);
  animation: pop var(--dur-slow) var(--ease-out);
}
/* Opt-in wider dialog for content that needs real room (the Ollama model
   manager's search results, size pickers, and per-model actions all on one
   row) — the default 460px cap plus overflow-x:hidden was clipping them. */
.modal__panel--wide { max-width: min(760px, 94vw); }
.modal__header {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s4) var(--s5); border-bottom: 1px solid var(--border);
}
.modal__title { font-size: var(--fs-md); font-weight: 600; flex: 1; }
.modal__body { padding: var(--s5); min-width: 0; }
.modal__footer {
  display: flex; justify-content: flex-end; gap: var(--s2);
  padding: var(--s4) var(--s5); border-top: 1px solid var(--border);
}
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.98); } }

/* ---- Toasts ---- */
.toasts {
  position: fixed; bottom: var(--s5); left: 50%; transform: translateX(-50%);
  z-index: var(--z-toast); display: flex; flex-direction: column; gap: var(--s2);
  width: min(420px, calc(100vw - var(--s8))); pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s4); border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--surface-3) 96%, transparent);
  border: 1px solid var(--border-strong);
  border-left: 3px solid var(--border-strong);
  box-shadow: var(--shadow-pop); font-size: var(--fs-sm);
  backdrop-filter: blur(12px);
  animation: toast-in var(--dur-slow) var(--ease-out); pointer-events: auto;
}
.toast svg { width: 18px; height: 18px; flex: none; }
.toast--ok    { border-left-color: var(--green); }
.toast--ok    svg { color: var(--green); }
.toast--error { border-left-color: var(--danger); }
.toast--error svg { color: var(--danger); }
.toast--info  { border-left-color: var(--accent); }
.toast--info  svg { color: var(--accent); }
.toast.is-leaving { animation: toast-out var(--dur) var(--ease) forwards; }
@keyframes toast-in  { from { opacity: 0; transform: translateY(14px) scale(.97); } }
@keyframes toast-out { to   { opacity: 0; transform: translateY(8px);             } }

/* ---- Auth screen ---- */
.auth {
  min-height: 100dvh; display: grid; place-items: center; padding: var(--s5);
  background-image: radial-gradient(ellipse 70% 60% at 50% -10%, rgba(91,155,213,.1), transparent 70%);
}
.auth__card {
  width: 100%; max-width: 380px;
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-pop);
  padding: var(--s8) var(--s6);
  animation: pop var(--dur-slow) var(--ease-out);
}
.auth__brand {
  display: flex; flex-direction: column; align-items: center; gap: var(--s2);
  margin-bottom: var(--s6); text-align: center;
}
.auth__brand .sidebar__logo svg { width: 36px; height: 36px; }
.auth__brand h1 { font-size: var(--fs-lg); }
.auth__brand p { font-size: var(--fs-sm); color: var(--text-muted); }

/* ---- Log viewer ---- */
.logview {
  font-family: var(--font-mono); font-size: var(--fs-xs); line-height: 1.65;
  background: var(--bg-elevated); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: var(--s3) var(--s4);
  max-height: 60dvh; overflow: auto; white-space: pre-wrap; word-break: break-word;
  box-shadow: inset 0 2px 8px rgba(0,0,0,.25);
}

.kv { display: grid; grid-template-columns: minmax(120px, auto) 1fr; gap: var(--s2) var(--s4); font-size: var(--fs-sm); }
.kv dt { color: var(--text-muted); }
.kv dd { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* ---- App launcher cards ---- */
.app-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: var(--s4);
}
.app-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--s5);
  display: flex; flex-direction: column; gap: var(--s3);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
              transform var(--dur) var(--ease);
  position: relative; overflow: hidden;
}
.app-card::after {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 1px;
  background: linear-gradient(to right, transparent, rgba(91,155,213,.5), transparent);
  opacity: 0; transition: opacity var(--dur) var(--ease);
}
.app-card:not(.app-card--unavailable):hover {
  border-color: var(--border-strong);
  box-shadow: var(--shadow-2);
  transform: translateY(-2px);
}
.app-card:not(.app-card--unavailable):hover::after { opacity: 1; }
.app-card--unavailable { opacity: .45; filter: grayscale(.3); }
.app-card__icon {
  width: 52px; height: 52px; border-radius: var(--radius-lg);
  display: grid; place-items: center; flex: none;
  box-shadow: inset 0 1px 0 rgba(255,255,255,.06);
}
.app-card__icon svg { width: 26px; height: 26px; }
.app-card__icon--blue   { background: radial-gradient(circle at 30% 30%, rgba(91,155,213,.28), var(--blue-bg));   color: var(--blue);   border: 1px solid rgba(91,155,213,.2); }
.app-card__icon--green  { background: radial-gradient(circle at 30% 30%, rgba(69,185,138,.28), var(--green-bg));  color: var(--green);  border: 1px solid rgba(69,185,138,.2); }
.app-card__icon--purple { background: radial-gradient(circle at 30% 30%, rgba(155,135,212,.28), var(--purple-bg)); color: var(--purple); border: 1px solid rgba(155,135,212,.2); }
.app-card__icon--cyan   { background: radial-gradient(circle at 30% 30%, rgba(79,182,201,.28), var(--cyan-bg));   color: var(--cyan);   border: 1px solid rgba(79,182,201,.2); }
.app-card__icon--amber  { background: radial-gradient(circle at 30% 30%, rgba(211,164,78,.28), var(--amber-bg));  color: var(--amber);  border: 1px solid rgba(211,164,78,.2); }
.app-card__name { font-weight: 600; font-size: var(--fs-md); }
.app-card__desc { font-size: var(--fs-sm); color: var(--text-muted); flex: 1; line-height: 1.5; }
.app-card__footer { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); margin-top: var(--s2); }
.app-card__hw-note { font-size: var(--fs-xs); color: var(--text-faint); display: flex; align-items: center; gap: 4px; }

/* ---- App folders (iOS-style groups) ---- */
.app-folder-tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--s5);
  display: flex; flex-direction: column; align-items: center; gap: var(--s3);
  cursor: pointer; transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.app-folder-tile:hover { border-color: var(--border-strong); box-shadow: var(--shadow-2); }
.app-folder-tile__icons {
  display: grid; gap: 6px;   /* 4 fixed columns (JS), rows grow with content */
  width: 100%; padding: 8px;
  background: var(--surface-2); border-radius: var(--radius-md);
}
.app-folder-tile__icons > * {
  aspect-ratio: 1;   /* cell size = tile-width / 4, constant regardless of row count */
  border-radius: 6px; display: grid; place-items: center; overflow: hidden;
  background: var(--surface-3);
  /* Without this, a grid item's content (a fixed-size <img>, an <svg>) can
     force its track wider than the 1fr share, pushing cells past the row's
     box and making icons visually overlap/spill into each other. */
  min-width: 0; min-height: 0;
}
.app-folder-tile__icons svg { width: 22px; height: 22px; max-width: 100%; max-height: 100%; }
.app-folder-tile__icons img { max-width: 100%; max-height: 100%; }
.app-folder-tile__more {
  font-size: var(--fs-xs); font-weight: 700; color: var(--text-muted);
  background: var(--surface-3);
}

/* ---- Organize-mode drag reordering ---- */
.is-draggable { cursor: grab; }
.is-draggable.is-dragging {
  cursor: grabbing;
  /* The "picked up" feel: lift + tilt slightly, dim a touch, deepen the
     shadow. Sits on top of .app-card's existing transform/box-shadow
     transitions, so this animates in and back out smoothly. */
  transform: scale(1.06) rotate(-1deg);
  box-shadow: 0 18px 38px rgba(0,0,0,.35);
  opacity: .85;
  z-index: 5;
}
.app-folder-tile__name { font-weight: 600; font-size: var(--fs-sm); text-align: center; }
.app-folder-tile__count { font-size: var(--fs-xs); color: var(--text-muted); }

.app-folder-overlay {
  position: fixed; inset: 0;
  /* Between --z-drawer (50) and --z-modal (100) — a gear-menu modal opened
     from inside an expanded folder (Manage/Move/etc.) must render ON TOP of
     this, not behind it. The old literal 900 sat above --z-modal entirely,
     which is what hid the modal. */
  z-index: 60;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  display: flex; align-items: center; justify-content: center;
  padding: var(--s6);
  opacity: 0; transition: opacity var(--dur) var(--ease);
}
.app-folder-overlay.is-open { opacity: 1; }
.app-folder-panel {
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-lg); box-shadow: var(--shadow-2);
  width: min(920px, 100%); max-height: 85vh; overflow: auto;
  display: flex; flex-direction: column; gap: var(--s4); padding: var(--s5);
  transform: scale(.85); opacity: 0;
  transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
}
.app-folder-overlay.is-open .app-folder-panel { transform: scale(1); opacity: 1; }
.app-folder-panel__header { display: flex; align-items: center; gap: var(--s3); }
.app-folder-panel__name {
  font-size: var(--fs-lg); font-weight: 700; flex: 1; background: transparent;
  border: 1px solid transparent; border-radius: var(--radius-sm); padding: 4px 8px;
}
.app-folder-panel__name:focus { border-color: var(--border-strong); background: var(--surface-2); outline: none; }
.app-folder-panel__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--s4); }

/* ---- Nav group divider ---- */
.nav-divider {
  margin: var(--s3) var(--s3) var(--s1);
  padding: var(--s3) 0 0 var(--s1);
  border-top: 1px solid var(--border);
  font-size: 10px; color: var(--text-faint);
  font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
}

/* ---- SMS app ---- */
.sms-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: var(--s4);
  height: calc(100dvh - var(--header-h) - var(--s8) * 2);
  min-height: 400px;
}
@media (max-width: 640px) {
  .sms-layout { grid-template-columns: 1fr; height: auto; }
  .sms-thread-panel { display: none; }
  .sms-layout.thread-open .sms-contact-panel { display: none; }
  .sms-layout.thread-open .sms-thread-panel { display: flex; }
}
.sms-contact-panel, .sms-thread-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); overflow: hidden;
  display: flex; flex-direction: column;
}
.sms-panel-head {
  padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: var(--s3);
  font-weight: 600; font-size: var(--fs-sm); min-height: 48px; flex: none;
}
.sms-contact-list { flex: 1; overflow-y: auto; }
.sms-contact-item {
  padding: var(--s3) var(--s4); cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--dur) var(--ease);
  display: grid; grid-template-columns: 1fr auto; gap: var(--s2) var(--s4);
  align-items: start;
}
.sms-contact-item:hover { background: var(--surface-2); }
.sms-contact-item.is-active { background: var(--blue-bg); }
.sms-contact-number { font-size: var(--fs-sm); font-weight: 500; }
.sms-contact-preview { font-size: var(--fs-xs); color: var(--text-muted); grid-column: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sms-contact-time { font-size: var(--fs-xs); color: var(--text-faint); white-space: nowrap; }
.sms-messages { flex: 1; overflow-y: auto; padding: var(--s4); display: flex; flex-direction: column; gap: var(--s3); }
.sms-bubble {
  max-width: 78%; padding: var(--s2) var(--s3);
  border-radius: var(--radius-lg); font-size: var(--fs-sm); line-height: 1.55;
}
.sms-bubble--in {
  background: var(--surface-3); color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: var(--radius-xs); align-self: flex-start;
}
.sms-bubble--out {
  background: linear-gradient(135deg, rgba(91,155,213,.22), rgba(91,155,213,.13));
  color: var(--text); border: 1px solid rgba(91,155,213,.28);
  border-bottom-right-radius: var(--radius-xs); align-self: flex-end;
}
.sms-bubble-time { font-size: var(--fs-xs); color: var(--text-faint); margin-top: 3px; }
.sms-compose {
  padding: var(--s3) var(--s4); border-top: 1px solid var(--border);
  display: flex; gap: var(--s2); flex: none;
}
.sms-compose textarea {
  flex: 1; min-height: 40px; max-height: 120px; resize: none;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: var(--s2) var(--s3);
  font: var(--fs-sm) var(--font-ui); color: var(--text); line-height: 1.5;
}
.sms-compose textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--focus-ring); }
.sms-empty { display: flex; flex-direction: column; align-items: center; justify-content: center; flex: 1; gap: var(--s3); color: var(--text-faint); }

/* ---- Dial pad (calls app) ---- */
.dialpad {
  display: grid; grid-template-columns: repeat(3, 1fr);
  gap: var(--s2); max-width: 280px; margin: 0 auto;
}
.dialpad-btn {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  height: 68px; border-radius: var(--radius-lg);
  background: var(--surface-2); border: 1px solid var(--border);
  font-weight: 600; font-size: var(--fs-lg); line-height: 1; gap: 2px;
  transition: background var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
              transform var(--dur) var(--ease);
}
.dialpad-btn:hover { background: var(--surface-3); }
.dialpad-btn:active { transform: scale(.95); background: var(--surface); }
.dialpad-btn small { font-size: 9px; font-weight: 400; color: var(--text-faint); letter-spacing: .1em; }
.dialpad-display {
  font-family: var(--font-mono); font-size: var(--fs-xl); font-weight: 300;
  text-align: center; letter-spacing: .08em; color: var(--text);
  min-height: 52px; padding: var(--s2); word-break: break-all;
  grid-column: 1 / -1;
  border-bottom: 1px solid var(--border); margin-bottom: var(--s1);
}
.dialpad-btn--call {
  background: radial-gradient(circle at 40% 35%, rgba(69,185,138,.3), var(--green-bg));
  border-color: rgba(69,185,138,.3); color: var(--green);
  box-shadow: 0 0 16px rgba(69,185,138,.1);
}
.dialpad-btn--call:hover {
  background: radial-gradient(circle at 40% 35%, rgba(69,185,138,.4), rgba(69,185,138,.18));
  box-shadow: 0 0 20px rgba(69,185,138,.2);
}

/* ---- Page header (apps / sub-pages) ---- */
.page-header { margin-bottom: var(--s8); }
.page-title  { font-size: var(--fs-xl); font-weight: 600; margin: 0 0 var(--s2); }
.page-sub    { font-size: var(--fs-sm); color: var(--text-muted); margin: 0; }

/* ---- Sidebar footer refinement ---- */
.sidebar__foot { padding: var(--s3); border-top: 1px solid var(--border); flex: none; }
.sidebar__foot .btn--ghost { color: var(--text-faint); }
.sidebar__foot .btn--ghost:hover { color: var(--text); background: var(--surface-2); }

/* ---- Page-enter animation on view children ---- */
.view > * { animation: page-enter var(--dur-slow) var(--ease-out) both; }
.view > *:nth-child(2) { animation-delay: 40ms; }
.view > *:nth-child(3) { animation-delay: 80ms; }
.view > *:nth-child(4) { animation-delay: 110ms; }
@keyframes page-enter { from { opacity: 0; transform: translateY(10px); } }

/* ---- Input focus — add inner glow ---- */
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 3px rgba(91,155,213,.15);
}

/* ---- Table row striping ---- */
.table tbody tr:nth-child(even) { background: rgba(255,255,255,.012); }

/* ---- Topbar title ---- */
.topbar__title { font-size: var(--fs-md); font-weight: 600; letter-spacing: -.01em; }

/* ---- Appearance region/zoom dropdowns: keep the native option popup legible
   on dark themes (options otherwise inherit low-contrast system colors). ---- */
.anim-select { color-scheme: dark; }
html[data-theme="light"] .anim-select { color-scheme: light; }
.anim-select option { background-color: var(--surface-2); color: var(--text); }

/* ── Pull-to-refresh (installed PWA only) ─────────────────────────────────────
   The custom pull-to-refresh (js/pull-refresh.js) runs ONLY in a standalone PWA
   (where base.css locks the body). In a normal browser tab we leave the browser's
   own pull-to-refresh alone, so there's never two. */
.ptr {
  position: fixed;
  /* At the top bar's bottom edge; JS rides it down into the gap the content opens
     as you pull, and keeps it above the content in the stack. */
  top: calc(var(--header-h, 56px) + env(safe-area-inset-top, 0px));
  left: 50%;
  z-index: calc(var(--z-sticky, 100) + 5);
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--surface-1, #161b22);
  border: 1px solid var(--border, #30363d);
  box-shadow: var(--shadow-pop, 0 6px 24px rgba(0,0,0,.35));
  opacity: 0;
  transform: translate(-50%, 0);
  will-change: transform, opacity;
  pointer-events: none;
}
.ptr__spin {
  width: 20px; height: 20px; border-radius: 50%;
  --ptr-c: var(--accent, #58a6ff);   /* blue by default, green when ready (below) */
  /* A ring whose --ptr-p (0..1, set from JS as you pull) fills with --ptr-c. */
  background: conic-gradient(var(--ptr-c) calc(var(--ptr-p, .1) * 1turn), var(--border, #30363d) 0);
  -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 3px), #000 calc(100% - 3px));
}
.ptr.is-ready .ptr__spin { --ptr-c: var(--good, #3fb950); }   /* turned green past the trigger */
.ptr.is-refreshing .ptr__spin { animation: spin .7s linear infinite; }   /* spins while reloading */
/* ── Settings shell (js/settings-shell.js) ───────────────────────────────────
   Phone/computer-style settings: a searchable category rail + a detail pane.
   Desktop shows both side by side; narrow screens show the rail full-width
   and slide the detail pane in on top of it (back button returns). */
.settings-shell {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: var(--s5);
  align-items: start;
}

.settings-shell__rail {
  display: flex; flex-direction: column; gap: var(--s2);
  position: sticky; top: var(--s4);
}

.settings-shell__search {
  display: flex; align-items: center; gap: var(--s2);
  padding: 0 var(--s3);
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text-faint);
}
.settings-shell__search-input {
  border: none; background: transparent; outline: none;
  padding: var(--s2) 0; width: 100%;
  color: var(--text); font-size: var(--fs-sm);
}

.settings-shell__cats { display: flex; flex-direction: column; gap: 2px; }

.settings-shell__cat {
  display: flex; align-items: center; gap: var(--s3);
  width: 100%; text-align: left;
  padding: var(--s2) var(--s3);
  border: none; border-radius: var(--radius);
  background: transparent; color: var(--text);
  cursor: pointer; font: inherit; font-size: var(--fs-sm);
}
.settings-shell__cat:hover { background: var(--surface-2); }
.settings-shell__cat.is-active { background: var(--surface-3); font-weight: 600; }
.settings-shell__cat-icon { display: flex; color: var(--text-muted); flex-shrink: 0; }
.settings-shell__cat.is-active .settings-shell__cat-icon { color: var(--accent); }
.settings-shell__cat-label { flex: 1; display: flex; flex-direction: column; gap: 1px; min-width: 0; }
.settings-shell__cat-hits {
  font-size: var(--fs-xs); color: var(--text-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.settings-shell__cat > svg:last-child { color: var(--text-faint); flex-shrink: 0; }

.settings-shell__no-results { padding: var(--s3); }

.settings-shell__show-all {
  margin-top: var(--s1);
  padding: var(--s2) var(--s3);
  border: 1px dashed var(--border); border-radius: var(--radius);
  background: transparent; color: var(--accent);
  cursor: pointer; font: inherit; font-size: var(--fs-sm); text-align: left;
}
.settings-shell__show-all:hover { background: var(--surface-2); }

.settings-shell__detail { min-width: 0; }
.settings-shell__detail-header {
  display: none;   /* shown only on mobile, where it doubles as a back bar */
  align-items: center; gap: var(--s3);
  margin-bottom: var(--s4);
}
.settings-shell__back {
  display: flex; align-items: center; gap: var(--s1);
  border: none; background: transparent; color: var(--accent);
  cursor: pointer; font: inherit; font-size: var(--fs-sm); padding: var(--s1) 0;
}
.settings-shell__detail-title { font-weight: 700; font-size: var(--fs-lg); }
.settings-shell__all-heading {
  font-size: var(--fs-xs); text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-faint); margin: var(--s5) 0 var(--s2);
}
.settings-shell__all-heading:first-child { margin-top: 0; }

@media (max-width: 1023px) {
  /* `.view > *` (base.css) plays a page-enter animation on transform, which
     makes this element a transform-affected box — that silently turns it
     into the containing block for any `position: fixed` descendant instead
     of the viewport (found live: the detail pane rendered at ~60px tall,
     sized to the rail's own content box, not the screen). Made explicit
     with `position: relative` + a real height so `.settings-shell__detail`
     below can reliably use `position: absolute` against IT, rather than
     depending on that animation side-effect. */
  .settings-shell {
    grid-template-columns: 1fr; gap: 0;
    position: relative;
    min-height: calc(100dvh - var(--header-h, 56px));
  }
  .settings-shell__rail { position: static; }
  .settings-shell__detail {
    position: absolute; inset: 0; z-index: var(--z-drawer);
    background: var(--bg); overflow-y: auto;
    padding: var(--s5) var(--s4) var(--s10);
    transform: translateX(100%); transition: transform var(--dur) var(--ease);
  }
  .settings-shell--detail-open .settings-shell__detail { transform: translateX(0); }
  .settings-shell--detail-open .settings-shell__rail { display: none; }
  .settings-shell__detail-header { display: flex; }
}
