/* FGS Unit Lifecycle Database — styles */

:root {
  --color-bg: #f5f7fa;
  --color-surface: #ffffff;
  --color-surface-alt: #f9fafc;
  --color-border: #e1e4ea;
  --color-border-strong: #c8cdd5;
  --color-text: #1a1f2c;
  --color-text-muted: #5a6473;
  --color-primary: #1e5fa8;
  --color-primary-hover: #174d8c;
  --color-danger: #b8311c;
  --color-success: #2d7c47;

  --status-stock: #5a6473;
  --status-lease: #b5731a;
  --status-deployed: #2d7c47;
  --status-sitestock: #1f7a8c;
  --status-repair: #b8311c;
  --status-quarantine: #6d4c9f;
  --status-decommissioned: #939aa6;

  --radius: 6px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.04), 0 1px 3px rgba(0,0,0,0.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Consolas, monospace;
}

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

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  font-size: 14px;
  line-height: 1.5;
}

.mono { font-family: var(--font-mono); font-size: 13px; }
.small { font-size: 12px; }

/* ---------- Login ---------- */

.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; padding: 20px;
}

.login-card {
  background: var(--color-surface);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  padding: 40px;
  width: 100%; max-width: 380px;
}

.login-logo { display: block; height: 64px; width: auto; margin: 0 auto 24px auto; }
.login-card h1 { margin: 0 0 4px 0; font-size: 22px; }
.login-subtitle { color: var(--color-text-muted); margin: 0 0 24px 0; }
.login-card label { display: block; margin-bottom: 14px; font-weight: 500; }
.login-card input { display: block; width: 100%; margin-top: 4px; }
.login-card button { width: 100%; margin-top: 8px; }
.mfa-setup { margin-top: 20px; padding-top: 20px; border-top: 1px solid var(--color-border); }

/* ---------- Topbar ---------- */

.topbar {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  position: sticky; top: 0; z-index: 10;
}

.topbar-inner {
  display: flex; align-items: center; gap: 32px;
  padding: 0 24px; height: 56px;
  max-width: 1400px; margin: 0 auto;
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand-logo { height: 32px; width: auto; display: block; }
.brand-title { font-weight: 600; }

.topnav { display: flex; gap: 4px; flex: 1; }
.topnav a {
  padding: 8px 14px; border-radius: var(--radius);
  color: var(--color-text-muted); text-decoration: none;
  font-weight: 500;
}
.topnav a:hover { background: var(--color-surface-alt); color: var(--color-text); }
.topnav a.active { background: var(--color-bg); color: var(--color-primary); }

.user-menu { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.user-name { font-weight: 500; }
.user-role {
  background: var(--color-surface-alt); color: var(--color-text-muted);
  padding: 2px 8px; border-radius: 10px; font-size: 11px; text-transform: uppercase;
}

/* ---------- Main ---------- */

.main { max-width: 1400px; margin: 0 auto; padding: 24px; }

.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 20px;
}
.page-header h1, .page h1 { margin: 0; font-size: 22px; }

/* ---------- Stats ---------- */

.stats {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 12px; margin-bottom: 20px;
}
.stat {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex; align-items: baseline; gap: 8px;
}
.stat-num { font-size: 22px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--color-text-muted); text-transform: uppercase; letter-spacing: 0.3px; }
.stat-stock { border-left: 3px solid var(--status-stock); }
.stat-lease { border-left: 3px solid var(--status-lease); }
.stat-deployed { border-left: 3px solid var(--status-deployed); }
.stat-sitestock { border-left: 3px solid var(--status-sitestock); }
.stat-repair { border-left: 3px solid var(--status-repair); }
.stat-quarantine { border-left: 3px solid var(--status-quarantine); }
.stat-customer { border-left: 3px solid #5b6470; }
.stat-support { border-left: 3px solid #1e5fa8; }

/* ---------- Filters ---------- */

.filters {
  display: flex; gap: 12px; align-items: center;
  background: var(--color-surface); padding: 12px;
  border-radius: var(--radius); border: 1px solid var(--color-border);
  margin-bottom: 12px;
}
.filters input[type="search"] { flex: 1; }
.toggle { display: flex; align-items: center; gap: 6px; font-size: 13px; cursor: pointer; }

/* ---------- Form elements ---------- */

input[type="text"], input[type="email"], input[type="password"],
input[type="date"], input[type="number"], input[type="search"],
select, textarea {
  font: inherit; padding: 7px 10px;
  border: 1px solid var(--color-border-strong);
  border-radius: var(--radius);
  background: white;
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(30,95,168,0.15);
}
textarea { resize: vertical; min-height: 60px; }
label { display: block; margin-bottom: 12px; font-weight: 500; font-size: 13px; }
label input, label select, label textarea { display: block; width: 100%; margin-top: 4px; font-weight: 400; }

/* ---------- Buttons ---------- */

button { font: inherit; cursor: pointer; border-radius: var(--radius); border: 1px solid transparent; padding: 7px 14px; }
.btn-primary {
  background: var(--color-primary); color: white;
  border: 1px solid var(--color-primary); font-weight: 500;
  text-decoration: none; display: inline-block;
}
.btn-primary:hover:not(:disabled) { background: var(--color-primary-hover); }
.btn-primary:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
  background: var(--color-surface); color: var(--color-text);
  border: 1px solid var(--color-border-strong);
}
.btn-secondary:hover { background: var(--color-surface-alt); }
.btn-ghost {
  background: transparent; color: var(--color-text-muted);
  border: 1px solid transparent; padding: 6px 10px;
}
.btn-ghost:hover { background: var(--color-surface-alt); color: var(--color-text); }
.btn-link {
  background: none; border: none; color: var(--color-primary);
  cursor: pointer; padding: 2px 6px; font-size: 13px;
}
.btn-link:hover { text-decoration: underline; }
.btn-link-danger { background: none; border: none; color: var(--color-danger); cursor: pointer; }
.btn-link-danger:hover { text-decoration: underline; }

/* ---------- Tables ---------- */

.data-table {
  width: 100%; background: var(--color-surface);
  border: 1px solid var(--color-border); border-radius: var(--radius);
  border-collapse: separate; border-spacing: 0;
  overflow: hidden;
  user-select: none;  /* shift-clicking checkboxes shouldn't drag-highlight row text */
}
.data-table th {
  text-align: left; background: var(--color-surface-alt);
  padding: 10px 14px; font-size: 12px; text-transform: uppercase;
  letter-spacing: 0.4px; color: var(--color-text-muted);
  border-bottom: 1px solid var(--color-border);
}
.data-table td {
  padding: 12px 14px; border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}
.data-table tr:last-child td { border-bottom: none; }
.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover { background: var(--color-surface-alt); }
.empty { color: var(--color-text-muted); font-style: italic; text-align: center; }
.summary-table { max-width: 360px; }
.summary-table tr.summary-total td { font-weight: 600; border-top: 2px solid var(--color-border); }

/* ---------- Status badges ---------- */

.status-badge {
  display: inline-block; padding: 3px 10px; border-radius: 12px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.3px;
  text-transform: uppercase; white-space: nowrap;
}
.status-badge-lg { padding: 6px 14px; font-size: 12px; }
.status-stock { background: #eceef2; color: var(--status-stock); }
.status-lease { background: #fbeed3; color: var(--status-lease); }
.status-deployed { background: #d6eed8; color: var(--status-deployed); }
.status-sitestock { background: #d4ecf1; color: var(--status-sitestock); }
.status-repair { background: #f5d1cc; color: var(--status-repair); }
.status-quarantine { background: #e7e0f3; color: var(--status-quarantine); }
.status-decommissioned { background: #e8eaee; color: var(--status-decommissioned); }

/* Ownership tag (Axis 2) — shown alongside the physical status badge. */
.own-badge {
  display: inline-block; padding: 3px 9px; border-radius: 12px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.3px;
  text-transform: uppercase; white-space: nowrap; margin-left: 4px;
}
.own-fgs { background: #eceef2; color: var(--status-stock); }
.own-lease { background: #fbeed3; color: var(--status-lease); }
.own-customer { background: #e7e9ed; color: #5b6470; }

/* Support contract chip (Axis 3). */
.sup-badge {
  display: inline-block; padding: 3px 9px; border-radius: 12px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.3px;
  text-transform: uppercase; white-space: nowrap; margin-left: 4px;
  background: #dde9f5; color: #1e5fa8;
}
.sup-on { background: #dde9f5; color: #1e5fa8; }
.sup-off { background: #eceef2; color: var(--status-stock); }

/* ---------- Unit detail ---------- */

.back-link {
  display: inline-block; color: var(--color-text-muted);
  text-decoration: none; margin-bottom: 12px; font-size: 13px;
}
.back-link:hover { color: var(--color-primary); }

.unit-header {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--color-surface); padding: 20px;
  border: 1px solid var(--color-border); border-radius: var(--radius);
  margin-bottom: 20px;
}
.unit-serial { font-family: var(--font-mono); font-size: 18px; font-weight: 600; }
.unit-product { color: var(--color-text-muted); margin-top: 4px; }

.panels {
  display: grid; grid-template-columns: 1fr 1fr; gap: 16px;
  margin-bottom: 20px;
}
.panel {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: 18px;
}
.panel h3 {
  margin: 0 0 14px 0; font-size: 13px; text-transform: uppercase;
  letter-spacing: 0.4px; color: var(--color-text-muted);
}
.panel dl { display: grid; grid-template-columns: 140px 1fr; gap: 8px 12px; margin: 0; }
.panel dt { color: var(--color-text-muted); font-size: 13px; }
.panel dd { margin: 0; font-size: 13px; }

.link-small { font-size: 12px; margin-left: 8px; color: var(--color-primary); }

.actions-row { display: flex; gap: 12px; margin-bottom: 24px; }
.section-title { font-size: 16px; margin: 20px 0 12px 0; }

/* ---------- Status timeline ---------- */

.timeline-block { margin-bottom: 8px; }
.timeline {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: 16px 18px;
}
.timeline-markers { position: relative; height: 14px; margin-bottom: 4px; }
.tl-marker {
  position: absolute; top: 2px; transform: translateX(-50%);
  width: 9px; height: 9px; padding: 0; border-radius: 50%;
  background: var(--color-surface); border: 2px solid var(--color-text-muted);
  cursor: pointer;
}
.tl-marker:hover { border-color: var(--color-text); }
.timeline-ribbon {
  display: flex; height: 38px; border-radius: 4px; overflow: hidden;
  border: 1px solid var(--color-border);
}
.tl-seg {
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 500; white-space: nowrap; overflow: hidden;
  cursor: pointer; border-right: 1px solid rgba(255, 255, 255, 0.55);
  min-width: 0;
}
.tl-seg:last-child { border-right: none; }
.tl-seg:hover { filter: brightness(0.96); }
/* Segments / markers whose status was inherited from a parent assembly: hatched ribbon,
   hollow ringed marker — so "via parent" periods read differently from the unit's own. */
.tl-seg.tl-inherited {
  background-image: repeating-linear-gradient(
    45deg, transparent, transparent 5px, rgba(255, 255, 255, 0.35) 5px, rgba(255, 255, 255, 0.35) 10px);
}
.tl-marker.tl-inherited { border-style: dashed; border-color: var(--color-primary); }
.timeline-axis { position: relative; height: 16px; margin-top: 6px; }
.tl-tick {
  position: absolute; transform: translateX(-50%);
  font-family: var(--font-mono); font-size: 11px; color: var(--color-text-muted);
  white-space: nowrap;
}
/* Anchor the edge ticks so their labels don't overhang the timeline. */
.timeline-axis .tl-tick:first-child { transform: none; }
.timeline-axis .tl-tick:last-child { transform: translateX(-100%); }
.timeline-legend {
  display: flex; flex-wrap: wrap; gap: 14px; margin-top: 14px;
  font-size: 12px; color: var(--color-text-muted);
}
.timeline-legend span { display: flex; align-items: center; gap: 6px; }
.timeline-legend .dot { width: 11px; height: 11px; border-radius: 2px; display: inline-block; }
.event-flash { animation: event-flash 1.5s ease-out; }
@keyframes event-flash {
  0% { background: #fbeed3; }
  100% { background: transparent; }
}

/* ---------- Event list ---------- */

.event-list { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius); overflow: hidden; }
.event {
  display: grid; grid-template-columns: 110px 1fr auto;
  gap: 18px; padding: 14px 18px;
  border-bottom: 1px solid var(--color-border);
}
.event:last-child { border-bottom: none; }
.event.voided { opacity: 0.55; }
/* Events inherited from a parent assembly — shown for context, not editable here. */
.event.inherited { background: var(--color-surface-alt); border-left: 3px solid var(--color-border-strong); }
.inherited-badge {
  font-size: 11px; font-weight: 500; color: var(--color-text-muted);
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: 10px; padding: 1px 8px; text-decoration: none;
}
.inherited-badge:hover { color: var(--color-primary); border-color: var(--color-primary); }
.event-date { font-family: var(--font-mono); font-size: 12px; color: var(--color-text-muted); padding-top: 4px; }
.event-type {
  display: inline-block; padding: 3px 10px; border-radius: 4px;
  font-weight: 600; font-size: 12px; margin-bottom: 6px;
}
.event-meta { font-size: 12px; color: var(--color-text-muted); }
.event-notes { margin-top: 6px; font-size: 13px; white-space: pre-wrap; }
.event-voided { margin-top: 6px; font-size: 12px; color: var(--color-danger); font-weight: 500; }
.silas-tag {
  background: var(--color-primary); color: white; padding: 1px 6px;
  border-radius: 3px; font-size: 10px; margin-left: 6px;
}

.evt-deploy { background: #d6eed8; color: var(--status-deployed); }
.evt-return { background: #eceef2; color: var(--status-stock); }
.evt-ownership { background: #fae3d8; color: #99461f; }
.evt-support { background: #dde9f5; color: #1e5fa8; }
.evt-repair { background: #f5d1cc; color: var(--status-repair); }
.evt-maintenance { background: #d6e3f0; color: var(--color-primary); }
.evt-fault { background: #fbdcd6; color: var(--color-danger); }
.evt-quarantine { background: #e7e0f3; color: var(--status-quarantine); }
.evt-decommission { background: #e8eaee; color: var(--status-decommissioned); }
.evt-correction { background: #fbeed3; color: var(--status-lease); }
.evt-runtime { background: #e2e8f0; color: var(--color-text-muted); }
.evt-component-fitted { background: #dbeafe; color: #1d4ed8; }
.evt-component-removed { background: #fbdcd6; color: var(--color-danger); }

.unit-header-status { text-align: right; }
.inherited-note { font-size: .8rem; font-weight: 400; color: var(--color-text-muted); margin-top: .25rem; }
.component-depth-marker { color: var(--color-text-muted); margin-right: .35rem; }
.component-row {
  display: flex; align-items: flex-start; gap: 18px;
  padding: 14px 18px; border-bottom: 1px solid var(--color-border);
}
.component-row:last-child { border-bottom: none; }
.component-row .event-body { flex: 1; min-width: 0; }
.component-row .btn-link-danger { flex-shrink: 0; align-self: center; }
.evt-other { background: #f0f1f4; color: var(--color-text-muted); }

/* ---------- Modal ---------- */

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100; padding: 20px;
}
.modal {
  background: white; border-radius: 8px; padding: 28px;
  width: 100%; max-width: 480px; max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-md);
}
.modal-wide { max-width: 640px; }
.modal h2 { margin: 0 0 16px 0; font-size: 18px; }
.modal-note { color: var(--color-text-muted); margin-bottom: 16px; font-size: 13px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-grid label { margin-bottom: 0; }
.required { color: var(--color-danger); }
.error { color: var(--color-danger); font-size: 13px; margin: 8px 0 0 0; }

.mfa-qr { text-align: center; margin: 16px 0; }
.mfa-secret {
  text-align: center; padding: 8px;
  background: var(--color-surface-alt); border-radius: var(--radius);
  font-size: 13px; letter-spacing: 1px;
}

/* ---------- Admin ---------- */

.admin-tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--color-border); }
.admin-tabs button {
  background: none; border: none; padding: 10px 16px;
  color: var(--color-text-muted); font-weight: 500;
  border-bottom: 2px solid transparent;
}
.admin-tabs button.active { color: var(--color-primary); border-bottom-color: var(--color-primary); }

.action-tag {
  font-family: var(--font-mono); font-size: 11px;
  background: var(--color-surface-alt); padding: 2px 6px; border-radius: 3px;
}
.audit-payload {
  margin: 0; font-size: 11px; max-width: 360px;
  max-height: 80px; overflow: auto;
  background: var(--color-surface-alt); padding: 6px; border-radius: 3px;
}

/* ---------- Toast ---------- */

.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--color-text); color: white;
  padding: 10px 20px; border-radius: var(--radius);
  box-shadow: var(--shadow-md); z-index: 200;
  display: flex; align-items: center; gap: 14px;
}
.toast-action {
  background: transparent; border: 1px solid rgba(255, 255, 255, 0.5);
  color: white; font-weight: 600; padding: 3px 12px; border-radius: var(--radius);
}
.toast-action:hover { background: rgba(255, 255, 255, 0.15); }

/* ---------- Today quick-fill + bulk review ---------- */

.date-with-today { display: flex; gap: 6px; align-items: stretch; margin-top: 4px; }
.date-with-today input { margin-top: 0; }
.btn-sm { padding: 4px 10px; font-size: 12px; white-space: nowrap; }

.bulk-review .review-summary { font-size: 14px; line-height: 1.5; margin-bottom: 16px; }
.review-section { margin-bottom: 16px; }
.review-section h4 { margin: 0 0 8px; font-size: 13px; color: var(--color-text-muted); }
.device-breakdown { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.device-breakdown li {
  background: var(--color-surface-alt); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: 4px 10px; font-size: 13px;
}
.review-warning {
  background: #fbe9e7; color: #b71c1c; border-radius: var(--radius);
  padding: 8px 12px; font-size: 13px; margin-bottom: 16px;
}
.review-serials summary { cursor: pointer; font-size: 13px; color: var(--color-text-muted); }
.review-serials .mono { margin-top: 8px; word-break: break-word; }

/* ---------- Event enhancements ---------- */

.event-type-row { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; flex-wrap: wrap; }
.event-type-row .event-type { margin-bottom: 0; }
.status-badge-sm { padding: 2px 8px; font-size: 10px; }
.event-details { font-size: 12px; color: var(--color-text-muted); margin-top: 4px; display: flex; flex-wrap: wrap; gap: 12px; }
.severity-tag {
  background: #fbe9e7; color: #b71c1c; padding: 1px 6px;
  border-radius: 3px; font-weight: 600;
}

/* ---------- Status-after hint in Log Event form ---------- */

.status-after-hint {
  display: flex; align-items: center; gap: 8px;
  font-size: 12px; color: var(--color-text-muted);
  background: var(--color-surface-alt); border: 1px solid var(--color-border);
  border-radius: var(--radius); padding: 8px 12px;
}

/* ---------- Version History modal ---------- */

.modal-xl { max-width: 900px; }

.checkbox-label { display: flex; align-items: center; gap: 8px; cursor: pointer; flex-direction: row; }
.checkbox-label input[type="checkbox"] { width: auto; margin: 0; }
.row-inactive { opacity: 0.5; }

/* ---------- Per-column filter row ---------- */
.data-table tr.filter-row th { padding: 4px 8px; background: var(--color-surface-alt); }
.filter-row input, .filter-row select {
  width: 100%; box-sizing: border-box; font-weight: normal;
  text-transform: none; letter-spacing: normal;
}
.filter-row .deploy-filter { display: flex; gap: 4px; align-items: center; }
.filter-row .deploy-filter select { width: auto; }
.filter-row .deploy-filter input { flex: 1; min-width: 0; }

/* ---------- Bulk selection ---------- */
.col-check { width: 36px; text-align: center; }
.col-check input[type="checkbox"] { width: auto; margin: 0; cursor: pointer; }
.data-table tr.row-selected { background: #eaf2fb; }
.data-table tr.row-selected:hover { background: #e1ecf8; }
.bulk-bar {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 12px; padding: 10px 14px;
  background: var(--color-surface-alt); border: 1px solid var(--color-border);
  border-radius: var(--radius); font-size: 14px;
}

/* ---------- CSV import preview ---------- */
.import-preview td { padding: 6px 8px; vertical-align: top; }
.import-preview input, .import-preview select { width: 100%; }
.import-preview tr.row-invalid { background: rgba(184, 49, 28, 0.04); }
.import-preview td.cell-invalid input,
.import-preview td.cell-invalid select { border-color: var(--color-danger); }
.cell-error { display: block; margin-top: 3px; font-size: 11px; color: var(--color-danger); }

/* ---------- Responsive ---------- */

@media (max-width: 800px) {
  .stats { grid-template-columns: repeat(2, 1fr); }
  .panels { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .topnav { display: none; }  /* simplified; add hamburger later */
}
