/* ============================================================
   tools — design system
   System colors · system fonts · grouped table view · components
   ------------------------------------------------------------
   common.css owns design tokens, base styles, and the host/app
   shells. UI components live under ./components/<name>.css —
   each is self-contained and documented in its own file. See
   ./components/README.md for the convention.
   ============================================================ */

@import url("./components/button.css");
@import url("./components/toggle.css");
@import url("./components/checkbox.css");
@import url("./components/segment.css");
@import url("./components/dropdown.css");
@import url("./components/colorpicker.css");
@import url("./components/datepicker.css");
@import url("./components/dropzone.css");
@import url("./components/loader.css");
@import url("./components/panel.css");
@import url("./components/list.css");
@import url("./components/toolbar.css");
@import url("./components/stat-tile.css");
@import url("./components/spotlight.css");
@import url("./components/stub-notice.css");
@import url("./components/modal.css");
@import url("./components/netstatus.css");
@import url("./components/activity.css");

:root {
  /* Opt native controls (date/time pickers, scrollbars, spinners) into the
     active light/dark scheme. Without this, native widgets render light even
     under prefers-color-scheme: dark. */
  color-scheme: light dark;

  /* System Backgrounds */
  --bg:               #F2F2F7;
  --bg-elev:          #FFFFFF;
  --bg-elev-2:        #F2F2F7;
  --bg-recessed:      #E5E5EA;
  --bg-fill:          rgba(120, 120, 128, 0.12);
  --bg-fill-2:        rgba(120, 120, 128, 0.08);
  --bg-vibrancy:      rgba(242, 242, 247, 0.90);
  --bg-hover:         rgba(0, 0, 0, 0.04);
  --bg-hover-strong:  rgba(0, 0, 0, 0.07);

  /* Separators */
  --sep:              rgba(60, 60, 67, 0.29);
  --sep-opaque:       #C6C6C8;
  --border:           rgba(60, 60, 67, 0.12);
  --border-strong:    rgba(60, 60, 67, 0.22);

  /* Label Hierarchy */
  --text:             #000000;
  --text-dim:         rgba(60, 60, 67, 0.85);
  --text-muted:       rgba(60, 60, 67, 0.60);
  --text-quaternary:  rgba(60, 60, 67, 0.28);
  --text-placeholder: rgba(60, 60, 67, 0.30);

  /* System Colors */
  --accent:             #007AFF;
  --accent-strong:      #0060DF;
  --accent-soft:        rgba(0, 122, 255, 0.12);
  --accent-soft-strong: rgba(0, 122, 255, 0.20);
  --success:            #34C759;
  --success-soft:       rgba(52, 199, 89, 0.12);
  --danger:             #FF3B30;
  --danger-soft:        rgba(255, 59, 48, 0.10);
  --warning:            #FF9500;
  --warning-soft:       rgba(255, 149, 0, 0.12);

  /* Checker (transparency previews) */
  --checker-1: #F0F0F3;
  --checker-2: #E0E0E6;
  --shadow-thumb: 0 2px 8px rgba(0, 0, 0, 0.18);

  /* Scrim — dark overlay for controls/captions layered over imagery
     (e.g. a remove button or caption sitting on a thumbnail). Stays dark in
     both schemes on purpose so white glyphs stay legible over any content. */
  --scrim:        rgba(0, 0, 0, 0.55);
  --scrim-strong: rgba(0, 0, 0, 0.82);

  /* Border Radius Scale */
  --radius-xs:   6px;
  --radius-sm:   10px;
  --radius-md:   13px;
  --radius:      16px;
  --radius-xl:   22px;
  --radius-pill: 999px;

  /* Layered Shadows */
  --shadow-1: 0 1px 0 rgba(0,0,0,0.05), 0 1px 3px rgba(0,0,0,0.05);
  --shadow-2: 0 2px 12px rgba(0,0,0,0.08), 0 1px 3px rgba(0,0,0,0.05);
  --shadow-3: 0 8px 32px rgba(0,0,0,0.13), 0 2px 8px rgba(0,0,0,0.08);

  /* Layout */
  --sidebar-w: 280px;
  --topbar-h:  52px;
  --cell-h:    44px;

  /* Spacing scale — 4pt grid */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-7: 32px;
  --space-8: 40px;
  --space-9: 56px;
  --space-10: 72px;

  /* Safe area (notch / home indicator) */
  --safe-top:    env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left:   env(safe-area-inset-left, 0px);
  --safe-right:  env(safe-area-inset-right, 0px);

  /* Motion — spring easing */
  --ease-spring:   cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-out:      cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --ease-standard: cubic-bezier(0.4, 0, 0.2, 1);
  --duration-snap:    200ms;
  --duration-default: 320ms;

  /* Typography — system default on each platform */
  --sans: system-ui, "Segoe UI", Roboto, "Helvetica Neue", Helvetica, Arial, sans-serif;
  --mono: ui-monospace, "Menlo", "Cascadia Code", "Consolas", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg:               #000000;
    --bg-elev:          #1C1C1E;
    --bg-elev-2:        #2C2C2E;
    --bg-recessed:      #0A0A0A;
    --bg-fill:          rgba(120, 120, 128, 0.24);
    --bg-fill-2:        rgba(120, 120, 128, 0.16);
    --bg-vibrancy:      rgba(28, 28, 30, 0.90);
    --bg-hover:         rgba(255, 255, 255, 0.06);
    --bg-hover-strong:  rgba(255, 255, 255, 0.10);

    --sep:              rgba(84, 84, 88, 0.65);
    --sep-opaque:       #38383A;
    --border:           rgba(255, 255, 255, 0.08);
    --border-strong:    rgba(255, 255, 255, 0.16);

    --text:             #FFFFFF;
    --text-dim:         rgba(235, 235, 245, 0.85);
    --text-muted:       rgba(235, 235, 245, 0.60);
    --text-quaternary:  rgba(235, 235, 245, 0.25);
    --text-placeholder: rgba(235, 235, 245, 0.28);

    --accent:             #0A84FF;
    --accent-strong:      #409CFF;
    --accent-soft:        rgba(10, 132, 255, 0.16);
    --accent-soft-strong: rgba(10, 132, 255, 0.24);
    --success:            #30D158;
    --success-soft:       rgba(48, 209, 88, 0.16);
    --danger:             #FF453A;
    --danger-soft:        rgba(255, 69, 58, 0.14);
    --warning:            #FF9F0A;
    --warning-soft:       rgba(255, 159, 10, 0.16);

    --checker-1: #2A2A2C;
    --checker-2: #1A1A1C;
    --shadow-thumb: 0 2px 8px rgba(0, 0, 0, 0.55);

    --shadow-1: 0 1px 0 rgba(0,0,0,0.3),  0 1px 3px  rgba(0,0,0,0.30);
    --shadow-2: 0 2px 12px rgba(0,0,0,0.4), 0 1px 4px rgba(0,0,0,0.30);
    --shadow-3: 0 8px 32px rgba(0,0,0,0.6), 0 2px 8px rgba(0,0,0,0.40);
  }
}

/* ============================================================ Base ============ */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 15px;
  line-height: 1.47;
  letter-spacing: -0.015em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
}

a {
  color: var(--accent);
  text-decoration: none;
  transition: opacity var(--duration-snap) var(--ease-standard);
}
a:hover { opacity: 0.72; }

code {
  font-family: var(--mono);
  background: var(--bg-fill);
  padding: 2px 6px;
  border-radius: 5px;
  font-size: 0.85em;
  color: var(--text);
}

kbd {
  font-family: var(--mono);
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  padding: 1px 6px;
  border-radius: 5px;
  font-size: 0.78em;
  color: var(--text-dim);
}

button {
  font-family: inherit;
  -webkit-tap-highlight-color: transparent;
}

::selection {
  background: var(--accent-soft-strong);
  color: var(--text);
}

:where(button, a, input, select, textarea, [tabindex]):focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ============================================================
   HOST — sidebar + iframe layout
   ============================================================ */
body.host {
  /* Wallpaper-style ambient background — visible behind welcome/springboard */
  background:
    radial-gradient(1200px 800px at 85% -5%, rgba(0, 122, 255, 0.10), transparent 60%),
    radial-gradient(1000px 700px at 0% 105%, rgba(255, 45, 85, 0.07), transparent 55%),
    radial-gradient(900px 600px at 50% 50%, rgba(175, 82, 222, 0.04), transparent 70%),
    var(--bg);
  background-attachment: fixed;
}

@media (prefers-color-scheme: dark) {
  body.host {
    background:
      radial-gradient(1200px 800px at 85% -5%, rgba(10, 132, 255, 0.20), transparent 60%),
      radial-gradient(1000px 700px at 0% 105%, rgba(255, 69, 58, 0.12), transparent 55%),
      radial-gradient(900px 600px at 50% 50%, rgba(191, 90, 242, 0.08), transparent 70%),
      var(--bg);
    background-attachment: fixed;
  }
}

/* Main area is transparent so wallpaper shows through welcome */
.host__main { background: transparent; }

@media (min-width: 880px) {
  body.host {
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
  }
}

/* ----- Sidebar ----- */
.host__sidebar {
  background: var(--bg-vibrancy);
  -webkit-backdrop-filter: saturate(180%) blur(30px);
  backdrop-filter: saturate(180%) blur(30px);
  border-right: 1px solid var(--sep);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  padding-left: var(--safe-left);
}

@media (min-width: 880px) {
  .host__sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
  }
}

@media (max-width: 879px) {
  .host__sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(86vw, 320px);
    z-index: 100;
    transform: translateX(-100%);
    transition: transform var(--duration-default) var(--ease-out);
    box-shadow: var(--shadow-3);
    padding-top: var(--safe-top);
    padding-bottom: var(--safe-bottom);
  }
  .host__sidebar.is-open { transform: translateX(0); }
}

/* Brand / app bar — sidebar header */
.host__brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px 12px;
  position: relative;
}

.host__brand-link {
  display: flex;
  align-items: center;
  gap: 9px;
  color: var(--text);
}
.host__brand-link:hover { opacity: 1; }

.host__logo {
  width: 28px;
  height: 28px;
  border-radius: 7px;
  background: linear-gradient(145deg, #47AAFF, #007AFF);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-size: 16px;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0, 122, 255, 0.32);
}

.host__brand-name {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.022em;
  color: var(--text);
}

.host__brand-badge {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 500;
  color: var(--success);
  background: var(--success-soft);
  border-radius: var(--radius-pill);
  padding: 3px 9px 3px 7px;
  letter-spacing: -0.01em;
  flex-shrink: 0;
}

/* Sidebar search — desktop toolbar field on desktop, pill on mobile */
.host__search {
  position: relative;
  padding: 6px 12px 10px;
  border-bottom: 1px solid var(--sep);
}

.host__search-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.host__search-icon {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  pointer-events: none;
  flex-shrink: 0;
}

.host__search input[type="search"] {
  width: 100%;
  box-sizing: border-box;
  background: var(--bg-fill);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  padding: 7px 56px 7px 30px;
  font-size: 13px;
  line-height: 1.3;
  letter-spacing: -0.01em;
  color: var(--text);
  outline: none;
  appearance: none;
  -webkit-appearance: none;
  transition:
    background var(--duration-snap) var(--ease-standard),
    border-color var(--duration-snap) var(--ease-standard),
    box-shadow var(--duration-snap) var(--ease-standard);
}

.host__search input[type="search"]::placeholder { color: var(--text-muted); }
.host__search input[type="search"]::-webkit-search-cancel-button,
.host__search input[type="search"]::-webkit-search-decoration { -webkit-appearance: none; display: none; }

.host__search input[type="search"]:focus {
  background: var(--bg-elev);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.host__search-kbd {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  font-family: var(--mono);
  font-size: 10.5px;
  font-weight: 500;
  color: var(--text-muted);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  padding: 1px 5px;
  border-radius: 4px;
  letter-spacing: 0;
  pointer-events: none;
  user-select: none;
}

.host__search-clear {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 18px;
  height: 18px;
  border: none;
  background: var(--text-quaternary);
  color: var(--bg-elev);
  border-radius: 50%;
  cursor: pointer;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  line-height: 1;
  padding: 0;
  transition: background var(--duration-snap) var(--ease-standard);
}

.host__search.has-text .host__search-kbd { display: none; }
.host__search.has-text .host__search-clear { display: inline-flex; }
.host__search-clear:hover { background: var(--text-muted); }

@media (max-width: 879px) {
  .host__search { padding: 4px 14px 12px; }
  .host__search input[type="search"] {
    padding: 9px 36px 9px 34px;
    font-size: 15px;
    border-radius: var(--radius-sm);
  }
  .host__search-icon { left: 11px; }
  .host__search-kbd { display: none; }
}

.host__search-empty {
  display: none;
  padding: 18px 16px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}
.host__search.is-empty .host__search-empty { display: block; }
.host__search.is-empty + .host__nav .host__list { display: none; }

/* Nav section header — sidebar style */
.host__nav {
  flex: 1;
  padding: 10px 0 0;
  overflow-y: auto;
}

.host__nav-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin: 0;
  padding: 6px 18px 4px;
}

.host__list {
  list-style: none;
  padding: 0 8px;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

/* List item — sidebar row */
.host__item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 10px;
  border-radius: 7px;
  color: var(--text);
  transition:
    background var(--duration-snap) var(--ease-standard),
    color var(--duration-snap) var(--ease-standard);
  min-height: 36px;
  position: relative;
}

.host__item:hover {
  background: var(--bg-hover);
  color: var(--text);
  opacity: 1;
}

.host__item.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

.host__item.is-active:hover { background: var(--accent-soft-strong); }

/* Colored app icon in sidebar */
.host__item-icon {
  flex-shrink: 0;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  transition: transform var(--duration-snap) var(--ease-spring);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.10);
}

.host__item-icon svg { width: 14px; height: 14px; }

/* Generated glass-tile icons fill their rounded container */
.host__item-icon .ticon,
.welcome-card__icon .ticon,
.spotlight__item-icon .ticon {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: inherit;
  display: block;
}

@media (max-width: 879px) {
  .host__item-icon { width: 28px; height: 28px; border-radius: 7px; }
  .host__item-icon svg { width: 16px; height: 16px; }
}

/* Per-tool color — matches welcome grid */
.host__list li:nth-child(1) .host__item-icon { background: linear-gradient(145deg, #FF6B6B, #FF3B30); }
.host__list li:nth-child(2) .host__item-icon { background: linear-gradient(145deg, #47AAFF, #007AFF); }
.host__list li:nth-child(3) .host__item-icon { background: linear-gradient(145deg, #65D97A, #34C759); }
.host__list li:nth-child(4) .host__item-icon { background: linear-gradient(145deg, #FFB340, #FF9500); }
.host__list li:nth-child(5) .host__item-icon { background: linear-gradient(145deg, #C96AE8, #AF52DE); }
.host__list li:nth-child(6) .host__item-icon { background: linear-gradient(145deg, #7876E8, #5856D6); }
.host__list li:nth-child(7) .host__item-icon { background: linear-gradient(145deg, #FF5977, #FF2D55); }
.host__list li:nth-child(8) .host__item-icon { background: linear-gradient(145deg, #62D6F5, #30B0C7); }

.host__item-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  min-width: 0;
  flex: 1;
}

.host__item-title {
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.008em;
  line-height: 1.25;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.host__item-desc {
  font-size: 11px;
  color: var(--text-muted);
  line-height: 1.3;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 879px) {
  /* Inset-grouped list */
  .host__nav { padding: 8px 0 0; }
  .host__nav-label {
    font-size: 13px;
    font-weight: 400;
    text-transform: none;
    letter-spacing: -0.01em;
    color: var(--text-muted);
    padding: 6px 30px 6px;
  }
  .host__list {
    background: var(--bg-elev);
    border-radius: var(--radius-md);
    margin: 0 14px;
    padding: 0;
    gap: 0;
    overflow: hidden;
  }
  .host__list li { position: relative; }
  /* Hairline separator, indented past the icon */
  .host__list li:not(:last-child)::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 56px;
    right: 0;
    height: 0.5px;
    background: var(--sep);
    pointer-events: none;
  }
  .host__item {
    border-radius: 0;
    padding: 10px 14px;
    min-height: 44px;
  }
  .host__item:hover { background: var(--bg-hover); }
  .host__item.is-active {
    background: var(--accent-soft);
    color: var(--accent);
  }
  .host__item-title { font-size: 15px; font-weight: 400; }
  .host__item-desc { font-size: 13px; }
}

/* Highlighted search match */
.host__item mark {
  background: transparent;
  color: var(--accent);
  font-weight: 600;
  padding: 0;
}

.host__item.is-active .host__item-desc {
  color: var(--accent);
  opacity: 0.7;
}

/* Disclosure chevron — hidden on desktop (desktop browsers don't use one); shown on mobile (mobile pattern) */
.host__item::after {
  content: '';
  flex-shrink: 0;
  display: none;
  width: 6px;
  height: 6px;
  border-right: 1.5px solid var(--text-quaternary);
  border-top: 1.5px solid var(--text-quaternary);
  transform: rotate(45deg);
  margin-right: 2px;
}

@media (max-width: 879px) {
  .host__item::after { display: block; }
}

.host__item.is-active::after {
  border-color: rgba(0, 122, 255, 0.4);
}

/* Keep icon white even when parent row is active */
.host__item.is-active .host__item-icon { color: #ffffff; }

/* Sidebar footer */
.host__sidebar-footer {
  padding: 12px 16px 14px;
  border-top: 1px solid var(--sep);
  color: var(--text-muted);
  font-size: 11.5px;
  line-height: 1.45;
}

.host__sidebar-footer strong {
  display: block;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 3px;
  font-size: 11.5px;
}

.host__sidebar-footer p { margin: 0; }

/* Mobile dimming overlay (sits between content and sidebar) */
.host__overlay {
  display: none;
}

@media (max-width: 879px) {
  .host__overlay {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 90;
    background: rgba(0, 0, 0, 0.36);
    opacity: 0;
    pointer-events: none;
    transition: opacity var(--duration-default) var(--ease-standard);
  }
  .host__overlay.is-visible {
    opacity: 1;
    pointer-events: auto;
  }
}

/* Mobile top nav bar — mobile style */
.host__menu-toggle { display: none; }
.host__topbar { display: none; }

@media (max-width: 879px) {
  body.host {
    padding-top: calc(var(--topbar-h) + var(--safe-top));
  }
  /* Full styled navigation bar */
  .host__topbar {
    display: flex;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: calc(var(--topbar-h) + var(--safe-top));
    padding: var(--safe-top) 12px 0;
    z-index: 110;
    background: var(--bg-vibrancy);
    -webkit-backdrop-filter: saturate(180%) blur(28px);
    backdrop-filter: saturate(180%) blur(28px);
    border-bottom: 0.5px solid var(--sep);
  }
  .host__topbar-title {
    flex: 1;
    text-align: center;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: -0.022em;
    color: var(--text);
    margin: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    padding: 0 var(--space-2);
  }
  .host__menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--duration-snap) var(--ease-standard);
  }
  .host__menu-toggle:active { background: var(--bg-hover); }
  .host__topbar-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 50%;
    background: transparent;
    border: none;
    color: var(--accent);
    cursor: pointer;
    flex-shrink: 0;
    transition: background var(--duration-snap) var(--ease-standard);
  }
  .host__topbar-action:active { background: var(--bg-hover); }

  /* Back chevron in top bar — shown when a tool is open */
  .host__topbar-back {
    display: none;
    align-items: center;
    gap: 1px;
    background: transparent;
    border: none;
    color: var(--accent);
    font-family: inherit;
    font-size: 17px;
    font-weight: 400;
    letter-spacing: -0.02em;
    padding: 6px 6px 6px 2px;
    cursor: pointer;
    flex-shrink: 0;
    margin-left: -4px;
    border-radius: 6px;
    transition: opacity var(--duration-snap) var(--ease-standard);
  }
  .host__topbar-back:active { opacity: 0.5; }
  .host__topbar-back svg { margin-right: -2px; }

  .host__topbar.is-tool .host__menu-toggle { display: none; }
  .host__topbar.is-tool .host__topbar-back { display: inline-flex; }
}

/* Main + iframe */
.host__main {
  position: relative;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: transparent;
}

.host__iframe {
  flex: 1;
  width: 100%;
  height: 100vh;
  border: 0;
  background: transparent;
  display: block;
}

@media (max-width: 879px) {
  .host__iframe { height: calc(100dvh - var(--topbar-h) - var(--safe-top)); }
}

/* ============================================================
   WELCOME — Springboard-style app grid
   ============================================================ */
.welcome {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: var(--space-9) var(--space-7) var(--space-10);
  padding-left: max(var(--space-7), var(--safe-left));
  padding-right: max(var(--space-7), var(--safe-right));
}

@media (max-width: 879px) {
  .welcome {
    padding: var(--space-5) var(--space-5) var(--space-9);
    padding-bottom: calc(var(--space-9) + var(--safe-bottom));
  }
}

.welcome__inner {
  width: 100%;
  max-width: 880px;
}

/* Large title style */
.welcome__title {
  font-size: clamp(34px, 5vw, 54px);
  font-weight: 700;
  letter-spacing: -0.04em;
  line-height: 1.05;
  margin: 0 0 10px;
  color: var(--text);
}

.welcome__sub {
  font-size: 17px;
  color: var(--text-muted);
  margin: 0 0 var(--space-8);
  max-width: 540px;
  line-height: 1.5;
  letter-spacing: -0.012em;
}

@media (max-width: 879px) {
  .welcome__title { font-size: 32px; margin-bottom: 6px; }
  .welcome__sub { font-size: 15px; margin-bottom: var(--space-7); }
}

.welcome__sub strong {
  color: var(--text-dim);
  font-weight: 600;
}

/* App-icon grid */
.welcome__grid {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(108px, 1fr));
  gap: var(--space-7) var(--space-4);
}

@media (max-width: 879px) {
  .welcome__grid {
    grid-template-columns: repeat(4, 1fr);
    gap: var(--space-6) var(--space-2);
  }
}

@media (max-width: 380px) {
  .welcome__grid { grid-template-columns: repeat(3, 1fr); }
}

.welcome__empty { display: none; }
.welcome__grid.is-empty { display: none; }
.welcome__grid.is-empty ~ .welcome__empty { display: block; }

.welcome__empty {
  margin-top: var(--space-7);
  padding: var(--space-7);
  background: var(--bg-elev);
  border-radius: var(--radius-xl);
  text-align: center;
  color: var(--text-muted);
  font-size: 15px;
  letter-spacing: -0.01em;
  border: 1px solid var(--border);
}

.welcome-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 9px;
  padding: 0;
  background: transparent;
  border-radius: 0;
  box-shadow: none;
  color: var(--text);
  text-align: center;
  cursor: pointer;
  transition: opacity var(--duration-snap) var(--ease-standard);
}

.welcome-card:hover { opacity: 0.78; color: var(--text); }

.welcome-card:active .welcome-card__icon {
  transform: scale(0.88);
}

/* App icon tile — Home-screen icon */
.welcome-card__icon {
  width: 64px;
  height: 64px;
  border-radius: 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: #ffffff;
  box-shadow:
    0 4px 14px rgba(0, 0, 0, 0.14),
    0 1px 2px rgba(0, 0, 0, 0.08),
    inset 0 1px 0 rgba(255, 255, 255, 0.18);
  transition: transform 280ms cubic-bezier(0.34, 1.56, 0.64, 1);
}

.welcome-card__icon svg { width: 28px; height: 28px; stroke-width: 1.8; }

@media (min-width: 880px) {
  .welcome-card__icon { width: 72px; height: 72px; border-radius: 18px; }
  .welcome-card__icon svg { width: 32px; height: 32px; }
}

/* Per-tool gradient — matches sidebar */
.welcome__grid li:nth-child(1) .welcome-card__icon { background: linear-gradient(145deg, #FF6B6B, #FF3B30); }
.welcome__grid li:nth-child(2) .welcome-card__icon { background: linear-gradient(145deg, #47AAFF, #007AFF); }
.welcome__grid li:nth-child(3) .welcome-card__icon { background: linear-gradient(145deg, #65D97A, #34C759); }
.welcome__grid li:nth-child(4) .welcome-card__icon { background: linear-gradient(145deg, #FFB340, #FF9500); }
.welcome__grid li:nth-child(5) .welcome-card__icon { background: linear-gradient(145deg, #C96AE8, #AF52DE); }
.welcome__grid li:nth-child(6) .welcome-card__icon { background: linear-gradient(145deg, #7876E8, #5856D6); }
.welcome__grid li:nth-child(7) .welcome-card__icon { background: linear-gradient(145deg, #FF5977, #FF2D55); }
.welcome__grid li:nth-child(8) .welcome-card__icon { background: linear-gradient(145deg, #62D6F5, #30B0C7); }

.welcome-card__title {
  font-size: 12px;
  font-weight: 500;
  letter-spacing: -0.008em;
  color: var(--text);
  line-height: 1.2;
  max-width: 88px;
  text-align: center;
}

.welcome-card__desc { display: none; }

@media (min-width: 880px) {
  .welcome-card__title { font-size: 13px; }
}

/* ============================================================
   APP shell — per-tool pages
   ============================================================ */
.app {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-7) var(--space-5) var(--space-9);
  padding-left: max(var(--space-5), var(--safe-left));
  padding-right: max(var(--space-5), var(--safe-right));
  padding-bottom: calc(var(--space-9) + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  min-height: 100vh;
  background: var(--bg);
}

.app__header {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding-bottom: 4px;
}

/* Back chevron */
.app__back {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 16px;
  font-weight: 400;
  color: var(--accent);
  padding: 4px 0;
  letter-spacing: -0.01em;
}

.app__back:hover { opacity: 0.7; }

.app__back::before {
  content: '';
  display: inline-block;
  width: 7px;
  height: 7px;
  border-left: 1.5px solid currentColor;
  border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg) translateY(-1px);
  flex-shrink: 0;
  margin-right: 3px;
  vertical-align: middle;
}

.app__title-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.app__title {
  font-size: clamp(28px, 3.5vw, 34px);
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.038em;
  line-height: 1.05;
  color: var(--text);
}

/* Glass tool icon beside the page title */
.app__title-icon {
  width: 44px;
  height: 44px;
  border-radius: 11px;
  flex-shrink: 0;
  object-fit: cover;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.12);
}
@media (max-width: 879px) {
  .app__title-icon { width: 38px; height: 38px; border-radius: 9px; }
}

.app__badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 500;
  color: var(--success);
  background: var(--success-soft);
  border-radius: var(--radius-pill);
  padding: 4px 10px 4px 8px;
  letter-spacing: -0.01em;
  margin-bottom: 3px;
}

.app__sub {
  color: var(--text-muted);
  margin: 0;
  max-width: 680px;
  font-size: 15px;
  line-height: 1.5;
  letter-spacing: -0.01em;
}

.app__main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.app__footer {
  margin-top: auto;
  padding-top: 28px;
  border-top: 1px solid var(--sep);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 28px;
  color: var(--text-muted);
  font-size: 13px;
  line-height: 1.55;
}

@media (max-width: 640px) {
  .app__footer { grid-template-columns: 1fr; gap: 20px; }
}

.footer__col strong {
  display: block;
  color: var(--text-dim);
  font-weight: 600;
  margin-bottom: 6px;
  font-size: 13px;
}

.footer__col p, .footer__col ul { margin: 0; }
.footer__col ul { padding-left: 18px; }
.footer__col li + li { margin-top: 4px; }
.footer__col a { color: var(--accent); }

/* Embedded mode */
html.embedded body { background: var(--bg); }
html.embedded .app {
  padding: 20px 18px 28px;
  gap: 16px;
  min-height: auto;
  max-width: none;
}
html.embedded .app__back,
html.embedded .app__footer { display: none; }

/* ============================================================
   FORM CONTROLS — native inputs styled to match the design system
   ============================================================ */
input[type="text"],
input[type="password"],
input[type="number"],
input[type="email"],
input[type="url"],
input[type="search"],
input[type="date"],
input[type="time"],
input[type="datetime-local"],
input[type="month"],
textarea {
  background: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 9px 13px;
  font-family: inherit;
  font-size: 15px;
  letter-spacing: -0.01em;
  outline: none;
  transition:
    border-color var(--duration-snap) var(--ease-standard),
    box-shadow var(--duration-snap) var(--ease-standard);
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="email"]:focus,
input[type="url"]:focus,
input[type="search"]:focus,
input[type="date"]:focus,
input[type="time"]:focus,
input[type="datetime-local"]:focus,
input[type="month"]:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
  /* Suppress the global :focus-visible outline so the soft box-shadow ring is
     the single, consistent focus indicator — matching select:focus below. (A
     bare `textarea` selector otherwise loses to :focus-visible on specificity,
     so textareas alone would show an extra hard outline.) */
  outline: none;
}

/* Strip native number-input spinner arrows — the OS steppers clash with the
   flat, Apple-style fields used everywhere else. Keyboard ↑/↓ still adjusts
   the value. (Datepicker time segments handle their own stripping.) */
input[type="number"] {
  -moz-appearance: textfield;
  appearance: textfield;
}
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

/* Native select — styled as a pop-up button.
   Twin chevrons (up + down) hint at "this opens a menu," with a
   slight inset highlight, subtle gradient, and tinted focus ring.
   The native popup still renders system-style. */
select {
  appearance: none;
  -webkit-appearance: none;
  background-color: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  padding: 9px 34px 9px 13px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: -0.01em;
  outline: none;
  cursor: pointer;
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='14' viewBox='0 0 12 14' fill='none' stroke='%23ffffff' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><polyline points='3 5 6 2 9 5'/><polyline points='3 9 6 12 9 9'/></svg>"),
    linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  background-repeat: no-repeat, no-repeat;
  background-position: right 8px center, right 0 top 0;
  background-size: 11px 13px, 28px 100%;
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.10),
    var(--shadow-1);
  transition:
    border-color var(--duration-snap) var(--ease-standard),
    box-shadow var(--duration-snap) var(--ease-standard),
    transform 80ms var(--ease-standard),
    background-color var(--duration-snap) var(--ease-standard);
}

select:hover { border-color: var(--accent); }
select:active { transform: scale(0.985); }

select:focus,
select:focus-visible {
  border-color: var(--accent);
  box-shadow:
    inset 0 1px 0 rgba(255,255,255,0.10),
    0 0 0 3px var(--accent-soft),
    var(--shadow-1);
  outline: none;
}

select:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* Inside the system popup, options inherit OS rendering — these
   color hints only apply where Chromium honors them (Linux, etc). */
select option {
  background: var(--bg-elev);
  color: var(--text);
  font-weight: 400;
}

/* Compact variant — sits inside a .toolbar at the toolbar's height. */
.toolbar select,
.select--compact {
  padding: 5px 28px 5px 10px;
  font-size: 13px;
  font-weight: 500;
  border-radius: var(--radius-sm);
  background-size: 9px 11px, 24px 100%;
  background-position: right 7px center, right 0 top 0;
}

/* "Ghost" variant — looks like an inline text control, the trigger
   chevron sits inside text bounds. Use inside captions / muted UI. */
.select--ghost {
  background-image:
    url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%236e6e73' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  background-color: var(--bg-fill);
  background-position: right 8px center;
  background-size: 10px;
  border-color: transparent;
  box-shadow: none;
  color: var(--text);
  font-weight: 400;
}
.select--ghost:hover { background-color: var(--bg-hover-strong); border-color: transparent; }
.select--ghost:focus,
.select--ghost:focus-visible {
  border-color: var(--accent);
  background-color: var(--bg-elev);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

@media (prefers-color-scheme: dark) {
  .select--ghost {
    background-image:
      url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 24 24' fill='none' stroke='%2398989d' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'><polyline points='6 9 12 15 18 9'/></svg>");
  }
}


input[type="range"] {
  accent-color: var(--accent);
  width: 100%;
  cursor: pointer;
  height: 4px;
  appearance: none;
  -webkit-appearance: none;
  background: transparent;
  outline: none;
}

/* styled slider: continuous track + glossy thumb with a faint shadow
   underneath, a clean rail, and an accent fill up to the thumb. WebKit exposes
   no progress pseudo-element, so the fill is a hard-stop gradient — accent left
   of the thumb, rail to the right — positioned by the --range-fill custom
   property (0–100%) that components/range.js sets per input. It defaults to 0%,
   so a slider on a page without that script just shows the plain rail. */
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--accent) var(--range-fill, 0%), var(--bg-fill) var(--range-fill, 0%));
}
input[type="range"]::-moz-range-track {
  height: 4px;
  border-radius: 999px;
  background: linear-gradient(to right, var(--accent) var(--range-fill, 0%), var(--bg-fill) var(--range-fill, 0%));
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  border: 0.5px solid rgba(0,0,0,0.08);
  box-shadow:
    0 3px 8px rgba(0,0,0,0.18),
    0 1px 2px rgba(0,0,0,0.10);
  margin-top: -9px;
  cursor: pointer;
  transition: transform 80ms var(--ease-standard);
}
input[type="range"]::-moz-range-thumb {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #ffffff;
  border: 0.5px solid rgba(0,0,0,0.08);
  box-shadow:
    0 3px 8px rgba(0,0,0,0.18),
    0 1px 2px rgba(0,0,0,0.10);
  cursor: pointer;
}
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.06); }

@media (prefers-color-scheme: dark) {
  input[type="range"]::-webkit-slider-thumb {
    background: #f0f0f3;
    border-color: rgba(0,0,0,0.5);
    box-shadow:
      0 3px 8px rgba(0,0,0,0.55),
      0 1px 2px rgba(0,0,0,0.40);
  }
  input[type="range"]::-moz-range-thumb {
    background: #f0f0f3;
    border-color: rgba(0,0,0,0.5);
  }
}

/* Checkbox is a custom component — see components/checkbox.css. */
input[type="radio"] {
  accent-color: var(--accent);
  width: 18px;
  height: 18px;
  cursor: pointer;
}

input[type="color"] { cursor: pointer; }

/* ============================================================
   UTILITIES
   ============================================================ */
.hidden { display: none !important; }

/* Make the HTML `hidden` attribute beat component display rules
   (e.g. .btn sets display:inline-flex which would otherwise override
   the UA stylesheet's [hidden] { display: none } rule). */
[hidden] { display: none !important; }

.error {
  background: var(--danger-soft);
  border: 1px solid color-mix(in srgb, var(--danger) 25%, transparent);
  color: var(--danger);
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: 14px;
  letter-spacing: -0.005em;
}

.label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.label--small {
  font-size: 11px;
  color: var(--text-muted);
}


/* ============================================================
   WELCOME — category section headers
   ============================================================ */
.welcome__section-header {
  grid-column: 1 / -1;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.05em;
  text-transform: uppercase;
  padding: var(--space-5) 0 var(--space-2);
  border-bottom: 0.5px solid var(--sep);
  margin-bottom: var(--space-3);
}

.welcome__section-header:first-child { padding-top: 0; }

.welcome__section-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  background: var(--bg-fill);
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  letter-spacing: 0;
  text-transform: none;
  margin-left: 7px;
  vertical-align: middle;
  line-height: 1.6;
}

/* Welcome grid — extended gradient selectors for tools 9-13 */
.welcome__grid li:nth-child(9)  .welcome-card__icon { background: linear-gradient(145deg, #5CE4C3, #00BFA5); }
.welcome__grid li:nth-child(10) .welcome-card__icon { background: linear-gradient(145deg, #B388FF, #7C4DFF); }
.welcome__grid li:nth-child(11) .welcome-card__icon { background: linear-gradient(145deg, #FFD740, #FF9F00); }
.welcome__grid li:nth-child(12) .welcome-card__icon { background: linear-gradient(145deg, #FF8A65, #FF5722); }
.welcome__grid li:nth-child(13) .welcome-card__icon { background: linear-gradient(145deg, #06B6D4, #0284C7); }

/* Sidebar list — extended gradient selectors for items 9-13 */
.host__list li:nth-child(9)  .host__item-icon { background: linear-gradient(145deg, #5CE4C3, #00BFA5); }
.host__list li:nth-child(10) .host__item-icon { background: linear-gradient(145deg, #B388FF, #7C4DFF); }
.host__list li:nth-child(11) .host__item-icon { background: linear-gradient(145deg, #FFD740, #FF9F00); }
.host__list li:nth-child(12) .host__item-icon { background: linear-gradient(145deg, #FF8A65, #FF5722); }
.host__list li:nth-child(13) .host__item-icon { background: linear-gradient(145deg, #06B6D4, #0284C7); }

/* Inline gradient override — JS sets style="background:…" directly on icon elements */
/* This pattern is used for tools listed after category headers, where nth-child is offset */
.host__item-icon[style],
.welcome-card__icon[style] { /* inline style wins; these declarations are just documentation */ }

/* ============================================================
   Reduced motion — honor the OS preference globally.
   Strips transitions and smooth scrolling everywhere; looping
   indicators (e.g. .spinner) get gentler per-component treatment.
   ============================================================ */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}




