:root {
  --matter-primary-rgb: 33, 150, 243;
  --matter-onprimary-rgb: 255, 255, 255;
  --matter-secondary-rgb: 156, 39, 176;
  --page-bg: #fafafa;
  --surface: #ffffff;
  --ink: rgba(0, 0, 0, 0.87);
  --muted: rgba(0, 0, 0, 0.6);
  --line: rgba(0, 0, 0, 0.12);
  --shadow: 0 2px 4px -1px rgba(0,0,0,.2), 0 4px 5px 0 rgba(0,0,0,.14), 0 1px 10px 0 rgba(0,0,0,.12);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  min-height: 100vh;
  background: var(--page-bg);
  color: var(--ink);
  font-family: Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: rgb(var(--matter-primary-rgb)); text-decoration: none; }
a:hover { text-decoration: underline; }

.app { min-height: 100vh; }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 250px;
  background: #1e1e1e;
  color: rgba(255,255,255,.78);
  overflow: auto;
  z-index: 20;
}
.sidebar-brand {
  display: block;
  padding: 1rem 1.1rem;
  color: #fff;
  font-size: 1.15rem;
  font-weight: 500;
  text-decoration: none;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar-brand:hover { text-decoration: none; color: #fff; }
.sidebar-nav { padding: .75rem .65rem 2rem; }
.nav-header {
  margin: 1rem .5rem .35rem;
  font-size: .72rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: rgba(255,255,255,.45);
}
.sidebar .nav-link {
  display: block;
  padding: .55rem .75rem;
  border-radius: 4px;
  color: rgba(255,255,255,.78);
  text-decoration: none;
}
.sidebar .nav-link:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.sidebar .nav-link.is-active { background: rgba(var(--matter-primary-rgb), .22); color: #fff; }
.nav-sub { margin: .15rem 0 .35rem .75rem; }
.nav-sub .nav-link { font-size: .92rem; padding: .4rem .7rem; }
.maincol { margin-left: 250px; min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex;
  align-items: center;
  gap: .75rem;
  padding: .55rem 1rem;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}
.top-search { display: flex; align-items: center; gap: .5rem; flex: 1; max-width: 520px; margin: 0 auto; }
.top-search .matter-textfield-outlined { flex: 1; margin: 0; }
.nav-toggle { display: none; }
.user-menu { position: relative; margin-left: auto; }
.user-menu summary { cursor: pointer; list-style: none; font-weight: 500; }
.user-menu summary::-webkit-details-marker { display: none; }
.user-pop {
  position: absolute;
  right: 0;
  top: 1.6rem;
  width: 220px;
  background: #fff;
  box-shadow: var(--shadow);
  border-radius: 4px;
  padding: .75rem;
  z-index: 30;
}
.page-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: 1rem 1.25rem 0;
}
.page-head h1 { margin: 0; }
.crumbs { color: var(--muted); font-size: .9rem; }
.crumbs a { color: inherit; }
.crumb-sep { margin: 0 .35rem; }
.content { padding: 1rem 1.25rem 2.5rem; flex: 1; }
.wrap { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.25rem 3rem; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .75rem; }
.card-head h2 { margin: 0; }
.card {
  background: var(--surface);
  border-radius: 4px;
  box-shadow: var(--shadow);
  padding: 1.25rem 1.35rem;
  margin-bottom: 1.25rem;
}
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); }
.stat { font-size: 2rem; font-weight: 500; line-height: 1.2; }
.muted { color: var(--muted); }
.flash {
  background: #e8f5e9;
  color: #1b5e20;
  border-left: 4px solid #43a047;
  padding: .85rem 1rem;
  margin-bottom: 1rem;
  border-radius: 2px;
}
.error {
  background: #ffebee;
  color: #b71c1c;
  border-left: 4px solid #e53935;
  padding: .85rem 1rem;
  margin-bottom: 1rem;
  border-radius: 2px;
}
.warn {
  background: #fff8e1;
  color: #e65100;
  border-left: 4px solid #fb8c00;
  padding: .85rem 1rem;
  margin-bottom: 1rem;
  border-radius: 2px;
}

table { width: 100%; border-collapse: collapse; }
th, td {
  text-align: left;
  padding: .7rem .45rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
th { color: var(--muted); font-size: .8rem; font-weight: 500; text-transform: uppercase; letter-spacing: .02em; }
td.actions { text-align: right; white-space: nowrap; }
tr[hidden] { display: none; }
.record-table .cell-input {
  font: inherit;
  width: 100%;
  min-width: 5.5rem;
  min-height: 40px;
  box-sizing: border-box;
  border: 1px solid rgba(0,0,0,.38);
  border-radius: 4px;
  padding: .4rem .6rem;
  background: #fff;
}
.record-table form.editor-form, #apply-form { display: none; }
.list-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: .75rem;
}
.list-bar p { margin: 0; }
.page-size {
  display: inline-flex;
  align-items: center;
  gap: .5rem;
  color: var(--muted);
  font-size: .9rem;
}
.page-size select {
  font: inherit;
  min-height: 36px;
  border: 1px solid rgba(0,0,0,.38);
  border-radius: 4px;
  padding: .2rem .45rem;
  background: #fff;
}
.page-size-form { margin: 0; }
.record-table td.actions .row-actions {
  display: inline-flex;
  gap: .15rem;
  align-items: center;
  justify-content: flex-end;
}
.record-table tr.is-editing td { background: #f8f9fa; }
.record-table tr.is-pending td { background: #fff8e1; }
.record-table tr.is-deleted td { text-decoration: line-through; }
.record-table tr.is-deleted td.actions { text-decoration: none; }
.pending-bar {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: center;
  margin-top: 1rem;
  padding: .85rem 1rem;
  background: #fff8e1;
  border-left: 4px solid #fb8c00;
}
.pending-bar[hidden] { display: none; }
.pending-bar p { margin: 0; }
.zone-tabs { display: flex; gap: .5rem; margin-bottom: 1rem; flex-wrap: wrap; }
#panel-records[hidden], #panel-soa[hidden] { display: none; }
.soa-lead { margin: 0 0 1rem; max-width: 46rem; }
.soa-grid { display: grid; gap: 1.25rem 1.5rem; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.soa-item { position: relative; }
.soa-item:hover,
.soa-item:focus-within { z-index: 3; }
.soa-name { display: flex; align-items: center; gap: .35rem; margin: 0 0 .4rem; font-size: .9rem; }
.soa-name label, .soa-name span { font-weight: 500; }
.soa-help {
  position: relative;
  flex: 0 0 auto;
  width: 1.15rem;
  height: 1.15rem;
  padding: 0;
  border: 1.5px solid #e65100;
  border-radius: 50%;
  background: #fff;
  color: #e65100;
  font: 700 .75rem/1 Roboto, "Helvetica Neue", Arial, sans-serif;
  cursor: help;
}
.soa-help-pop {
  display: none;
  position: absolute;
  z-index: 4;
  bottom: calc(100% + .45rem);
  left: 0;
  width: 16rem;
  padding: .65rem .75rem;
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  font: 400 .8rem/1.45 Roboto, "Helvetica Neue", Arial, sans-serif;
  text-align: left;
  box-shadow: 0 4px 16px rgba(0,0,0,.22);
}
.soa-grid .soa-item:nth-child(3n) .soa-help-pop { left: auto; right: 0; }
.soa-help:hover .soa-help-pop,
.soa-help:focus .soa-help-pop,
.soa-help:focus-visible .soa-help-pop { display: block; }
.soa-input {
  font: inherit;
  width: 100%;
  min-height: 40px;
  border: 1px solid rgba(0,0,0,.38);
  border-radius: 4px;
  padding: .5rem .75rem;
  background: #fff;
  color: inherit;
}
.soa-unit-row { display: flex; align-items: center; gap: .5rem; }
.soa-unit-row .soa-input { flex: 1; }
.soa-unit { color: var(--muted); font-size: .85rem; }
.soa-serial { margin: .15rem 0 0; font-size: 1.25rem; font-weight: 500; }

.form-row {
  display: grid;
  gap: 1rem;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  align-items: end;
  margin-bottom: .25rem;
}
.form-actions { margin-top: 1rem; display: flex; gap: .75rem; flex-wrap: wrap; align-items: center; }
.pager { display: flex; flex-wrap: wrap; gap: .35rem; align-items: center; margin-top: 1rem; }
.pager .is-current { font-weight: 500; background: rgba(var(--matter-primary-rgb), .12); }
.stack > * + * { margin-top: 1rem; }
.inline-form { display: inline; }
.login-box { max-width: 420px; margin: 8vh auto; }
.login-box .matter-textfield-outlined,
.login-box .matter-textfield-filled { width: 100%; display: block; }
.field { display: flex; flex-direction: column; gap: .35rem; }
.field > span { color: var(--muted); font-size: .8rem; }
.field select, .field textarea {
  font: inherit;
  min-height: 48px;
  border: 1px solid rgba(0,0,0,.38);
  border-radius: 4px;
  padding: .65rem .75rem;
  background: #fff;
  width: 100%;
}
code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  background: #f1f3f4;
  padding: .1rem .35rem;
  border-radius: 3px;
  word-break: break-all;
}

@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform .2s ease; }
  body.sidebar-open .sidebar { transform: none; }
  .maincol { margin-left: 0; }
  .nav-toggle { display: inline-flex; }
  .page-head { flex-direction: column; align-items: flex-start; }
  .wrap { padding: 1rem; }
  .stat { font-size: 1.6rem; }
}
