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

:root {
  --brand: #2563eb;
  --brand-dark: #1d4ed8;
  --brand-soft: #eff6ff;
  --ink: #0f172a;
  --ink-strong: #020617;
  --ink-muted: #64748b;
  --bg: #ffffff;
  --line: #e2e8f0;
  --line-strong: #94a3b8;
  --line-soft: #f8fafc;
}

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: 'Inter', ui-sans-serif, system-ui, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  margin: 0;
  font-family: 'Outfit', ui-sans-serif, system-ui, sans-serif;
  font-weight: 500;
  letter-spacing: -0.02em;
  color: var(--ink-strong);
  line-height: 1.15;
}

p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }
a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; background: transparent; border: 0; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }
input, textarea, select { font: inherit; color: inherit; }

.visually-hidden { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); border: 0; }
.hidden { display: none !important; }

/* Topbar */
.topbar {
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.topbar-inner {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 1.25rem 2rem;
  display: flex;
  align-items: center;
}
.brand {
  font-family: 'Outfit', sans-serif;
  font-size: 1.65rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--ink-strong);
}

/* Command Center Header */
.command-center-header {
  border-bottom: 2px solid var(--line);
  background: #f8fafc;
  padding: 0 2rem;
}
.command-center-nav {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 1rem 0;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.incoming-banner {
  background: var(--brand);
  color: #fff;
  padding: 0.75rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.95rem;
  animation: slideDown 0.3s ease-out;
}
@keyframes slideDown {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* App Shell */
.app-shell {
  width: 100%;
}
.workspace {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 3rem 2rem calc(6rem + env(safe-area-inset-bottom));
  display: grid;
  gap: 5rem;
  grid-template-columns: 1fr 340px;
  align-items: start;
}

.auth-panel {
  max-width: 440px;
  margin: 4rem auto;
  display: flex;
  flex-direction: column;
  gap: 2rem;
}
.auth-header {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}
.auth-header h1 {
  font-size: clamp(2rem, 5vw, 3rem);
}
.auth-header p {
  color: var(--ink-muted);
  font-size: 1.1rem;
}
.auth-beta {
  font-size: 0.85rem !important;
  padding: 0.75rem;
  border: 1px solid var(--line);
  background: var(--line-soft);
}
.auth-note {
  border-top: 1px solid var(--line);
  padding-top: 1.25rem;
  font-size: 0.9rem;
  color: var(--ink-muted);
}
.turnstile-slot {
  display: flex;
}

/* Modal / Dialog */
.modal {
  border: 1px solid var(--line);
  border-radius: 2px;
  padding: 2rem;
  background: var(--bg);
  max-width: 480px;
  width: calc(100% - 2rem);
  margin: auto;
}
.modal::backdrop {
  background: rgba(15, 23, 42, 0.4);
}
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal textarea {
  width: 100%;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  resize: vertical;
  min-height: 120px;
}
.modal textarea:focus {
  outline: none;
  border-color: var(--ink-strong);
  box-shadow: 0 0 0 1px var(--ink-strong);
}
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

@media (max-width: 920px) {
  .workspace { grid-template-columns: 1fr; gap: 3rem; }
}

/* Thread Column */
.thread-column {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  min-width: 0;
}
.thread-children {
  display: flex;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.context-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}
.context-button {
  display: inline-flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.2rem;
  padding: 0.6rem 1.25rem;
  border: 1px solid var(--line);
  background: #fff;
  transition: border-color 150ms;
  border-radius: 2px;
}
.context-button:hover { border-color: var(--ink-strong); }
.context-item-active .context-button { 
  border-color: var(--ink-strong); 
  background: var(--ink-strong); 
  color: #fff; 
}
.context-name { font-family: 'Outfit', sans-serif; font-weight: 500; font-size: 1rem; }
.context-meta { font-size: 0.75rem; color: var(--ink-muted); }
.context-item-active .context-meta { color: rgba(255,255,255,0.7); }

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.25rem 0.75rem;
  border: 1px solid var(--line);
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--ink-strong);
  border-radius: 999px;
}

.thread-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 2rem;
  padding-bottom: 2rem;
  border-bottom: 2px solid var(--line);
}
.thread-heading h2 { font-size: clamp(2rem, 4vw, 2.75rem); margin-bottom: 0.75rem; }
.thread-subtitle { color: var(--ink-muted); max-width: 60ch; }
.thread-integrity-status { margin-top: 0.5rem; font-size: 0.85rem; color: var(--ink-muted); font-family: monospace; }
.thread-meta { display: flex; align-items: center; gap: 1.5rem; flex-shrink: 0; }
.socket-status { position: relative; padding-left: 1rem; font-size: 0.85rem; }
.socket-status::before {
  content: "";
  position: absolute; left: 0; top: 50%; width: 6px; height: 6px; border-radius: 50%;
  background: var(--ink-muted); transform: translateY(-50%);
}
.socket-status[data-state="live"]::before, .socket-status:not(:empty)::before { background: var(--brand); }

/* Context Mode Nav */
.context-mode-nav {
  display: flex;
  gap: 2rem;
  border-bottom: 1px solid var(--line);
  margin-bottom: 2rem;
}
.context-mode-btn {
  padding: 0.75rem 0;
  font-family: 'Outfit', sans-serif;
  font-weight: 500;
  color: var(--ink-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color 150ms, border-color 150ms;
}
.context-mode-btn:hover { color: var(--ink-strong); }
.context-mode-btn.active { color: var(--brand); border-bottom-color: var(--brand); }

.thread-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.call-action-btn {
  min-width: 118px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

/* Messages */
.empty-state {
  padding: 4rem 0;
  color: var(--ink-muted);
  font-size: 1rem;
  border-bottom: 1px solid var(--line);
}
.message-list {
  display: flex;
  flex-direction: column;
  gap: 2rem;
  max-height: 65vh;
  overflow-y: auto;
  padding-right: 1rem;
  -webkit-overflow-scrolling: touch;
}
.message-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding-left: 1.5rem;
  border-left: 2px solid var(--line);
  max-width: 90%;
}
.message-mine { border-left-color: var(--brand); margin-left: auto; text-align: right; padding-left: 0; padding-right: 1.5rem; border-left: none; border-right: 2px solid var(--brand); }
.message-theirs { margin-right: auto; }
.message-meta { font-size: 0.75rem; color: var(--ink-muted); letter-spacing: 0.05em; text-transform: uppercase; }
.message-body { font-size: 1.05rem; color: var(--ink-strong); }
.message-footer { font-size: 0.75rem; color: var(--ink-muted); }
.message-card-targeted { background: var(--brand-soft); }

/* Composer */
.composer {
  position: sticky;
  bottom: 0;
  padding: 1.5rem 0 calc(1.5rem + env(safe-area-inset-bottom));
  background: var(--bg);
  border-top: 1px solid var(--line);
  z-index: 10;
}
.composer textarea {
  width: 100%;
  padding: 1.25rem;
  border: 1px solid var(--line-strong);
  border-radius: 2px;
  min-height: 120px;
  resize: vertical;
}
.composer textarea:focus {
  outline: none;
  border-color: var(--ink-strong);
  box-shadow: 0 0 0 1px var(--ink-strong);
}
.composer-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 1rem;
}
.composer-status { font-size: 0.85rem; color: var(--ink-muted); }

/* Thread Search */
.thread-search {
  padding: 2rem 0;
  border-bottom: 1px solid var(--line);
}
.search-results { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 1.5rem; }
.search-result-row {
  display: flex; flex-direction: column; gap: 0.5rem;
  padding: 1rem; border: 1px solid var(--line); text-align: left;
  transition: border-color 150ms; border-radius: 2px;
}
.search-result-row:hover { border-color: var(--ink-strong); cursor: pointer; }
.search-result-meta { font-size: 0.75rem; color: var(--ink-muted); display: flex; justify-content: space-between; }
.search-result-snippet { font-size: 0.95rem; }
.search-highlight { background: var(--brand-soft); color: var(--brand-dark); font-weight: 500; padding: 0 0.2rem; }

/* Utilities */
.utility-column { display: flex; flex-direction: column; gap: 3.5rem; }
.utility-block { display: flex; flex-direction: column; gap: 1rem; }
.utility-header { display: flex; justify-content: space-between; align-items: baseline; }
.utility-header-stack-mobile { align-items: center; }
.utility-copy { font-size: 0.9rem; color: var(--ink-muted); }
.utility-note { font-size: 0.8rem; color: var(--ink-muted); }
.utility-block--quiet { border-top: 1px solid var(--line); padding-top: 1.5rem; }

/* Forms & Inputs */
.stack-form { display: flex; flex-direction: column; gap: 1.25rem; }
.compact-form { gap: 1rem; }
.field { display: flex; flex-direction: column; gap: 0.5rem; }
.field span { font-size: 0.85rem; font-weight: 500; }
.field input, .field select {
  height: 48px; padding: 0 1rem; border: 1px solid var(--line-strong); border-radius: 2px;
}
.field input:focus, .field select:focus {
  outline: none; border-color: var(--ink-strong); box-shadow: 0 0 0 1px var(--ink-strong);
}

.inline-select-control { display: flex; align-items: center; gap: 0.75rem; font-size: 0.85rem;}
.inline-select-control select { height: 36px; padding: 0 0.75rem; border: 1px solid var(--line-strong); border-radius: 2px;}

/* Buttons */
.primary-button {
  height: 48px; padding: 0 1.5rem; background: var(--brand); color: #fff;
  font-size: 0.85rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase;
  border-radius: 2px; transition: background 150ms;
}
.primary-button:hover:not(:disabled) { background: var(--brand-dark); }

.ghost-button {
  height: 48px; padding: 0 1.5rem; background: #fff; color: var(--ink-strong);
  font-size: 0.85rem; font-weight: 600; letter-spacing: 0.05em; text-transform: uppercase;
  border: 1px solid var(--line-strong); border-radius: 2px; transition: border-color 150ms;
}
.ghost-button:hover:not(:disabled) { border-color: var(--ink-strong); }

/* Verify Summary */
.verify-summary { display: grid; grid-template-columns: 1fr auto; gap: 0.75rem 1.5rem; border-top: 1px solid var(--line); padding-top: 1rem; margin-top: 1rem;}
.verify-summary dt { font-size: 0.85rem; color: var(--ink-muted); }
.verify-summary dd { margin: 0; font-family: monospace; font-size: 1.1rem; font-weight: 600; }

/* Journal */
.journal-list { display: flex; flex-direction: column; gap: 1.5rem; }
.journal-composer-footer { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; }
.journal-entry-card { padding: 1.5rem; border: 1px solid var(--line); border-radius: 2px; }
.journal-entry-meta { font-size: 0.75rem; color: var(--ink-muted); margin-bottom: 1rem; }
.journal-entry-body pre { background: var(--line-soft); padding: 1rem; overflow-x: auto; font-family: monospace; font-size: 0.85rem; border: 1px solid var(--line); }
.journal-entry-actions { margin-top: 1.5rem; display: flex; gap: 1rem; border-top: 1px dashed var(--line); padding-top: 1rem; }
.journal-entry-actions button { font-size: 0.85rem; color: var(--ink-muted); font-weight: 500; }
.journal-entry-actions button:hover { color: var(--ink-strong); }

/* Toasts */
.toast-region { position: fixed; bottom: 1.5rem; right: 1.5rem; display: flex; flex-direction: column; gap: 0.5rem; z-index: 100; }
.toast { background: var(--ink-strong); color: #fff; padding: 1rem 1.5rem; font-size: 0.9rem; border-radius: 4px; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
.toast-error { background: #dc2626; }
.toast-success { background: var(--brand-dark); }
