/* ===========================================================================
   HAYSTACK Ultimate Toolkit — visual system
   Design language: Apple HIG (Clarity · Deference · Depth · Consistency) with
   "Liquid Glass" surfaces. Light mode uses Apple's signature greys + blue;
   dark mode is pure black / white / grey.
   =========================================================================== */

/* ----------------------------- Tokens ----------------------------------- */
:root,
[data-theme="light"] {
  --bg: #f5f5f7;
  --bg-grad-1: #f3f4f8;
  --bg-grad-2: #e9ecf3;
  --surface: #ffffff;
  --surface-2: #f0f2f6;
  --panel: #ffffff;            /* solid shell (header + sidebar) — never see-through */
  --glass: rgba(255, 255, 255, 0.72);
  --glass-border: rgba(0, 0, 0, 0.08);
  --border: #e3e6ec;
  --text: #1d1d1f;
  --text-muted: #6e6e73;
  --primary: #0071e3;
  --primary-hover: #0a84ff;
  --primary-contrast: #ffffff;
  --primary-soft: rgba(0, 113, 227, 0.10);
  --danger: #d70015;
  --danger-soft: rgba(215, 0, 21, 0.10);
  --ring: rgba(0, 113, 227, 0.35);
  --shadow-sm: 0 1px 2px rgba(20, 30, 60, 0.10), 0 6px 16px rgba(20, 30, 60, 0.10);
  --shadow-md: 0 6px 22px rgba(20, 30, 60, 0.14), 0 16px 44px rgba(20, 30, 60, 0.12);
  --shadow-lg: 0 18px 56px rgba(20, 30, 60, 0.22);
  --radius: 20px;
  --radius-sm: 12px;
  --radius-pill: 980px;
  --blur: saturate(180%) blur(20px);
  --topbar-h: 90px;
  --sidebar-w: 264px;
  color-scheme: light;
}

[data-theme="dark"] {
  /* Pure monochrome. Apple's dark greys (#1c1c1e / #2c2c2e) are neutral. */
  color-scheme: dark;
  --bg: #000000;
  --bg-grad-1: #000000;
  --bg-grad-2: #000000;
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --panel: #141416;            /* solid shell (header + sidebar) — never see-through */
  --glass: rgba(28, 28, 30, 0.66);
  --glass-border: rgba(255, 255, 255, 0.10);
  --border: #2e2e30;
  --text: #f5f5f7;
  --text-muted: #98989d;
  --primary: #ffffff;
  --primary-hover: #e4e4e6;
  --primary-contrast: #000000;
  --primary-soft: rgba(255, 255, 255, 0.10);
  --danger: #cfcfcf;
  --danger-soft: rgba(255, 255, 255, 0.08);
  --ring: rgba(255, 255, 255, 0.30);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.5), 0 4px 14px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 24px rgba(0, 0, 0, 0.55);
  --shadow-lg: 0 16px 60px rgba(0, 0, 0, 0.65);
}

* { box-sizing: border-box; }
/* NOTE: height:100% makes <body> a FIXED-height flex column. On tall,
   scrolling pages this means flex children can be shrunk to fit — see
   `.topbar { flex-shrink: 0 }`, which pins the header so it stays aligned
   with the sidebar's sticky `top: var(--topbar-h)`. */
html, body { height: 100%; }

/* Paint the canvas itself so page-to-page navigation never flashes white in
   dark mode (the html background is what shows between document swaps). */
html { background-color: var(--bg); }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Text",
    "Segoe UI", system-ui, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  background: var(--bg);
  background-image: radial-gradient(1200px 600px at 100% -10%, var(--bg-grad-2), transparent),
                    linear-gradient(180deg, var(--bg-grad-1), var(--bg));
  background-attachment: fixed;
  color: var(--text);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  letter-spacing: -0.01em;
}
[data-theme="dark"] body { background-image: none; }

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: none; }
h1, h2, h3 { letter-spacing: -0.022em; }
.muted { color: var(--text-muted); }
.center { text-align: center; }
.ic { flex: 0 0 auto; }

/* ------------------------------ Top bar --------------------------------- */
/* Two layouts:
   - default (auth pages, no sidebar): one full-width glass bar.
   - .topbar--app (logged in): a left "brand" cell that shares the sidebar's
     width, background and right border so brand + sidebar form ONE connected
     column; the horizontal divider lives only under the right-hand bar. */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: stretch;
  height: var(--topbar-h);
  /* body is a fixed-height flex column (html,body{height:100%}); on tall,
     scrolling pages (e.g. Hub) flex-shrink would squash the header below
     --topbar-h, so it no longer meets the sidebar's sticky top:var(--topbar-h)
     — leaving a gap. Pin the header to its full height. */
  flex-shrink: 0;
}
.topbar:not(.topbar--app) {
  align-items: center; justify-content: space-between; padding: 0 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

.topbar-brand { display: flex; align-items: center; }
.topbar-main { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: flex-end; }

/* App shell: connected brand + sidebar column.
   These use a SOLID panel colour (not frosted glass) so the brand cell and the
   sidebar always match — a glass header would tint lighter when content scrolls
   behind it, while the sidebar (nothing behind it) would stay dark, breaking
   the seam between them. */
.topbar--app .topbar-brand {
  flex: 0 0 var(--sidebar-w); width: var(--sidebar-w);
  padding: 0 0.8rem 0 1.55rem;   /* left pad aligns the logo with the nav icons */
  overflow: hidden;              /* safety: brand never spills into the content */
  background: var(--panel);
  border-right: 1px solid var(--border);
}
.topbar--app .topbar-main {
  padding: 0 1.5rem;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
}

@supports not ((-webkit-backdrop-filter: blur(1px)) or (backdrop-filter: blur(1px))) {
  .user-dropdown, .toast { background: var(--surface); }
}

.brand { display: flex; align-items: center; gap: 0.6rem; color: var(--text); height: 100%; flex-shrink: 0; min-width: 0; }
.brand:hover { opacity: 0.85; }
/* Two stacked lines: "HAYSTACK" eyebrow over the "Ultimate Toolkit" wordmark. */
/* Stacked wordmark: HAYSTACK (big) over "Ultimate ToolKit" which is justified
   to span exactly the width of HAYSTACK above it. */
.brand-text { display: inline-flex; flex-direction: column; align-items: stretch;
  justify-content: center; line-height: 1.0; min-width: 0; }
.brand-eyebrow { font-weight: 800; font-size: 1.6rem; letter-spacing: 0.01em; white-space: nowrap; }
.brand-sub { font-weight: 500; font-size: 1.18rem; color: var(--text);
  text-align: justify; text-align-last: justify; }
.brand-logo-wrap { display: inline-flex; align-items: center; color: #000; line-height: 0; }
[data-theme="dark"] .brand-logo-wrap { color: #fff; }
.brand-logo { height: 58px; width: auto; display: block; }

.topbar-right { display: flex; align-items: center; gap: 0.55rem; }

.theme-toggle {
  width: 44px; height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-pill);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.2s ease, background 0.2s ease;
}
.theme-toggle:hover { border-color: var(--primary); transform: translateY(-1px); }
.theme-toggle:active { transform: scale(0.94); }
.theme-icon { display: inline-flex; }
[data-theme="light"] .theme-icon-dark { display: none; }
[data-theme="dark"] .theme-icon-light { display: none; }

/* User menu (dropdown) */
.user-menu { position: relative; }
.user-trigger {
  display: inline-flex; align-items: center; gap: 0.55rem;
  height: 44px; padding: 0 0.7rem 0 0.45rem;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-pill);
  cursor: pointer; font-size: 0.92rem; font-weight: 560;
  transition: border-color 0.2s ease, transform 0.15s ease, box-shadow 0.2s ease;
}
.user-trigger:hover { border-color: var(--primary); box-shadow: var(--shadow-sm); }
.avatar {
  width: 32px; height: 32px; border-radius: 50%; overflow: hidden;
  display: inline-flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--primary), var(--primary-hover));
  color: var(--primary-contrast); font-weight: 700; font-size: 0.85rem;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.user-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chevron { transition: transform 0.2s ease; color: var(--text-muted); }
.user-menu.open .chevron { transform: rotate(180deg); }

.badge {
  background: var(--primary); color: var(--primary-contrast);
  border-radius: var(--radius-pill); padding: 0.08rem 0.5rem;
  font-size: 0.62rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.05em;
}

.user-dropdown {
  position: absolute; right: 0; top: calc(100% + 10px);
  min-width: 232px;
  background: var(--glass);
  -webkit-backdrop-filter: var(--blur);
  backdrop-filter: var(--blur);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 0.4rem;
  opacity: 0; transform: translateY(-6px) scale(0.98); transform-origin: top right;
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.user-menu.open .user-dropdown { opacity: 1; transform: translateY(0) scale(1); pointer-events: auto; }
.dropdown-head { padding: 0.6rem 0.7rem 0.5rem; }
.dropdown-name { font-weight: 650; }
.dropdown-email { color: var(--text-muted); font-size: 0.82rem; overflow: hidden; text-overflow: ellipsis; }
.dropdown-sep { height: 1px; background: var(--border); margin: 0.35rem 0.2rem; }
.dropdown-item {
  display: flex; align-items: center; gap: 0.6rem; width: 100%;
  padding: 0.62rem 0.7rem; border: none; background: none;
  color: var(--text); font: inherit; font-size: 0.92rem; font-weight: 520;
  border-radius: 9px; cursor: pointer; text-align: left;
  transition: background 0.15s ease;
}
.dropdown-item:hover, .dropdown-item.active { background: var(--primary-soft); color: var(--primary); }
[data-theme="dark"] .dropdown-item:hover, [data-theme="dark"] .dropdown-item.active { color: var(--text); }
.dropdown-item.danger:hover { background: var(--danger-soft); color: var(--danger); }

/* ------------------------- Shell: sidebar + content --------------------- */
.shell { flex: 1; display: flex; align-items: flex-start; width: 100%; }

.sidebar {
  /* Sticks directly under the header. `top` MUST equal the header's real
     rendered height, so the header is pinned with `flex-shrink: 0` (see
     `.topbar`) — otherwise a shrunk header leaves a gap above the sidebar. */
  position: sticky; top: var(--topbar-h);
  align-self: stretch;
  width: var(--sidebar-w); flex: 0 0 var(--sidebar-w);
  height: calc(100vh - var(--topbar-h));
  padding: 1.25rem 0.9rem;
  display: flex; flex-direction: column;
  border-right: 1px solid var(--border);
  background: var(--panel);
}
.side-nav { display: flex; flex-direction: column; gap: 0.25rem; }
.nav-item {
  display: flex; align-items: center; gap: 0.85rem;
  padding: 0.8rem 0.9rem;
  border-radius: var(--radius-sm);
  color: var(--text); font-weight: 560; font-size: 1.08rem;
  transition: background 0.18s ease, color 0.18s ease, transform 0.12s ease;
}
.nav-item .ic { width: 22px; height: 22px; }
.nav-item:hover { background: var(--surface-2); }
.nav-item:active { transform: scale(0.985); }
.nav-item.active { background: var(--primary-soft); color: var(--primary); font-weight: 620; }
[data-theme="dark"] .nav-item.active { color: var(--text); background: var(--surface-2); }
.nav-item .ic { color: currentColor; }
.sidebar-foot { margin-top: auto; padding: 0.85rem; font-size: 0.78rem; line-height: 1.4; }

.content {
  flex: 1; min-width: 0;
  width: 100%; max-width: 1160px;
  margin: 0 auto;
  padding: 2.2rem 2rem 3rem;
}
.content-centered { display: flex; align-items: center; justify-content: center; min-height: calc(100vh - var(--topbar-h)); }

/* ------------------------------ Buttons --------------------------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.45rem;
  min-height: 44px; padding: 0.6rem 1.25rem;
  border: 1px solid transparent; border-radius: var(--radius-pill);
  font-size: 0.95rem; font-weight: 590; cursor: pointer;
  background: var(--surface-2); color: var(--text);
  transition: transform 0.12s ease, box-shadow 0.2s ease, background 0.2s ease, opacity 0.2s ease;
}
.btn:active { transform: scale(0.97); }
.btn-primary { background: var(--primary); color: var(--primary-contrast); box-shadow: 0 4px 14px var(--ring); }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn-ghost { background: transparent; border-color: var(--border); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(1.05); }
/* In dark mode --danger is grey (monochrome theme), which left the delete
   button white-on-grey with poor contrast. Use a proper red so destructive
   actions read clearly and legibly. */
[data-theme="dark"] .btn-danger { background: #ff453a; color: #ffffff; }
[data-theme="dark"] .btn-danger:hover { background: #ff5c52; filter: none; }
.btn-block { width: 100%; }
.btn-small { min-height: 36px; padding: 0.4rem 0.85rem; font-size: 0.85rem; border-radius: 10px; }
.inline-form { display: inline; margin: 0; }
/* Cursor affordances for everything clickable. */
summary, label[role="button"], .file-pick { cursor: pointer; }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

/* ------------------------------- Auth ----------------------------------- */
.auth-wrap { width: 100%; display: flex; align-items: center; justify-content: center; padding: 2rem 1rem; }
.auth-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-md);
  padding: 2.25rem; width: 100%; max-width: 410px;
}
.auth-card h1 { margin: 0 0 0.3rem; font-size: 1.6rem; }
.auth-alt { margin-top: 1.4rem; text-align: center; font-size: 0.92rem; color: var(--text-muted); }
.resend { margin-top: 0.85rem; text-align: center; display: block; }

.form { display: flex; flex-direction: column; gap: 1.05rem; margin-top: 1.4rem; }
.field { display: flex; flex-direction: column; gap: 0.4rem; font-size: 0.85rem; font-weight: 600; }
.field input {
  min-height: 46px; padding: 0.65rem 0.85rem;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); color: var(--text);
  font-size: 0.98rem; font-weight: 450;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.field input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--ring); }
.hint { color: var(--text-muted); font-weight: 400; }

.alert { padding: 0.8rem 1rem; border-radius: var(--radius-sm); font-size: 0.9rem; margin-bottom: 1rem; }
.alert-error { background: var(--danger-soft); color: var(--danger); border: 1px solid transparent; }
.alert-info { background: var(--primary-soft); color: var(--text); border: 1px solid var(--glass-border); }
[data-theme="dark"] .alert-error { background: #1c1c1e; color: #fff; border-color: #4a4a4a; }

/* -------------------------------- Hub ----------------------------------- */
.page-head { margin-bottom: 1.6rem; }
.page-head h1 { margin: 0 0 0.3rem; font-size: 2rem; }
.page-head p { margin: 0; color: var(--text-muted); }

.toolbar { display: flex; align-items: center; gap: 0.8rem; margin: 1.2rem 0 1.6rem; flex-wrap: wrap; }
.search {
  position: relative; flex: 1; min-width: 220px; max-width: 420px;
}
.search .ic { position: absolute; left: 0.95rem; top: 50%; transform: translateY(-50%); color: var(--text-muted); }
.search input {
  width: 100%; min-height: 46px; padding: 0.6rem 1rem 0.6rem 2.7rem;
  border: 1px solid var(--border); border-radius: var(--radius-pill);
  background: var(--surface); color: var(--text); font-size: 0.96rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.search input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 4px var(--ring); }

.hub-category { margin-top: 2rem; }
.hub-category:first-of-type { margin-top: 0; }
.category-title {
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); font-weight: 680; margin: 0 0 0.9rem;
}

.dashboard-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(248px, 1fr)); gap: 1.1rem; }

.dashboard-card {
  position: relative; overflow: hidden;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1.4rem;
  box-shadow: var(--shadow-sm); cursor: pointer; user-select: none;
  display: flex; flex-direction: column; gap: 0.7rem;
  transition: transform 0.2s cubic-bezier(0.34, 1.3, 0.64, 1), box-shadow 0.2s ease, border-color 0.2s ease;
  outline: none;
}
.dashboard-card::after {
  content: ""; position: absolute; inset: 0; border-radius: inherit;
  background: radial-gradient(420px circle at var(--mx, 50%) var(--my, 0%), var(--primary-soft), transparent 60%);
  opacity: 0; transition: opacity 0.25s ease; pointer-events: none;
}
.dashboard-card:hover, .dashboard-card:focus-visible {
  transform: translateY(-4px); box-shadow: var(--shadow-md); border-color: var(--primary);
}
.dashboard-card:hover::after { opacity: 1; }
.dashboard-card:active { transform: translateY(-1px) scale(0.99); }
.dashboard-card.launching { opacity: 0.55; }
.dashboard-card:hover .card-title { color: var(--primary); }
[data-theme="dark"] .dashboard-card:hover .card-title { color: var(--text); }

/* Hover-revealed "Open ↗" cue (keeps the click affordance after we replaced the
   open-hint text with the creator name). */
.card-open-cue {
  position: absolute; top: 0.9rem; right: 1rem; z-index: 1;
  display: inline-flex; align-items: center; gap: 0.25rem;
  font-size: 0.74rem; font-weight: 650; color: var(--primary);
  background: var(--primary-soft); padding: 0.2rem 0.5rem; border-radius: var(--radius-pill);
  opacity: 0; transform: translateY(-3px); pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}
[data-theme="dark"] .card-open-cue { color: var(--text); background: var(--surface-2); }
.dashboard-card:hover .card-open-cue,
.dashboard-card:focus-visible .card-open-cue { opacity: 1; transform: none; }
.card-icon {
  width: 54px; height: 54px; border-radius: 15px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.9rem; background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--glass-border);
  overflow: hidden; flex: 0 0 auto;
}
.card-icon-img { width: 100%; height: 100%; object-fit: cover; display: block; }
/* Brand-logo tiles: no tile background; the SVG's line-art uses currentColor,
   so it is black in light mode and white in dark mode (the coloured cube faces
   keep their own colour). */
.card-icon--brand { background: transparent; box-shadow: none; color: var(--text); }
.card-icon--brand .brand-logo { height: 46px; width: auto; }
.card-title { margin: 0; font-size: 1.1rem; font-weight: 620; display: flex; align-items: center; gap: 0.5rem; }
.card-desc { margin: 0; color: var(--text-muted); font-size: 0.88rem; line-height: 1.45; }
.card-hint { margin-top: auto; font-size: 0.76rem; color: var(--text-muted); display: flex; align-items: center; gap: 0.3rem; }

.empty {
  text-align: center; padding: 3.5rem 1rem; color: var(--text-muted);
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
}
.no-results { display: none; text-align: center; padding: 2.5rem; color: var(--text-muted); }

/* ------------------------------ Panels / admin -------------------------- */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 1.5rem 1.6rem; margin-top: 1.5rem;
}
.panel h2 { margin-top: 0; font-size: 1.2rem; }

.add-block { margin-bottom: 1rem; }
.add-block summary { display: inline-flex; list-style: none; margin-bottom: 0.5rem; }
.add-block summary::-webkit-details-marker { display: none; }
.grid-form { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0.8rem; align-items: end; }
.field-wide { grid-column: 1 / -1; }

.table-wrap { overflow-x: auto; border-radius: var(--radius-sm); }
.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table th, .table td { padding: 0.6rem 0.7rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { color: var(--text-muted); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.05em; }
.table tbody tr { transition: background 0.15s ease; }
.table tbody tr:hover { background: var(--surface-2); }
.table code { background: var(--surface-2); padding: 0.1rem 0.4rem; border-radius: 6px; font-size: 0.8rem; }

.cell-input {
  width: 100%; min-width: 90px; padding: 0.4rem 0.5rem;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); color: var(--text); font-size: 0.83rem;
}
.cell-input:focus { outline: none; border-color: var(--primary); }
.cell-narrow { min-width: 56px; }
.cell-wide { min-width: 200px; }
.actions-cell { display: flex; gap: 0.4rem; align-items: center; white-space: nowrap; }

/* ------------------------------ Toast ----------------------------------- */
.toast {
  position: fixed; bottom: 1.75rem; left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--glass); -webkit-backdrop-filter: var(--blur); backdrop-filter: var(--blur);
  color: var(--text); border: 1px solid var(--glass-border);
  padding: 0.8rem 1.2rem; border-radius: var(--radius-pill);
  font-size: 0.9rem; font-weight: 540; box-shadow: var(--shadow-lg);
  opacity: 0; pointer-events: none; z-index: 60;
  transition: opacity 0.25s ease, transform 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* --------------------- Avatars / image uploads -------------------------- */
.avatar-edit { display: flex; align-items: center; gap: 1.1rem; }
.avatar-lg { width: 84px; height: 84px; font-size: 2rem; box-shadow: var(--shadow-sm); }
.avatar-initial { display: inline-flex; }
.file-pick { position: relative; }

.icon-upload-row { display: inline-flex; align-items: center; gap: 0.6rem; margin-top: 0.4rem; }
.icon-preview { position: relative; width: 48px; height: 48px; border-radius: 10px; overflow: hidden;
  background: var(--surface-2); box-shadow: inset 0 0 0 1px var(--glass-border); flex: 0 0 auto;
  display: inline-flex; align-items: center; justify-content: center; }
.icon-preview-ph { font-size: 0.6rem; font-weight: 600; color: var(--text-muted); letter-spacing: 0.01em; }
.icon-preview img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: block; }

/* ------------------------------ Crop modal ------------------------------ */
.crop-modal {
  position: fixed; inset: 0; z-index: 80; display: none;
  align-items: center; justify-content: center; padding: 1.25rem;
  background: rgba(0, 0, 0, 0.55); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px);
}
.crop-modal.open { display: flex; }
.crop-dialog {
  width: 100%; max-width: 460px; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  padding: 1.4rem; animation: pop-in 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes pop-in { from { opacity: 0; transform: scale(0.96); } to { opacity: 1; transform: none; } }
.crop-head h3 { margin: 0 0 0.2rem; font-size: 1.2rem; }
.crop-head p { margin: 0 0 1rem; font-size: 0.85rem; }
.crop-stage { width: 100%; height: 320px; background: var(--surface-2); border-radius: var(--radius-sm); overflow: hidden; }
.crop-stage img { display: block; max-width: 100%; }
.crop-error { margin: 0.9rem 0 0; }
.crop-actions { display: flex; justify-content: flex-end; gap: 0.6rem; margin-top: 1.1rem; }

/* ----------------------------- Responsive ------------------------------- */
/* Tablet & smaller: stack the shell — header bar on top, the sidebar becomes a
   horizontal, scrollable nav row (labels kept), content full-width. */
@media (max-width: 860px) {
  :root { --topbar-h: 68px; }
  .topbar--app { align-items: center; justify-content: space-between; padding: 0 1rem;
    background: var(--panel); border-bottom: 1px solid var(--border); }
  .topbar--app .topbar-brand {
    flex: 0 0 auto; width: auto; padding: 0; border-right: none; background: none; overflow: visible;
  }
  .topbar--app .topbar-main {
    flex: 1; padding: 0 0 0 0.5rem; border-bottom: none; background: none;
  }
  .brand-logo { height: 40px; }
  .brand-eyebrow { font-size: 1.16rem; }
  .brand-sub { font-size: 0.82rem; }

  .shell { flex-direction: column; }
  .sidebar {
    position: static; width: 100%; flex: 0 0 auto; height: auto;
    flex-direction: row; align-items: center; gap: 0.35rem;
    border-right: none; border-bottom: 1px solid var(--border);
    padding: 0.55rem 0.7rem; overflow-x: auto; -webkit-overflow-scrolling: touch;
  }
  .side-nav { flex-direction: row; flex-wrap: nowrap; gap: 0.35rem; }
  .nav-item { padding: 0.5rem 0.85rem; white-space: nowrap; font-size: 0.98rem; }
  .nav-item span { display: inline; }
  .sidebar-foot { display: none; }
  .content { padding: 1.3rem 1rem 2.4rem; }
  .page-head h1 { font-size: 1.55rem; }
}

/* Phones */
@media (max-width: 560px) {
  .user-name { display: none; }
  .topbar { padding: 0 0.8rem; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .panel { padding: 1.1rem 1rem; }
  .grid-form { grid-template-columns: 1fr; }
  .crop-stage { height: 260px; }
  .crop-dialog { padding: 1.1rem; }
  .auth-card { padding: 1.6rem 1.25rem; }
  .toolbar .search { max-width: none; }
}

/* Small phones: drop the wordmark, keep the logo. */
@media (max-width: 380px) {
  .brand-text { display: none; }
}
