@charset "utf-8";
/* ==========================================================================
   CYB — shell design system + layout
   RTL-first. Logical properties only. No external fonts, no build step.
   Sections:
     1 tokens · 2 reset · 3 typography · 4 primitives · 5 layout
     6 sidebar · 7 topbar · 8 content & views · 9 tiles · 10 forms
     11 modals/sheet/toast · 12 tabbar · 13 onboarding · 14 utilities
   ========================================================================== */

/* --------------------------------------------------------------------------
   1. Tokens
   -------------------------------------------------------------------------- */
:root {
  /* brand orange scale */
  --orange-50:  #FFF7ED;
  --orange-100: #FFEDD5;
  --orange-300: #FDBA74;
  --orange-400: #FB923C;
  --orange-500: #F97316;
  --orange-600: #EA580C;
  --orange-700: #C2410C;

  /* status */
  --success: #16A34A;
  --warning: #D97706;
  --danger:  #DC2626;
  /* text-safe variants for use on tinted backgrounds (AA at 12–16px) */
  --danger-ink:  #B91C1C;
  --success-ink: #15803D;
  --warning-ink: #B45309;

  /* light theme (warm neutrals) */
  --bg:          #FAFAF9;
  --surface:     #FFFFFF;
  --surface-2:   #F5F5F4;
  --border:      #E7E5E4;
  --text:        #1C1917;
  --text-muted:  #78716C;

  --accent:        var(--orange-500);
  --accent-strong: var(--orange-700);
  --accent-tint:   var(--orange-100);
  --on-accent:     #FFFFFF;
  --success-bg: #F0FDF4;
  --warning-bg: #FFFBEB;
  --danger-bg:  #FEF2F2;
  /* filled primary button: white text only on --orange-700 or darker */
  --btn-primary-text: #FFFFFF;
  --btn-primary-hover-bg: #9A3412;   /* --orange-800, 7.3:1 with white */

  /* shape + motion */
  --r-control: 8px;
  --r-card: 12px;
  --r-modal: 16px;
  --border-w: 1px;
  --shadow-1: 0 1px 2px rgba(28, 25, 23, .06);
  --shadow-2: 0 4px 12px rgba(28, 25, 23, .08);
  --shadow-pop: 0 12px 32px -8px rgba(28, 25, 23, .22), 0 2px 6px rgba(28, 25, 23, .08);
  --dur: 160ms;
  --dur-slow: 200ms;
  --ease: cubic-bezier(.2, .7, .3, 1);

  /* metrics */
  --sidebar-w: 248px;
  --sidebar-w-collapsed: 72px;
  --topbar-h: 56px;
  --tabbar-h: 64px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-i: env(safe-area-inset-left, 0px);
  --safe-e: env(safe-area-inset-right, 0px);

  /* type */
  --font: system-ui, -apple-system, "Segoe UI", "Noto Sans Arabic",
          "Noto Naskh Arabic", Tahoma, sans-serif;
  --fs-12: 12px;
  --fs-13: 13px;   /* dense data tables */
  --fs-14: 14px;
  --fs-16: 16px;
  --fs-18: 18px;
  --fs-22: 22px;
  --fs-28: 28px;

  --tap: 44px;
}

/* ---- Dark theme: follows the OS ---- */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg:         #141210;
    --surface:    #1C1917;
    --surface-2:  #26211E;
    --border:     #2E2925;
    --text:       #FAFAF9;
    --text-muted: #A8A29E;

    --accent:        var(--orange-400);
    --accent-strong: var(--orange-500);
    --accent-tint:   rgba(249, 115, 22, .14);
    --on-accent:     #1C1917;
    --success-bg: rgba(22, 163, 74, .16);
    --warning-bg: rgba(217, 119, 6, .16);
    --danger-bg:  rgba(220, 38, 38, .16);
    --danger-ink:  #FCA5A5;
    --success-ink: #86EFAC;
    --warning-ink: #FCD34D;
    --btn-primary-text: #1C1917;
    --btn-primary-hover-bg: var(--orange-400);

    --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
    --shadow-2: 0 4px 12px rgba(0, 0, 0, .45);
    --shadow-pop: 0 12px 32px -8px rgba(0, 0, 0, .7), 0 2px 6px rgba(0, 0, 0, .5);
  }
}

/* ---- Dark theme: chosen by hand ---- */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg:         #141210;
  --surface:    #1C1917;
  --surface-2:  #26211E;
  --border:     #2E2925;
  --text:       #FAFAF9;
  --text-muted: #A8A29E;

  --accent:        var(--orange-400);
  --accent-strong: var(--orange-500);
  --accent-tint:   rgba(249, 115, 22, .14);
  --on-accent:     #1C1917;
  --success-bg: rgba(22, 163, 74, .16);
  --warning-bg: rgba(217, 119, 6, .16);
  --danger-bg:  rgba(220, 38, 38, .16);
  --danger-ink:  #FCA5A5;
  --success-ink: #86EFAC;
  --warning-ink: #FCD34D;
  --btn-primary-text: #1C1917;
  --btn-primary-hover-bg: var(--orange-400);

  --shadow-1: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow-2: 0 4px 12px rgba(0, 0, 0, .45);
  --shadow-pop: 0 12px 32px -8px rgba(0, 0, 0, .7), 0 2px 6px rgba(0, 0, 0, .5);
}

:root[data-theme="light"] { color-scheme: light; }

/* --------------------------------------------------------------------------
   2. Reset
   -------------------------------------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow-x: hidden;
  overscroll-behavior-y: none;
}

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-14);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

img, svg, video, canvas, iframe { display: block; max-width: 100%; }
img, svg { height: auto; }

button, input, select, textarea {
  font: inherit;
  color: inherit;
  margin: 0;
}
button { background: none; border: 0; cursor: pointer; }

a { color: var(--accent-strong); text-decoration: none; }
a:hover { text-decoration: underline; }

ul, ol { margin: 0; padding: 0; list-style: none; }

h1, h2, h3, h4, p, figure { margin: 0; }

:where(h1, h2, h3, h4) { font-weight: 600; line-height: 1.3; }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 4px;
}
:focus:not(:focus-visible) { outline: none; }

::selection { background: var(--accent-tint); }

.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.skip-link {
  position: fixed;
  inset-block-start: calc(var(--safe-t) + 8px);
  inset-inline-start: 8px;
  z-index: 200;
  padding: 10px 16px;
  min-height: var(--tap);
  display: inline-flex;
  align-items: center;
  background: var(--surface);
  color: var(--text);
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-control);
  box-shadow: var(--shadow-pop);
  transform: translateY(-200%);
  transition: transform var(--dur) var(--ease);
}
.skip-link:focus { transform: translateY(0); }

.tnum { font-variant-numeric: tabular-nums; font-feature-settings: "tnum" 1; }

/* --------------------------------------------------------------------------
   3. Typography helpers
   -------------------------------------------------------------------------- */
.page-head { margin-block-end: 20px; }
.page-head h2 { font-size: var(--fs-22); letter-spacing: -.01em; }
.page-sub {
  margin-block-start: 6px;
  color: var(--text-muted);
  font-size: var(--fs-14);
  line-height: 1.7;           /* Arabic paragraphs breathe */
  max-inline-size: 68ch;
}
.card-sub {
  color: var(--text-muted);
  font-size: var(--fs-14);
  line-height: 1.7;
  margin-block: 4px 14px;
}
.muted { color: var(--text-muted); }

/* --------------------------------------------------------------------------
   4. Primitives
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 8px 16px;
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-control);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-14);
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--dur) var(--ease),
              border-color var(--dur) var(--ease),
              transform var(--dur) var(--ease);
}
.btn:hover { background: var(--surface-2); border-color: var(--text-muted); }
.btn:active { transform: translateY(1px); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.btn.primary {
  background: var(--accent-strong);
  border-color: var(--accent-strong);
  color: var(--btn-primary-text);   /* #FFF on --orange-700 = 5.2:1; #1C1917 on --orange-500 = 7.4:1 */
}
.btn.primary:hover {
  background: var(--btn-primary-hover-bg);
  border-color: var(--btn-primary-hover-bg);
}
.btn.danger { color: var(--danger-ink); border-color: color-mix(in srgb, var(--danger) 60%, var(--border)); background: var(--surface); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--surface-2); border-color: var(--border); }
.btn.sm { min-height: 36px; padding: 6px 12px; font-size: var(--fs-12); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  inline-size: var(--tap);
  block-size: var(--tap);
  flex: 0 0 auto;
  border-radius: var(--r-control);
  color: var(--text-muted);
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.is-on { color: var(--accent-strong); }

.ico { inline-size: 20px; block-size: 20px; flex: 0 0 auto; }
.ico-sm { inline-size: 16px; block-size: 16px; }

.card {
  background: var(--surface);
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-card);
  padding: 20px;
  box-shadow: var(--shadow-1);
}
.card h3 { font-size: var(--fs-16); }
.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-block-start: 16px;
}

.kv { display: grid; gap: 8px; }
.kv-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  padding-block: 6px;
  border-block-end: var(--border-w) solid var(--border);
  font-size: var(--fs-14);
}
.kv-row:last-child { border-block-end: 0; }
.kv-row dt, .kv-row .k { color: var(--text-muted); }
.kv-row dd, .kv-row .v {
  margin: 0;
  font-weight: 500;
  text-align: end;
  word-break: break-word;
}

/* sync diagnostics table */
.diag-wrap {
  margin-block-start: 16px;
  overflow-x: auto;
  border: var(--border-w) solid var(--border);
  border-radius: calc(var(--r-card) * 0.6);
}
.diag-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-13);
  white-space: nowrap;
}
.diag-table th,
.diag-table td {
  padding: 8px 10px;
  text-align: start;
  border-block-end: var(--border-w) solid var(--border);
}
.diag-table thead th {
  font-weight: 600;
  color: var(--text-muted);
  background: var(--surface-2);
  position: sticky;
  inset-block-start: 0;
}
.diag-table tbody tr:last-child td { border-block-end: 0; }
.diag-table .mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  direction: ltr;
  unicode-bidi: isolate;
}
.diag-table .ok { color: var(--success-ink); }
.diag-table .warn { color: var(--warning-ink); }
.diag-table .bad { color: var(--danger-ink); }
.diag-empty {
  padding: 12px 10px;
  color: var(--text-muted);
  font-size: var(--fs-13);
}

/* segmented control */
.seg {
  display: inline-flex;
  padding: 3px;
  gap: 3px;
  background: var(--surface-2);
  border: var(--border-w) solid var(--border);
  border-radius: 10px;
  max-inline-size: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg button {
  min-height: 38px;
  padding: 6px 14px;
  border-radius: 7px;
  font-size: var(--fs-14);
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.seg button:hover { color: var(--text); }
.seg button[aria-checked="true"] {
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
  box-shadow: var(--shadow-1);
}

/* --------------------------------------------------------------------------
   5. Layout
   -------------------------------------------------------------------------- */
.app {
  display: flex;
  block-size: 100vh;
  block-size: 100dvh;
  inline-size: 100%;
  padding-inline-start: var(--safe-i);
  padding-inline-end: var(--safe-e);
  overflow: hidden;
}

.main {
  flex: 1 1 auto;
  min-inline-size: 0;
  display: flex;
  flex-direction: column;
  block-size: 100%;
}

.content {
  flex: 1 1 auto;
  min-block-size: 0;
  overflow: auto;
  overflow-x: hidden;
  padding: 24px;
  padding-block-end: calc(24px + var(--safe-b));
  scrollbar-gutter: stable;
}
.content:focus { outline: none; }

.view { max-inline-size: 1180px; margin-inline: auto; }
.view[hidden] { display: none; }

/* --------------------------------------------------------------------------
   6. Sidebar
   -------------------------------------------------------------------------- */
.sidebar {
  flex: 0 0 auto;
  inline-size: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-inline-size: 0;
  background: var(--surface);
  border-inline-end: var(--border-w) solid var(--border);
  padding-block-start: var(--safe-t);
  padding-block-end: var(--safe-b);
  transition: inline-size var(--dur-slow) var(--ease);
  overflow: hidden;
}
.sidebar[hidden] { display: none; }

/* collapsed */
.app.is-collapsed .sidebar { inline-size: var(--sidebar-w-collapsed); }
.app.is-collapsed .side-head { padding-inline: 12px; justify-content: center; }
.app.is-collapsed .wordmark,
.app.is-collapsed .apb-label,
.app.is-collapsed .sfl,
.app.is-collapsed .nav-item-label,
.app.is-collapsed .side-foot-btn .sync-text { display: none; }
.app.is-collapsed .collapse-btn { display: none; }
.app.is-collapsed .nav-item,
.app.is-collapsed .add-page-btn,
.app.is-collapsed .side-foot-btn {
  justify-content: center;
  padding-inline: 0;
  inline-size: 44px;
  margin-inline: auto;
}
.app.is-collapsed .nav-item::before { inset-inline-start: 0; }
.app.is-collapsed .side-foot { padding-inline: 12px; }

.side-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  block-size: var(--topbar-h);
  padding-inline: 16px;
  flex: 0 0 auto;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-inline-size: 0;
  color: var(--text);
  text-decoration: none;
  border-radius: var(--r-control);
}
.brand:hover { text-decoration: none; }
.brand-mark {
  display: grid;
  place-items: center;
  inline-size: 32px;
  block-size: 32px;
  flex: 0 0 auto;
}
.brand-mark img { inline-size: 32px; block-size: 32px; border-radius: 9px; }
.wordmark {
  font-size: var(--fs-18);
  font-weight: 700;
  letter-spacing: .14em;
  line-height: 1;
}

.nav {
  flex: 1 1 auto;
  min-block-size: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  scrollbar-width: thin;
}
.nav-item {
  position: relative;
  display: flex;
  align-items: center;
  gap: 10px;
  min-block-size: var(--tap);
  padding: 8px 12px;
  border-radius: var(--r-control);
  color: var(--text-muted);
  font-size: var(--fs-14);
  font-weight: 500;
  text-decoration: none;
  text-align: start;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.nav-item:hover { background: var(--surface-2); color: var(--text); text-decoration: none; }
.nav-item-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-item-emoji { inline-size: 22px; text-align: center; font-size: 15px; flex: 0 0 auto; }

/* active: soft orange tint + 3px indicator on the inline-start edge + bold */
.nav-item.is-active {
  background: var(--accent-tint);
  color: var(--text);
  font-weight: 600;
}
.nav-item.is-active::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  inset-block: 8px;
  inline-size: 3px;
  border-radius: 0 3px 3px 0;
  background: var(--accent);
}
:root[dir="ltr"] .nav-item.is-active::before { border-radius: 3px 0 0 3px; }
.nav-item[hidden] { display: none; }

.side-divider {
  flex: 0 0 auto;
  block-size: 1px;
  margin: 8px 16px;
  background: var(--border);
}

.add-page-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  min-block-size: var(--tap);
  margin: 4px 12px 8px;
  padding: 8px 12px;
  border: var(--border-w) dashed var(--border);
  border-radius: var(--r-control);
  color: var(--text-muted);
  font-size: var(--fs-14);
  font-weight: 500;
  transition: color var(--dur) var(--ease), border-color var(--dur) var(--ease),
              background var(--dur) var(--ease);
}
.add-page-btn:hover {
  color: var(--accent-strong);
  border-color: var(--accent);
  background: var(--accent-tint);
}
.apb-ico { display: grid; place-items: center; inline-size: 22px; flex: 0 0 auto; }

.side-foot {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 12px calc(8px + var(--safe-b));
  border-block-start: var(--border-w) solid var(--border);
}
.side-foot-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  min-block-size: var(--tap);
  padding: 8px 12px;
  border-radius: var(--r-control);
  color: var(--text-muted);
  font-size: var(--fs-12);
  font-weight: 500;
  text-align: start;
  transition: background var(--dur) var(--ease), color var(--dur) var(--ease);
}
.side-foot-btn:hover { background: var(--surface-2); color: var(--text); }
.sfi { display: grid; place-items: center; inline-size: 22px; flex: 0 0 auto; }

/* sync chip */
.sync-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-block-size: 36px;
  padding: 6px 12px;
  border: var(--border-w) solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text-muted);
  font-size: var(--fs-12);
  font-weight: 500;
  white-space: nowrap;
  transition: background var(--dur) var(--ease), border-color var(--dur) var(--ease),
              color var(--dur) var(--ease);
}
.sync-chip:hover { background: var(--surface-2); color: var(--text); }
.sync-chip .dot {
  inline-size: 8px;
  block-size: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  flex: 0 0 auto;
}
.sync-chip .sync-text { overflow: hidden; text-overflow: ellipsis; }
.sync-chip[data-state="synced"]  { border-color: color-mix(in srgb, var(--success) 40%, var(--border)); }
.sync-chip[data-state="synced"]  .dot { background: var(--success); }
.sync-chip[data-state="syncing"] .dot { background: var(--warning); animation: pulse-dot 1.1s infinite; }
.sync-chip[data-state="offline"] .dot { background: var(--text-muted); }
.sync-chip[data-state="error"]   { border-color: color-mix(in srgb, var(--danger) 55%, var(--border)); }
.sync-chip[data-state="error"]   .dot { background: var(--danger); }
.sync-chip[data-state="off"]     .dot { background: var(--border); }

@keyframes pulse-dot { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }

/* drawer (mobile) */
.scrim {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(28, 25, 23, .45);
  animation: fade-in var(--dur) var(--ease);
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

/* --------------------------------------------------------------------------
   7. Topbar
   -------------------------------------------------------------------------- */
.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  block-size: calc(var(--topbar-h) + var(--safe-t));
  padding-block-start: var(--safe-t);
  padding-inline: 16px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: saturate(1.4) blur(8px);
  -webkit-backdrop-filter: saturate(1.4) blur(8px);
  border-block-end: var(--border-w) solid var(--border);
}
.topbar-title {
  flex: 1 1 auto;
  min-inline-size: 0;
  display: flex;
  align-items: center;
  gap: 8px;
}
.tb-emoji { font-size: 18px; line-height: 1; flex: 0 0 auto; }
.topbar-title h1 {
  font-size: var(--fs-16);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.topbar-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  flex: 0 0 auto;
}
.menu-btn { display: none; }

.theme-wrap { position: relative; }
.menu {
  position: absolute;
  inset-block-start: calc(100% + 6px);
  inset-inline-end: 0;
  z-index: 60;
  min-inline-size: 148px;
  padding: 4px;
  background: var(--surface);
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-pop);
  animation: menu-in var(--dur) var(--ease);
}
.menu[hidden] { display: none; }
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  inline-size: 100%;
  min-block-size: 40px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: var(--fs-14);
  color: var(--text);
  text-align: start;
}
.menu button:hover { background: var(--surface-2); }
.menu button[aria-checked="true"] { font-weight: 600; color: var(--accent-strong); }
.menu button[aria-checked="true"]::after { content: "✓"; margin-inline-start: auto; }

/* --------------------------------------------------------------------------
   8. Content & views
   -------------------------------------------------------------------------- */
.view-page { display: flex; flex-direction: column; gap: 12px; block-size: 100%; }
.view-page[hidden] { display: none; }

.frame {
  position: relative;
  flex: 1 1 auto;
  min-block-size: 0;
  background: var(--surface);
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-card);
  overflow: hidden;
}
.frame iframe {
  inline-size: 100%;
  block-size: 100%;
  border: 0;
  display: block;
  background: var(--surface);
}
.frame iframe[hidden] { display: none; }

.skeleton {
  position: absolute;
  inset: 0;
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  background: var(--surface);
}
.skeleton[hidden] { display: none; }
.sk-row {
  block-size: 14px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--border) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: sk 1.4s ease infinite;
}
.sk-row-lg { block-size: 26px; inline-size: 40%; }
.sk-row-sm { inline-size: 60%; }
@keyframes sk { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.sr-status {
  position: absolute;
  inset-block-end: 8px;
  inset-inline: 8px;
  text-align: center;
  font-size: var(--fs-12);
  color: var(--text-muted);
  pointer-events: none;
}
.embed-note {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-control);
  background: var(--warning-bg);
  color: var(--text);
  font-size: var(--fs-12);
  line-height: 1.6;
}
.embed-note[hidden] { display: none; }

/* settings */
.settings-grid {
  display: grid;
  gap: 16px;
  grid-template-columns: 1fr;
}

/* --------------------------------------------------------------------------
   9. Home tiles
   -------------------------------------------------------------------------- */
.status-strip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  margin-block-end: 20px;
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-card);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  font-size: var(--fs-12);
  color: var(--text-muted);
}
.strip-ico { display: grid; place-items: center; flex: 0 0 auto; }
.strip-text { flex: 1 1 auto; min-inline-size: 0; }
.strip-action {
  flex: 0 0 auto;
  min-block-size: 32px;
  padding: 4px 12px;
  border: var(--border-w) solid var(--border);
  border-radius: 999px;
  font-size: var(--fs-12);
  font-weight: 500;
  color: var(--text);
}
.strip-action:hover { background: var(--surface-2); }
.strip-action[hidden] { display: none; }
.strip-action:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* the dot mirrors the sync state; app.js sets data-state on #statusStrip */
.status-strip .strip-ico::before {
  content: '';
  inline-size: 8px;
  block-size: 8px;
  border-radius: 50%;
  background: var(--text-muted);
}
.status-strip[data-state="synced"] .strip-ico::before { background: var(--success); }
.status-strip[data-state="syncing"] .strip-ico::before { background: var(--accent); }
.status-strip[data-state="offline"] .strip-ico::before { background: var(--warning); }
.status-strip[data-state="error"] .strip-ico::before { background: var(--danger); }

.tiles {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
}
.tile {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 16px;
  min-block-size: 88px;
  text-align: start;
  background: var(--surface);
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-card);
  box-shadow: var(--shadow-1);
  text-decoration: none;
  color: var(--text);
  transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease),
              border-color var(--dur) var(--ease);
}
.tile:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-2);
  border-color: var(--text-muted);
  text-decoration: none;
}
.tile:active { transform: translateY(0); }
.tile-emoji {
  inline-size: 40px;
  block-size: 40px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  font-size: 20px;
  background: var(--surface-2);
  border-radius: 10px;
}
.tile-body { min-inline-size: 0; flex: 1 1 auto; }
.tile-name {
  font-size: var(--fs-16);
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile-meta {
  margin-block-start: 3px;
  font-size: var(--fs-12);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tile--add {
  border-style: dashed;
  border-color: var(--border);
  color: var(--text-muted);
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 6px;
  font-weight: 500;
}
.tile--add:hover { color: var(--accent-strong); border-color: var(--accent); background: var(--accent-tint); }

.home-hint {
  margin-block-start: 20px;
  padding: 12px 14px;
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-control);
  background: var(--surface);
  color: var(--text-muted);
  font-size: var(--fs-12);
  line-height: 1.7;
}
.home-hint[hidden] { display: none; }

/* --------------------------------------------------------------------------
   10. Forms & manage list
   -------------------------------------------------------------------------- */
.field { display: block; margin-block-end: 16px; }
.field-label {
  display: block;
  margin-block-end: 6px;
  font-size: var(--fs-12);
  font-weight: 600;
  color: var(--text-muted);
}
.field input[type="text"],
.field input[type="url"],
.field input[type="password"],
.field select,
.field textarea {
  inline-size: 100%;
  min-block-size: var(--tap);
  padding: 10px 12px;
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-control);
  background: var(--surface);
  color: var(--text);
  font-size: var(--fs-14);
  transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
.field textarea { min-block-size: 88px; resize: vertical; line-height: 1.7; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-tint);
}
.field input[aria-invalid="true"] { border-color: var(--danger); }
.field-error { margin-block-start: 6px; font-size: var(--fs-12); color: var(--danger-ink); }
.field-hint { margin-block-start: 6px; font-size: var(--fs-12); color: var(--text-muted); line-height: 1.6; }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(44px, 1fr));
  gap: 6px;
  max-block-size: 176px;
  overflow-y: auto;
  padding: 4px;
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-control);
  background: var(--surface-2);
}
.emoji-grid button {
  block-size: 44px;
  border-radius: 6px;
  font-size: 19px;
  line-height: 1;
  transition: background var(--dur) var(--ease);
}
.emoji-grid button:hover { background: var(--surface); }
.emoji-grid button[aria-pressed="true"] {
  background: var(--accent-tint);
  box-shadow: inset 0 0 0 2px var(--accent);
}

.manage-list { display: grid; gap: 8px; }
.manage-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-control);
  background: var(--surface);
}
.manage-row.is-hidden-page { opacity: .6; }
.mr-grip { color: var(--text-muted); cursor: grab; display: grid; place-items: center; inline-size: 28px; }
.mr-emoji { font-size: 17px; inline-size: 26px; text-align: center; flex: 0 0 auto; }
.mr-name {
  flex: 1 1 auto;
  min-inline-size: 0;
  font-size: var(--fs-14);
  font-weight: 500;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mr-url {
  font-size: var(--fs-12);
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  direction: ltr;
  text-align: start;
}
.mr-tag {
  flex: 0 0 auto;
  padding: 2px 8px;
  border: var(--border-w) solid var(--border);
  border-radius: 999px;
  color: var(--text-muted);
  font-size: var(--fs-12);
  white-space: nowrap;
}
.manage-row.dragging { opacity: .4; }
.manage-row.drop-target { border-color: var(--accent); }

.backup-list { display: grid; gap: 6px; margin-block-start: 16px; }
.backup-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-control);
  font-size: var(--fs-12);
  color: var(--text-muted);
}
.backup-list .tnum { direction: ltr; }

/* --------------------------------------------------------------------------
   11. Modal / sheet / toast
   -------------------------------------------------------------------------- */
.modal-root {
  position: fixed;
  inset: 0;
  z-index: 120;
  display: grid;
  place-items: center;
  padding: 16px;
  padding-block: calc(16px + var(--safe-t)) calc(16px + var(--safe-b));
  background: rgba(28, 25, 23, .5);
  animation: fade-in var(--dur) var(--ease);
  overflow-y: auto;
}
.modal-root[hidden] { display: none; }
.modal {
  inline-size: 100%;
  max-inline-size: 520px;
  max-block-size: 100%;
  overflow-y: auto;
  background: var(--surface);
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-modal);
  box-shadow: var(--shadow-pop);
  padding: 24px;
  animation: modal-in var(--dur-slow) var(--ease);
}
.modal-sm { max-inline-size: 420px; }
@keyframes modal-in { from { opacity: 0; transform: translateY(8px) scale(.99); } to { opacity: 1; transform: none; } }
.modal h2 { font-size: var(--fs-18); margin-block-end: 6px; }
.modal-body { color: var(--text-muted); font-size: var(--fs-14); line-height: 1.7; }
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-start;
  margin-block-start: 20px;
}
.modal-actions .btn.primary { order: -1; }

.notice {
  display: flex;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--r-control);
  font-size: var(--fs-12);
  line-height: 1.7;
  background: var(--surface-2);
  color: var(--text);
}
.notice.warn { background: var(--warning-bg); }
.notice.danger { background: var(--danger-bg); }
.notice-ico { flex: 0 0 auto; padding-block-start: 1px; }

.toasts {
  position: fixed;
  z-index: 150;
  inset-block-end: calc(16px + var(--safe-b));
  inset-inline: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: center;
  gap: 10px;
  max-inline-size: 520px;
  padding: 12px 16px;
  background: var(--surface);
  border: var(--border-w) solid var(--border);
  border-inline-start: 3px solid var(--accent);
  border-radius: var(--r-control);
  box-shadow: var(--shadow-pop);
  font-size: var(--fs-14);
  animation: toast-in var(--dur-slow) var(--ease);
}
.toast[data-kind="success"] { border-inline-start-color: var(--success); }
.toast[data-kind="error"]   { border-inline-start-color: var(--danger); }
.toast[data-kind="warn"]    { border-inline-start-color: var(--warning); }
.toast .t-actions { display: flex; gap: 6px; margin-inline-start: auto; }
.toast.is-out { animation: toast-out var(--dur) var(--ease) forwards; }
@keyframes toast-in  { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(6px); } }

.sheet-root {
  position: fixed;
  inset: 0;
  z-index: 130;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(28, 25, 23, .5);
  animation: fade-in var(--dur) var(--ease);
}
.sheet-root[hidden] { display: none; }
.sheet {
  inline-size: 100%;
  max-inline-size: 560px;
  max-block-size: 82dvh;
  overflow-y: auto;
  background: var(--surface);
  border-start-start-radius: var(--r-modal);
  border-start-end-radius: var(--r-modal);
  border: var(--border-w) solid var(--border);
  padding: 8px 12px calc(16px + var(--safe-b));
  animation: sheet-in var(--dur-slow) var(--ease);
}
@keyframes sheet-in { from { transform: translateY(100%); } to { transform: none; } }
.sheet-grip {
  inline-size: 40px;
  block-size: 4px;
  border-radius: 2px;
  background: var(--border);
  margin: 8px auto 12px;
}
.sheet h2 { font-size: var(--fs-16); padding: 4px 8px 10px; }
.sheet .nav-item { inline-size: 100%; }

/* --------------------------------------------------------------------------
   12. Mobile tab bar
   -------------------------------------------------------------------------- */
.tabbar {
  display: none;
  position: fixed;
  inset-inline: 0;
  inset-block-end: 0;
  z-index: 80;
  block-size: calc(var(--tabbar-h) + var(--safe-b));
  padding-block-end: var(--safe-b);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  border-block-start: var(--border-w) solid var(--border);
}
.tab-item {
  flex: 1 1 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-block-size: var(--tap);
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  position: relative;
  text-decoration: none;
}
.tab-item:hover { text-decoration: none; }
.tab-item .tab-emoji { font-size: 19px; line-height: 1; }
.tab-item.is-active { color: var(--accent-strong); font-weight: 600; }
.tab-item.is-active::before {
  content: "";
  position: absolute;
  inset-block-start: 0;
  inset-inline: 22%;
  block-size: 3px;
  border-radius: 0 0 3px 3px;
  background: var(--accent);
}

/* --------------------------------------------------------------------------
   13. Onboarding
   -------------------------------------------------------------------------- */
.onboard {
  position: fixed;
  inset: 0;
  z-index: 160;
  display: grid;
  place-items: center;
  padding: 16px;
  padding-block: calc(16px + var(--safe-t)) calc(16px + var(--safe-b));
  background: var(--bg);
  overflow-y: auto;
}
.onboard[hidden] { display: none; }
.onboard-card {
  inline-size: 100%;
  max-inline-size: 420px;
  padding: 32px 24px;
  text-align: center;
  background: var(--surface);
  border: var(--border-w) solid var(--border);
  border-radius: var(--r-modal);
  box-shadow: var(--shadow-2);
}
.onboard-mark { margin: 0 auto 16px; border-radius: 14px; }
.onboard-card h2 { font-size: var(--fs-22); }
.onboard-lead {
  margin: 8px 0 24px;
  color: var(--text-muted);
  font-size: var(--fs-14);
  line-height: 1.7;
}
.onboard-card .field { text-align: start; }
.onboard-msg {
  margin: -8px 0 12px;
  padding: 10px 12px;
  border-radius: var(--r-control);
  background: var(--danger-bg);
  color: var(--danger-ink);
  font-size: var(--fs-12);
  line-height: 1.6;
  text-align: start;
}
.onboard-msg[hidden] { display: none; }
.onboard-actions { display: flex; flex-direction: column; gap: 8px; }
.onboard-actions .btn { inline-size: 100%; }
.onboard-foot { margin-block-start: 16px; font-size: var(--fs-12); color: var(--text-muted); }

/* --------------------------------------------------------------------------
   14. Responsive
   -------------------------------------------------------------------------- */
/* tablet: collapsed icon rail with tooltips */
@media (min-width: 640px) and (max-width: 1023px) {
  .app:not(.is-mobile) .sidebar { inline-size: var(--sidebar-w-collapsed); }
  .app:not(.is-mobile) .wordmark,
  .app:not(.is-mobile) .apb-label,
  .app:not(.is-mobile) .sfl,
  .app:not(.is-mobile) .nav-item-label,
  .app:not(.is-mobile) .side-foot-btn .sync-text { display: none; }
  .app:not(.is-mobile) .side-head { padding-inline: 12px; justify-content: center; }
  .app:not(.is-mobile) .collapse-btn { display: none; }
  .app:not(.is-mobile) .nav-item,
  .app:not(.is-mobile) .add-page-btn,
  .app:not(.is-mobile) .side-foot-btn {
    justify-content: center;
    padding-inline: 0;
    inline-size: 44px;
    margin-inline: auto;
  }
  .app:not(.is-mobile) .nav-item::before { inset-inline-start: 0; }
  .app:not(.is-mobile) .side-foot { padding-inline: 12px; }

  /* tooltip on the rail */
  .app:not(.is-mobile) .nav-item[data-tip]::after,
  .app:not(.is-mobile) .add-page-btn[data-tip]::after {
    content: attr(data-tip);
    position: absolute;
    inset-inline-start: calc(100% + 10px);
    inset-block-start: 50%;
    transform: translateY(-50%);
    padding: 5px 10px;
    border-radius: 6px;
    background: var(--text);
    color: var(--bg);
    font-size: var(--fs-12);
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--dur) var(--ease);
    z-index: 70;
  }
  .app:not(.is-mobile) .nav-item { position: relative; }
  .app:not(.is-mobile) .nav-item:hover::after,
  .app:not(.is-mobile) .nav-item:focus-visible::after,
  .app:not(.is-mobile) .add-page-btn:hover::after { opacity: 1; }
}

@media (max-width: 639px) {
  .sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    z-index: 100;
    inline-size: min(300px, 84vw);
    box-shadow: var(--shadow-pop);
    transform: translateX(100%);
    transition: transform var(--dur-slow) var(--ease);
    padding-block-start: var(--safe-t);
  }
  :root[dir="ltr"] .sidebar { transform: translateX(-100%); }
  .app.is-drawer-open .sidebar { transform: none; }

  .content { padding: 16px; }
  .menu-btn { display: inline-flex; }
  .topbar { padding-inline: 8px; }
  .topbar-title h1 { font-size: var(--fs-14); }
  .tb-emoji { font-size: 16px; }
  .topbar-chip .sync-text { display: none; }
  .topbar-chip { min-inline-size: 36px; padding-inline: 10px; justify-content: center; }

  .tabbar { display: flex; }
  .content { padding-block-end: calc(16px + var(--tabbar-h) + var(--safe-b)); }
  .toasts { inset-block-end: calc(var(--tabbar-h) + var(--safe-b) + 12px); }

  .tiles { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  .tile { padding: 12px; gap: 10px; }
  .tile-emoji { inline-size: 34px; block-size: 34px; font-size: 18px; }
  .tile-name { font-size: var(--fs-14); }

  /* full-bleed iframes on mobile */
  .view-page { gap: 8px; }
  .frame {
    border-radius: 0;
    border-inline: 0;
    margin-inline: -16px;
    border-block-start: 0;
    border-block-end: 0;
  }
  .skeleton { padding: 18px; }
  .modal { padding: 20px; }
  .settings-grid { gap: 12px; }
  .card { padding: 16px; }
}

/* very small phones */
@media (max-width: 360px) {
  .tiles { grid-template-columns: 1fr 1fr; }
  .topbar-actions .icon-btn { inline-size: 40px; block-size: 40px; }
}

/* desktop: bigger gutters */
@media (min-width: 1024px) {
  .content { padding: 28px 32px; }
  .settings-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .card-wide { grid-column: 1 / -1; }
}

/* --------------------------------------------------------------------------
   Motion / print
   -------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }
  .tile:hover { transform: none; }
}

@media print {
  .sidebar, .topbar, .tabbar, .toasts { display: none !important; }
  .app { display: block; block-size: auto; }
  .content { overflow: visible; padding: 0; }
}
