:root {
  --red: #ff0000;
  --text: #f5f5f5;
  --muted: #c9c9c9;
  --border: #363636;
  --surface: #101010;
  --surface-muted: #181818;
  --surface-strong: #0d0d0d;
  --focus: #ffffff;
  --page-bg: #070707;
  --input-bg: #151515;
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; overflow-x: hidden; }
body { color: var(--text); background: var(--page-bg); font-family: "Segoe UI", Arial, sans-serif; font-size: 16px; line-height: 1.5; }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: 34px; line-height: 1.16; font-weight: 650; }
h2 { margin-bottom: 0; font-size: 20px; line-height: 1.25; font-weight: 650; }
a { color: inherit; }
.hidden { display: none !important; }

.login-shell, .admin-body { border-top: 10px solid var(--red); }
.login-shell { min-height: 100svh; display: flex; flex-direction: column; justify-content: center; align-items: center; padding: 24px; gap: 12px; }
.admin-shell { width: min(1280px, 100%); min-height: 100svh; margin: 0 auto; padding: 24px; display: grid; gap: 18px; }

.auth-page {
  min-height: 100svh;
  padding: 24px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 12px;
  border-top: 10px solid var(--red);
  background:
    linear-gradient(135deg, rgba(255, 0, 0, 0.10), transparent 34%),
    var(--page-bg);
}

.auth-panel {
  width: min(460px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
  overflow: hidden;
}

.auth-panel__brand {
  padding: 28px 28px 22px;
  border-bottom: 1px solid var(--border);
}

.auth-panel__logo {
  width: min(230px, 100%);
  margin: 0 auto 24px;
}

.auth-panel__copy {
  margin: 8px 0 0;
  color: var(--muted);
}

.auth-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border-bottom: 1px solid var(--border);
}

.auth-switch__item {
  min-height: 52px;
  color: var(--text);
  background: var(--surface-muted);
  border: 0;
  border-radius: 0;
}

.auth-switch__item.is-active {
  background: var(--red);
}

.auth-form {
  display: grid;
  gap: 10px;
  padding: 24px 28px 28px;
}

.auth-form label {
  font-weight: 650;
}

.login-panel, .admin-login, .admin-card, .staff-panel, .portal-card {
  width: min(540px, 100%);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.admin-card, .staff-panel, .portal-card { width: 100%; }
.login-header, .login, .admin-login, .admin-card, .staff-panel, .portal-card, .dialog-form { padding: 22px; }
.login-header { border-bottom: 1px solid var(--border); }

.brand-logo, .app-logo, .workspace-logo { display: block; height: auto; }
.brand-logo, .app-logo { width: min(240px, 58vw, 100%); margin: 0 auto 24px; }
.brand-logo--portal { width: 180px; margin: 0 0 16px; }
.workspace-logo { width: 190px; margin-bottom: 16px; }

.system-label, .section-label {
  margin: 0 0 6px;
  padding-left: 12px;
  border-left: 6px solid var(--red);
  font-size: 14px;
  font-weight: 700;
}

.form-stack, .form-grid, .dialog-form { display: grid; gap: 10px; }
.login label, .form-stack label, .form-grid label, .dialog-form label { display: block; margin-bottom: 6px; font-weight: 650; }

input, select, button {
  min-height: 50px; border-radius: 4px; font: inherit;
}
input, select {
  width: 100%; min-width: 0; padding: 0 12px; color: var(--text); background: var(--input-bg); border: 1px solid #666666;
}
button {
  padding: 0 18px; color: #ffffff; background: var(--red); border: 2px solid var(--red); font-weight: 700; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
}
button:hover { text-decoration: underline; }
.secondary-button {
  min-height: 50px;
  padding: 0 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 2px solid #707070;
  border-radius: 4px;
  color: var(--text);
  background: transparent;
  font: inherit;
  font-weight: 650;
  text-decoration: none;
  cursor: pointer;
}
.secondary-button:hover { text-decoration: underline; }
.icon-button {
  width: 52px;
  min-width: 52px;
  max-width: 52px;
  padding: 0;
  flex: 0 0 52px;
}
.icon-button i { font-size: 18px; line-height: 1; }

.login__hint, .form-status, .dialog-copy, .portal-org, .inventory-org-name, .dashboard-topbar__copy { min-height: 24px; margin: 8px 0 0; color: var(--muted); font-size: 14px; }

.login-footer {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 16px 22px 18px;
  color: var(--muted); background: var(--surface-muted); border-top: 1px solid var(--border); font-size: 13px;
}
.login-footer__title { font-weight: 700; }
.login-footer__by, .admin-credit a, .subtle-link, .admin-entry { opacity: 0.78; color: inherit; text-decoration: none; }
.login-footer__by:hover, .admin-credit a:hover, .subtle-link:hover, .admin-entry:hover { opacity: 1; text-decoration: underline; }
.build-line, .admin-credit { margin: 0; font-size: 12px; color: var(--muted); opacity: 0.78; text-align: center; }

.admin-links { display: flex; width: 100%; justify-content: center; }
.admin-entry {
  min-height: 46px; min-width: 240px; padding: 0 24px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border); background: transparent;
}

.workspace-head, .inventory-head, .portal-head, .form-card-head, .toolbar-row {
  display: flex; justify-content: space-between; gap: 12px; align-items: center;
}

.toolbar-row { flex-wrap: wrap; }
.toolbar-row--icons { justify-content: end; }
.toolbar-row input { flex: 1 1 240px; min-width: min(240px, 100%); }
.admin-workspace { display: grid; gap: 18px; min-width: 0; }
.admin-shell--internal { width: min(1180px, 100%); }
.workspace-head--compact { align-items: end; padding-bottom: 2px; }
.workspace-head--compact h1 { font-size: 30px; }
.org-list-stack, .mini-list, .material-list, .movement-list, .inventory-lists, .portal-grid, .portal-stats, .dashboard-grid, .dashboard-cards, .category-list { display: grid; gap: 12px; }
.inventory-lists { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.org-list {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  max-height: min(620px, calc(100svh - 230px));
  overflow: hidden;
}
.org-list-stack {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}
.inventory-lists > .admin-card {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 0;
  max-height: 520px;
  overflow: hidden;
}
.inventory-lists .mini-list,
.inventory-lists .material-list,
.inventory-lists .movement-list,
#staff-list {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}
#staff-list { max-height: min(420px, 52svh); }

.admin-overview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.admin-metric {
  min-width: 0;
  min-height: 86px;
  padding: 16px;
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
}

.admin-metric i {
  width: 34px;
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--red);
  font-size: 22px;
}

.admin-metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.admin-metric strong {
  display: block;
  margin-top: 2px;
  font-size: 26px;
  line-height: 1;
}

.admin-directory {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  max-height: min(680px, calc(100svh - 260px));
  overflow: hidden;
}

.org-list-stack--compact {
  gap: 8px;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding-right: 4px;
}

.org-row {
  min-width: 0;
  padding: 14px;
  display: grid;
  grid-template-columns: minmax(190px, 1.15fr) minmax(190px, 1.05fr) minmax(180px, 1fr) auto;
  gap: 16px;
  align-items: center;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface-muted);
}

.org-row__identity,
.org-row__license,
.org-row__access {
  min-width: 0;
  display: grid;
  gap: 4px;
}

.org-row__identity strong {
  display: block;
  font-size: 17px;
  line-height: 1.2;
}

.org-row__identity span,
.org-row__license small,
.org-row__access span {
  color: var(--muted);
  font-size: 13px;
  overflow-wrap: anywhere;
}

.org-row__access i {
  width: 18px;
  color: var(--text);
  opacity: 0.82;
}

.org-row__actions {
  display: flex;
  justify-content: end;
  gap: 8px;
}

.org-item, .material-item, .stat-chip, .dashboard-stat {
  min-width: 0; padding: 16px; border: 1px solid var(--border); border-radius: 4px; background: var(--surface-muted);
}
.org-item__head, .material-item__head, .org-item__actions, .material-item__actions { display: flex; justify-content: space-between; gap: 12px; align-items: start; }
.org-item__head > div, .material-item__head > div, .mini-item > div, .staff-item > div, .category-row > div { min-width: 0; }
.org-item__head strong, .material-item__head strong, .mini-item strong, .dashboard-stat strong { display: block; font-size: 16px; }
.org-item__head span, .material-item__head span, .mini-item span, .staff-item span, .dashboard-stat span, .category-row span { display: block; color: var(--muted); font-size: 14px; overflow-wrap: anywhere; }
.org-item__meta, .material-item__meta { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin-top: 14px; }
.org-item__meta p, .material-item__meta p { margin: 0; }
.org-item__meta span, .material-item__meta span { display: block; color: var(--muted); font-size: 12px; }
.org-item__meta strong, .material-item__meta strong { display: block; margin-top: 2px; overflow-wrap: anywhere; }
.org-item__actions button, .material-item__actions button { flex: 1 1 0; min-width: 0; }
.org-item__actions .icon-button, .material-item__actions .icon-button { width: auto; max-width: none; }

.count-pill, .status, .alert-chip {
  display: inline-flex; align-items: center; min-height: 28px; padding: 0 10px; border: 1px solid var(--border);
  border-radius: 999px; color: var(--text); font-size: 13px; font-weight: 700; max-width: 100%;
}
.status-ok { border-color: #ffffff; }
.status-stop, .alert-chip { border-color: var(--red); color: #ffffff; background: var(--red); }
.material-flags { display: flex; flex-wrap: wrap; gap: 6px; }

.mini-item, .staff-item, .category-row {
  display: flex; justify-content: space-between; gap: 12px; align-items: center; padding: 12px 0; border-top: 1px solid var(--border);
}
.empty-state { margin: 0; color: var(--muted); }

.portal-shell { width: min(1380px, 100%); display: grid; gap: 18px; }
.dashboard-layout { display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 0; border: 1px solid var(--border); background: var(--surface); }
.dashboard-sidebar {
  background: linear-gradient(180deg, #0d0d0d 0%, #090909 100%);
  border-right: 1px solid var(--border);
  padding: 22px;
  display: grid;
  gap: 24px;
  align-content: start;
}
.dashboard-brand { display: grid; gap: 12px; }
.dashboard-brand__eyebrow, .dashboard-brand__title { margin: 0; }
.dashboard-brand__eyebrow { color: var(--muted); font-size: 13px; }
.dashboard-brand__title { font-size: 28px; font-weight: 700; line-height: 1.05; }
.dashboard-nav { display: grid; gap: 8px; }
.dashboard-nav__item {
  min-height: 52px;
  justify-content: start;
  background: transparent;
  border: 1px solid transparent;
  color: var(--text);
}
.dashboard-nav__item.is-active {
  background: #b8000a;
  border-color: #d9000d;
}
.dashboard-sidebar__footer { display: grid; gap: 12px; }

.dashboard-main {
  padding: 22px;
  background: linear-gradient(180deg, #121212 0%, #0c0c0c 100%);
  display: grid;
  gap: 18px;
}
.dashboard-topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: start;
}
.dashboard-alerts { display: flex; flex-wrap: wrap; gap: 10px; }
.dashboard-cards { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.dashboard-stat {
  background: linear-gradient(180deg, #171717 0%, #121212 100%);
  min-height: 150px;
  display: grid;
  align-content: space-between;
}
.dashboard-stat strong { font-size: 46px; line-height: 1; }
.dashboard-stat span { font-size: 18px; color: var(--text); }
.dashboard-stat small { color: var(--muted); font-size: 14px; }
.dashboard-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.portal-panel { min-height: 100%; }

.inventory-panel { display: grid; gap: 18px; min-width: 0; }
.action-strip { display: grid; grid-template-columns: repeat(5, minmax(52px, 72px)); gap: 8px; }
.action-strip .icon-button { width: 100%; max-width: none; }
.action-strip--portal {
  justify-content: start;
  padding: 4px 0;
}
.mini-actions {
  display: inline-flex;
  align-items: center;
  justify-content: end;
  gap: 8px;
  min-width: 0;
}
.mini-actions .icon-button { width: 44px; min-width: 44px; max-width: 44px; min-height: 44px; }
.inline-field {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 52px;
  gap: 8px;
}

.app-dialog {
  width: min(560px, calc(100vw - 20px));
  max-width: calc(100vw - 20px);
  max-height: calc(100svh - 20px);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0;
  overflow: hidden;
  background: var(--surface);
  color: var(--text);
}
.app-dialog .dialog-form {
  max-height: calc(100svh - 20px);
  overflow-y: auto;
  overscroll-behavior: contain;
}
.app-dialog::backdrop { background: rgba(0, 0, 0, 0.72); }
.scan-video { width: 100%; border-radius: 4px; background: #000; aspect-ratio: 4 / 3; object-fit: cover; }

@media (max-width: 1180px) {
  .dashboard-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-grid, .inventory-lists { grid-template-columns: 1fr 1fr; }
  .admin-overview { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .org-row { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .org-row__actions { justify-content: start; grid-column: 1 / -1; }
}

@media (max-width: 960px) {
  .dashboard-layout { grid-template-columns: 1fr; }
  .dashboard-sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
  .dashboard-nav { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .login-shell, .admin-shell, .auth-page { padding: 14px 10px 18px; }
  .workspace-head, .inventory-head, .portal-head, .form-card-head, .toolbar-row, .org-item__head, .org-item__actions, .material-item__head, .material-item__actions, .mini-item, .staff-item, .category-row, .dashboard-topbar {
    flex-direction: column; align-items: stretch;
  }
  .login-header, .login, .admin-login, .admin-card, .staff-panel, .portal-card, .dialog-form, .dashboard-sidebar, .dashboard-main, .auth-panel__brand, .auth-form { padding: 18px 16px; }
  .portal-stats, .org-item__meta, .material-item__meta, .dashboard-cards, .dashboard-grid, .inventory-lists { grid-template-columns: 1fr; }
  .action-strip, .dashboard-nav { grid-template-columns: 1fr 1fr; display: grid; }
  .brand-logo, .app-logo { width: min(220px, 100%); }
  .workspace-logo { width: min(190px, 72vw); }
  .admin-entry, button, .secondary-button { width: 100%; min-width: 0; }
  .toolbar-row--icons { display: grid; grid-template-columns: repeat(3, 52px); justify-content: start; }
  .toolbar-row--icons .icon-button, .org-row__actions .icon-button { width: 52px; min-width: 52px; max-width: 52px; }
  .action-strip--portal { grid-template-columns: repeat(5, 52px); }
  .action-strip--portal .icon-button { width: 52px; min-width: 52px; max-width: 52px; }
  .workspace-head--compact h1 { font-size: 26px; }
  .admin-overview { grid-template-columns: 1fr 1fr; }
  .admin-metric { min-height: 74px; padding: 12px; gap: 10px; }
  .admin-metric strong { font-size: 22px; }
  .admin-metric span { font-size: 12px; }
  .admin-directory { max-height: none; }
  .org-row { grid-template-columns: 1fr; gap: 10px; padding: 12px; }
  .org-row__actions { display: grid; grid-template-columns: repeat(4, 52px); justify-content: start; }
}

@media (max-width: 520px) {
  h1 { font-size: 30px; }
  .dashboard-nav, .action-strip { grid-template-columns: 1fr; }
  .action-strip--portal { grid-template-columns: repeat(5, 48px); }
  .action-strip--portal .icon-button { width: 48px; min-width: 48px; max-width: 48px; }
  .mini-actions { justify-content: start; }
  .inline-field { grid-template-columns: minmax(0, 1fr) 48px; }
  .admin-overview { grid-template-columns: 1fr; }
  .org-row__actions { grid-template-columns: repeat(4, 48px); gap: 7px; }
  .org-row__actions .icon-button { width: 48px; min-width: 48px; max-width: 48px; }
}
