:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-alt: #f8fafc;
  --ink: #0f172a;
  --muted: #475569;
  --border: #cbd5e1;
  --nav-bg: #0f172a;
  --nav-ink: #e2e8f0;
  --primary: #0369a1;
  --primary-hover: #075985;
  --ok-bg: #dcfce7;
  --ok-ink: #166534;
  --warn-bg: #fef3c7;
  --warn-ink: #92400e;
  --danger-bg: #fee2e2;
  --danger-ink: #991b1b;
  --radius: 8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  line-height: 1.45;
  min-height: 100dvh;
}

code, pre, .mono {
  font-family: "Cascadia Mono", "Consolas", monospace;
  font-size: 0.9em;
}

.topbar {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--nav-bg);
  color: #ffffff;
  border-bottom: 2px solid #0284c7;
}

.brand { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.brand-title { font-weight: 700; font-size: 1.05rem; letter-spacing: 0.01em; }
.user-bar { display: flex; align-items: center; gap: 0.65rem; flex-wrap: wrap; }
.user-label { font-size: 0.9rem; color: #cbd5e1; }

.auth-layout {
  display: grid;
  place-items: center;
  min-height: calc(100dvh - 60px);
  padding: 1.5rem;
}

.auth-card { width: min(460px, 100%); }

.workspace-grid {
  display: grid;
  grid-template-columns: 230px minmax(0, 1fr);
  min-height: calc(100dvh - 56px);
}

.sidebar {
  background: #1e293b;
  padding: 1rem 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.nav-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  text-align: left;
  padding: 0.65rem 0.85rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--nav-ink);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
}
.nav-btn:hover { background: rgba(255, 255, 255, 0.08); }
.nav-btn.is-active { background: var(--primary); color: #ffffff; font-weight: 600; }

.main-pane {
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  min-width: 0;
}

.section-head, .subhead {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}
.section-head h1 { margin: 0; font-size: 1.35rem; }
.subhead h2, .card h2 { margin: 0 0 0.75rem 0; font-size: 1.05rem; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  box-shadow: 0 1px 2px rgba(15, 23, 42, 0.04);
}

.two-col {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(360px, 1fr));
  gap: 1rem;
  align-items: start;
}

.stack-form { display: flex; flex-direction: column; gap: 0.75rem; }
.inline-form { display: flex; flex-wrap: wrap; gap: 0.75rem; align-items: end; }
.inline-form .field { flex: 1 1 150px; }

.search-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  align-items: end;
}
.bom-add-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 0.5rem;
  align-items: end;
  margin: 0.75rem 0 1rem 0;
}
.impact-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 0.5rem;
}
.roles-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(185px, 1fr));
  gap: 0.35rem;
}

.field { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.86rem; font-weight: 600; color: var(--muted); }
.field input, .field select, .field textarea {
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #ffffff;
}
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; font-size: 0.88rem; cursor: pointer; }
.fieldset { border: 1px solid var(--border); border-radius: 6px; padding: 0.75rem; }
.fieldset legend { font-weight: 600; font-size: 0.88rem; padding: 0 0.35rem; }

.btn-row, .dialog-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; justify-content: flex-end; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.48rem 0.85rem;
  border-radius: 6px;
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}
.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: #ffffff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: var(--surface-alt); color: var(--ink); border-color: var(--border); }
.btn-secondary:hover { background: #e2e8f0; }
.btn-danger { background: var(--danger-ink); color: #ffffff; }
.btn-ghost { background: transparent; color: #e2e8f0; border-color: rgba(255,255,255,0.28); }
.btn-sm { padding: 0.25rem 0.55rem; font-size: 0.8rem; }

.table-wrap { overflow-x: auto; scrollbar-gutter: stable; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.87rem; }
.data-table th, .data-table td {
  text-align: left;
  padding: 0.55rem 0.6rem;
  border-bottom: 1px solid #e2e8f0;
  vertical-align: middle;
}
.data-table th { background: var(--surface-alt); font-weight: 700; color: var(--muted); white-space: nowrap; }
.data-table tbody tr:hover { background: #f8fafc; }

.pill, .badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 700;
  white-space: nowrap;
}
.pill-neutral { background: rgba(255,255,255,0.16); color: #ffffff; }
.pill-ok { background: var(--ok-bg); color: var(--ok-ink); }
.pill-warn { background: var(--warn-bg); color: var(--warn-ink); }
.pill-danger { background: var(--danger-bg); color: var(--danger-ink); }
.badge { background: #ef4444; color: #ffffff; }

.muted { color: var(--muted); font-size: 0.88rem; }
.stack-cards { display: flex; flex-direction: column; gap: 0.65rem; }

.gantt-board { display: flex; flex-direction: column; gap: 0.6rem; }
.gantt-row {
  display: grid;
  grid-template-columns: 180px 1fr auto;
  gap: 0.75rem;
  align-items: center;
  padding: 0.45rem 0;
  border-bottom: 1px solid #e2e8f0;
}
.gantt-track {
  position: relative;
  height: 22px;
  background: #e2e8f0;
  border-radius: 4px;
  overflow: hidden;
}
.gantt-fill {
  height: 100%;
  background: var(--primary);
  color: #ffffff;
  font-size: 0.74rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  padding-inline-start: 0.4rem;
}

.doc-detail-grid { display: flex; flex-direction: column; gap: 1rem; }
.thumb-box { max-width: 240px; border: 1px solid var(--border); border-radius: 6px; padding: 0.35rem; background: var(--surface-alt); }
.thumb-box img { display: block; max-width: 100%; height: auto; }

.toast-region {
  position: fixed;
  bottom: 1rem;
  right: 1rem;
  z-index: 900;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}
.toast {
  background: #0f172a;
  color: #ffffff;
  padding: 0.65rem 0.95rem;
  border-radius: 6px;
  font-size: 0.88rem;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}
.toast.is-err { background: var(--danger-ink); }

dialog {
  width: min(560px, 94%);
  max-height: 88dvh;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: 0 18px 40px rgba(15, 23, 42, 0.25);
}
dialog.dialog-wide { width: min(860px, 95%); }
dialog:modal { overscroll-behavior: contain; }
dialog::backdrop {
  background: rgba(15, 23, 42, 0.55);
  overflow: hidden;
  overscroll-behavior: contain;
}

@media (max-width: 800px) {
  .workspace-grid { grid-template-columns: 1fr; }
  .sidebar { flex-direction: row; overflow-x: auto; }
  .nav-btn { width: auto; white-space: nowrap; }
}
