/* ============================================================================
 * MSFinder — css/app.css
 * Self-contained app stylesheet: design tokens (dark default + light), toolbar,
 * command bar, filter chips, cloud toggle, results list, empty/no-result
 * states, status bar. No external resources. Token values mirror cmtrace.
 * ==========================================================================*/

/* ---- Self-hosted variable Manrope (relative to /css/) ---- */
@font-face {
  font-family: "Manrope";
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
  src: url("../assets/fonts/manrope.woff2") format("woff2");
}

/* ---------------------------------------------------------------------------
 * Design tokens — DARK is the default brand theme.
 * ------------------------------------------------------------------------- */
:root,
:root[data-theme="dark"] {
  color-scheme: dark;

  --bg: #000000;
  --bg-elev: #0c120b;
  --bg-grid: #050705;

  --fg: #d2d7dc;
  --fg-dim: #9aa1a8;
  --fg-faint: rgba(255, 255, 255, 0.42);

  --border: rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.18);

  --accent: #39a751;
  --accent-fg: #ffffff;
  --accent-soft: rgba(57, 167, 81, 0.16);
  --accent-border: rgba(57, 167, 81, 0.55);

  --hover-bg: rgba(255, 255, 255, 0.06);
  --active-bg: rgba(255, 255, 255, 0.10);
  --row-sel-bg: rgba(57, 167, 81, 0.18);
  --hl: rgba(57, 167, 81, 0.32);

  --heading: #ffffff;
  --tile-fg: #ffffff;

  --shadow: 0 16px 48px rgba(0, 0, 0, 0.55), 0 2px 8px rgba(0, 0, 0, 0.4);
  --scroll-thumb: rgba(255, 255, 255, 0.16);
  --scroll-thumb-hover: rgba(255, 255, 255, 0.30);

  --font-ui: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, "Cascadia Code",
    "Cascadia Mono", Menlo, Consolas, "DejaVu Sans Mono", "Liberation Mono",
    monospace;

  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --radius-sm: 6px;
  --radius: 10px;
  --radius-lg: 14px;

  --toolbar-h: 56px;
  --status-h: 30px;
}

/* ---- LIGHT theme ---- */
:root[data-theme="light"] {
  color-scheme: light;

  --bg: #ffffff;
  --bg-elev: #f5f7f5;
  --bg-grid: #ffffff;

  --fg: #1d2421;
  --fg-dim: #5b665f;
  --fg-faint: #8a948c;

  --border: #e2e8e3;
  --border-strong: #cdd6cf;

  --accent: #1f8f3d;
  --accent-fg: #ffffff;
  --accent-soft: rgba(31, 143, 61, 0.12);
  --accent-border: rgba(31, 143, 61, 0.45);

  --hover-bg: rgba(0, 0, 0, 0.05);
  --active-bg: rgba(0, 0, 0, 0.08);
  --row-sel-bg: rgba(31, 143, 61, 0.14);
  --hl: rgba(31, 143, 61, 0.22);

  --heading: #0c130f;
  --tile-fg: #ffffff;

  --shadow: 0 10px 30px rgba(16, 24, 40, 0.16), 0 2px 6px rgba(16, 24, 40, 0.08);
  --scroll-thumb: rgba(0, 0, 0, 0.18);
  --scroll-thumb-hover: rgba(0, 0, 0, 0.32);
}

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

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}
html {
  font-family: var(--font-ui);
  font-size: 16px;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body {
  background: var(--bg);
  color: var(--fg);
  overflow: hidden;
  line-height: 1.45;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}
button { cursor: pointer; border: none; background: none; }
a { color: var(--accent); text-decoration: none; }

[hidden] { display: none !important; }

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

/* Thin styled scrollbars */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) transparent;
}
*::-webkit-scrollbar { width: 11px; height: 11px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 6px;
  border: 3px solid transparent;
  background-clip: padding-box;
}
*::-webkit-scrollbar-thumb:hover {
  background: var(--scroll-thumb-hover);
  background-clip: padding-box;
}

/* ---------------------------------------------------------------------------
 * App shell
 * ------------------------------------------------------------------------- */
#app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  background:
    radial-gradient(1100px 560px at 50% -10%, var(--accent-soft), transparent 70%),
    var(--bg);
}

/* ---------------------------------------------------------------------------
 * Toolbar
 * ------------------------------------------------------------------------- */
#toolbar {
  flex: 0 0 auto;
  height: var(--toolbar-h);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-4);
  background: color-mix(in srgb, var(--bg) 78%, transparent);
  -webkit-backdrop-filter: saturate(140%) blur(12px);
  backdrop-filter: saturate(140%) blur(12px);
  border-bottom: 1px solid var(--border);
  user-select: none;
}

.brand-home {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  font-weight: 800;
  font-size: 1.18rem;
  letter-spacing: -0.02em;
  color: var(--heading);
}
.brand-home:hover { text-decoration: none; }
.brand-glyph {
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  border-radius: 9px;
  display: block;
}
.brand-name { color: var(--heading); }
.brand-dev { color: var(--accent); }

.tb-spacer { flex: 1 1 auto; }
.tb-group { display: inline-flex; align-items: center; gap: var(--sp-1); }

.tb-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-width: 38px;
  height: 38px;
  padding: 0 12px;
  border-radius: 999px;
  color: var(--fg-dim);
  background: transparent;
  border: 1px solid transparent;
  font-size: 0.9rem;
  font-weight: 600;
  transition: background-color 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}
.tb-btn:hover { background: var(--hover-bg); color: var(--fg); }
.tb-btn:active { background: var(--active-bg); }
.tb-btn .icon { width: 18px; height: 18px; pointer-events: none; }
.tb-link { color: var(--fg-dim); }
.tb-link:hover { text-decoration: none; }

/* Sun / moon swap by theme */
.icon-sun { display: none; }
:root[data-theme="light"] .icon-sun { display: inline-block; }
:root[data-theme="light"] .icon-moon { display: none; }

@media (max-width: 560px) {
  .tb-label { display: none; }
}

/* ---------------------------------------------------------------------------
 * Main / search stage
 * ------------------------------------------------------------------------- */
#main {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
}

#search-stage {
  width: 100%;
  max-width: 880px;
  padding: clamp(1.4rem, 4vw, 3.2rem) var(--sp-4) var(--sp-4);
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
}

/* ---- Command bar ---- */
#search-form { width: 100%; }
#command-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  width: 100%;
  height: 66px;
  padding: 0 var(--sp-3) 0 var(--sp-4);
  border-radius: var(--radius-lg);
  background: var(--bg-elev);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  transition: border-color 0.14s ease, box-shadow 0.14s ease;
}
#command-bar:focus-within {
  border-color: var(--accent-border);
  box-shadow: var(--shadow), 0 0 0 4px var(--accent-soft);
}
.cb-icon {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  color: var(--fg-dim);
}
.cb-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 100%;
  border: none;
  background: transparent;
  color: var(--fg);
  font-size: clamp(1.05rem, 0.95rem + 0.5vw, 1.35rem);
  font-weight: 500;
  letter-spacing: -0.01em;
}
.cb-input:focus { outline: none; }
.cb-input::placeholder { color: var(--fg-faint); font-weight: 500; }
/* Hide native search clear; we provide our own. */
.cb-input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }

.cb-clear {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 999px;
  color: var(--fg-dim);
}
.cb-clear:hover { background: var(--hover-bg); color: var(--fg); }
.cb-clear .icon { width: 16px; height: 16px; }

.cb-hint {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--fg-dim);
  padding: 5px 9px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: var(--radius-sm);
  background: var(--bg);
  white-space: nowrap;
}

/* ---- Filters ---- */
#filters {
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
}

.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 32px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--fg-dim);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  transition: background-color 0.14s ease, color 0.14s ease, border-color 0.14s ease;
}
.chip:hover { color: var(--fg); border-color: var(--border-strong); }
.chip.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-border);
}
.chip-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  flex: 0 0 auto;
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--bg-elev) 70%, transparent);
}
.chip-count {
  font-variant-numeric: tabular-nums;
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--fg-faint);
  padding: 1px 6px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--fg) 8%, transparent);
}
.chip.is-active .chip-count { color: var(--accent); background: color-mix(in srgb, var(--accent) 14%, transparent); }

.cloud-toggle {
  display: inline-flex;
  align-self: flex-start;
  padding: 3px;
  gap: 2px;
  border-radius: 999px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
}
.cloud-btn {
  height: 28px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--fg-dim);
  transition: background-color 0.14s ease, color 0.14s ease;
}
.cloud-btn:hover { color: var(--fg); }
.cloud-btn.is-active {
  color: var(--accent-fg);
  background: var(--accent);
}

/* Row holding the type toggle (left) and cloud toggle (right). */
.filter-controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
}

/* Type filter — independent multi-select pills (all on by default). */
.type-toggle {
  display: inline-flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
}
.type-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 30px;
  padding: 0 13px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--fg-faint);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  transition: background-color 0.14s ease, color 0.14s ease, border-color 0.14s ease, opacity 0.14s ease;
}
.type-btn:hover { color: var(--fg); border-color: var(--border-strong); }
.type-btn.is-active {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: var(--accent-border);
}
/* The dot reads filled (accent) when on, hollow/dim when the type is excluded. */
.type-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex: 0 0 auto;
  background: currentColor;
  opacity: 0.35;
}
.type-btn.is-active .type-dot { opacity: 1; }

/* ---------------------------------------------------------------------------
 * Results list
 * ------------------------------------------------------------------------- */
#results {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.result {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 12px 14px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--bg-elev);
  color: var(--fg);
  transition: background-color 0.12s ease, border-color 0.12s ease, transform 0.06s ease;
}
.result:hover { text-decoration: none; }
.result.is-active {
  border-color: var(--accent-border);
  background: var(--row-sel-bg);
}
.result.is-active .result-ext { color: var(--accent); }

.result-tile {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border-radius: var(--radius-sm);
  color: var(--tile-fg);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: -0.01em;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.25);
}
.result-tile .svc-ico {
  width: 23px;
  height: 23px;
  display: block;
}

.result-main {
  flex: 1 1 auto;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.result-title-row {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  min-width: 0;
}
.result-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--heading);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.result-title mark {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 3px;
  padding: 0 1px;
  font-weight: 800;
}
.result-cmd {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  font-weight: 600;
  color: var(--fg-dim);
  padding: 1px 7px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
}
.result-crumb {
  font-size: 0.8rem;
  color: var(--fg-dim);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.crumb-sep { color: var(--fg-faint); margin: 0 2px; }
.result-desc {
  font-size: 0.82rem;
  color: var(--fg-faint);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.result-meta {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
}
.result-type {
  font-size: 0.66rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--fg-dim);
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--bg);
}
.result-type.type-portal { color: var(--accent); border-color: var(--accent-border); }
.result-ext {
  width: 16px;
  height: 16px;
  color: var(--fg-faint);
  flex: 0 0 auto;
}

/* ---------------------------------------------------------------------------
 * Empty / recents / popular / no-results states
 * ------------------------------------------------------------------------- */
#state { display: flex; flex-direction: column; gap: var(--sp-4); }

.state-section { display: flex; flex-direction: column; gap: var(--sp-2); }
.state-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 2px;
}
.state-title {
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-dim);
}
.state-clear {
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--fg-dim);
  padding: 2px 8px;
  border-radius: 999px;
}
.state-clear:hover { background: var(--hover-bg); color: var(--fg); }

.state-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.no-results {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: var(--sp-2);
  padding: clamp(1.6rem, 6vw, 3.4rem) var(--sp-4);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius-lg);
  background: var(--bg-elev);
}
.no-results-icon {
  width: 48px;
  height: 48px;
  color: var(--fg-faint);
  opacity: 0.8;
}
.no-results-title {
  margin: 6px 0 0;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--heading);
}
.no-results-sub { margin: 0; color: var(--fg-dim); font-size: 0.9rem; }
.suggest-row {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  justify-content: center;
  margin-top: var(--sp-2);
}
.suggest-chip {
  height: 32px;
  padding: 0 14px;
  border-radius: 999px;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--accent-border);
  transition: filter 0.14s ease;
}
.suggest-chip:hover { filter: brightness(1.08); }

/* ---------------------------------------------------------------------------
 * Status bar
 * ------------------------------------------------------------------------- */
#statusbar {
  flex: 0 0 auto;
  height: var(--status-h);
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  padding: 0 var(--sp-4);
  background: var(--bg-elev);
  border-top: 1px solid var(--border);
  font-size: 0.74rem;
  color: var(--fg-dim);
  white-space: nowrap;
  overflow: hidden;
  user-select: none;
}
#statusbar .status-item { font-variant-numeric: tabular-nums; }
#status-count { font-weight: 700; color: var(--fg); }
.status-spacer { flex: 1 1 auto; }
@media (max-width: 560px) {
  #status-meta { overflow: hidden; text-overflow: ellipsis; }
}

/* ---------------------------------------------------------------------------
 * Responsive — phones
 * ------------------------------------------------------------------------- */
@media (max-width: 600px) {
  #toolbar { padding: 0 var(--sp-3); }
  #search-stage { padding: var(--sp-4) var(--sp-3) var(--sp-3); gap: var(--sp-3); }
  #command-bar { height: 58px; padding: 0 var(--sp-2) 0 var(--sp-3); gap: var(--sp-2); }
  .cb-hint { display: none; }
  .result { padding: 10px 11px; gap: var(--sp-2); }
  .result-tile { width: 38px; height: 38px; }
  .result-desc { display: none; }
  .result-type { display: none; }
}

/* ---------------------------------------------------------------------------
 * Motion preferences
 * ------------------------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
