:root {
  --ink: #17202a;
  --muted: #66717d;
  --line: #d8dde3;
  --panel: #ffffff;
  --canvas: #f4f6f8;
  --navy: #123a5a;
  --blue: #146c94;
  --yellow: #f3c623;
  --green: #247a52;
  --red: #b33a3a;
  --radius: 6px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--ink);
  background: var(--canvas);
}

* { box-sizing: border-box; }
html { max-width: 100%; overflow-x: clip; }
body { margin: 0; min-width: 0; max-width: 100%; overflow-x: clip; background: var(--canvas); }
button, input, select, textarea { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 1.65rem; }
h2 { font-size: 1.35rem; }
.muted { color: var(--muted); margin: .3rem 0 0; }
.eyebrow { margin: 0 0 .25rem; color: var(--blue); font-size: .72rem; font-weight: 800; letter-spacing: 0; text-transform: uppercase; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }
[hidden] { display: none !important; }

.auth-screen { width: 100%; min-height: 100vh; min-height: 100svh; display: grid; place-items: center; padding: 32px max(16px, env(safe-area-inset-right)) 32px max(16px, env(safe-area-inset-left)); background: var(--navy); }
.auth-layout { width: min(420px, 100%); min-width: 0; }
.auth-card { padding: clamp(26px, 5vw, 42px); border: 1px solid var(--line); border-radius: 10px; background: var(--panel); }
.auth-logo { display: block; width: min(210px, 100%); height: auto; margin-bottom: 34px; }
.auth-product-name { margin: 0; color: var(--muted); font-size: .82rem; font-weight: 700; }
.auth-card h2 { margin: 7px 0 10px; color: var(--navy); font-size: 1.8rem; letter-spacing: -.035em; }
.auth-description { margin: 0 0 26px; color: var(--muted); line-height: 1.55; }
.auth-primary { min-height: 48px; }
.auth-card .form-error:not(:empty) { margin-top: 18px; }
.auth-card .form-error:empty { display: none; }

.app-shell { min-height: 100vh; min-width: 0; max-width: 100%; overflow-x: clip; }
.topbar { height: 68px; min-width: 0; padding: 0 28px; display: flex; align-items: center; justify-content: space-between; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand-lockup { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-lockup small { display: block; color: var(--muted); margin-top: 2px; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; background: var(--navy); color: white; border-bottom: 4px solid var(--yellow); font-weight: 900; }
.topbar-actions, .toolbar, .form-actions, .dialog-actions { display: flex; align-items: center; gap: 10px; }
.status-pill { border: 1px solid var(--line); border-radius: 999px; padding: 5px 9px; font-size: .78rem; color: var(--muted); }
.status-pill[data-status="online"] { border-color: #a9d5c0; color: var(--green); background: #eef8f3; }
.section-nav { display: flex; gap: 2px; min-width: 0; max-width: 100%; padding: 0 28px; background: var(--panel); border-bottom: 1px solid var(--line); overflow-x: auto; }
.nav-button { height: 46px; padding: 0 18px; border: 0; border-bottom: 3px solid transparent; background: transparent; color: var(--muted); font-weight: 700; }
.nav-button.active { color: var(--navy); border-bottom-color: var(--yellow); }

.app-shell main { width: 100%; min-width: 0; padding: 26px 28px 52px; max-width: 1600px; margin: 0 auto; }
.view { display: none; min-width: 0; max-width: 100%; }
.view.active { display: block; }
.view-header { min-height: 68px; margin-bottom: 18px; display: flex; justify-content: space-between; align-items: flex-end; gap: 18px; }
.search-field input { width: min(320px, 38vw); }
.button { min-height: 44px; padding: 8px 14px; border: 1px solid transparent; border-radius: 6px; background-clip: padding-box; font-weight: 750; }
.button.primary { border-color: var(--navy); background: var(--navy); color: white; }
.button.primary:hover { background: var(--blue); }
.button.secondary { border-color: var(--line); background: var(--panel); color: var(--ink); }
.button.wide { width: 100%; }
.icon-button { width: 44px; height: 44px; border: 0; background: transparent; color: var(--muted); font-size: 1.75rem; line-height: 1; }
.action-spacer { flex: 1; }

.table-wrap { max-width: 100%; overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { width: 100%; border-collapse: collapse; min-width: 760px; }
th, td { padding: 12px 14px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; }
th { background: #eef1f4; color: #4b5661; font-size: .75rem; text-transform: uppercase; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #f8fafb; }
.cell-title { display: block; font-weight: 750; }
.cell-subtitle { display: block; margin-top: 2px; color: var(--muted); font-size: .8rem; }
.row-action { min-height: 44px; padding: 8px 10px; border: 1px solid var(--blue); border-radius: 6px; background: transparent; color: var(--blue); font-weight: 750; }
.badge { display: inline-block; border-radius: 999px; padding: 4px 8px; background: #e8edf1; color: #46515d; font-size: .75rem; font-weight: 700; }
.badge.public { background: #e5f5ec; color: var(--green); }
.badge.draft { background: #fff6d6; color: #725b00; }

label { display: grid; gap: 6px; color: #39434d; font-size: .84rem; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid #bfc7cf; border-radius: 4px; padding: 9px 10px; background: white; color: var(--ink); }
input:focus, select:focus, textarea:focus { outline: 3px solid #b9dcee; border-color: var(--blue); }
textarea { resize: vertical; }
select[multiple] { padding: 4px; }
select[multiple] option { padding: 5px; }
.toggle { display: flex; align-items: center; gap: 8px; }
.toggle input { width: 18px; height: 18px; }
.form-grid { display: grid; gap: 14px; }
.form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.workspace-form { padding: 20px; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
.compact-form { display: grid; gap: 16px; max-width: 1050px; }
.reference-layout { display: grid; grid-template-columns: minmax(0, 2fr) minmax(260px, 1fr); gap: 20px; align-items: start; }
.summary-list { border-top: 1px solid var(--line); background: var(--panel); }
.summary-row { display: flex; justify-content: space-between; padding: 13px 4px; border-bottom: 1px solid var(--line); }
.audit-filters { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.audit-filter-actions { grid-column: 1 / -1; flex-wrap: wrap; }
.audit-note { margin: 16px 0 10px; color: var(--muted); font-size: .84rem; }
.audit-table { min-width: 900px; }
.monospace { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .8rem; }
.breakable { overflow-wrap: anywhere; }
.pagination { display: flex; align-items: center; justify-content: flex-end; gap: 12px; margin-top: 14px; }
.button:disabled { cursor: not-allowed; opacity: .55; }

dialog { border: 1px solid var(--line); border-radius: 8px; padding: 0; color: var(--ink); background: var(--panel); box-shadow: 0 18px 60px rgba(18, 33, 48, .22); }
dialog::backdrop { background: rgba(18, 32, 44, .5); }
.editor-dialog { width: min(1000px, calc(100vw - 30px)); max-height: 92vh; }
.editor-dialog form, .small-dialog form { padding: 22px; display: grid; gap: 18px; }
.small-dialog { width: min(520px, calc(100vw - 30px)); }
.dialog-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding-bottom: 14px; border-bottom: 1px solid var(--line); }
.dialog-actions { position: sticky; bottom: -22px; margin: 0 -22px -22px; padding: 14px 22px; border-top: 1px solid var(--line); background: var(--panel); }
fieldset { min-width: 0; margin: 0; padding: 16px 0 0; border: 0; border-top: 1px solid var(--line); display: grid; gap: 14px; }
legend { padding: 0 10px 0 0; color: var(--navy); font-weight: 800; }
.form-error { min-height: 1.1em; margin: 0; color: var(--red); font-size: .86rem; }
.toast { position: fixed; right: 24px; bottom: 24px; max-width: min(420px, calc(100vw - 48px)); padding: 12px 16px; border-radius: 5px; color: white; background: var(--navy); opacity: 0; transform: translateY(10px); pointer-events: none; transition: opacity .18s, transform .18s; }
.toast.visible { opacity: 1; transform: translateY(0); }
.toast.error { background: var(--red); }

@media (max-width: 780px) {
  .auth-screen { padding-block: 20px; }
  .auth-card { padding: 26px 22px; }
  .auth-logo { width: 190px; margin-bottom: 28px; }
  .topbar { height: auto; min-height: 68px; padding: 12px 16px; }
  .brand-lockup small, .status-pill { display: none; }
  .section-nav { padding: 0 12px; }
  .app-shell main { padding: 20px 14px 42px; }
  .view-header { align-items: stretch; flex-direction: column; }
  .toolbar { width: 100%; }
  .search-field { flex: 1; }
  .search-field input { width: 100%; }
  .form-grid.two, .form-grid.three, .reference-layout { grid-template-columns: 1fr; }
  .audit-filters { grid-template-columns: 1fr; }
  .pagination { justify-content: space-between; }
  .audit-table { min-width: 0; }
  .audit-table thead { display: none; }
  .audit-table tbody tr { display: block; border-bottom: 1px solid var(--line); }
  .audit-table tbody tr:last-child { border-bottom: 0; }
  .audit-table td { display: grid; grid-template-columns: 92px minmax(0, 1fr); gap: 8px; align-items: start; }
  .audit-table td::before { content: attr(data-label); color: var(--muted); font-size: .72rem; font-weight: 800; text-transform: uppercase; }
  .audit-table td[colspan] { display: block; }
  .audit-table td[colspan]::before { content: none; }
  .view:is(#products-view, #equipment-view, #inventory-view) .table-wrap { overflow: visible; border: 0; background: transparent; }
  .view:is(#products-view, #equipment-view, #inventory-view) .table-wrap table { display: block; min-width: 0; }
  .view:is(#products-view, #equipment-view, #inventory-view) .table-wrap thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .view:is(#products-view, #equipment-view, #inventory-view) .table-wrap tbody { display: grid; gap: 12px; }
  .view:is(#products-view, #equipment-view, #inventory-view) .table-wrap tr { display: block; overflow: hidden; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
  .view:is(#products-view, #equipment-view, #inventory-view) .table-wrap td { display: grid; grid-template-columns: minmax(88px, 34%) minmax(0, 1fr); gap: 8px; padding: 9px 12px; overflow-wrap: anywhere; }
  .view:is(#products-view, #equipment-view, #inventory-view) .table-wrap td::before { content: attr(data-label); color: var(--muted); font-size: .72rem; font-weight: 800; text-transform: uppercase; }
  .view:is(#products-view, #equipment-view, #inventory-view) .table-wrap td:first-child { display: block; padding: 13px 12px; background: var(--canvas); }
  .view:is(#products-view, #equipment-view, #inventory-view) .table-wrap td:first-child::before,
  .view:is(#products-view, #equipment-view, #inventory-view) .table-wrap td:last-child::before { display: none; }
  .view:is(#products-view, #equipment-view, #inventory-view) .table-wrap td:last-child { display: block; border-bottom: 0; }
  .view:is(#products-view, #equipment-view, #inventory-view) .table-wrap td[colspan] { display: block; }
  .view:is(#products-view, #equipment-view, #inventory-view) .table-wrap td[colspan]::before { display: none; }
  .view:is(#products-view, #equipment-view, #inventory-view) .table-wrap .row-action { width: 100%; }
  .editor-dialog { width: calc(100vw - 12px); max-height: 96vh; }
  .dialog-actions { flex-wrap: wrap; }
}

@media (max-width: 480px) {
  .topbar { gap: 8px; }
  .brand-lockup { gap: 8px; }
  .brand-lockup strong { font-size: .82rem; white-space: nowrap; }
  #disconnect-button { padding-inline: 8px; font-size: .8rem; white-space: nowrap; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .search-field { width: 100%; }
  .toolbar .button { width: 100%; }
  .dialog-actions { bottom: 0; margin-bottom: 0; padding: 12px 22px; }
  .dialog-actions .button { flex: 1 1 100%; }
}
