@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&family=Inter:wght@400;500;600&display=swap');

:root {
  /* --- PALETTE: BIOSPHERE (Regenerative / Organic Tech) --- */

  /* DEEP (Backgrounds) */
  --bio-deep-moss: #0c1915;
  /* Very dark organic green */
  --bio-abyss: #020617;
  /* Deepest blue/black */
  --bio-void: #000000;
  /* Total black */

  /* SUBSTRATE (Surfaces) */
  --bio-glass-light: rgba(255, 255, 255, 0.7);
  --bio-glass-dark: rgba(12, 25, 21, 0.7);
  --bio-surface-light: #ffffff;
  --bio-surface-dark: #0f1c19;

  /* ENERGY (Accents) */
  --energy-algae: #10b981;
  /* Emerald 500 - Life */
  --energy-algae-dim: #059669;
  --energy-algae-glow: rgba(16, 185, 129, 0.4);

  --energy-solar: #fbbf24;
  /* Amber 400 - Sun */
  --energy-solar-glow: rgba(251, 191, 36, 0.4);

  --energy-alert: #ef4444;
  /* Red 500 */

  /* TEXTURE */
  --mesh-doc: radial-gradient(at 0% 0%, rgba(16, 185, 129, 0.15) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(251, 191, 36, 0.1) 0px, transparent 50%);

  /* --- SEMANTIC MAPPING (DEFAULT: LIGHT / CLEAN WHITE) --- */
  --bg-app: #f8fafc;
  --bg-app-texture: var(--mesh-doc);

  --bg-surface: var(--bio-surface-light);
  --bg-glass: var(--bio-glass-light);

  --border-subtle: rgba(16, 185, 129, 0.15);
  /* Algae trace */
  --border-highlight: var(--energy-algae);

  --text-primary: #022c22;
  /* Pine 900 */
  --text-secondary: #374151;
  /* Grey 700 */
  --text-tertiary: #9ca3af;
  /* Grey 400 */

  --accent-primary: var(--bio-deep-moss);
  --text-on-accent: #ffffff;

  /* --- SHAPE & PHYSICS --- */
  --radius-pane: 24px;
  /* Floating panels */
  --radius-node: 12px;
  /* Inner cards */
  --radius-pill: 999px;

  --ease-organic: cubic-bezier(0.25, 0.8, 0.25, 1);
  --ease-pulse: cubic-bezier(0.4, 0, 0.6, 1);
}

/* --- CINEMATIC MODE (Dark / Green Bio-Tech) --- */
body.bio-mode {
  --bg-app: var(--bio-deep-moss);
  --bg-app-texture: radial-gradient(circle at 50% 50%, #132a24 0%, #0c1915 100%);

  --bg-surface: #11241f;
  /* Dark Moss Surface */
  --bg-glass: rgba(17, 36, 31, 0.8);

  --border-subtle: rgba(255, 255, 255, 0.1);
  --border-highlight: var(--energy-algae);

  --text-primary: #ecfdf5;
  /* Mint 50 */
  --text-secondary: #a7f3d0;
  /* Mint 200 */
  --text-tertiary: #6ee7b7;
  /* Mint 300 (Dim) */

  --accent-primary: var(--energy-algae);
  --text-on-accent: #022c22;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Space Grotesk', sans-serif;
  /* Tech/Future */
  color: var(--text-primary);
  background-color: var(--bg-app);
  background-image: var(--bg-app-texture);
  background-attachment: fixed;
  height: 100dvh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  letter-spacing: -0.01em;
  transition: background 0.5s var(--ease-organic), color 0.5s var(--ease-organic);
}

@media (max-width: 768px) {
  body {
    height: auto;
    overflow-y: auto;
    /* Enable native scroll */
  }
}

/* --- THE TERRAFORM (Layout) --- */
#app-container {
  display: flex;
  height: 100dvh;
  width: 95%;
  max-width: 1600px;
  margin: 0 auto;
  padding: 1.5rem;
  gap: 1.5rem;
  transition: all 0.4s var(--ease-organic);
}

#app-container.wide-view {
  width: 100vw;
  max-width: 100vw;
  padding: 0;
  gap: 0;
}

/* --- ELEMENT: FLOATING DOCK (Sidebar) --- */
#sidebar {
  width: 260px;
  background: var(--bg-glass);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-pane);
  display: flex;
  flex-direction: column;
  padding: 2rem 1.5rem;
  flex-shrink: 0;
  z-index: 50;
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.1);
  transition: all 0.5s var(--ease-organic);
}

.brand {
  margin-bottom: 3rem;
  padding-left: 0;
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand::before {
  content: '';
  display: block;
  width: 4px;
  height: 24px;
  background: var(--energy-algae);
  border-radius: 4px;
  box-shadow: 0 0 10px var(--energy-algae-glow);
}

.brand h1 {
  font-size: 1.25rem !important;
  font-weight: 700 !important;
  letter-spacing: -0.02em;
  padding-left: 0;
  margin: 0;
  color: var(--text-primary);
  text-transform: uppercase;
  line-height: 1;
}

.brand::after {
  display: none;
}

nav {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.nav-section {
  display: flex;
  flex-direction: column;
  margin-bottom: 0.5rem;
  padding-bottom: 0.5rem;
}

.nav-heading {
  font-family: 'Inter', sans-serif;
  font-size: 0.70rem;
  font-weight: 600;
  color: var(--text-tertiary);
  margin-bottom: 0.25rem;
  margin-left: 1rem;
  padding-left: 0;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-node);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-secondary);
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  text-align: left;
  transition: all 0.3s var(--ease-organic);
  position: relative;
  overflow: hidden;
  text-decoration: none;
}

.nav-item:hover {
  background: rgba(16, 185, 129, 0.05);
  color: var(--text-primary);
}

.nav-item.active {
  background: rgba(16, 185, 129, 0.1);
  border-color: var(--energy-algae);
  color: var(--energy-algae);
  /* Use energy color for active state in light mode too for contrast */
  box-shadow: 0 0 15px var(--energy-algae-glow);
}

/* In light mode, maybe keep it darker green? */
body:not(.bio-mode) .nav-item.active {
  color: var(--bio-deep-moss);
  border-color: var(--bio-deep-moss);
}


.pillar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 2rem;
  margin-top: 2rem;
}

.ledger-grid {
  display: grid;
  gap: 1.5rem;
  width: 100%;
}

.portal-list-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-node);
  padding: 1.5rem 2rem;
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 2fr;
  gap: 2rem;
  align-items: center;
  transition: all 0.4s var(--ease-organic);
  position: relative;
  overflow: hidden;
  min-height: auto;
  margin-bottom: 0.5rem;
}

/* --- ELEMENT: VIEWPORT (Main Content) --- */
#main-content {
  flex: 1;
  background: var(--bg-glass);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border-radius: var(--radius-pane);
  border: 1px solid var(--border-subtle);
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.05);
  padding: 0;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* The Wrapper inside Main Content for Scrolling */
#main-content>div {
  flex: 1;
  overflow-y: auto;
  height: auto;
  padding: 3rem 4rem;
}

#main-content>div::after {
  content: "";
  display: block;
  height: 3rem;
}

/* --- COMPONENTS: MONOLITHS --- */
.spine-section,
.ledger-container,
.log-entry,
.pillar-card,
.stakeholder-card,
.quick-capture,
.card {
  background: #ffffff;
  /* Contrast Fix */
  border: 1px solid rgba(0, 0, 0, 0.12);
  border-radius: var(--radius-node);
  transition: all 0.4s var(--ease-organic);
  position: relative;
  padding: 1.5rem;
  box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.05);
}

/* Dark Mode Overrides */
body.bio-mode .spine-section,
body.bio-mode .ledger-container,
body.bio-mode .pillar-card,
body.bio-mode .portal-list-card,
body.bio-mode .card {
  background: var(--bg-surface);
  border-color: var(--border-subtle);
  box-shadow: none;
}

/* --- LAYOUT TOGGLE --- */
/* (Styles moved to #app-container default and #app-container.wide-view) */
#app-container.wide-view #sidebar,
#app-container.wide-view #main-content {
  border-radius: 0;
  border: none;
}

/* Corner Markers */
.spine-section::before,
.ledger-container::before,
.pillar-card::before,
.portal-list-card::before,
.card::before {
  content: '';
  position: absolute;
  top: -1px;
  left: -1px;
  width: 12px;
  height: 12px;
  border-top: 2px solid var(--border-subtle);
  border-left: 2px solid var(--border-subtle);
  border-radius: var(--radius-node) 0 0 0;
  opacity: 0.5;
}

.pillar-card:hover::before,
.stakeholder-card:hover::before,
.card:hover::before {
  border-color: var(--energy-algae);
  opacity: 1;
}

.pillar-card:hover,
.portal-list-card:hover,
.card:hover {
  transform: translateY(-4px) scale(1.01);
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.1);
  border-color: var(--energy-algae);
}

body.bio-mode .pillar-card:hover,
body.bio-mode .portal-list-card:hover,
body.bio-mode .card:hover {
  box-shadow: 0 0 20px var(--energy-algae-glow);
}

/* --- TYPOGRAPHY --- */
h1 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 2.5rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  margin-bottom: 2rem;
  color: var(--text-primary);
}

h2 {
  font-family: 'Space Grotesk', sans-serif;
  font-size: 2rem;
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.03em;
  margin-bottom: 2rem;
  color: var(--text-primary);
}

.portal-list-card h2 {
  font-size: 1.5rem !important;
  margin-bottom: 0.5rem;
  background: none !important;
  -webkit-text-fill-color: initial !important;
  color: var(--text-primary) !important;
}

body.bio-mode h2 {
  background: linear-gradient(135deg, #ffffff 0%, #a7f3d0 100%);
  background-clip: text;
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

h3 {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--energy-algae-dim);
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

h3::before {
  content: '';
  display: block;
  width: 6px;
  height: 6px;
  background: currentColor;
  border-radius: 50%;
}

.view-section p {
  max-width: 100%;
}

p,
li,
td,
th {
  font-family: 'Inter', sans-serif;
  font-size: 1rem;
  line-height: 1.7;
  color: var(--text-secondary);
}

/* --- UI ELEMENTS: CONTROLS --- */

.btn-primary,
.btn {
  /* Mapping .btn to primary */
  background: var(--accent-primary);
  color: var(--text-on-accent);
  border: none;
  height: 44px;
  padding: 0 1.5rem;
  border-radius: var(--radius-node);
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  transition: all 0.3s var(--ease-organic);
  position: relative;
  overflow: hidden;
  text-decoration: none;
}

.btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
}

.btn-secondary {
  background: transparent;
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  height: 44px;
  padding: 0 1.25rem;
  border-radius: var(--radius-node);
  font-family: 'Space Grotesk', sans-serif;
  font-weight: 500;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.75rem;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-secondary:hover {
  background: rgba(16, 185, 129, 0.05);
  border-color: var(--energy-algae);
}

/* Inputs */
input,
select,
textarea {
  background: var(--bg-app);
  border: 1px solid transparent;
  border-bottom: 2px solid var(--border-subtle);
  border-radius: 4px 4px 0 0;
  padding: 0.75rem 1rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.9rem;
  color: var(--text-primary);
  width: 100%;
  outline: none;
  transition: all 0.3s;
}

input:focus,
select:focus,
textarea:focus {
  background: var(--bg-surface);
  border-bottom-color: var(--energy-algae);
}

/* Tables */
.table-container {
  background: transparent;
  border: none;
  border-radius: 0;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0 0.5rem;
}

th {
  text-align: left;
  padding: 0 1.5rem;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.7rem;
  text-transform: uppercase;
  color: var(--text-tertiary);
  background: transparent;
  border: none;
  padding-bottom: 0.5rem;
}

td {
  padding: 1.25rem 1.5rem;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  font-family: 'Inter', sans-serif;
  color: var(--text-secondary);
}

td:first-child {
  border-left: 1px solid var(--border-subtle);
  border-top-left-radius: var(--radius-node);
  border-bottom-left-radius: var(--radius-node);
}

td:last-child {
  border-right: 1px solid var(--border-subtle);
  border-top-right-radius: var(--radius-node);
  border-bottom-right-radius: var(--radius-node);
}

tbody tr {
  transition: all 0.4s var(--ease-organic);
  position: relative;
}

tbody tr td:first-child {
  position: relative;
  /* Anchor for the marker */
}

/* Table Row Corner Marker */
tbody tr td:first-child::before {
  content: '';
  position: absolute;
  top: -1px;
  /* Align with border-top */
  left: -1px;
  /* Align with border-left */
  width: 12px;
  height: 12px;
  border-top: 2px solid var(--border-subtle);
  border-left: 2px solid var(--border-subtle);
  border-radius: var(--radius-node) 0 0 0;
  opacity: 0.5;
  transition: all 0.4s var(--ease-organic);
  z-index: 11;
}

tbody tr:hover td:first-child::before {
  border-color: var(--energy-algae);
  opacity: 1;
}

tbody tr:hover td {
  border-color: var(--energy-algae);
  background: var(--bg-app);
}

tbody tr:hover {
  transform: translateY(-4px) scale(1.01);
  box-shadow: 0 10px 30px -10px rgba(0, 0, 0, 0.1);
  z-index: 10;
}

/* Status Badges */
.status-badge {
  display: inline-block;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-pill);
  font-size: 0.8rem;
  font-weight: 500;
  background: var(--bg-app);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
}

/* --- THEME TOGGLE SWITCH --- */
.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border-subtle);
  margin-top: auto;
}

.theme-switch-container {
  position: static;
  width: 100%;
  padding: 0;
  border: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.theme-switch-label {
  font-size: 0.75rem;
  color: var(--text-tertiary);
  font-family: 'JetBrains Mono', monospace;
  text-transform: uppercase;
  font-weight: 600;
}

.theme-switch {
  position: relative;
  display: inline-block;
  width: 48px;
  height: 24px;
}

.theme-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.slider {
  position: absolute;
  cursor: pointer;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: #ccc;
  /* Generic Grey for Light Mode */
  transition: .4s;
  border-radius: 34px;
}

.slider:before {
  position: absolute;
  content: "";
  height: 18px;
  width: 18px;
  left: 3px;
  bottom: 3px;
  background-color: white;
  transition: .4s;
  border-radius: 50%;
}

input:checked+.slider {
  background-color: var(--energy-algae);
}

input:focus+.slider {
  box-shadow: 0 0 1px var(--energy-algae);
}

input:checked+.slider:before {
  transform: translateX(24px);
}

/* Bio Mode specific overrides for Slider */
body.bio-mode .slider {
  background-color: #374151;
  /* Darker grey */
}

body.bio-mode input:checked+.slider {
  background-color: var(--energy-algae);
}

/* --- MOBILE RESPONSIVENESS (Advanced Resource Recovery) --- */
@media (max-width: 768px) {
  #app-container {
    padding: 0;
    gap: 0;
    flex-direction: column;
    height: auto;
    overflow: visible;
  }

  #sidebar {
    width: 100%;
    height: auto;
    flex-shrink: 0;
    flex-direction: column;
    align-items: stretch;
    justify-content: flex-start;
    padding: 1rem;
    border-radius: 0;
    border: none;
    border-bottom: 1px solid var(--border-subtle);
    background: var(--bg-surface);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.02);
    /* Subtle shadow fix */
  }

  .brand {
    margin-bottom: 0;
    justify-content: space-between;
    width: 100%;
  }

  /* Show Burger Button on Mobile */
  #burger-menu {
    display: inline-flex !important;
  }

  /* Hide Nav by default on mobile, show when open */
  #nav-links-container,
  .sidebar-footer {
    display: none !important;
  }

  #nav-links-container {
    margin-top: 1rem;
  }

  .sidebar-footer {
    border-top: none;
    padding-bottom: 1rem;
  }

  nav.open #nav-links-container,
  nav.open .sidebar-footer {
    display: flex !important;
  }

  nav.open {
    /* Ensure the nav container itself (which is #sidebar now acting as nav wrapper) allows expansion */
    height: auto;
  }

  .theme-switch-container {
    position: relative;
    width: auto;
    padding: 0;
    border: none;
    bottom: auto;
  }

  #main-content {
    border-radius: 0;
    border: none;
    flex: none;
    height: auto;
    overflow: visible;
    display: block;
  }

  #main-content>div {
    padding: 1.5rem 1rem 4rem 1rem;
    height: auto;
    overflow: visible;
  }

  .spine-section,
  .ledger-container,
  .pillar-card,
  .card {
    padding: 1rem;
  }

  h1 {
    font-size: 1.8rem;
  }
}