/* =====================================================================
   Ivalco BMT
   Palette taken from the mechanical room: painted steel, concrete floor,
   duct-blue pipe markers and the safety-yellow of guards and valves.
   Equipment tags are drawn like engraved lamacoid nameplates.
   ===================================================================== */

:root {
  --steel:      #1d3a4f;   /* sidebar, nameplates */
  --steel-2:    #2a4d66;
  --concrete:   #e8ecee;   /* page background */
  --paper:      #ffffff;
  --ink:        #1f2d37;
  --ink-soft:   #5a6a75;
  --rule:       #d3dae0;
  --duct:       #2b6c9b;   /* primary actions */
  --duct-dark:  #1f5277;
  --safety:     #f1c21b;   /* focus, highlights */
  --ok:         #2e7d4f;
  --warn:       #a8680a;
  --bad:        #b3261e;
  --muted-bg:   #f3f5f7;

  --font: "Barlow", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-cond: "Barlow Condensed", "Arial Narrow", "Segoe UI", sans-serif;
  --radius: 6px;
}

* { box-sizing: border-box; }
html { font-size: 15px; }
body {
  margin: 0;
  font-family: var(--font);
  color: var(--ink);
  background: var(--concrete);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--duct); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--duct-dark); }
:focus-visible { outline: 3px solid var(--safety); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--font-cond); font-weight: 600; line-height: 1.15; margin: 0; }
h1 { font-size: 2rem; letter-spacing: -0.01em; }
h2 { font-size: 1.3rem; }
h3 { font-size: 1.1rem; }
p { margin: 0 0 .8em; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip { position: absolute; left: -999px; top: 0; background: var(--safety); color: var(--ink); padding: .5rem 1rem; z-index: 99; }
.skip:focus { left: 0; }
.muted { color: var(--ink-soft); font-size: .9em; }
.empty { color: var(--ink-soft); padding: .75rem 0; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.nowrap { white-space: nowrap; }

/* ---------- Shell ---------- */
.shell { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.sidebar {
  background: var(--steel);
  color: #dfe7ec;
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.brand { display: flex; gap: .7rem; align-items: center; padding: 1.1rem 1.2rem 1rem; color: #fff; text-decoration: none; }
.brand-mark {
  width: 30px; height: 30px; border-radius: 50%;
  border: 5px solid var(--safety); position: relative; flex: none;
}
.brand-mark::after { /* valve handwheel spoke */
  content: ""; position: absolute; left: 50%; top: -5px; bottom: -5px; width: 4px; margin-left: -2px; background: var(--safety);
}
.brand-text { font-family: var(--font-cond); font-size: 1.45rem; font-weight: 700; line-height: 1; }
.brand-text small { display: block; font-size: .8rem; font-weight: 500; color: #a9bccb; margin-top: 3px; }
.sidebar nav { flex: 1; padding: .3rem 0 1rem; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar nav a {
  display: block; padding: .48rem 1.2rem; color: #dfe7ec; text-decoration: none;
  border-left: 4px solid transparent; font-weight: 500;
}
.sidebar nav a:hover { background: var(--steel-2); color: #fff; }
.sidebar nav a[aria-current="page"] { border-left-color: var(--safety); background: var(--steel-2); color: #fff; }
.nav-group { margin: 1.2rem 1.2rem .3rem; font-size: .82rem; color: #8fa6b7; font-weight: 600; }
.sidebar-user { padding: 1rem 1.2rem; border-top: 1px solid var(--steel-2); font-size: .88rem; }
.sidebar-user strong { display: block; color: #fff; }
.sidebar-user span { display: block; color: #a9bccb; margin-bottom: .4rem; }
.sidebar-user a { color: #dfe7ec; }

.main-col { min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; gap: .75rem; align-items: center; flex-wrap: wrap;
  padding: .7rem 1.6rem; background: var(--paper); border-bottom: 1px solid var(--rule);
  position: sticky; top: 0; z-index: 10;
}
.building-switch select { min-width: 240px; font-weight: 600; }
.top-search { flex: 1; min-width: 200px; }
.top-search input { width: 100%; max-width: 420px; }
.topbar .nav-toggle { display: none; }
.content { padding: 1.4rem 1.6rem 3rem; max-width: 1500px; width: 100%; }

.crumbs { font-size: .9rem; margin-bottom: .6rem; color: var(--ink-soft); }
.crumbs .sep { margin: 0 .35rem; color: #9aa7b0; }

/* ---------- Page heading ---------- */
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: 1.2rem; }
.page-head .sub { color: var(--ink-soft); margin-top: .3rem; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ---------- Nameplate (signature element) ---------- */
.plate {
  display: inline-block;
  font-family: var(--font-cond); font-weight: 600; font-size: .92rem; letter-spacing: .04em;
  color: #f4f6f2; background: var(--steel);
  padding: .1rem .5rem; border-radius: 2px;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18), 0 1px 0 rgba(0,0,0,.25);
  white-space: nowrap;
}
.plate-link { text-decoration: none; }
.plate-link:hover .plate { background: var(--duct-dark); }
.plate-lg { font-size: 1.6rem; padding: .25rem .8rem; letter-spacing: .06em; }

/* ---------- Panels ---------- */
.panel { background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius); padding: 1rem 1.2rem; margin-bottom: 1.2rem; }
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: .8rem; margin-bottom: .7rem; flex-wrap: wrap; }
.panel-flush { padding: 0; }
.panel-flush .panel-head { padding: 1rem 1.2rem 0; }
.grid-2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 1.2rem; }
.grid-main { display: grid; grid-template-columns: minmax(0, 2fr) minmax(280px, 1fr); gap: 1.2rem; align-items: start; }

/* ---------- Dashboard counters ---------- */
.gauges { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .8rem; margin-bottom: 1.4rem; }
.gauge {
  background: var(--paper); border: 1px solid var(--rule); border-radius: var(--radius);
  padding: .8rem 1rem; text-decoration: none; color: var(--ink); display: block;
  border-top: 4px solid var(--rule);
}
.gauge strong { display: block; font-family: var(--font-cond); font-size: 2.1rem; font-weight: 600; line-height: 1; }
.gauge span { color: var(--ink-soft); font-size: .92rem; }
.gauge.is-bad  { border-top-color: var(--bad); }
.gauge.is-warn { border-top-color: var(--safety); }
.gauge.is-ok   { border-top-color: var(--ok); }
.gauge:hover { border-color: var(--duct); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .94rem; }
th, td { text-align: left; padding: .5rem .65rem; border-bottom: 1px solid var(--rule); vertical-align: top; }
th { font-weight: 600; color: var(--ink-soft); font-size: .86rem; background: var(--muted-bg); white-space: nowrap; }
tbody tr:hover { background: #f7f9fb; }
tr.is-overdue td:first-child { box-shadow: inset 4px 0 0 var(--bad); }
tr.is-soon td:first-child { box-shadow: inset 4px 0 0 var(--safety); }
td.is-overdue, span.is-overdue { color: var(--bad); font-weight: 600; }
td.is-soon, span.is-soon { color: var(--warn); font-weight: 600; }
tr.is-inactive td { color: #98a4ad; }
dl.facts { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dl.facts dt { color: var(--ink-soft); }
dl.facts dd { margin: 0; }

/* Asset tree */
.tree-name { display: inline-flex; align-items: center; gap: .4rem; }
.tree-indent { display: inline-block; border-left: 1px dashed #a9b6bf; height: 1.2em; margin-left: .6rem; width: .9rem; border-bottom: 1px dashed #a9b6bf; transform: translateY(-.35em); }
.level-unit td { background: #f6f8f9; font-weight: 600; }
.lvl { font-size: .8rem; color: var(--ink-soft); }

/* ---------- Pills ---------- */
.pill { display: inline-block; font-size: .8rem; font-weight: 600; padding: .08rem .5rem; border-radius: 99px; background: #e4e9ec; color: var(--ink); white-space: nowrap; }
.pill-wo_status-requested, .pill-po_status-submitted { background: #e6eef6; color: #23507a; }
.pill-wo_status-approved, .pill-wo_status-scheduled, .pill-po_status-approved, .pill-po_status-ordered { background: #dde9f3; color: #1f5277; }
.pill-wo_status-in_progress, .pill-po_status-partially_received { background: #fff1c2; color: #6a4b00; }
.pill-wo_status-on_hold { background: #f7e1c8; color: #7a4200; }
.pill-wo_status-completed, .pill-wo_status-closed, .pill-po_status-received,
.pill-asset_status-operational, .pill-comp_result-pass, .pill-check_result-pass, .pill-contract_status-active { background: #d9eedf; color: #1f5a37; }
.pill-wo_status-cancelled, .pill-po_status-cancelled, .pill-asset_status-decommissioned, .pill-asset_status-removed,
.pill-contract_status-expired, .pill-contract_status-cancelled { background: #e7e9eb; color: #5a6a75; }
.pill-asset_status-degraded, .pill-comp_result-conditional { background: #fff1c2; color: #6a4b00; }
.pill-asset_status-down, .pill-comp_result-fail, .pill-check_result-fail { background: #f8d9d6; color: #8a1c15; }
.pill-asset_status-standby { background: #e6eef6; color: #23507a; }
.pill-priority-urgent, .pill-criticality-critical, .pill-wo_type-emergency { background: var(--bad); color: #fff; }
.pill-priority-high, .pill-criticality-high { background: #f8d9d6; color: #8a1c15; }
.pill-priority-low, .pill-criticality-low { background: #eef1f3; color: #5a6a75; }
.pill-wo_type-preventive { background: #d9eedf; color: #1f5a37; }
.pill-wo_type-inspection { background: #e6eef6; color: #23507a; }

/* ---------- Forms ---------- */
input, select, textarea, button { font: inherit; color: inherit; }
input[type=text], input[type=email], input[type=tel], input[type=password], input[type=number], input[type=date],
input[type=datetime-local], input[type=search], input[type=file], select, textarea {
  width: 100%; padding: .45rem .6rem; border: 1px solid #b9c4cc; border-radius: 4px; background: #fff;
}
input[type=file] { padding: .3rem; }
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--duct); outline: 2px solid var(--safety); outline-offset: 0; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .9rem 1.1rem; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-all { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: .25rem; }
.field-label { font-weight: 600; font-size: .9rem; }
.field-hint { font-size: .82rem; color: var(--ink-soft); }
.check { display: flex; gap: .45rem; align-items: center; font-weight: 500; }
.check input { width: auto; }
fieldset { border: 1px solid var(--rule); border-radius: var(--radius); padding: .8rem 1rem 1rem; margin: 0 0 1rem; }
legend { font-family: var(--font-cond); font-weight: 600; font-size: 1.1rem; padding: 0 .4rem; }
.form-actions { display: flex; gap: .6rem; margin-top: 1.1rem; flex-wrap: wrap; }
.row-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: flex-end; margin-top: .8rem; }
.row-form > * { flex: 1 1 140px; }
.row-form > button, .row-form > .btn { flex: 0 0 auto; }
.row-form .field { flex: 1 1 140px; }
.filters { display: flex; gap: .6rem; flex-wrap: wrap; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { min-width: 150px; flex: 0 1 190px; }
form.inline { display: inline; }
.select-filter { margin-bottom: .3rem; font-size: .9rem; background: var(--muted-bg) !important; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  padding: .45rem .9rem; border-radius: 4px; border: 1px solid #a9b6bf; background: #fff;
  color: var(--ink); text-decoration: none; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--duct); color: var(--duct-dark); }
.btn-primary { background: var(--duct); border-color: var(--duct); color: #fff; }
.btn-primary:hover { background: var(--duct-dark); border-color: var(--duct-dark); color: #fff; }
.btn-danger { color: var(--bad); border-color: #d9a29e; }
.btn-danger:hover { background: var(--bad); color: #fff; border-color: var(--bad); }
.btn-sm { padding: .2rem .55rem; font-size: .86rem; }
.btn-link { background: none; border: 0; padding: 0; color: var(--duct); cursor: pointer; text-decoration: underline; font-size: inherit; }
.btn-link.danger { color: var(--bad); }

/* Status workflow buttons on a work order */
.workflow { display: flex; gap: .4rem; flex-wrap: wrap; }

/* ---------- Flash ---------- */
.flash { padding: .7rem 1rem; border-radius: 4px; margin-bottom: 1rem; border-left: 5px solid var(--duct); background: #e6eef6; }
.flash-success { border-left-color: var(--ok); background: #e2f2e7; }
.flash-error { border-left-color: var(--bad); background: #fbe4e1; }
.flash-warning { border-left-color: var(--safety); background: #fff6d6; }

/* ---------- Lists ---------- */
.file-list, .timeline { list-style: none; padding: 0; margin: 0; }
.file-list li { padding: .45rem 0; border-bottom: 1px solid var(--rule); display: flex; gap: .7rem; flex-wrap: wrap; align-items: baseline; }
.timeline li { padding: .5rem 0 .5rem 1rem; border-left: 2px solid var(--rule); position: relative; }
.timeline li::before { content: ""; position: absolute; left: -6px; top: .9rem; width: 10px; height: 10px; border-radius: 50%; background: var(--rule); }
.timeline .who { font-weight: 600; }
.comment-body { white-space: pre-wrap; margin-top: .2rem; }

.pager { display: flex; gap: .3rem; margin-top: 1rem; flex-wrap: wrap; }
.pager a, .pager span { padding: .25rem .6rem; border: 1px solid var(--rule); border-radius: 4px; background: #fff; text-decoration: none; }
.pager [aria-current] { background: var(--steel); color: #fff; border-color: var(--steel); }

/* Equipment state on a work order */
.state-choice { display: inline-flex; border: 1px solid #b9c4cc; border-radius: 4px; overflow: hidden; }
.state-opt { position: relative; cursor: pointer; }
.state-opt input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.state-opt span { display: block; padding: .35rem .7rem; font-weight: 600; font-size: .88rem; border-left: 1px solid #b9c4cc; white-space: nowrap; }
.state-opt:first-child span { border-left: 0; }
.state-opt input:focus-visible + span { outline: 3px solid var(--safety); outline-offset: -3px; }
.state-operational input:checked + span { background: var(--ok); color: #fff; }
.state-degraded input:checked + span { background: var(--safety); color: var(--ink); }
.state-down input:checked + span { background: var(--bad); color: #fff; }
.state-opt input:disabled + span { opacity: .6; cursor: default; }
.state-table td { vertical-align: middle; }

/* Checklist */
.check-item { display: grid; grid-template-columns: 2rem 1fr minmax(200px, 280px); gap: .7rem; padding: .6rem 0; border-bottom: 1px solid var(--rule); align-items: start; }
.check-item .n { font-family: var(--font-cond); font-weight: 600; color: var(--ink-soft); }
.check-item.flagged { background: #fff6f5; }
.check-range { font-size: .82rem; color: var(--ink-soft); }

/* ---------- Login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; background: var(--steel); padding: 1rem; }
.login-card { background: var(--paper); border-radius: var(--radius); padding: 2rem; width: 100%; max-width: 380px; border-top: 6px solid var(--safety); }
.login-card h1 { margin-bottom: .2rem; }
.login-card .form-grid { grid-template-columns: 1fr; }

/* ---------- Print (work orders) ---------- */
@media print {
  .sidebar, .topbar, .no-print, .form-actions, .row-form, form button { display: none !important; }
  .shell { display: block; }
  body { background: #fff; }
  .panel { border: 0; padding: 0; }
}

/* ---------- Responsive ---------- */
@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; top: 0; width: 260px; transform: translateX(-100%); transition: transform .2s ease; z-index: 50; }
  .sidebar.open { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.35); }
  .topbar .nav-toggle { display: inline-flex; }
  .grid-2, .grid-main { grid-template-columns: 1fr; }
  .content { padding: 1rem; }
  .topbar { padding: .6rem 1rem; }
  .building-switch select { min-width: 0; }
  .check-item { grid-template-columns: 1.5rem 1fr; }
  .check-item > :last-child { grid-column: 2; }
  .form-grid .span-2 { grid-column: auto; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
