:root {
  --bg: #f4f5f2;
  --surface: #ffffff;
  --surface-soft: #fafaf8;
  --ink: #202528;
  --muted: #697176;
  --line: #dfe3df;
  --accent: #236f65;
  --accent-soft: #e7f2ee;
  --red: #b23a34;
  --red-soft: #fae9e7;
  --yellow: #a96812;
  --yellow-soft: #fff2cf;
  --green: #23724e;
  --green-soft: #e5f4eb;
  --blue: #336d9c;
  --blue-soft: #e5f0fa;
  --gray-soft: #eef0ef;
  --focus: #172026;
  --shadow: 0 12px 34px rgba(23, 32, 38, 0.07);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, "Segoe UI", Arial, sans-serif;
  font-size: 14px;
}

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

.app-main {
  min-width: 0;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
  gap: 14px;
  padding: 18px 14px;
  overflow-y: auto;
  background: var(--surface);
  border-right: 1px solid var(--line);
  z-index: 12;
}

.sidebar-brand {
  display: grid;
  grid-template-columns: 42px 1fr;
  align-items: center;
  gap: 10px;
  padding: 6px 6px 12px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  display: grid;
  width: 42px;
  height: 42px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.sidebar-status {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 0 4px;
}

.sidebar-nav {
  display: grid;
  align-content: start;
  gap: 18px;
  padding: 4px;
}

.nav-group {
  display: grid;
  gap: 6px;
}

.nav-heading {
  padding: 0 10px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.nav-item {
  width: 100%;
  min-height: 54px;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  text-align: left;
  white-space: normal;
}

.nav-item span {
  font-weight: 750;
}

.nav-item small {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.25;
}

.nav-item.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.nav-item.active small {
  color: rgba(255, 255, 255, 0.78);
}

.nav-backdrop {
  display: none;
}

button,
input,
select {
  font: inherit;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  position: sticky;
  top: 0;
  z-index: 10;
  padding: 18px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.page-heading {
  min-width: 0;
  flex: 1;
}

.eyebrow {
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.1;
}

h2 {
  font-size: 17px;
  line-height: 1.3;
}

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

.icon-button {
  display: inline-grid;
  width: 38px;
  height: 38px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
}

.nav-toggle {
  display: none;
}

.user-pill,
.live-pill {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 700;
}

.live-pill.paused {
  background: var(--gray-soft);
  color: var(--muted);
}

.live-pill.syncing {
  background: var(--blue-soft);
  color: var(--blue);
}

.live-pill.problem {
  background: var(--red-soft);
  color: var(--red);
}

.login-layer {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: none;
  place-items: center;
  background: rgba(244, 245, 242, 0.92);
  padding: 24px;
}

.login-layer.active {
  display: grid;
}

.login-panel {
  width: min(380px, 100%);
  display: grid;
  gap: 16px;
  padding: 22px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.compact-form,
.user-form,
.runner-card {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.user-form {
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  align-items: end;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.form-actions {
  display: flex;
  align-items: end;
  gap: 8px;
  flex-wrap: wrap;
}

.checkbox-label {
  display: flex;
  min-height: 36px;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.runner-grid,
.artifact-grid,
.autosync-grid,
.task-summary-grid,
.manual-grid,
.access-card-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(240px, 1fr));
  gap: 12px;
  padding: 16px;
}

.access-card-grid {
  grid-template-columns: repeat(5, minmax(170px, 1fr));
}

.manual-grid {
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
}

.runner-card,
.artifact-card,
.autosync-card,
.task-summary-card,
.manual-card,
.access-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
}

.access-card {
  min-height: 86px;
  display: grid;
  gap: 6px;
  padding: 13px;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.access-card:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.access-card strong {
  font-size: 14px;
}

.access-card span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.autosync-card,
.task-summary-card,
.manual-card {
  display: grid;
  gap: 6px;
  padding: 12px;
}

.runner-card h3,
.manual-card h3 {
  margin: 0;
}

.runner-row {
  display: grid;
  grid-template-columns: minmax(120px, 1fr) 90px;
  gap: 8px;
}

.tabs {
  display: flex;
  gap: 6px;
  padding: 12px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
}

.tab,
.button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
}

.tab {
  padding: 0 14px;
}

.tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.sidebar .nav-item {
  min-height: 54px;
  display: grid;
  align-content: center;
  gap: 2px;
  padding: 9px 10px;
  border-color: transparent;
  background: transparent;
  text-align: left;
  white-space: normal;
}

.sidebar .nav-item.active {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.button {
  padding: 0 12px;
  font-weight: 650;
}

.link-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.button:hover,
.tab:hover {
  border-color: var(--focus);
}

.button.secondary {
  color: var(--accent);
  background: var(--accent-soft);
  border-color: #c9e1da;
}

.button.danger {
  color: var(--red);
}

.button.small {
  min-height: 30px;
  padding: 0 9px;
  font-size: 12px;
}

main {
  padding: 18px 28px 32px;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(4, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

label {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 650;
}

select,
input[type="file"],
input[type="password"],
input[type="number"],
input[type="url"],
input:not([type]) {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 0 10px;
}

textarea {
  width: 100%;
  min-height: 88px;
  resize: vertical;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 8px 10px;
  font: inherit;
}

.view {
  display: none;
}

.view.active {
  display: grid;
  gap: 16px;
}

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

.store-card,
.import-card,
.notification-card,
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.store-card {
  padding: 14px;
  display: grid;
  gap: 10px;
  border-left-width: 5px;
}

.import-grid,
.notification-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(220px, 1fr));
  gap: 12px;
  padding: 16px;
}

.notification-grid {
  grid-template-columns: repeat(3, minmax(240px, 1fr));
}

.import-card,
.notification-card {
  padding: 14px;
  display: grid;
  gap: 10px;
  box-shadow: none;
}

.import-card h3 {
  margin: 0;
  font-size: 15px;
}

.import-card p {
  margin: 0;
}

.notification-card pre {
  margin: 0;
  max-height: 180px;
  overflow: auto;
  white-space: pre-wrap;
  line-height: 1.4;
  color: var(--ink);
  background: #fbfbfa;
}

.task-summary-card pre {
  margin: 0;
  max-height: 220px;
  overflow: auto;
  white-space: pre-wrap;
  line-height: 1.4;
}

.store-card h3 {
  margin: 0;
  font-size: 15px;
}

.card-row,
.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.panel {
  overflow: hidden;
}

#usersPanel,
#productionPanel,
#syncPanel,
#integrationsPanel,
#passwordPanel,
#browserPanel {
  scroll-margin-top: 92px;
}

.panel-head {
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.split {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.8fr);
  gap: 16px;
}

.summary-text {
  margin: 0;
  padding: 16px;
  min-height: 260px;
  white-space: pre-wrap;
  line-height: 1.45;
  color: var(--ink);
  background: var(--surface-soft);
}

.muted {
  color: var(--muted);
}

.number {
  font-size: 20px;
  font-weight: 750;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 750;
  line-height: 1;
  border: 1px solid transparent;
}

.badge.red {
  color: var(--red);
  background: var(--red-soft);
  border-color: #f1c4bf;
}

.badge.yellow {
  color: #71470b;
  background: var(--yellow-soft);
  border-color: #f3d68d;
}

.badge.green {
  color: var(--green);
  background: var(--green-soft);
  border-color: #b9dfc8;
}

.badge.blue {
  color: var(--blue);
  background: var(--blue-soft);
  border-color: #bdd7ee;
}

.badge.gray {
  color: #596166;
  background: var(--gray-soft);
  border-color: #d8ddda;
}

.red-zone-list {
  display: grid;
}

.red-zone {
  display: grid;
  gap: 6px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  border-left: 5px solid transparent;
}

.red-zone:last-child {
  border-bottom: 0;
}

.red-zone strong {
  font-size: 13px;
}

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

table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 750;
  background: var(--surface-soft);
}

td {
  line-height: 1.35;
}

tbody tr {
  border-left: 5px solid transparent;
}

tbody td:first-child {
  border-left: 5px solid transparent;
}

tbody tr:hover {
  background: #fcfcfb;
}

.row-red,
.row-red td:first-child {
  border-left-color: var(--red);
  background: #fffafa;
}

.row-yellow,
.row-yellow td:first-child {
  border-left-color: #d58d21;
  background: #fffdf6;
}

.row-green,
.row-green td:first-child {
  border-left-color: var(--green);
}

.row-blue,
.row-blue td:first-child {
  border-left-color: var(--blue);
}

.row-gray,
.row-gray td:first-child {
  border-left-color: #9aa2a6;
}

.store-card.row-red {
  background: #fffafa;
}

.store-card.row-yellow {
  background: #fffdf6;
}

.store-card.row-green {
  background: #fbfffc;
}

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

.actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.actions.vertical {
  display: grid;
  grid-template-columns: 1fr;
  min-width: 120px;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.wide-cell {
  min-width: 260px;
  max-width: 420px;
}

.wide-cell pre,
.reply-cell textarea {
  white-space: pre-wrap;
}

.reply-cell {
  min-width: 280px;
}

.export-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.upload-row {
  padding: 16px;
}

/* Production is auto-first: API sync and data/inbox imports run in the background. */
#runNowButton,
#runNowAccessButton,
#scanInboxButton,
#uploadButton,
#wbFile,
[data-upload],
[data-process-upload],
.import-card input[type="file"] {
  display: none !important;
}

.auto-note {
  display: inline-flex;
  min-height: 30px;
  align-items: center;
  padding: 0 10px;
  border: 1px solid #c9e1da;
  border-radius: 8px;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  max-width: 380px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--focus);
  color: #fff;
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 160ms ease, transform 160ms ease;
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 980px) {
  .metric-grid,
  .import-grid,
  .manual-grid,
  .access-card-grid,
  .notification-grid,
  .split,
  .toolbar,
  .user-form,
  .runner-grid,
  .artifact-grid,
  .autosync-grid,
  .task-summary-grid {
    grid-template-columns: 1fr;
  }

  .app-shell {
    display: block;
  }

  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(320px, calc(100vw - 44px));
    transform: translateX(-105%);
    transition: transform 180ms ease;
    box-shadow: var(--shadow);
  }

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

  body.sidebar-open .nav-backdrop {
    position: fixed;
    inset: 0;
    z-index: 11;
    display: block;
    background: rgba(23, 32, 38, 0.28);
  }

  .nav-toggle {
    display: inline-grid;
    flex: 0 0 auto;
  }

  .topbar {
    align-items: center;
    gap: 12px;
  }

  .topbar-actions {
    justify-content: flex-end;
  }

  main,
  .topbar {
    padding-left: 16px;
    padding-right: 16px;
  }

  .page-heading h1 {
    font-size: 20px;
  }
}

@media (max-width: 640px) {
  .topbar {
    flex-wrap: wrap;
  }

  .page-heading {
    order: 1;
    flex-basis: calc(100% - 54px);
  }

  .topbar-actions {
    order: 2;
    width: 100%;
    justify-content: flex-start;
  }

  .topbar-actions .button,
  .topbar-actions .user-pill {
    flex: 1 1 auto;
    justify-content: center;
  }

  main {
    padding-top: 12px;
  }

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