:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #edf1f5;
  --surface-3: #f8fafc;
  --ink: #16202f;
  --muted: #617083;
  --line: #d9e0e7;
  --line-strong: #c5cfda;
  --blue: #2563eb;
  --blue-strong: #174ea6;
  --green: #16794c;
  --amber: #a35c00;
  --red: #b42318;
  --teal: #087a7a;
  --charcoal: #151a23;
  --shadow: 0 16px 40px rgba(22, 32, 47, 0.10);
  --soft-shadow: 0 1px 2px rgba(22, 32, 47, 0.05), 0 8px 22px rgba(22, 32, 47, 0.06);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html,
body {
  min-height: 100%;
  max-width: 100%;
}

body {
  margin: 0;
  overflow-x: hidden;
  background:
    linear-gradient(180deg, #eef2f6 0, var(--bg) 260px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

.app-shell {
  min-height: 100vh;
  max-width: 100vw;
  overflow-x: hidden;
}

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(115deg, rgba(37, 99, 235, 0.10), rgba(8, 122, 122, 0.08)),
    var(--bg);
}

.auth-panel {
  width: min(920px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 48px;
  align-items: center;
  padding: 48px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-panel h1 {
  margin: 8px 0 14px;
  font-size: clamp(34px, 6vw, 56px);
  line-height: 0.98;
  letter-spacing: 0;
}

.form-grid {
  display: grid;
  gap: 14px;
}

label {
  display: grid;
  gap: 6px;
  color: #344052;
  font-weight: 650;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 12px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

textarea {
  min-height: 220px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(31, 111, 235, 0.14);
}

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: 260px;
  display: grid;
  grid-template-rows: auto 1fr;
  background: var(--charcoal);
  color: #eef2f7;
  border-right: 1px solid #252b36;
  z-index: 20;
}

.brand-block {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
  padding: 16px 18px;
  border-bottom: 1px solid #252b36;
}

.brand-block span:last-child {
  display: block;
  color: #aab4c3;
  font-size: 12px;
  margin-top: 2px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 6px;
  background: #f8fafc;
  color: var(--charcoal);
  font-weight: 800;
}

.nav-list {
  display: grid;
  align-content: start;
  gap: 4px;
  padding: 14px 12px;
  overflow: auto;
}

.nav-button {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 42px;
  padding: 9px 10px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #cbd5e1;
  text-align: left;
}

.nav-button svg,
.icon-button svg,
.small-icon svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex: 0 0 auto;
}

.nav-button:hover,
.nav-button.active {
  background: rgba(255, 255, 255, 0.10);
  color: #fff;
}

.main-area {
  min-height: 100vh;
  margin-left: 260px;
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
  max-width: calc(100vw - 260px);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  min-height: 72px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 24px;
  background: rgba(244, 246, 248, 0.90);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(12px);
}

.topbar > div {
  min-width: 0;
}

.topbar h2 {
  margin: 2px 0 0;
  font-size: 21px;
  overflow-wrap: anywhere;
}

.topbar-actions,
.row-actions,
.toolbar,
.segmented,
.inline-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.content {
  display: grid;
  gap: 20px;
  padding: 18px 28px 40px;
  min-width: 0;
}

.page-intro {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--soft-shadow);
}

.page-intro h1 {
  margin: 4px 0 8px;
  font-size: 25px;
  line-height: 1.08;
}

.page-intro p:last-child {
  max-width: 760px;
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

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

.section-band {
  display: grid;
  gap: 14px;
  min-width: 0;
}

.section-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 16px;
  min-width: 0;
}

.section-header h3 {
  margin: 0;
  font-size: 18px;
  overflow-wrap: anywhere;
}

.eyebrow {
  margin: 0;
  color: var(--blue-strong);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.muted {
  color: var(--muted);
}

.metric-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

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

.kpi-card {
  min-height: 96px;
  display: grid;
  align-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  border-radius: 8px;
  box-shadow: var(--soft-shadow);
}

.kpi-card span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
}

.kpi-card strong {
  display: block;
  margin-top: 8px;
  font-size: 23px;
  line-height: 1;
  overflow-wrap: anywhere;
}

.kpi-card p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.kpi-card.good {
  border-left-color: var(--green);
}

.kpi-card.attention {
  border-left-color: var(--amber);
}

.kpi-card.info {
  border-left-color: var(--blue);
}

.metric-card,
.panel,
.table-shell,
.detail-pane,
.empty-state {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--soft-shadow);
}

.metric-card {
  min-height: 124px;
  display: grid;
  align-content: space-between;
  gap: 12px;
  padding: 16px;
  min-width: 0;
}

.metric-card strong {
  font-size: 28px;
  line-height: 1;
  overflow-wrap: anywhere;
}

.metric-card span {
  color: var(--muted);
}

.metric-card .trend {
  font-size: 12px;
  color: #344052;
}

.panel {
  padding: 16px;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 380px);
  gap: 14px;
  align-items: start;
  min-width: 0;
  overflow: hidden;
}

.management-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
  gap: 14px;
  align-items: start;
  min-width: 0;
}

.management-grid > .section-band {
  min-width: 0;
  overflow: hidden;
}

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

.two-column > .section-band {
  min-width: 0;
  overflow: hidden;
}

.two-column .kpi-rail {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.table-shell {
  overflow: hidden;
  min-width: 0;
  max-width: 100%;
}

.table-filter {
  padding: 10px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-3);
}

.table-filter input {
  min-height: 34px;
  padding: 7px 10px;
}

.table-scroll {
  overflow: auto;
  max-width: 100%;
}

.two-column .table-scroll,
.report-workspace .table-scroll {
  min-width: 0;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 820px;
}

.compact-table table {
  min-width: 0;
}

.compact-table th,
.compact-table td {
  padding: 10px 12px;
}

th,
td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 0;
  background: var(--surface-3);
  color: #435266;
  font-size: 12px;
  font-weight: 750;
  z-index: 1;
}

.sort-button {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 800;
  text-align: left;
}

.sort-button:hover,
.sort-button.active {
  color: var(--blue-strong);
}

tr:last-child td {
  border-bottom: 0;
}

.click-row {
  cursor: pointer;
}

.click-row:hover td {
  background: #f5f9ff;
}

.status-pill,
.role-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
  white-space: nowrap;
}

.status-ok {
  color: var(--green);
  background: #eaf7ef;
}

.status-warn {
  color: var(--amber);
  background: #fff4de;
}

.status-bad {
  color: var(--red);
  background: #fdeceb;
}

.status-info {
  color: var(--blue-strong);
  background: #eaf2ff;
}

.role-pill {
  margin: 2px 4px 2px 0;
  color: #1b365d;
  background: #e9eef7;
}

.stock-cell {
  display: grid;
  gap: 4px;
  justify-items: start;
}

.stock-cell span:last-child {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.primary-button,
.secondary-button,
.danger-button,
.ghost-button,
.icon-button {
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid transparent;
  padding: 8px 12px;
  font-weight: 750;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.primary-button {
  background: var(--blue);
  color: #fff;
  box-shadow: 0 8px 18px rgba(37, 99, 235, 0.20);
}

.primary-button:hover {
  background: var(--blue-strong);
}

.secondary-button {
  background: #fff;
  border-color: var(--line-strong);
  color: var(--ink);
}

.secondary-button:hover {
  background: var(--surface-2);
}

.danger-button {
  background: #fff;
  border-color: #f2b8b5;
  color: var(--red);
}

.ghost-button {
  background: transparent;
  color: var(--blue-strong);
}

.icon-button {
  width: 40px;
  padding: 0;
  background: #fff;
  border-color: var(--line);
  color: #344052;
}

.filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
  align-items: end;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
}

.report-workspace {
  display: grid;
  grid-template-columns: minmax(240px, 320px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}

.report-library {
  display: grid;
  gap: 8px;
}

.report-card {
  display: grid;
  gap: 5px;
  width: 100%;
  padding: 13px;
  border: 1px solid var(--line);
  border-left: 4px solid transparent;
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  text-align: left;
  box-shadow: var(--soft-shadow);
}

.report-card span {
  font-weight: 800;
}

.report-card small {
  color: var(--muted);
  line-height: 1.4;
}

.report-card:hover,
.report-card.active {
  border-left-color: var(--blue);
  background: #f8fbff;
}

.report-builder {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr)) auto;
  gap: 10px;
  align-items: end;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--soft-shadow);
}

.trust-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 7px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #f8fafc;
  color: var(--muted);
  font-weight: 800;
}

.trust-badge svg,
.primary-button svg,
.secondary-button svg {
  width: 17px;
  height: 17px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.segmented {
  padding: 4px;
  background: var(--surface-2);
  border-radius: 8px;
}

.segment-button {
  min-height: 34px;
  padding: 7px 11px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #435266;
  font-weight: 750;
}

.segment-button.active {
  background: #fff;
  color: var(--ink);
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.08);
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.detail-item {
  min-height: 58px;
  display: grid;
  align-content: center;
  gap: 4px;
  padding: 10px;
  background: #f9fafb;
  border: 1px solid var(--line);
  border-radius: 6px;
  overflow-wrap: anywhere;
}

.detail-item span {
  color: var(--muted);
  font-size: 12px;
}

.product-detail {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr);
  gap: 14px;
  min-width: 0;
}

.product-image {
  width: 180px;
  aspect-ratio: 1;
  object-fit: contain;
  background: #f3f5f8;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.json-preview {
  max-height: 320px;
  overflow: auto;
  padding: 12px;
  background: #101828;
  color: #e6edf3;
  border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", monospace;
  font-size: 12px;
  line-height: 1.55;
  white-space: pre-wrap;
}

.form-message {
  min-height: 20px;
  margin: 0;
  color: var(--red);
}

.empty-state {
  min-height: 120px;
  display: grid;
  place-items: center;
  padding: 22px;
  color: var(--muted);
  text-align: center;
  min-width: 0;
  overflow-wrap: anywhere;
}

.table-empty-message {
  min-height: 82px;
  display: grid;
  place-items: center;
  padding: 18px;
  color: var(--muted);
  text-align: center;
}

.loading {
  min-height: 220px;
  display: grid;
  place-items: center;
  color: var(--muted);
}

.mobile-only {
  display: none;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(17, 24, 39, 0.55);
}

.modal-panel {
  width: min(1040px, 100%);
  max-height: min(860px, calc(100vh - 40px));
  display: grid;
  gap: 14px;
  overflow: auto;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.drawer-open .sidebar {
  transform: translateX(0);
}

@media (max-width: 1360px) {
  .management-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 1180px) {
  .metric-grid,
  .kpi-rail {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .two-column,
  .management-grid,
  .three-column,
  .report-workspace {
    grid-template-columns: 1fr;
  }

  .filters,
  .report-builder {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 820px) {
  .auth-panel {
    grid-template-columns: 1fr;
    padding: 28px;
    gap: 24px;
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 160ms ease;
  }

  .main-area {
    margin-left: 0;
    max-width: 100vw;
  }

  .mobile-only {
    display: grid;
  }

  .topbar {
    align-items: center;
    padding: 12px 14px;
  }

  .content {
    padding: 14px;
  }

  .page-intro {
    align-items: start;
    flex-direction: column;
    padding: 18px;
  }

  .page-intro h1 {
    font-size: 24px;
  }

  .metric-grid,
  .kpi-rail,
  .filters,
  .report-builder,
  .detail-grid,
  .product-detail {
    grid-template-columns: 1fr;
  }

  .section-header {
    align-items: start;
    flex-direction: column;
  }

  .topbar-actions {
    flex-wrap: nowrap;
  }

  .toolbar,
  .pagination-bar,
  .pagination-bar .row-actions {
    width: 100%;
  }

  .pagination-bar {
    align-items: stretch;
    flex-direction: column;
  }

  .product-image {
    width: 100%;
    max-width: 260px;
  }

  .modal-backdrop {
    align-items: end;
    padding: 10px;
  }

  .modal-panel {
    max-height: calc(100vh - 20px);
    padding: 14px;
  }
}
