:root {
  color-scheme: light;
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-muted: #f8fafc;
  --ink: #172033;
  --muted: #69758a;
  --line: #dfe5ef;
  --line-strong: #cbd5e1;
  --accent: #176b87;
  --accent-strong: #0f5267;
  --accent-soft: #e5f4f8;
  --warn: #b7791f;
  --warn-soft: #fff7df;
  --danger: #b42318;
  --danger-soft: #fff0ed;
  --ok: #147a50;
  --ok-soft: #e9f8f0;
  --purple: #6a4bbc;
  --purple-soft: #f0ecff;
  --shadow: 0 16px 42px rgba(30, 41, 59, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

.login-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 22px;
  background: linear-gradient(135deg, #f5f7fb 0%, #eaf1f6 100%);
}

.login-card {
  width: min(420px, 100%);
  display: grid;
  gap: 14px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-logo {
  width: 150px;
  height: 62px;
  object-fit: contain;
  justify-self: start;
}

.login-card h1 {
  margin: 0;
  font-size: 28px;
}

.login-card p {
  margin: -8px 0 8px;
  color: var(--muted);
}

.login-card label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-weight: 700;
}

.login-error {
  padding: 10px 12px;
  border-radius: 8px;
  background: var(--danger-soft);
  color: var(--danger);
  font-weight: 700;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 18px 14px;
  background: #162235;
  color: #e8edf5;
  border-right: 1px solid rgba(255,255,255,0.08);
}

.brand {
  height: 58px;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 8px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
}

.brand-logo {
  width: 58px;
  height: 38px;
  border-radius: 6px;
  object-fit: contain;
  background: #fff;
  border: 1px solid rgba(255,255,255,0.16);
  flex: 0 0 auto;
}

.brand strong,
.brand span {
  display: block;
}

.brand span {
  margin-top: 2px;
  color: #9aa8bd;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
  margin-top: 18px;
}

.nav-item {
  height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 12px;
  background: transparent;
  color: #b8c3d4;
  text-align: left;
}

.nav-item:hover,
.nav-item.active {
  background: rgba(255,255,255,0.08);
  color: #fff;
  border-color: rgba(255,255,255,0.1);
}

.main {
  min-width: 0;
  padding: 22px;
}

.session-user {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
}

.topbar {
  min-height: 70px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.topbar h1,
.drawer-header h2 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.eyebrow {
  margin: 0 0 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.primary-button,
.ghost-button,
.icon-button,
.small-button,
.danger-button {
  min-height: 38px;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
  padding: 0 14px;
  background: var(--panel);
  color: var(--ink);
  font-weight: 700;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: #fff;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.ghost-button:hover,
.small-button:hover,
.icon-button:hover {
  background: var(--panel-muted);
}

.danger-button {
  border-color: #f2b8b0;
  background: var(--danger-soft);
  color: var(--danger);
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 20px;
}

.mobile-menu {
  display: none;
}

.view {
  display: none;
}

.view.active {
  display: block;
}

.grid {
  display: grid;
  gap: 14px;
}

.grid.metrics {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.grid.two {
  grid-template-columns: minmax(0, 1.1fr) minmax(340px, 0.9fr);
}

.grid.three {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.panel,
.metric,
.record-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.panel {
  padding: 16px;
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-header h2,
.panel-header h3 {
  margin: 0;
  font-size: 16px;
}

.panel-header p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.metric {
  padding: 15px;
  width: 100%;
  text-align: left;
}

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

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.metric small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
}

.metric-action {
  border: 1px solid var(--line);
  transition: border-color 160ms ease, box-shadow 160ms ease, transform 160ms ease;
}

.metric-action:hover,
.metric-action:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 18px 46px rgba(23, 107, 135, 0.14);
  outline: none;
  transform: translateY(-1px);
}

.metric-action:active {
  transform: translateY(0);
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 13px;
}

td p {
  margin: 3px 0 0;
  color: var(--ink);
}

th {
  background: var(--panel-muted);
  color: #4b5565;
  font-size: 12px;
  font-weight: 800;
}

tr:last-child td {
  border-bottom: 0;
}

.summary-row td {
  background: #f8fafc;
  border-top: 2px solid var(--line-strong);
  font-weight: 800;
}

.nested-list {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border-radius: 8px;
  background: #f8fafc;
}

.nested-list > strong {
  font-size: 12px;
  color: #4b5565;
}

.nested-list p {
  margin: 0;
  color: var(--muted);
}

.nested-row {
  display: grid;
  grid-template-columns: minmax(160px, 1.1fr) minmax(120px, 0.8fr) minmax(180px, 1.2fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.status,
.tag {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 800;
  white-space: nowrap;
}

.status.ok,
.tag.ok {
  background: var(--ok-soft);
  color: var(--ok);
}

.status.warn,
.tag.warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.status.danger,
.tag.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.status.info,
.tag.info {
  background: var(--accent-soft);
  color: var(--accent);
}

.status.purple,
.tag.purple {
  background: var(--purple-soft);
  color: var(--purple);
}

.task-list {
  display: grid;
  gap: 10px;
}

.task-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 12px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-muted);
}

.task-dot {
  width: 10px;
  height: 10px;
  margin-top: 5px;
  border-radius: 999px;
  background: var(--accent);
}

.task-dot.warn {
  background: var(--warn);
}

.task-dot.danger {
  background: var(--danger);
}

.task-dot.ok {
  background: var(--ok);
}

.task-item strong,
.record-card strong {
  display: block;
}

.task-item p,
.record-card p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.task-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.record-card {
  padding: 14px;
}

.record-card .meta-row,
.meta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.toolbar {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 14px;
}

.search,
.select {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 0 12px;
  background: #fff;
}

.search {
  min-width: min(100%, 280px);
}

.product-cell {
  display: flex;
  align-items: center;
  gap: 10px;
}

.product-thumb {
  width: 48px;
  height: 48px;
  border-radius: 8px;
  object-fit: cover;
  border: 1px solid var(--line);
  background: var(--panel-muted);
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  display: none;
  background: rgba(15, 23, 42, 0.28);
  z-index: 30;
}

.detail-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: min(1440px, calc(100vw - 40px));
  height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border-left: 1px solid var(--line);
  box-shadow: -24px 0 60px rgba(15, 23, 42, 0.18);
  transform: translateX(100%);
  transition: transform 180ms ease;
  z-index: 40;
}

.drawer-backdrop.open {
  display: block;
}

.detail-drawer.open {
  transform: translateX(0);
}

.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.drawer-body {
  overflow: auto;
  padding: 18px;
}

.detail-drawer .table-wrap table {
  min-width: 1260px;
}

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

.field {
  display: grid;
  gap: 6px;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field input,
.field textarea,
.field select {
  min-height: 38px;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  padding: 8px 10px;
}

.field textarea {
  min-height: 82px;
  resize: vertical;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #172033;
  color: #fff;
  box-shadow: var(--shadow);
  transform: translate(-50%, 20px);
  opacity: 0;
  pointer-events: none;
  transition: all 180ms ease;
  z-index: 60;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

@media (max-width: 1100px) {
  .grid.metrics,
  .grid.three,
  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .grid.two {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: 248px;
    transform: translateX(-100%);
    transition: transform 180ms ease;
    z-index: 50;
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .mobile-menu {
    display: inline-grid;
    place-items: center;
  }

  .main {
    padding: 14px;
  }

  .topbar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .topbar-actions {
    width: 100%;
    justify-content: stretch;
  }

  .topbar-actions button {
    flex: 1;
  }

  .grid.metrics,
  .grid.three,
  .cards,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .task-item {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .task-item button {
    grid-column: 2;
    justify-self: start;
  }

  .nested-row {
    grid-template-columns: 1fr;
    align-items: start;
  }
}
