:root {
  font-family: "Manrope", "Segoe UI", sans-serif;
  --bg: #060b1a;
  --panel: #0d1328;
  --panel-2: #131c35;
  --border: #2a3557;
  --text: #e8edff;
  --muted: #9faecf;
  --primary: #4f8cff;
  --primary-strong: #3a74df;
  --success: #1fce8b;
  --danger: #ff6f7f;
  --danger-bg: #3a1b27;
  --shadow: 0 14px 34px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html, body, #app { min-height: 100%; }
body {
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(1200px 550px at 10% -8%, #1a2550 0%, transparent 65%),
    radial-gradient(1000px 500px at 90% -18%, #19263e 0%, transparent 70%),
    var(--bg);
}
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: inherit; }
.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}
.topbar {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(5, 11, 26, 0.9);
  backdrop-filter: blur(12px);
}
.eyebrow {
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-size: 0.74rem;
  color: var(--muted);
}
h1, h2, h3 { margin: 0; }
h1 { font-size: 1.45rem; }
.tab-row { display: flex; gap: 10px; align-items: center; }
.tab {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--muted);
  border-radius: 999px;
  padding: 10px 15px;
  font-weight: 700;
  text-decoration: none;
}
.tab.active {
  background: linear-gradient(135deg, #2b4ba6, #335ed2);
  border-color: #4f78e8;
  color: #fff;
}
.layout {
  padding: 16px 24px 24px;
  display: grid;
  grid-template-columns: minmax(0, 1.6fr) minmax(320px, 0.9fr);
  gap: 16px;
}
.single-layout { grid-template-columns: 1fr; }
.panel {
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(17, 25, 49, 0.94), rgba(11, 17, 34, 0.95));
  box-shadow: var(--shadow);
  border-radius: 16px;
  padding: 14px;
}
.panel-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
  align-items: center;
}
.toolbar-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.toolbar-actions input { min-width: 260px; }
input, textarea, select {
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #0a1124;
  color: var(--text);
  padding: 10px 12px;
}
input::placeholder, textarea::placeholder { color: #8a99bb; }
textarea { min-height: 98px; resize: vertical; }
textarea[readonly], .readonly-field {
  color: #c5d2ef;
  background: #101b35;
  resize: none;
}
select[multiple] { min-height: 118px; }
button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
.project-card:focus-visible {
  outline: 2px solid #79a6ff;
  outline-offset: 2px;
}
.metrics-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 12px;
}
.metric-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  background: #101937;
  display: grid;
  gap: 4px;
}
.metric-card span { color: var(--muted); font-size: 0.85rem; }
.metric-card strong { font-size: 1.2rem; }
.project-list, .document-list { display: grid; gap: 10px; }
.project-card, .document-item {
  width: 100%;
  text-align: left;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  background: linear-gradient(180deg, #121b37, #0f1830);
  color: var(--text);
}
.project-card:hover { border-color: #4963a5; background: #15203e; }
.project-card-top, .document-item-head {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  align-items: center;
}
.status-chip {
  display: inline-flex;
  border-radius: 999px;
  padding: 4px 9px;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  background: rgba(79, 140, 255, 0.15);
  color: #a8c4ff;
  border: 1px solid rgba(79, 140, 255, 0.35);
}
.status-chip.success-chip {
  background: rgba(31, 206, 139, 0.14);
  color: #86ebc4;
  border-color: rgba(31, 206, 139, 0.34);
}
.status-chip.danger-chip {
  background: rgba(255, 111, 127, 0.14);
  color: #ffc6d5;
  border-color: rgba(255, 111, 127, 0.38);
}
.muted-id { color: #95a5ca; font-size: 0.78rem; }
.project-card h3 { margin: 8px 0 6px; font-size: 1.05rem; }
.project-card p, .helper-copy, .document-item p {
  margin: 0;
  color: var(--muted);
  line-height: 1.45;
}
.document-summary {
  margin-top: 10px !important;
  color: #dce5ff !important;
  white-space: pre-wrap;
  word-break: break-word;
}
.project-card p { margin-bottom: 10px; }
.project-card-meta { display: flex; flex-wrap: wrap; gap: 8px 16px; color: #b2bfdc; font-size: 0.88rem; }
.form-panel { display: grid; gap: 12px; align-content: start; }
.form-grid { display: grid; gap: 10px; }
.form-field { display: grid; gap: 6px; }
.form-field span { font-weight: 600; }
.form-actions, .row-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.primary-button, .secondary-button, .danger-button {
  border-radius: 10px;
  border: 1px solid transparent;
  padding: 10px 14px;
  font-weight: 700;
}
.primary-button { background: var(--primary); color: #fff; }
.primary-button:hover { background: var(--primary-strong); }
.secondary-button { background: #111a31; color: #dce5ff; border-color: var(--border); }
.danger-button { background: #9e2742; color: #fff; border-color: #c14462; }
.inline-error, .error-banner {
  border: 1px solid #7f2f49;
  background: var(--danger-bg);
  color: #ffc6d5;
  border-radius: 10px;
  padding: 8px 10px;
}
.inline-success {
  border: 1px solid #2d7a5f;
  background: #0e2b26;
  color: #78e2bb;
  border-radius: 10px;
  padding: 8px 10px;
}
.table-wrap { overflow: auto; }
.entity-table { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
.entity-table th, .entity-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  text-align: left;
}
.summary-cell {
  min-width: 260px;
  max-width: 460px;
  color: var(--muted);
  line-height: 1.4;
  white-space: normal;
}
.entity-table th {
  color: #a9b8db;
  font-weight: 700;
  font-size: 0.79rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.entity-table tbody tr { cursor: pointer; }
.entity-table tbody tr:hover, .entity-table tbody tr.selected { background: rgba(79, 140, 255, 0.16); }
.empty-state {
  border: 1px dashed #39486f;
  border-radius: 12px;
  padding: 16px;
  text-align: center;
  color: var(--muted);
}
.project-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}
.project-meta-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}
.project-meta-grid div {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 10px;
  display: grid;
  gap: 2px;
}
.project-meta-grid span { color: var(--muted); word-break: break-word; }
.auth-layout {
  min-height: 100vh;
  align-content: center;
}
.auth-panel {
  width: min(460px, 100%);
  justify-self: center;
}
.auth-mode-row {
  display: flex;
  gap: 8px;
}
.auth-mode-row .pill {
  flex: 1;
}
.pill {
  border: 1px solid var(--border);
  background: #0a1124;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 10px;
  font-weight: 700;
}
.pill.active {
  color: #fff;
  background: #244697;
  border-color: #3d6edb;
}
.toast-stack {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1400;
  display: grid;
  gap: 8px;
  width: min(360px, calc(100vw - 32px));
}
.db-activity {
  border-radius: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  background: #0d152d;
  box-shadow: var(--shadow);
  font-weight: 600;
}
.db-activity.done { border-color: #2d7a5f; background: #0e2b26; color: #78e2bb; }
.db-activity.busy { border-color: #3557a7; background: #0f1d40; color: #a9c3ff; }
.hidden { display: none !important; }

@media (max-width: 1100px) { .layout { grid-template-columns: 1fr; } }
@media (max-width: 800px) {
  .topbar, .panel-toolbar, .toolbar-actions, .project-detail-header { flex-direction: column; align-items: stretch; }
  .tab-row { flex-wrap: wrap; }
  .toolbar-actions input { min-width: 0; width: 100%; }
  .metrics-grid, .project-meta-grid { grid-template-columns: 1fr; }
}
