:root {
  color-scheme: light;
  --bg: #f6f8fb;
  --surface: #ffffff;
  --surface-soft: #eef6f2;
  --ink: #172026;
  --muted: #65717b;
  --line: #dbe3ea;
  --green: #1f8a5f;
  --green-strong: #14704b;
  --blue: #286fbb;
  --coral: #c94f3a;
  --amber: #a16a17;
  --shadow: 0 16px 40px rgba(23, 32, 38, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  padding: 28px 22px;
  background: #10251d;
  color: #f5fbf8;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 34px;
}

.brand-mark {
  width: 46px;
  height: 46px;
  flex: 0 0 46px;
  fill: #eaf7f1;
  stroke: var(--green);
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}

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

.brand strong {
  font-size: 18px;
}

.brand span {
  color: #a9c9bc;
  font-size: 13px;
  margin-top: 2px;
}

nav {
  display: grid;
  gap: 8px;
}

nav a {
  color: #d8e8e1;
  text-decoration: none;
  padding: 11px 12px;
  border-radius: 8px;
}

nav a.active,
nav a:hover {
  background: rgba(255, 255, 255, 0.1);
  color: #ffffff;
}

.content {
  min-width: 0;
  padding: 28px;
}

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

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

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 32px;
  line-height: 1.15;
}

h2 {
  margin-bottom: 0;
  font-size: 19px;
  line-height: 1.2;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button,
.text-button,
.primary-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 14px;
  font-weight: 750;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--surface);
  border-color: var(--line);
  color: var(--ink);
}

.icon-button svg,
.panel-icon {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.text-button {
  background: #fdf4f1;
  border-color: #f0c6ba;
  color: var(--coral);
}

.primary-button {
  width: 100%;
  background: var(--green);
  color: #ffffff;
}

.primary-button:disabled,
.icon-button:disabled,
.text-button:disabled {
  cursor: not-allowed;
  opacity: 0.6;
}

.auth-panel {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 420px);
  gap: 28px;
  align-items: stretch;
  min-height: 420px;
}

.auth-copy,
.sign-in-form,
.panel,
.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 34px;
}

.auth-copy h2 {
  max-width: 520px;
  font-size: 34px;
  margin-bottom: 12px;
}

.auth-copy p:last-child {
  max-width: 520px;
  color: var(--muted);
  line-height: 1.6;
  margin-bottom: 0;
}

.sign-in-form {
  display: grid;
  align-content: center;
  gap: 16px;
  padding: 28px;
}

label span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 750;
}

input {
  width: 100%;
  height: 46px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  background: #fbfdff;
  color: var(--ink);
}

input:focus,
button:focus-visible {
  outline: 3px solid rgba(31, 138, 95, 0.2);
  outline-offset: 2px;
}

.form-message,
.status-line {
  min-height: 20px;
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.form-message.error,
.status-line.error {
  color: var(--coral);
}

.dashboard {
  display: grid;
  gap: 18px;
}

.section-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 14px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  background: #edf4fb;
  color: var(--blue);
  font-size: 12px;
  font-weight: 850;
}

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

.stat-card {
  min-height: 124px;
  padding: 18px;
}

.stat-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.stat-icon {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--green-strong);
  font-weight: 900;
}

.stat-card strong {
  display: block;
  margin-top: 16px;
  font-size: 30px;
  line-height: 1;
}

.stat-card span,
.stat-card small {
  color: var(--muted);
}

.stat-card small {
  display: block;
  margin-top: 8px;
}

.auth-admin-panel {
  margin-top: 16px;
}

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

.wide-panel {
  grid-column: 1 / -1;
}

.panel {
  min-width: 0;
  padding: 18px;
}

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

.panel-icon {
  color: var(--blue);
}

.metric-strip {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 10px;
}

.metric-strip-wide {
  grid-template-columns: repeat(8, minmax(0, 1fr));
}

.compact-strip {
  grid-template-columns: repeat(5, minmax(0, 1fr));
  margin-bottom: 12px;
}

.metric {
  min-height: 86px;
  padding: 13px;
  border-radius: 8px;
  background: #f7fafc;
  border: 1px solid var(--line);
}

.metric strong {
  display: block;
  font-size: 24px;
}

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

.metric small {
  display: block;
  margin-top: 7px;
  color: var(--muted);
  font-size: 11px;
}

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

.leader-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.leader-item strong,
.leader-item span {
  display: block;
}

.leader-item span {
  color: var(--muted);
  font-size: 13px;
}

.leader-score {
  color: var(--amber);
  font-weight: 900;
}

.inventory-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  max-height: 460px;
  overflow: auto;
  padding-right: 4px;
}

.inventory-item {
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.inventory-item strong,
.inventory-item span,
.inventory-item small {
  display: block;
}

.inventory-item strong {
  font-size: 22px;
}

.inventory-item span {
  margin-top: 4px;
  font-weight: 800;
}

.inventory-item small {
  margin-top: 5px;
  color: var(--muted);
}

.quality-list {
  display: grid;
  gap: 10px;
  max-height: 460px;
  overflow: auto;
  padding-right: 4px;
}

.quality-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdff;
}

.quality-item strong,
.quality-item small {
  display: block;
}

.quality-item small {
  margin-top: 4px;
  color: var(--muted);
}

.quality-item > span {
  min-width: 46px;
  text-align: right;
  font-size: 20px;
  font-weight: 900;
}

.quality-item.warn {
  border-color: #efcf88;
  background: #fffaf0;
}

.quality-item.warn > span {
  color: var(--amber);
}

.quality-item.ok > span {
  color: var(--green-strong);
}

.table-wrap {
  width: 100%;
  overflow-x: auto;
}

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

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

td {
  font-size: 14px;
}

.empty-row td {
  color: var(--muted);
  text-align: center;
}

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

  .analytics-grid,
  .tables-grid {
    grid-template-columns: 1fr;
  }

  .metric-strip-wide,
  .compact-strip {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

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

  .sidebar {
    position: static;
    height: auto;
  }

  nav {
    grid-template-columns: repeat(6, minmax(0, 1fr));
    overflow-x: auto;
  }

  nav a {
    text-align: center;
    white-space: nowrap;
  }

  .content {
    padding: 20px;
  }

  .topbar,
  .auth-panel {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .topbar-actions {
    width: 100%;
  }

  .icon-button,
  .text-button {
    flex: 1;
    justify-content: center;
  }

  .auth-copy h2 {
    font-size: 28px;
  }

  .metric-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .metric-strip-wide,
  .compact-strip,
  .inventory-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 540px) {
  .stats-grid,
  .metric-strip,
  .metric-strip-wide,
  .compact-strip,
  .inventory-grid {
    grid-template-columns: 1fr;
  }

  h1 {
    font-size: 28px;
  }
}
