:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text: #18212f;
  --muted: #667085;
  --line: #d9e0ea;
  --primary: #0f766e;
  --primary-dark: #115e59;
  --accent: #315a9b;
  --danger: #b42318;
  --success: #067647;
  --shadow: 0 18px 50px rgba(18, 24, 40, 0.08);
}

* {
  box-sizing: border-box;
}

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

button,
input,
select {
  font: inherit;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  min-height: 76px;
  padding: 16px clamp(16px, 4vw, 48px);
  border-bottom: 1px solid var(--line);
  background: rgba(247, 248, 250, 0.94);
  backdrop-filter: blur(14px);
}

.main-menu {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex: 1;
}

.menu-group {
  position: relative;
}

.menu-trigger,
.submenu-item {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
}

.menu-trigger {
  padding: 0 16px;
}

.menu-trigger[aria-expanded="true"] {
  border-color: rgba(15, 118, 110, 0.35);
  color: var(--primary-dark);
}

.submenu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  display: none;
  min-width: 220px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.submenu.is-open {
  display: grid;
}

.submenu-item {
  width: 100%;
  padding: 0 12px;
  text-align: left;
}

.submenu-item:hover {
  border-color: rgba(15, 118, 110, 0.35);
  background: #f0fdfa;
}

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

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

h1 {
  font-size: clamp(28px, 4vw, 42px);
}

h2 {
  font-size: 18px;
}

.status-pill {
  min-width: 112px;
  padding: 8px 12px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
  text-align: center;
}

.status-pill.is-ok {
  border-color: rgba(6, 118, 71, 0.35);
  background: #ecfdf3;
  color: var(--success);
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 320px;
  gap: 24px;
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 24px clamp(16px, 4vw, 48px) 48px;
}

.workspace,
.side-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.workspace {
  min-width: 0;
}

.tabs {
  display: flex;
  gap: 2px;
  padding: 8px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  border-radius: 8px 8px 0 0;
}

.tab {
  min-height: 40px;
  padding: 0 16px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.tab.is-active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 3px rgba(18, 24, 40, 0.08);
}

.panel {
  display: none;
  padding: 18px;
}

.panel.is-active {
  display: block;
}

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

.tool-grid.compact {
  grid-template-columns: minmax(0, 1fr);
}

fieldset {
  display: grid;
  gap: 14px;
  min-width: 0;
  margin: 0;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

legend {
  padding: 0 6px;
  color: var(--accent);
  font-size: 13px;
  font-weight: 800;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
}

label span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select {
  width: 100%;
  min-height: 42px;
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

input:focus,
select:focus {
  outline: 2px solid rgba(15, 118, 110, 0.2);
  border-color: var(--primary);
}

.primary-action {
  align-self: end;
  min-height: 44px;
  border: 0;
  border-radius: 6px;
  background: var(--primary);
  color: #ffffff;
  cursor: pointer;
  font-weight: 800;
}

.primary-action:hover {
  background: var(--primary-dark);
}

.secondary-action,
.icon-action {
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 800;
}

.secondary-action {
  padding: 0 12px;
}

.secondary-action:hover,
.icon-action:hover {
  border-color: rgba(15, 118, 110, 0.35);
  background: #f0fdfa;
  color: var(--primary-dark);
}

.icon-action {
  width: 34px;
  min-height: 34px;
  padding: 0;
  line-height: 1;
}

.formula-strip {
  display: flex;
  gap: 10px;
  align-items: center;
  margin: 18px 0;
  padding: 12px 14px;
  border: 1px solid #c7d7fe;
  border-radius: 8px;
  background: #eef4ff;
  color: #20325a;
  overflow-wrap: anywhere;
}

.formula-strip strong {
  min-width: 32px;
  color: var(--accent);
  font-size: 18px;
}

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

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

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

.summary-pill {
  min-height: 34px;
  padding: 8px 12px;
  border: 1px solid rgba(49, 90, 155, 0.22);
  border-radius: 999px;
  background: #eef4ff;
  color: #20325a;
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.account-controls {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(180px, 260px);
  gap: 14px;
  margin-bottom: 14px;
}

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

.batch-results {
  grid-template-columns: repeat(4, minmax(0, 1fr));
  margin-bottom: 14px;
}

.entry-form {
  display: grid;
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
  gap: 16px;
}

.classification-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  margin: 16px 0;
  padding: 12px 14px;
  border: 1px solid rgba(15, 118, 110, 0.22);
  border-radius: 8px;
  background: #f0fdfa;
  color: var(--primary-dark);
  font-size: 14px;
}

.classification-preview strong {
  font-weight: 850;
}

.classification-preview span {
  color: var(--muted);
}

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

.batch-table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  max-height: 68vh;
}

.accounts-table {
  width: 100%;
  min-width: 860px;
  border-collapse: collapse;
  background: var(--surface);
}

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

.batch-table {
  width: 100%;
  min-width: 1760px;
  border-collapse: collapse;
  background: var(--surface);
}

.batch-table th,
.batch-table td {
  padding: 8px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
}

.batch-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  text-transform: uppercase;
}

.batch-table input {
  min-height: 34px;
  padding: 6px 8px;
  font-size: 13px;
}

.batch-table input[type="number"] {
  min-width: 92px;
  text-align: right;
}

.batch-table .batch-name {
  min-width: 180px;
  text-align: left;
}

.batch-table .batch-sku {
  min-width: 100px;
  text-align: left;
}

.batch-result,
.batch-status {
  min-width: 104px;
  color: var(--text);
  font-size: 13px;
  font-weight: 850;
  white-space: nowrap;
}

.batch-status {
  max-width: 220px;
  color: var(--muted);
  font-weight: 700;
  white-space: normal;
}

.batch-table tr.is-error-row {
  background: #fffbfa;
}

.batch-table tr.is-error-row .batch-status {
  color: var(--danger);
}

.accounts-table th {
  position: sticky;
  top: 0;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  text-transform: uppercase;
}

.accounts-table tbody tr:hover {
  background: #f8fafc;
}

.accounts-table code {
  display: inline-block;
  min-width: 86px;
  padding: 4px 6px;
  border-radius: 6px;
  background: #eef4ff;
  color: #20325a;
  font-size: 13px;
  font-weight: 850;
}

.entries-table {
  min-width: 980px;
}

.entries-table td:nth-child(3) {
  font-weight: 850;
  white-space: nowrap;
}

.account-name {
  display: inline-block;
  padding-left: var(--account-indent);
  font-weight: 760;
}

.metric {
  min-height: 112px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.metric h3 {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 13px;
  letter-spacing: 0;
}

.metric .value {
  margin: 0;
  color: var(--text);
  font-size: clamp(22px, 3vw, 32px);
  font-weight: 850;
}

.metric .detail {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.metric.is-primary {
  border-color: rgba(15, 118, 110, 0.28);
  background: #f0fdfa;
}

.metric.is-primary .value {
  color: var(--primary-dark);
}

.metric.is-danger .value {
  color: var(--danger);
}

.side-panel {
  align-self: start;
  padding: 18px;
}

.side-panel dl {
  display: grid;
  gap: 12px;
  margin: 16px 0 0;
}

.side-panel dt {
  font-weight: 850;
}

.side-panel dd {
  margin: -8px 0 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.45;
}

.error-box {
  padding: 14px;
  border: 1px solid #fecdca;
  border-radius: 8px;
  background: #fffbfa;
  color: var(--danger);
  font-weight: 700;
}

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

  .tool-grid,
  .results-grid,
  .batch-results,
  .managerial-results,
  .entry-form {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .main-menu {
    justify-content: flex-start;
  }
}

@media (max-width: 680px) {
  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .status-pill {
    width: 100%;
  }

  .main-menu,
  .menu-group,
  .menu-trigger {
    width: 100%;
  }

  .submenu {
    position: static;
    margin-top: 8px;
    width: 100%;
  }

  .tabs {
    overflow-x: auto;
  }

  .tab {
    flex: 1 0 auto;
  }

  .tool-grid,
  .results-grid,
  .batch-results,
  .managerial-results,
  .account-controls,
  .entry-form {
    grid-template-columns: 1fr;
  }

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

  .summary-pill {
    width: 100%;
  }

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