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

/* Design system ported from deargrant.org's app (editorial paper/green/acid,
   hover-elevated cards, large light-weight display numerals) and
   grantflows.org's bold dark hero for the sign-in moment — not a color swap,
   the actual elevation/typography treatment. */
:root {
  --paper: #122013;
  --rail: #182719;
  --panel: #1d2c1d;
  --ink: #f1f0e9;
  --muted: #b1baa8;
  --muted-dim: #879181;
  --line: #3d4b3a;
  --green: #101c11;
  --green-2: #b8c47a;
  --acid: #b8c47a;
  --amber: #d0ab5c;
  --rust: #d37155;
  --rust-bg: #3c211b;
  --ease: cubic-bezier(.22,.61,.36,1);
  --font: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;

  /* aliases used across the app */
  --bg: var(--paper);
  --surface: var(--panel);
  --border: var(--line);
  --text: var(--ink);
  --text-dim: var(--muted);
  --accent: var(--green-2);
  --accent-bg: #2b3a27;
  --danger: var(--rust);
  --danger-bg: var(--rust-bg);
  --radius: 5px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font);
  font-style: normal !important;
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-transform: lowercase;
}
/* Form controls don't reliably inherit text-transform from body in every
   browser (Safari in particular resets it via the UA stylesheet) — force it
   explicitly, the way deargrant/grantflows do, so nothing renders in
   mixed/title case regardless of how the source string was written. */
button, input, select, textarea, option { text-transform: lowercase; }

h1, h2, h3 { font-family: var(--font); font-weight: 400; letter-spacing: -0.03em; }
a { color: var(--green-2); }
::selection { background: var(--green); color: var(--acid); }

/* ---- buttons: deargrant's rectangular, not a pill ---- */
button {
  font-family: var(--font);
  display: inline-flex; align-items: center; justify-content: flex-start; gap: 7px;
  min-height: 38px;
  padding: 0 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--ink);
  font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: background 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.1s var(--ease), box-shadow 0.15s var(--ease);
}
/* Auto-width buttons (most of the app: pills, modal actions, CTAs) look
   identical left- or center-aligned, so default to flex-start — it's only
   full-width buttons (nav rows, dropdown menus, list items) where centering
   was actually a bug. Explicitly center the handful of full-width buttons
   that are meant to read as a single centered label. */
button.primary:not(nav.primary-nav button):not(.workspace-menu button),
.filter-tabs button,
.sidebar .compose-btn,
.sidebar-footer button {
  justify-content: center;
}
button:hover { border-color: var(--muted-dim); }
button:active { transform: scale(0.98); }
button.primary { background: var(--green); color: var(--acid); border-color: var(--green); font-weight: 600; }
button.primary:hover { background: #313f26; box-shadow: 0 6px 18px rgba(38,48,31,0.25); }
button.subtle { border: none; background: none; color: var(--muted); min-height: auto; padding: 5px 8px; }
button.subtle:hover { background: var(--rail); color: var(--ink); }
button:disabled { opacity: 0.5; cursor: default; }

input, textarea, select {
  font-family: var(--font);
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  color: var(--ink);
  width: 100%;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--green-2);
}
input::placeholder, textarea::placeholder { color: var(--muted-dim); }

/* ---- auth: bold dark hero, like grantflows.org's landing moment ---- */
.auth-page {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 40px 20px; background: var(--green); color: #d8dccc;
}
.auth-shell { max-width: 460px; width: 100%; }
.auth-shell .wordmark {
  display: inline-flex; align-items: center; gap: 10px;
  margin-bottom: 40px;
}
.auth-shell .wordmark i { display: block; width: 20px; height: 20px; border-radius: 50%; background: var(--acid); }
.auth-shell h1 {
  font-size: clamp(2.4rem, 6vw, 3.4rem); font-weight: 300; letter-spacing: -0.04em; line-height: 1.02;
  margin: 0 0 18px; color: #fff; max-width: 11ch;
}
.auth-shell p.lede { color: #aab89b; font-size: 14px; margin: 0 0 30px; line-height: 1.6; max-width: 42ch; }
.auth-shell p.hint { color: #8ea080; font-size: 12px; margin-top: 16px; }
.auth-shell .value-list { list-style: none; margin: 0 0 32px; padding: 0; display: flex; flex-direction: column; gap: 11px; }
.auth-shell .value-list li { display: flex; gap: 10px; font-size: 13px; color: #b9c4ac; align-items: flex-start; }
.auth-shell .value-list li::before { content: '—'; color: var(--acid); font-weight: 700; flex-shrink: 0; }
.auth-shell #google-btn { width: 100%; background: transparent; border: 0; overflow: visible; }
.auth-shell .google-signin,
.auth-shell .email-toggle {
  width: 100%;
  min-height: 64px;
  justify-content: center;
  gap: 17px;
  padding: 0 24px;
  border: 1px solid rgba(241, 240, 233, .24);
  border-radius: 18px;
  background: rgba(12, 20, 12, .16);
  color: #b9beb2;
  font-size: 16px;
  font-weight: 400;
  letter-spacing: .01em;
  white-space: nowrap;
}
.auth-shell .google-signin:hover,
.auth-shell .email-toggle:hover { background: rgba(12, 20, 12, .3); border-color: rgba(241, 240, 233, .46); color: #f1f0e9; }
.auth-divider { display: flex; align-items: center; gap: 28px; margin: 32px 0; color: #b9beb2; font-size: 12px; }
.auth-divider::before, .auth-divider::after { content: ''; height: 1px; flex: 1; background: rgba(241, 240, 233, .24); }
.google-g {
  display: inline-block;
  text-transform: none;
  font-family: Arial, sans-serif;
  font-size: 22px;
  font-weight: 700;
  line-height: 1.2;
  padding-bottom: 2px;
  background: conic-gradient(from -45deg, #4285f4 0 25%, #34a853 0 45%, #fbbc05 0 66%, #ea4335 0 82%, #4285f4 0);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.auth-shell #result { color: #cdd6bf; }
.auth-shell #result a { color: var(--acid); }
.auth-page button.primary { background: var(--acid); color: var(--green); border-color: var(--acid); }
.auth-page button.primary:hover { background: #c7d18e; box-shadow: 0 6px 18px rgba(184,196,122,0.3); }
.auth-page button:not(.primary) { background: transparent; color: #d8dccc; border-color: #45543a; }
.auth-page button:not(.primary):hover { border-color: var(--acid); color: var(--acid); }
.auth-page input, .auth-page textarea, .auth-page select { background: #1d2517; border-color: #3d4c33; color: #eef1e6; }
.auth-page input::placeholder { color: #798a6c; }

/* ---- app shell ---- */
#app { display: flex; height: 100vh; }

.sidebar {
  width: 250px;
  flex-shrink: 0;
  background: var(--rail);
  border-right: 1px solid var(--line);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  padding: 18px 14px;
}
.wordmark-row { display: flex; align-items: center; gap: 10px; padding: 2px 4px 22px; }
.wordmark-row i { display: block; width: 18px; height: 18px; border-radius: 50%; background: var(--green); flex-shrink: 0; }

.workspace-switcher { position: relative; margin-bottom: 22px; }
.workspace-switcher > button {
  width: 100%; text-align: left; display: flex; justify-content: space-between; align-items: center;
  font-weight: 600; background: var(--panel); border: 1px solid var(--line);
  color: var(--ink); font-size: 13.5px; padding: 0 12px;
}
.workspace-switcher > button:hover { border-color: var(--muted-dim); }
.workspace-switcher > button .chev { color: var(--muted); font-size: 10px; }
.workspace-menu {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 14px 35px rgba(22,27,21,0.12); z-index: 10; max-height: 320px; overflow-y: auto; padding: 5px;
}
.workspace-menu .org-label { font-size: 10px; letter-spacing: 0.1em; text-transform: uppercase; color: var(--muted); padding: 8px 8px 2px; font-weight: 600; }
.workspace-menu button { border: none; border-radius: 4px; width: 100%; min-height: 34px; justify-content: flex-start; text-align: left; font-weight: 500; color: var(--ink); background: transparent; padding: 0 10px; font-size: 13px; }
.workspace-menu button:hover { background: var(--paper); }

.nav-label { font-size: 10px; letter-spacing: 0.12em; color: var(--muted-dim); font-weight: 600; padding: 6px 10px; margin-top: 8px; text-transform: uppercase; }
nav.primary-nav { display: flex; flex-direction: column; gap: 2px; }
nav.primary-nav button {
  border: none; text-align: left; background: transparent; min-height: 38px; padding: 0 10px; border-radius: 4px;
  color: var(--muted); font-weight: 500; font-size: 12px; letter-spacing: 0.06em; text-transform: uppercase;
  display: flex; align-items: center; justify-content: flex-start; gap: 10px;
}
nav.primary-nav button:hover { background: rgba(38,48,31,0.06); color: var(--ink); }
nav.primary-nav button.active { background: var(--green); color: var(--acid); font-weight: 600; }
nav.primary-nav button .icon { width: 16px; text-align: center; opacity: 0.85; font-size: 12.5px; }

.sidebar .compose-btn { margin: 16px 2px 4px; font-weight: 600; }

.sidebar-footer { margin-top: auto; font-size: 12px; color: var(--muted); padding: 14px 8px 4px; border-top: 1px solid var(--line); }
.sidebar-footer .who { display: flex; align-items: center; gap: 9px; margin-bottom: 10px; color: var(--ink); font-size: 12.5px; overflow: hidden; }
.sidebar-footer .who span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-footer button { width: 100%; }

.avatar {
  width: 27px; height: 27px; border-radius: 50%; background: var(--green); color: var(--acid);
  display: inline-flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700;
  flex-shrink: 0;
}
.avatar.sm { width: 20px; height: 20px; font-size: 9.5px; }

main { flex: 1; overflow-y: auto; padding: 34px 44px; max-width: 1000px; }
.view-header { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 22px; }
.view-header h2 { font-size: clamp(1.4rem, 2.2vw, 1.9rem); margin: 0; font-weight: 400; letter-spacing: 0.01em; text-transform: uppercase; color: var(--ink); }

.search-bar { margin-bottom: 26px; position: relative; }
.search-bar input { padding-left: 36px; height: 42px; }
.search-bar::before {
  content: '⌕'; position: absolute; left: 13px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 17px; pointer-events: none;
}

.empty-state { color: var(--muted); padding: 80px 24px; text-align: center; font-size: 13.5px; }
.empty-state .empty-icon {
  width: 38px; height: 38px; margin: 0 auto 14px; border-radius: 50%; background: var(--rail);
  display: flex; align-items: center; justify-content: center; font-size: 15px; color: var(--muted-dim);
}
.empty-state .empty-title { font-weight: 600; color: var(--ink); font-size: 13px; letter-spacing: 0.04em; text-transform: uppercase; margin-bottom: 6px; }
.empty-state .empty-body { max-width: 320px; margin: 0 auto; color: var(--muted); }

/* ---- cards / rows: elevated on hover, like deargrant's grant-card ---- */
.row-list { display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row {
  padding: 16px 18px; border-bottom: 1px solid var(--line); cursor: pointer; display: flex; gap: 14px; align-items: flex-start;
  transition: background 0.15s var(--ease);
}
.row:last-child { border-bottom: none; }
.row:hover { background: #f9f7f1; }
.row .row-main { flex: 1; min-width: 0; }
.row .row-title { font-weight: 600; font-size: 14px; color: var(--ink); }
.row.unread .row-title { font-weight: 700; }
.row .row-preview { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; margin-top: 3px; }
.row .row-meta { font-size: 11.5px; color: var(--muted-dim); white-space: nowrap; padding-top: 1px; }
.dot-unread { width: 7px; height: 7px; border-radius: 50%; background: var(--green-2); margin-top: 6px; flex-shrink: 0; }

.demo-banner {
  background: #efe6d8; color: var(--amber); font-size: 12.5px; padding: 10px 14px; border-radius: var(--radius);
  margin-bottom: 16px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border: 1px solid #e3d3ae;
}
.demo-banner button { flex-shrink: 0; }

/* ---- stat strip: full-bleed dark banner, like deargrant's weekly-brief/pipeline-summary ---- */
.stat-strip {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  background: var(--green); color: #fff; border-radius: var(--radius); margin-bottom: 22px; overflow: hidden;
}
.stat-strip > div { padding: 16px 20px; border-right: 1px solid #3a4830; display: flex; flex-direction: column; gap: 4px; }
.stat-strip > div:last-child { border-right: none; }
.stat-strip strong { font-size: 1.7rem; font-weight: 300; color: var(--acid); letter-spacing: -0.02em; }
.stat-strip span { font-size: 11px; color: #b9c4ac; }

/* ---- task rows ---- */
.row-list.tasks { border: none; background: none; overflow: visible; display: flex; flex-direction: column; gap: 8px; }
.task-row {
  display: flex; align-items: center; gap: 13px; padding: 14px 18px; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--panel); transition: box-shadow 0.15s var(--ease), border-color 0.15s var(--ease), transform 0.15s var(--ease);
}
.task-row:hover { border-color: var(--muted-dim); box-shadow: 0 8px 22px rgba(22,27,21,0.06); transform: translateY(-1px); }
.task-row input[type="checkbox"] { width: 17px; height: 17px; accent-color: var(--green-2); cursor: pointer; }
.task-row.done { opacity: 0.7; }
.task-row.done .task-title { text-decoration: line-through; color: var(--muted); }
.task-row .task-title { flex: 1; font-size: 14px; color: var(--ink); }
.task-meta { font-size: 11.5px; color: var(--muted); display: flex; gap: 10px; align-items: center; }

/* ---- pills (status/badges) ---- */
.badge, .pill {
  display: inline-flex; align-items: center; gap: 4px; font-size: 10px; font-weight: 600;
  letter-spacing: 0.04em; padding: 3px 10px; border-radius: 999px;
  background: var(--green); color: var(--acid);
}

.filter-tabs { display: flex; gap: 6px; margin-bottom: 20px; }
.filter-tabs button { font-size: 12px; min-height: 32px; padding: 0 14px; border-radius: 999px; }
.filter-tabs button.primary { background: var(--green); color: var(--acid); border-color: var(--green); }

/* ---- chat ---- */
.chat-panel { display: flex; flex-direction: column; height: calc(100vh - 76px); }
.chat-messages { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; padding-bottom: 14px; }
.chat-msg { max-width: 640px; display: flex; gap: 12px; }
.chat-msg .bubble { flex: 1; }
.chat-msg .author { font-weight: 700; font-size: 13px; color: var(--ink); }
.chat-msg .time { color: var(--muted-dim); font-size: 11px; margin-left: 7px; font-weight: 400; }
.chat-msg .body { white-space: pre-wrap; font-size: 14px; margin-top: 3px; color: var(--ink); }
.chat-compose { display: flex; gap: 10px; padding-top: 14px; border-top: 1px solid var(--line); }
.chat-compose textarea { resize: none; height: 48px; }

.thread-view { border: 1px solid var(--line); border-radius: var(--radius); padding: 22px; background: var(--panel); }
.thread-actions { display: flex; gap: 8px; margin-bottom: 18px; flex-wrap: wrap; }
.thread-actions button { font-size: 12px; min-height: 32px; padding: 0 12px; }
.thread-body { white-space: pre-wrap; font-size: 14px; color: var(--ink); }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(23,25,20,0.5); display: flex; align-items: flex-start; justify-content: center; padding-top: 8vh; z-index: 50;
}
.modal { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 26px; width: 480px; max-width: 90vw; box-shadow: 0 20px 50px rgba(22,27,21,0.2); }
.modal h3 { margin: 0 0 18px; font-size: 1.1rem; font-weight: 500; letter-spacing: 0.02em; text-transform: uppercase; color: var(--ink); }
.field { margin-bottom: 15px; }
.field label { display: block; font-size: 10.5px; color: var(--muted); margin-bottom: 6px; letter-spacing: 0.08em; text-transform: uppercase; font-weight: 600; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.ai-note { font-size: 12px; color: var(--muted); margin-top: 8px; }

/* ---- koox: restrained workspace treatment ---- */
.auth-page {
  background-color: var(--green);
  background-image: linear-gradient(rgba(16, 28, 17, .78), rgba(16, 28, 17, .78)), url('/assets/koox-wood-background.png');
  background-position: center;
  background-size: cover;
}
.auth-shell { max-width: 400px; }
.auth-shell .wordmark { margin-bottom: 52px; }
.auth-shell .lede { letter-spacing: .025em; }
.auth-shell .value-list { display: none; }

#app, main { background: var(--paper); }
.sidebar { border-right-color: rgba(184, 196, 122, .18); }
.wordmark-row { padding-bottom: 28px; }
.workspace-switcher > button,
.workspace-menu,
.row-list,
.task-row,
.thread-view,
.modal,
input, textarea, select,
button { border-radius: 2px; }
.workspace-switcher > button,
input, textarea, select,
button { background: var(--panel); border-color: var(--line); color: var(--ink); }
button.primary { background: var(--acid); border-color: var(--acid); color: var(--green); }
button.primary:hover { background: #cad68c; box-shadow: none; }
button.subtle:hover, .hamburger:hover { background: #273724; color: var(--ink); }
.sidebar .compose-btn { align-self: flex-start; width: fit-content; padding-inline: 14px; }

.nav-label,
.workspace-menu .org-label,
nav.primary-nav button,
.view-header h2,
.modal h3,
.field label,
.empty-state .empty-title { text-transform: uppercase; letter-spacing: .04em; }
nav.primary-nav button { color: var(--muted); }
nav.primary-nav button.active { color: var(--green); background: var(--acid); }
nav.primary-nav button:hover { background: #273724; color: var(--ink); }
.view-header h2 { font-weight: 400; }
.row-list, .task-row, .thread-view, .modal { background: var(--panel); border-color: var(--line); box-shadow: none; }
.row { border-bottom-color: var(--line); }
.row:hover { background: #273724; }
.task-row:hover { background: #273724; border-color: var(--muted-dim); box-shadow: none; transform: none; }
.demo-banner { background: #293524; color: #d6ddc8; border-color: #46583f; }
.stat-strip { background: var(--green); }
.stat-strip > div { border-right-color: #344630; }
.stat-strip strong { color: var(--acid); }
.filter-tabs button { border-radius: 2px; }
.filter-tabs button.primary { color: var(--green); background: var(--acid); border-color: var(--acid); }
.chat-compose { border-top: 1px solid var(--line); padding-top: 20px; }
.modal-overlay { background: rgba(6, 12, 6, .7); }
.coauthor-panel { background: #273724; border-color: var(--line); }
.coauthor-issues li { background: var(--panel); border-color: var(--line); }
.coauthor-head strong { color: var(--acid); }
a { color: var(--acid); }

/* ---- coauthor: AI clarity/tone/completeness review, e.g. in Compose ---- */
.coauthor-panel { margin: 12px 0; padding: 14px 16px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--rail); }
.coauthor-head { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.coauthor-head strong { font-size: 12.5px; color: var(--green-2); font-weight: 600; }
.coauthor-head strong.needs-work { color: var(--amber); }
.coauthor-issues { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.coauthor-issues li { padding: 10px 12px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); font-size: 12.5px; line-height: 1.55; color: var(--ink); }
.coauthor-issues li b { display: inline-block; margin-right: 7px; padding: 1px 8px; border-radius: 999px; background: var(--green); color: var(--acid); font-size: 9.5px; font-weight: 700; }
.coauthor-issues li q { display: block; margin: 5px 0; padding-left: 9px; border-left: 2px solid var(--line); color: var(--muted); quotes: none; }

/* ---- mobile top bar + hamburger (hidden on desktop) ---- */
.mobile-topbar { display: none; }
.hamburger { display: none; }
.sidebar-backdrop { display: none; }

@media (max-width: 720px) {
  #app { display: block; height: 100vh; overflow: hidden; }

  .mobile-topbar {
    display: flex; align-items: center; gap: 12px; height: 54px; padding: 0 16px;
    background: var(--rail); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20;
  }
  .mobile-topbar .mobile-title { font-weight: 600; font-size: 13.5px; color: var(--ink); }
  .hamburger {
    display: flex; flex-direction: column; justify-content: center; gap: 4px;
    width: 32px; height: 32px; border: none; background: none; padding: 0; border-radius: 4px;
  }
  .hamburger:hover { background: var(--paper); }
  .hamburger span { display: block; width: 16px; height: 2px; background: var(--muted); margin: 0 auto; border-radius: 1px; }

  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 40;
    width: min(84vw, 300px); transform: translateX(-100%);
    transition: transform 0.2s var(--ease);
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 8px 0 24px rgba(22,27,21,0.2); }
  .sidebar.open + .sidebar-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(23,25,20,0.4); z-index: 35;
  }
  .sidebar-footer { display: block; }

  main { padding: 20px; max-width: none; height: calc(100vh - 54px); }
  .chat-panel { height: calc(100vh - 54px - 24px); }
  .modal { width: 92vw; }
}
