/* =============================================================================
   Arivarton PLM — single hand-written stylesheet (SPEC §3, §8).
   Dense, neutral, engineering-flavored. No framework, no CDN, no @import.
   Styles only the classes/elements that the Jinja templates actually emit.
   ========================================================================== */

:root {
  /* surfaces & ink */
  --bg:          #f3f4f6;   /* app background */
  --panel:       #ffffff;   /* cards, panels, table fields */
  --panel-alt:   #f7f8fa;   /* zebra / subtle fills */
  --ink:         #1b2027;   /* primary text */
  --ink-soft:    #38414c;   /* secondary text */
  --muted:       #6b7480;   /* de-emphasized text */
  --line:        #d8dde3;   /* hairline borders */
  --line-strong: #c2c9d1;   /* heavier borders / focus rings */

  /* topbar (dark, engineering console feel) */
  --bar:         #1f262e;
  --bar-ink:     #e7eaee;
  --bar-dim:     #aab2bd;
  --bar-line:    #2c3540;

  /* accent / actions */
  --accent:      #1f6feb;
  --accent-700:  #195bc4;
  --accent-ink:  #ffffff;
  --focus:       #6ea8fe;

  /* status palette — SPEC §8 exact intent:
     draft grey · in_review amber · approved green · rejected red · released blue */
  --st-grey:     #5c6570;
  --st-amber:    #b26a00;
  --st-green:    #1f7a3d;
  --st-red:      #c62828;
  --st-blue:     #1f6feb;
  --st-kind:     #313c49;

  --radius:      6px;
  --radius-sm:   4px;
  --shadow:      0 1px 2px rgba(20, 25, 31, 0.06);
}

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

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

body {
  margin: 0;
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji", sans-serif;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }

strong { font-weight: 600; }

code {
  font-family: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
               "Liberation Mono", monospace;
  font-size: 0.92em;
  background: #eef1f4;
  border: 1px solid var(--line);
  padding: 0.08rem 0.35rem;
  border-radius: 3px;
  word-break: break-all;
}

/* ----------------------------------------------------------------------------
   Headings
   -------------------------------------------------------------------------- */
h1 { font-size: 1.45rem; font-weight: 650; margin: 0.1rem 0 0.7rem; line-height: 1.25; }
h2 { font-size: 1.1rem;  font-weight: 600; margin: 0 0 0.6rem; }
h3 { font-size: 0.95rem; font-weight: 600; margin: 1rem 0 0.45rem;
     text-transform: uppercase; letter-spacing: 0.04em; color: var(--ink-soft); }

h1 .badge, h1 a { vertical-align: middle; }
h1 a { font-weight: inherit; }

/* ----------------------------------------------------------------------------
   Top bar / primary nav  (sticky)
   -------------------------------------------------------------------------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  padding: 0 1.1rem;
  height: 48px;
  background: var(--bar);
  color: var(--bar-ink);
  border-bottom: 1px solid var(--bar-line);
}

.brand {
  color: #fff;
  font-weight: 700;
  letter-spacing: 0.02em;
  white-space: nowrap;
  font-size: 0.98rem;
}
.brand:hover { text-decoration: none; color: #fff; }

.mainnav {
  display: flex;
  align-items: center;
  gap: 1.1rem;
  flex: 1;
  min-width: 0;
}
.mainnav a {
  color: var(--bar-dim);
  font-size: 0.9rem;
  padding: 0.2rem 0;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
}
.mainnav a:hover { color: #fff; text-decoration: none; border-bottom-color: #46505c; }

.userbox { display: flex; align-items: center; gap: 0.75rem; white-space: nowrap; }
.userbox .who { color: var(--bar-dim); font-size: 0.85rem; }
.userbox .who em { color: #7f8995; font-style: normal; }

/* ----------------------------------------------------------------------------
   Page container
   -------------------------------------------------------------------------- */
.content {
  max-width: 1120px;
  margin: 1.3rem auto 3rem;
  padding: 0 1.1rem;
}

/* ----------------------------------------------------------------------------
   Cards & panels
   -------------------------------------------------------------------------- */
.card,
.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.95rem 1.05rem;
  margin-bottom: 1rem;
}
.card > :last-child,
.panel > :last-child { margin-bottom: 0; }

.tree { margin: 0; }

/* ----------------------------------------------------------------------------
   Tables — dense, subtle borders
   -------------------------------------------------------------------------- */
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
.table th,
.table td {
  text-align: left;
  padding: 0.4rem 0.65rem;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
.table thead th {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}
.table tbody tr:hover { background: var(--panel-alt); }
.table tbody tr:last-child td { border-bottom: none; }

/* Key/value style tables (revision details use <th> in <tbody>) */
.table tbody th {
  font-weight: 600;
  color: var(--ink-soft);
  white-space: nowrap;
  width: 1%;
  background: var(--panel-alt);
}

/* BOM tree rows */
.tree-row td { vertical-align: middle; }
.tree-row.drift,
.tree-row.drift:hover { background: #fdeded; }
.tree-row.drift td { border-bottom-color: #f3c9c9; }

/* ----------------------------------------------------------------------------
   Forms & inputs
   -------------------------------------------------------------------------- */
.formrow {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: end;
  margin: 0.6rem 0 0.2rem;
}
.formrow:first-child { margin-top: 0; }

.inline {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin: 0;
}

label {
  display: inline-flex;
  flex-direction: column;
  gap: 0.2rem;
  font-size: 0.8rem;
  color: var(--muted);
}
/* Inline (checkbox) labels read horizontally, normal weight */
label.inline {
  flex-direction: row;
  align-items: center;
  font-size: 0.9rem;
  color: var(--ink);
}

input,
select {
  font: inherit;
  color: var(--ink);
  background: #fff;
  padding: 0.36rem 0.5rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  min-width: 0;
}
input[type="checkbox"] { width: auto; padding: 0; accent-color: var(--accent); }
input::placeholder { color: #98a1ac; }

input:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.18);
}

/* search boxes get a touch more room */
input[type="search"] { min-width: 240px; }

/* ----------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.4rem 0.85rem;
  font: inherit;
  font-weight: 500;
  line-height: 1.2;
  color: var(--ink);
  background: #eef1f4;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.1s ease, border-color 0.1s ease;
}
.btn:hover { background: #e3e7ec; text-decoration: none; }
.btn:active { background: #d8dde3; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.3); }

.btn.primary {
  color: var(--accent-ink);
  background: var(--accent);
  border-color: var(--accent);
}
.btn.primary:hover { background: var(--accent-700); border-color: var(--accent-700); }
.btn.primary:active { background: #1450ad; }

.btn.danger {
  color: #fff;
  background: var(--st-red);
  border-color: var(--st-red);
}
.btn.danger:hover { background: #a92121; border-color: #a92121; }

/* Link-styled buttons (logout, archive, revoke, remove BOM line) */
.linkbtn {
  display: inline;
  padding: 0;
  border: none;
  background: none;
  color: var(--accent);
  font: inherit;
  cursor: pointer;
}
.linkbtn:hover { text-decoration: underline; }
.linkbtn:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: 2px; }
.linkbtn.danger { color: var(--st-red); }

/* ----------------------------------------------------------------------------
   Utility text
   -------------------------------------------------------------------------- */
.muted { color: var(--muted); }
p.muted { margin: 0.2rem 0 0.8rem; }

/* ----------------------------------------------------------------------------
   Status badges (SPEC §8)
   draft grey · in_review amber · approved green · rejected red · released blue
   -------------------------------------------------------------------------- */
.badge {
  display: inline-block;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 600;
  line-height: 1.5;
  letter-spacing: 0.02em;
  color: #fff;
  white-space: nowrap;
  vertical-align: baseline;
}
.badge-draft    { background: var(--st-grey); }
.badge-review   { background: var(--st-amber); }
.badge-approved { background: var(--st-green); }
.badge-rejected { background: var(--st-red); }
.badge-released { background: var(--st-blue); }
.badge-kind     { background: var(--st-kind); }

/* ----------------------------------------------------------------------------
   Error banner — fixed, top, noticeable red strip (HTMX surfaces here).
   The `.static` modifier (login error, one-time token notice) sits in flow.
   -------------------------------------------------------------------------- */
.error-banner {
  background: #fbe4e4;
  border: 1px solid #e9a9a9;
  border-left: 4px solid var(--st-red);
  color: #7e1a1a;
  font-size: 0.9rem;
  padding: 0.55rem 0.85rem;
  border-radius: var(--radius-sm);
  margin: 0.5rem 0;
}

/* The dynamic banner (#error-banner) spans the top of the viewport. */
#error-banner {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 60;
  border: none;
  border-radius: 0;
  border-bottom: 2px solid #9b2222;
  background: var(--st-red);
  color: #fff;
  font-weight: 500;
  text-align: center;
  padding: 0.7rem 1rem;
  box-shadow: 0 2px 8px rgba(20, 25, 31, 0.25);
}
#error-banner[hidden] { display: none; }

/* The in-flow modifier overrides the fixed/strip styling. */
.error-banner.static {
  position: static;
  text-align: left;
  font-weight: 400;
}

/* ----------------------------------------------------------------------------
   Login & error pages (narrow centered cards)
   -------------------------------------------------------------------------- */
.login-card,
.error-page {
  max-width: 360px;
  margin: 3.5rem auto;
}
.login-card h1 { text-align: center; }
.login-card p.muted { text-align: center; }
.login-card label {
  width: 100%;
  margin-bottom: 0.7rem;
  font-size: 0.85rem;
  color: var(--ink-soft);
}
.login-card input { width: 100%; }
.login-card .btn { width: 100%; margin-top: 0.3rem; }

.error-page h1 { font-size: 2.4rem; color: var(--muted); margin-bottom: 0.3rem; }

/* ----------------------------------------------------------------------------
   PDF embed (revision page drawing preview)
   -------------------------------------------------------------------------- */
embed {
  display: block;
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-alt);
  margin-bottom: 0.6rem;
}

/* ----------------------------------------------------------------------------
   Plain lists (archived projects)
   -------------------------------------------------------------------------- */
.card ul { margin: 0.2rem 0; padding-left: 1.2rem; }
.card ul li { margin: 0.15rem 0; }

/* ----------------------------------------------------------------------------
   Responsive — laptop down to small windows
   -------------------------------------------------------------------------- */
@media (max-width: 820px) {
  .topbar {
    height: auto;
    flex-wrap: wrap;
    gap: 0.6rem 1rem;
    padding: 0.5rem 0.85rem;
  }
  .mainnav { order: 3; flex-basis: 100%; gap: 0.9rem; overflow-x: auto; }
  .content { margin-top: 1rem; padding: 0 0.85rem; }
  .table { font-size: 0.85rem; }
  .table th, .table td { padding: 0.35rem 0.45rem; }
  input[type="search"] { min-width: 0; flex: 1; }
}

/* ----------------------------------------------------------------------------
   Annotator (Phase 2, SPEC §9) — SVG overlay over rasterized PDF pages
   -------------------------------------------------------------------------- */
.anno-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem 0.8rem;
  padding: 0.5rem 0.6rem;
  margin-bottom: 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-alt);
}
.anno-tools { display: flex; flex-wrap: wrap; gap: 0.3rem; }
.anno-tool {
  font: inherit;
  font-size: 0.82rem;
  padding: 0.25rem 0.55rem;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--panel);
  color: var(--ink-soft);
  cursor: pointer;
}
.anno-tool:hover { background: #eef1f5; }
.anno-tool.active {
  background: var(--accent);
  border-color: var(--accent-700);
  color: var(--accent-ink);
}
.anno-del { color: var(--st-red); }
.anno-color { display: inline-flex; align-items: center; gap: 0.3rem; font-size: 0.82rem; color: var(--muted); }
.anno-color input[type="color"] { width: 28px; height: 24px; padding: 0; border: 1px solid var(--line-strong); background: none; }
.anno-zoom { display: inline-flex; align-items: center; gap: 0.3rem; }
.anno-zoom-label { min-width: 3em; text-align: center; font-size: 0.82rem; color: var(--muted); }
.anno-authors { display: flex; flex-wrap: wrap; align-items: center; gap: 0.3rem 0.7rem; font-size: 0.8rem; }
.anno-author { display: inline-flex; align-items: center; gap: 0.25rem; cursor: pointer; }
.anno-swatch { display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 2px; border: 1px solid rgba(0,0,0,0.2); }
.anno-readonly { font-size: 0.85rem; }

.anno-viewport {
  position: relative;
  max-height: 720px;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #5b626b;
  padding: 1rem;
}
.anno-viewport.tool-draw { cursor: crosshair; }
.anno-viewport.panning { cursor: grabbing; }
.anno-pages { display: flex; flex-direction: column; align-items: flex-start; gap: 1.2rem; }
.anno-page-wrap { will-change: transform; }
.anno-page-no { font-size: 0.75rem; color: #d7dbe0; margin-bottom: 0.2rem; }
.anno-page {
  position: relative;
  background: #fff;
  box-shadow: 0 1px 6px rgba(0,0,0,0.4);
}
.anno-page-img { display: block; user-select: none; -webkit-user-drag: none; }
.anno-svg { position: absolute; top: 0; left: 0; overflow: visible; }
.anno-mark { pointer-events: all; }
.anno-mark.editable { cursor: move; }
.anno-mark.selected { outline: none; }
.anno-mark.selected rect,
.anno-mark.selected ellipse,
.anno-mark.selected line,
.anno-mark.selected polyline { filter: drop-shadow(0 0 2px var(--accent)); }
.anno-page-error {
  padding: 2rem 1.5rem;
  background: var(--panel);
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  text-align: center;
  color: var(--ink-soft);
}
.anno-page-error .btn { margin-top: 0.6rem; }
.anno-fallback { font-size: 0.8rem; margin-top: 0.5rem; }
