/* ============================================================
   FOUNDERY · BASE STYLES
   Layout, typography, sidebar, header, overview, projects.
   Theme overrides live in themes.css (loaded after).
   ============================================================ */

/* ============================================================
   ROOT TOKENS — Foundery brand (signature dark + copper)
   ============================================================ */
:root {
  /* surfaces */
  --bg:          #0A0B0E;
  --bg-1:        #0E1015;
  --bg-2:        #14171F;
  --bg-3:        #1B1F2A;
  --bg-glass:    rgba(14, 16, 21, 0.86);
  --bg-inset:    #06070A;

  /* type */
  --t:           #ECEEF2;
  --t-soft:      #A6ADBB;
  --t-mute:      #6B7383;
  --t-faint:     #404756;
  --t-on-accent: #1A0F08;

  /* lines */
  --line:        rgba(255, 255, 255, 0.06);
  --line-2:      rgba(255, 255, 255, 0.10);
  --line-3:      rgba(255, 255, 255, 0.16);

  /* Foundery signature — warm copper / molten gold */
  --accent:      #E8A06B;
  --accent-hi:   #F2BB8E;
  --accent-lo:   #C68252;
  --accent-soft: rgba(232, 160, 107, 0.10);
  --accent-glow: rgba(232, 160, 107, 0.36);
  --accent-line: rgba(232, 160, 107, 0.36);
  --accent-wash: rgba(232, 160, 107, 0.06);

  /* secondary — cool steel */
  --steel:       #7A8FA5;
  --steel-soft:  rgba(122, 143, 165, 0.10);

  /* semantic */
  --good:        #4ADE80;
  --warn:        #F5B042;
  --bad:         #F87171;

  /* type stacks */
  --f-display:   'Fraunces', 'Times New Roman', Georgia, serif;
  --f-body:      'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --f-mono:      'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* shape */
  --r:           14px;
  --r-md:        8px;
  --r-sm:        4px;
  --r-pill:      999px;

  /* layout */
  --sidebar-w:   280px;
  --header-h:    64px;
  --maxw:        1280px;
  --pad:         clamp(1rem, 3vw, 2.4rem);
  --e:           cubic-bezier(0.22, 1, 0.36, 1);

  color-scheme: dark;
}

/* ============================================================
   RESET
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { scroll-behavior: smooth; -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--f-body);
  font-feature-settings: "ss01", "cv11";
  background: var(--bg);
  color: var(--t);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overflow-x: hidden;
  position: relative;
  min-height: 100vh;
}
img, svg { display: block; max-width: 100%; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
a { color: inherit; text-decoration: none; }
ul, ol { list-style: none; padding: 0; margin: 0; }
::selection { background: var(--accent); color: var(--t-on-accent); }

/* atmospheric layer — dot grid + accent glow */
body::before {
  content: "";
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(circle at 18% -10%, var(--accent-soft), transparent 50%),
    radial-gradient(circle at 100% 110%, var(--accent-wash), transparent 60%);
  transition: background 0.8s var(--e);
}
body::after {
  content: "";
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background-image: radial-gradient(rgba(255, 255, 255, 0.04) 1px, transparent 1px);
  background-size: 28px 28px;
  mask-image: radial-gradient(ellipse at center, #000 30%, transparent 80%);
  -webkit-mask-image: radial-gradient(ellipse at center, #000 30%, transparent 80%);
}

/* ============================================================
   ANIMATIONS
   ============================================================ */
@keyframes pulse  { 50% { opacity: 0.5; } }
@keyframes blink  { 0%, 49%, 100% { opacity: 1; } 50%, 99% { opacity: 0.3; } }
@keyframes float  { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: translateY(0); } }
@keyframes spin   { to { transform: rotate(360deg); } }
@keyframes fadein { from { opacity: 0; } to { opacity: 1; } }

/* ============================================================
   APP LAYOUT — sidebar + main content
   ============================================================ */
.app {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
  position: relative;
  z-index: 1;
}
@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
}

/* ============================================================
   SIDEBAR — collapsible project list with sub-nav nested in
   ============================================================ */
.sidebar {
  position: sticky; top: 0; left: 0;
  height: 100vh;
  border-right: 1px solid var(--line);
  background: linear-gradient(180deg, var(--bg-1) 0%, var(--bg) 100%);
  display: flex; flex-direction: column;
  overflow-y: auto;
  z-index: 30;
  scrollbar-width: thin;
  scrollbar-color: var(--line-3) transparent;
}
.sidebar::-webkit-scrollbar { width: 6px; }
.sidebar::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb { background: var(--line-3); border-radius: 3px; }

@media (max-width: 980px) {
  .sidebar {
    position: fixed;
    width: var(--sidebar-w);
    transform: translateX(-100%);
    transition: transform 0.32s var(--e);
    box-shadow: 12px 0 40px rgba(0, 0, 0, 0.5);
  }
  .sidebar.is-open { transform: translateX(0); }
}

/* SIDEBAR — Foundery brand block */
.brand-block {
  padding: 1.4rem 1.2rem 1.1rem;
  border-bottom: 1px solid var(--line);
  position: relative;
}
.brand-mark-row {
  display: flex; align-items: center; gap: 0.7rem;
  margin-bottom: 0.65rem;
}
.brand-seal {
  width: 36px; height: 36px;
  position: relative;
  flex-shrink: 0;
  filter: drop-shadow(0 0 14px var(--accent-glow));
}
.brand-name {
  font-family: var(--f-mono);
  font-size: 0.66rem;
  letter-spacing: 0.20em;
  text-transform: uppercase;
  color: var(--t);
  font-weight: 600;
}
.brand-name .dot { color: var(--accent); margin: 0 0.2em; }
.brand-tagline {
  font-family: var(--f-display);
  font-style: italic;
  font-weight: 400;
  font-size: 1.15rem;
  letter-spacing: -0.012em;
  color: var(--t);
  line-height: 1.1;
  margin: 0.4rem 0 0.3rem;
}
.brand-meta {
  font-family: var(--f-mono);
  font-size: 0.56rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--t-mute);
  display: flex; gap: 0.7rem; align-items: center;
}
.brand-meta .live-dot {
  width: 0.4rem; height: 0.4rem; border-radius: 50%;
  background: var(--good);
  box-shadow: 0 0 0 2px rgba(74, 222, 128, 0.18), 0 0 12px rgba(74, 222, 128, 0.65);
  animation: pulse 2.4s ease-in-out infinite;
}

/* SIDEBAR — section labels */
.side-label {
  font-family: var(--f-mono);
  font-size: 0.55rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--t-mute);
  font-weight: 600;
  padding: 1.1rem 1.2rem 0.5rem;
}

/* SIDEBAR — primary nav items (Portfolio Overview etc) */
.side-nav { padding: 0 0.6rem; }
.side-item {
  display: flex; align-items: center; gap: 0.7rem;
  padding: 0.55rem 0.7rem;
  border-radius: var(--r-md);
  color: var(--t-soft);
  font-size: 0.86rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.18s var(--e), color 0.18s var(--e);
  position: relative;
  border: 1px solid transparent;
}
.side-item:hover { background: var(--bg-2); color: var(--t); }
.side-item.is-active {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-line);
}
.side-item.is-active::before {
  content: "";
  position: absolute; left: -0.6rem; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 14px; border-radius: 2px;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent-glow);
}
.side-item .icon {
  width: 16px; height: 16px;
  flex-shrink: 0;
  opacity: 0.7;
  transition: opacity 0.18s var(--e);
}
.side-item:hover .icon, .side-item.is-active .icon { opacity: 1; }

/* SIDEBAR — project group (collapsible) */
.proj-group { padding: 0.15rem 0.6rem; }
.proj-head {
  display: grid;
  grid-template-columns: 26px 1fr auto auto;
  align-items: center;
  gap: 0.6rem;
  padding: 0.55rem 0.7rem;
  border-radius: var(--r-md);
  font-size: 0.86rem;
  font-weight: 500;
  color: var(--t-soft);
  cursor: pointer;
  transition: background 0.18s var(--e), color 0.18s var(--e);
  border: 1px solid transparent;
}
.proj-head:hover { background: var(--bg-2); color: var(--t); }
.proj-head.is-active {
  background: var(--bg-2);
  color: var(--t);
  border-color: var(--line-3);
}
.proj-icon {
  width: 26px; height: 26px;
  border-radius: 6px;
  display: grid; place-items: center;
  background: var(--bg-3);
  border: 1px solid var(--line-2);
  font-family: var(--f-mono);
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0;
  color: var(--t);
}
.proj-head.is-active .proj-icon {
  background: var(--accent-soft);
  border-color: var(--accent-line);
  color: var(--accent);
  box-shadow: 0 0 12px var(--accent-glow);
}
.proj-status-dot {
  width: 0.42rem; height: 0.42rem; border-radius: 50%;
  flex-shrink: 0;
  position: relative;
}
.proj-status-dot::after {
  content: ""; position: absolute; inset: -3px;
  border-radius: 50%;
  border: 1px solid currentColor;
  opacity: 0.4;
  animation: pulse 2.4s ease-in-out infinite;
}
.proj-status-dot.green  { background: var(--good); color: var(--good); box-shadow: 0 0 10px rgba(74, 222, 128, 0.65); }
.proj-status-dot.yellow { background: var(--warn); color: var(--warn); box-shadow: 0 0 10px rgba(245, 176, 66, 0.65); }
.proj-status-dot.red    { background: var(--bad);  color: var(--bad);  box-shadow: 0 0 10px rgba(248, 113, 113, 0.65); }
.proj-chevron {
  width: 12px; height: 12px;
  color: var(--t-mute);
  transition: transform 0.22s var(--e);
}
.proj-head.is-open .proj-chevron { transform: rotate(90deg); color: var(--accent); }

/* SIDEBAR — sub-nav for a project (only visible when expanded) */
.proj-sub {
  display: none;
  flex-direction: column;
  gap: 1px;
  padding: 0.35rem 0 0.55rem 2.3rem;
  margin-bottom: 0.2rem;
  position: relative;
  border-left: 1px solid var(--line-2);
  margin-left: 1.0rem;
  animation: fadein 0.25s var(--e);
}
.proj-head.is-open + .proj-sub { display: flex; }
.proj-sub-cat {
  font-family: var(--f-mono);
  font-size: 0.5rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--t-faint);
  font-weight: 600;
  padding: 0.5rem 0.7rem 0.2rem;
}
.proj-sub-link {
  font-size: 0.78rem;
  color: var(--t-mute);
  padding: 0.32rem 0.7rem;
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background 0.16s var(--e), color 0.16s var(--e);
}
.proj-sub-link:hover { background: var(--bg-2); color: var(--t-soft); }
.proj-sub-link.is-active { color: var(--accent); background: var(--accent-soft); }
.proj-sub-out {
  display: flex; align-items: center; gap: 0.4rem;
  font-family: var(--f-mono);
  font-size: 0.56rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--t-mute);
  padding: 0.45rem 0.7rem;
  margin-top: 0.3rem;
  border-top: 1px dashed var(--line-2);
  transition: color 0.16s var(--e);
}
.proj-sub-out:hover { color: var(--accent); }
.proj-sub-out.is-active { color: var(--accent); background: var(--accent-soft); }
.proj-sub-out svg { width: 10px; height: 10px; }
/* main-area scrollbar — already thin via `.main { scrollbar-width: thin }`, add webkit + visual polish */
.main::-webkit-scrollbar { width: 10px; height: 10px; }
.main::-webkit-scrollbar-track { background: transparent; }
.main::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.12);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
.main::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.24); background-clip: padding-box; }

/* SIDEBAR — engage list (8 paths) */
.engage-list { padding: 0 0.6rem; }
.engage-item {
  display: grid;
  grid-template-columns: 22px 1fr;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.7rem;
  border-radius: var(--r-md);
  font-size: 0.78rem;
  color: var(--t-soft);
  cursor: pointer;
  transition: background 0.18s var(--e), color 0.18s var(--e);
}
.engage-item:hover { background: var(--bg-2); color: var(--t); }
.engage-icon {
  width: 22px; height: 22px;
  display: grid; place-items: center;
  color: var(--t-mute);
  transition: color 0.18s var(--e);
}
.engage-icon svg { width: 14px; height: 14px; }
.engage-item:hover .engage-icon { color: var(--accent); }

/* SIDEBAR — footer */
.side-foot {
  margin-top: auto;
  padding: 1rem 1.2rem 1.2rem;
  border-top: 1px solid var(--line);
  font-family: var(--f-mono);
  font-size: 0.56rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--t-faint);
  line-height: 1.5;
}
.side-foot .accent { color: var(--accent); }
.side-foot a { color: var(--t-mute); transition: color 0.16s var(--e); }
.side-foot a:hover { color: var(--t); }
/* hidden edit toggle, bottom-right of side-foot */
.side-foot { position: relative; padding-right: 2rem; }
.side-foot-edit {
  position: absolute; right: 0.5rem; bottom: 0.6rem;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  background: rgba(255,255,255,0.04);
  border: 1px solid var(--line-2, rgba(255,255,255,0.10));
  color: var(--t-mute);
  border-radius: 5px; cursor: pointer;
  opacity: 0.55;
  transition: opacity 0.2s var(--e), color 0.2s var(--e), border-color 0.2s var(--e), background 0.2s var(--e);
}
.side-foot-edit:hover { opacity: 1; color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
body.foundery-editing .side-foot-edit { opacity: 1; color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }
/* edit-mode bar */
.foundery-edit-bar {
  position: fixed; top: 0.7rem; right: 0.7rem; z-index: 9999;
  display: flex; align-items: center; gap: 0.45rem;
  padding: 0.5rem 0.65rem;
  background: rgba(11, 14, 16, 0.92); backdrop-filter: blur(12px);
  border: 1px solid var(--accent); border-radius: 8px;
  box-shadow: 0 8px 28px rgba(0,0,0,0.5);
  font-family: var(--f-mono);
}
.foundery-edit-bar .feb-label {
  font-size: 0.6rem; letter-spacing: 0.16em; text-transform: uppercase;
  color: var(--accent); font-weight: 600; padding-right: 0.4rem;
  border-right: 1px solid rgba(255,255,255,0.1); margin-right: 0.2rem;
}
.foundery-edit-bar .feb-btn {
  font-family: inherit; font-size: 0.7rem; font-weight: 500;
  padding: 0.4rem 0.7rem; border-radius: 5px; border: 1px solid var(--line-2, rgba(255,255,255,0.12));
  background: transparent; color: var(--t-soft); cursor: pointer;
  transition: background 0.16s var(--e), color 0.16s var(--e), border-color 0.16s var(--e);
}
.foundery-edit-bar .feb-btn:hover { background: rgba(255,255,255,0.06); color: var(--t); border-color: var(--accent-line, rgba(255,255,255,0.22)); }
.foundery-edit-bar .feb-primary { background: var(--accent); color: var(--accent-on, #0a0512); border-color: var(--accent); }
.foundery-edit-bar .feb-primary:hover { background: var(--accent); filter: brightness(1.15); }
.foundery-edit-bar .feb-danger { color: #f87171; border-color: rgba(248,113,113,0.35); }
.foundery-edit-bar .feb-danger:hover { background: rgba(248,113,113,0.08); color: #f87171; }
/* outline editable elements in foundery shell */
body.foundery-editing [contenteditable="true"] {
  outline: 1px dashed rgba(167,139,250,0.45);
  outline-offset: 2px; cursor: text;
  transition: background 0.15s, outline-color 0.15s;
}
body.foundery-editing [contenteditable="true"]:hover {
  outline-color: rgba(167,139,250,0.85);
  background: rgba(167,139,250,0.04);
}
body.foundery-editing [contenteditable="true"]:focus {
  outline: 2px solid var(--accent);
  background: rgba(167,139,250,0.07);
}
/* save toast */
.foundery-edit-toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%) translateY(8px);
  z-index: 9998;
  padding: 0.55rem 1rem;
  background: rgba(11,14,16,0.94); backdrop-filter: blur(12px);
  border: 1px solid var(--accent);
  border-radius: 6px;
  font-family: var(--f-mono); font-size: 0.7rem; letter-spacing: 0.04em;
  color: var(--t); opacity: 0;
  transition: opacity 0.2s var(--e), transform 0.2s var(--e);
}
.foundery-edit-toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ============================================================
   MAIN COLUMN
   ============================================================ */
.main {
  position: relative;
  min-height: 100vh;
  display: flex; flex-direction: column;
}

/* ============================================================
   HEADER — sticky top bar
   ============================================================ */
.header {
  position: sticky; top: 0; z-index: 20;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 1rem;
  height: var(--header-h);
  padding: 0 var(--pad);
  background: var(--bg-glass);
  backdrop-filter: blur(12px) saturate(140%);
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  border-bottom: 1px solid var(--line);
}
.header-l { display: flex; align-items: center; gap: 1rem; }
.header-mobile-toggle {
  display: none;
  width: 32px; height: 32px;
  align-items: center; justify-content: center;
  border-radius: var(--r-sm);
  border: 1px solid var(--line-2);
  color: var(--t-soft);
}
@media (max-width: 980px) {
  .header-mobile-toggle { display: inline-flex; }
}

/* breadcrumb */
.crumb {
  display: flex; align-items: center; gap: 0.5rem;
  font-family: var(--f-mono);
  font-size: 0.62rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--t-mute);
}
.crumb .sep { color: var(--t-faint); }
.crumb .here { color: var(--t); font-weight: 600; }

/* tabs */
.header-tabs {
  display: flex; align-items: center; gap: 0.4rem;
  justify-self: end;
  margin-right: 0.5rem;
}
.tab {
  display: inline-flex; align-items: center;
  padding: 0.45rem 0.8rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--t-mute);
  border-radius: var(--r-sm);
  position: relative;
  transition: color 0.16s var(--e);
}
.tab:hover { color: var(--t-soft); }
.tab.is-active { color: var(--t); }
.tab.is-active::after {
  content: "";
  position: absolute;
  left: 0.8rem; right: 0.8rem;
  bottom: 2px;
  height: 1.5px;
  background: var(--accent);
  border-radius: 2px;
  box-shadow: 0 0 8px var(--accent-glow);
}
.tab.is-disabled {
  color: var(--t-faint, var(--t-mute));
  opacity: 0.4;
  pointer-events: none;
  cursor: not-allowed;
}
.tab.is-disabled:hover { color: var(--t-faint, var(--t-mute)); }
@media (max-width: 720px) { .header-tabs { display: none; } }

.header-r { display: flex; align-items: center; gap: 0.5rem; }
.header-iconbtn {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: var(--r-sm);
  color: var(--t-soft);
  border: 1px solid transparent;
  transition: all 0.16s var(--e);
}
.header-iconbtn:hover { color: var(--t); background: var(--bg-2); border-color: var(--line-2); }
.header-iconbtn svg { width: 16px; height: 16px; }
.header-cta {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.45rem 0.95rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--accent);
  color: var(--t-on-accent);
  border-radius: var(--r-sm);
  border: 1px solid var(--accent);
  transition: all 0.18s var(--e);
  position: relative;
  overflow: hidden;
}
.header-cta::before {
  content: "";
  position: absolute; inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255, 255, 255, 0.4) 50%, transparent 70%);
  transform: translateX(-100%);
  transition: transform 0.6s var(--e);
}
.header-cta:hover::before { transform: translateX(100%); }
.header-cta:hover { background: var(--accent-hi); }
.header-cta svg { width: 12px; height: 12px; }

/* ============================================================
   MAIN CONTENT WRAP
   ============================================================ */
.view {
  flex: 1;
  padding: 2rem var(--pad) 4rem;
  max-width: var(--maxw);
  width: 100%;
  margin: 0 auto;
  animation: float 0.5s var(--e) both;
}

/* ============================================================
   MOBILE OVERLAY
   ============================================================ */
.mobile-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 25;
  backdrop-filter: blur(2px);
}
.mobile-overlay.is-open { display: block; animation: fadein 0.2s var(--e); }

/* ============================================================
   FOCUS — keyboard accessibility (was missing)
   ============================================================ */
:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}
.btn:focus-visible,
.header-cta:focus-visible,
.tab:focus-visible {
  outline-offset: 3px;
}

/* Smooth, themeable scrollbar on the main column */
.main { scrollbar-width: thin; scrollbar-color: var(--line-3) transparent; }
