:root {
  --ink: #17202f;
  --muted: #637083;
  --line: #dde4ee;
  --page: #f4f6f9;
  --panel: #ffffff;
  --nav: #ffffff;
  --nav-hover: #eef3fb;
  --blue: #1f5fbf;
  --blue-soft: #e8f0ff;
  --green: #13785f;
  --green-soft: #e7f6f1;
  --amber: #97680e;
  --amber-soft: #fff3d8;
  --red: #b93232;
  --red-soft: #ffecec;
  --shadow: 0 8px 20px rgba(25, 34, 50, 0.07);
  --shadow-soft: 0 1px 2px rgba(25, 34, 50, 0.08);
}

:root[data-theme="dark"] {
  --ink: #e7ecf3;
  --muted: #97a4b8;
  --line: #2a3447;
  --page: #0f1622;
  --panel: #161f2e;
  --nav: #161f2e;
  --nav-hover: #1e2a3d;
  --blue: #5b9bff;
  --blue-soft: #1b2942;
  --green: #4cc4a0;
  --green-soft: #12302a;
  --amber: #e0b15a;
  --amber-soft: #362e16;
  --red: #ef6b6b;
  --red-soft: #3a1f22;
  --shadow: 0 8px 20px rgba(0, 0, 0, 0.45);
  --shadow-soft: 0 1px 2px rgba(0, 0, 0, 0.4);
}

:root[data-theme="dark"] body {
  background: var(--page);
}

:root[data-theme="dark"] .app-header {
  background: rgba(22, 31, 46, 0.96);
}

:root[data-theme="dark"] .btn,
:root[data-theme="dark"] select,
:root[data-theme="dark"] input,
:root[data-theme="dark"] textarea,
:root[data-theme="dark"] .topbar-context select,
:root[data-theme="dark"] .main-menu select {
  background: #1b2536;
  color: var(--ink);
}

:root[data-theme="dark"] .btn.primary {
  color: #0a1220;
}

:root[data-theme="dark"] th {
  background: #1a2336;
}

:root[data-theme="dark"] .landing-copy,
:root[data-theme="dark"] .intro-panel,
:root[data-theme="dark"] .section-switcher,
:root[data-theme="dark"] .template-option {
  background: var(--panel);
}

:root[data-theme="dark"] .landing-steps div,
:root[data-theme="dark"] .intro-steps div,
:root[data-theme="dark"] .entity-menu-tile,
:root[data-theme="dark"] .login-mode,
:root[data-theme="dark"] .login-mode button.active,
:root[data-theme="dark"] .flow-step,
:root[data-theme="dark"] .setup-alert,
:root[data-theme="dark"] .status-tile,
:root[data-theme="dark"] .production-summary,
:root[data-theme="dark"] .production-test-actions,
:root[data-theme="dark"] .pending-item,
:root[data-theme="dark"] .empty-state,
:root[data-theme="dark"] .drop-zone,
:root[data-theme="dark"] .template-preview {
  background: #131b29;
}

:root[data-theme="dark"] .pill,
:root[data-theme="dark"] .alloc-progress,
:root[data-theme="dark"] .bar-track,
:root[data-theme="dark"] .progress-track {
  background: #222e42;
}

:root[data-theme="dark"] .change-tray {
  border-bottom-color: #5a4a1d;
  background: #2b2412;
}

:root[data-theme="dark"] .change-tray span {
  color: #cfbd8a;
}

:root[data-theme="dark"] .setup-alert span,
:root[data-theme="dark"] .setup-alert p {
  color: #cfbd8a;
}

:root[data-theme="dark"] .report-preview {
  background: #0c121d;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: linear-gradient(180deg, #eef3f8 0, var(--page) 220px);
  font-family: Arial, Helvetica, sans-serif;
  letter-spacing: 0;
}

[hidden] {
  display: none !important;
}

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

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.landing-panel {
  width: min(100%, 1180px);
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(360px, 0.65fr);
  gap: 28px;
  align-items: stretch;
}

.landing-copy {
  display: grid;
  align-content: center;
  gap: 22px;
  padding: 34px;
  border: 1px solid #cddbf4;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.landing-copy h1 {
  max-width: 760px;
  font-size: 34px;
  line-height: 1.12;
}

.landing-copy p {
  max-width: 780px;
  color: var(--muted);
  line-height: 1.55;
}

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

.landing-steps div {
  min-width: 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.landing-steps strong,
.landing-steps span {
  display: block;
}

.landing-steps span {
  margin-top: 5px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.login-card {
  display: grid;
  align-content: center;
  gap: 16px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.login-brand {
  min-width: 0;
}

.login-mode {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.login-mode button {
  min-height: 36px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 700;
}

.login-mode button.active {
  color: var(--blue);
  border-color: #cddbf4;
  background: #ffffff;
  box-shadow: var(--shadow-soft);
}

.app-shell {
  min-height: 100vh;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 18px;
  align-items: center;
  min-height: 70px;
  padding: 12px 24px;
  background: rgba(255, 255, 255, 0.96);
  border-bottom: 1px solid var(--line);
  box-shadow: var(--shadow-soft);
  backdrop-filter: blur(10px);
}

.brand {
  display: flex;
  gap: 10px;
  align-items: center;
  min-width: 190px;
}

.brand-mark {
  width: 40px;
  height: 40px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  background: #173b6d;
  color: #ffffff;
  font-weight: 700;
}

.logo-mark {
  overflow: hidden;
  background: transparent;
}

.logo-mark img {
  width: 100%;
  height: 100%;
  display: block;
}

.brand-mark.large {
  width: 56px;
  height: 56px;
  font-size: 18px;
}

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

.brand span {
  color: var(--muted);
  font-size: 12px;
  margin-top: 2px;
}

.main-menu {
  display: none;
  gap: 4px;
  min-width: 190px;
}

.main-menu label {
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
}

.main-menu select {
  width: 100%;
  font-weight: 700;
  border-color: #cddbf4;
  background: #f8fafc;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  overflow-x: visible;
  padding: 2px 0;
  scrollbar-width: thin;
}

.nav button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 40px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 8px 12px;
  color: #415066;
  background: transparent;
  text-align: center;
  cursor: pointer;
  white-space: nowrap;
  font-weight: 700;
}

.nav button span {
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  color: #415066;
}

.nav button span svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.7;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav button.active,
.nav button:hover {
  color: var(--blue);
  background: var(--nav-hover);
  border-color: #cddbf4;
}

.nav button.active span,
.nav button:hover span {
  color: var(--blue);
}

.sidebar-note {
  display: none;
}

.main {
  min-width: 0;
}

.topbar {
  min-height: 72px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px 20px;
  flex-wrap: wrap;
  max-width: 1440px;
  margin: 0 auto;
  padding: 16px 24px;
  background: transparent;
  border-bottom: 1px solid var(--line);
}

.topbar-entity {
  min-width: 0;
}

.topbar-context {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  box-shadow: var(--shadow-soft);
}

.topbar-context select {
  min-height: 34px;
  border-color: transparent;
  background: #f8fafc;
  font-weight: 700;
  font-size: 13px;
}

.topbar-context select:hover {
  border-color: #cddbf4;
}

.topbar-status {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-left: auto;
}

.icon-command {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.icon-command > span {
  margin: 0;
  color: inherit;
  font-size: 17px;
  line-height: 1;
}

.btn:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.table-sort {
  width: 100%;
  min-height: 30px;
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  font: inherit;
  font-weight: 700;
  text-align: left;
  cursor: pointer;
}

.table-sort:hover,
.table-sort:focus-visible {
  color: var(--blue);
}

.table-sort span {
  display: inline-block;
  min-width: 12px;
  margin-left: 4px;
}

.amount-sort {
  text-align: right;
}

.pill.locked {
  color: #ffffff;
  background: var(--ink);
}

.pill.locked::before {
  content: "\1F512";
  margin-right: 5px;
  font-size: 11px;
}

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

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

.topbar span {
  color: var(--muted);
  font-size: 13px;
  margin-top: 3px;
}

.change-tray {
  position: sticky;
  top: 71px;
  z-index: 18;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 10px 24px;
  border-bottom: 1px solid #d8c18d;
  background: #fff7e3;
  box-shadow: var(--shadow-soft);
}

.change-tray strong,
.change-tray span {
  display: block;
}

.change-tray strong {
  color: var(--amber);
}

.change-tray span {
  margin-top: 2px;
  color: #6d5a2d;
  font-size: 13px;
}

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

.setup-alert {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid #d8c18d;
  border-radius: 8px;
  background: #fff7e3;
  box-shadow: var(--shadow-soft);
}

.setup-alert div {
  min-width: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.setup-alert strong {
  color: var(--amber);
}

.setup-alert span,
.setup-alert p {
  color: #6d5a2d;
}

.setup-alert p {
  flex: 1;
  min-width: 240px;
  margin: 0;
  font-size: 13px;
  line-height: 1.45;
}

.top-actions,
.action-row,
.card-head,
.page-heading {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}

.top-actions,
.card-head,
.page-heading {
  justify-content: space-between;
}

.content {
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
}

.view {
  display: none;
  gap: 18px;
}

.view.active {
  display: grid;
}

.page-heading {
  align-items: flex-end;
}

.section-switcher {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: -2px;
  padding: 5px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #ffffff;
  box-shadow: var(--shadow-soft);
}

.section-tab {
  border: 1px solid transparent;
  border-radius: 7px;
  padding: 8px 14px;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}

.section-tab:hover {
  background: var(--nav-hover);
  color: var(--blue);
}

.section-tab.active {
  background: var(--blue-soft);
  color: var(--blue);
  border-color: #cddbf4;
}

.section-tab-all {
  margin-left: auto;
  color: var(--ink);
}

h1,
h2,
h3,
p {
  margin: 0;
}

h1 {
  font-size: 28px;
  line-height: 1.15;
}

h2 {
  font-size: 19px;
}

.page-heading p {
  color: var(--muted);
  margin-top: 6px;
  line-height: 1.45;
}

.intro-panel {
  display: grid;
  grid-template-columns: minmax(220px, 0.75fr) minmax(260px, 1fr) minmax(300px, 1.5fr);
  gap: 18px;
  align-items: stretch;
  padding: 18px;
  border: 1px solid #cddbf4;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow-soft);
}

.intro-logo,
.intro-copy,
.intro-steps {
  min-width: 0;
}

.intro-logo {
  display: flex;
  gap: 12px;
  align-items: center;
}

.intro-logo strong,
.intro-logo span,
.intro-steps strong,
.intro-steps span {
  display: block;
}

.intro-logo strong {
  font-size: 22px;
}

.intro-logo span,
.intro-copy p,
.intro-steps span {
  color: var(--muted);
  line-height: 1.45;
}

.intro-copy {
  display: grid;
  gap: 8px;
}

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

.intro-steps div {
  min-width: 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.intro-steps strong {
  margin-bottom: 5px;
}

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

.entity-menu-tile {
  min-width: 0;
  min-height: 78px;
  display: grid;
  align-content: start;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.entity-menu-tile:hover {
  border-color: var(--accent);
  background: #eef5ff;
}

.entity-menu-tile strong,
.entity-menu-tile span {
  display: block;
}

.entity-menu-tile span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.compact-statement .statement-row {
  padding: 6px 0;
}

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

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

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

.card {
  min-width: 0;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-soft);
  padding: 16px;
}

.card:hover {
  box-shadow: var(--shadow);
}

.metric {
  min-height: 126px;
  display: grid;
  gap: 9px;
}

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

.metric strong {
  font-size: 27px;
  line-height: 1.1;
}

.metric small {
  margin-top: auto;
}

.compact-metrics .metric {
  min-height: 104px;
}

.compact-metrics .metric strong {
  font-size: 22px;
}

.btn,
select,
input,
textarea {
  min-height: 38px;
  border-radius: 6px;
  border: 1px solid var(--line);
  background: #ffffff;
  color: var(--ink);
  padding: 8px 11px;
}

.btn {
  cursor: pointer;
  font-weight: 700;
}

.btn.primary {
  border-color: var(--blue);
  background: var(--blue);
  color: #ffffff;
}

.btn.secondary {
  background: #ffffff;
}

.btn.danger {
  border-color: var(--red);
  background: var(--red);
  color: #ffffff;
}

.import-batch-select {
  min-height: auto;
  margin: 0 8px 0 0;
  vertical-align: middle;
}

.btn:hover,
select:hover,
input:hover,
textarea:hover {
  border-color: #b7c7dd;
}

.pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  border-radius: 999px;
  padding: 3px 9px;
  color: var(--muted);
  background: #eef1f6;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.pill.good {
  color: var(--green);
  background: var(--green-soft);
}

.pill.warn {
  color: var(--amber);
  background: var(--amber-soft);
}

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

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

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

.flow-step {
  min-width: 0;
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 8px 10px;
  align-items: start;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow-soft);
}

.flow-step span {
  grid-row: span 2;
  width: 30px;
  height: 30px;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: var(--muted);
  background: #eef1f6;
  font-weight: 800;
}

.flow-step strong {
  min-width: 0;
  line-height: 1.2;
}

.flow-step small {
  color: var(--muted);
  line-height: 1.35;
}

.flow-step.done span {
  color: #ffffff;
  background: var(--green);
}

.flow-step.current {
  border-color: #b9cbed;
  background: var(--blue-soft);
}

.flow-step.current span {
  color: #ffffff;
  background: var(--blue);
}

.stack {
  display: grid;
  gap: 12px;
}

.muted {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.drop-zone {
  min-height: 96px;
  border: 1px dashed #9aa8bc;
  border-radius: 8px;
  background: #fbfcff;
  display: grid;
  place-items: center;
  gap: 4px;
  padding: 16px;
  text-align: center;
  color: var(--muted);
}

.drop-zone strong {
  color: var(--ink);
}

.drop-zone.drag-over {
  border-color: var(--blue);
  background: var(--blue-soft);
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

label input,
label select,
label textarea {
  width: 100%;
  color: var(--ink);
  text-transform: none;
  font-weight: 400;
}

textarea {
  resize: vertical;
  line-height: 1.4;
}

.mapping-grid,
.asset-form,
.settings-grid,
.rule-form,
.account-form,
.journal-form {
  display: grid;
  gap: 10px;
}

.journal-form {
  grid-template-columns: repeat(8, minmax(0, 1fr));
  align-items: end;
  margin-bottom: 12px;
}

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

.asset-form {
  grid-template-columns: repeat(8, minmax(0, 1fr));
  align-items: end;
}

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

.settings-grid.note-grid {
  grid-template-columns: repeat(2, minmax(280px, 1fr));
}

.rule-form {
  grid-template-columns: 1.2fr 1.2fr 1fr auto;
  align-items: end;
  margin-bottom: 14px;
}

.account-form {
  grid-template-columns: 0.7fr 1.4fr 1fr 1.3fr auto;
  align-items: end;
}

.template-grid {
  display: grid;
  grid-template-columns: minmax(240px, 1fr) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.template-selector {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.template-option {
  min-width: 0;
  min-height: 112px;
  display: grid;
  align-content: start;
  gap: 7px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
}

.template-option:hover,
.template-option.active {
  border-color: var(--accent);
  background: #eef5ff;
}

.template-option strong,
.template-option span,
.template-option small {
  display: block;
}

.template-option span,
.template-option small {
  color: var(--muted);
  line-height: 1.35;
}

.template-option small {
  font-size: 12px;
  font-weight: 700;
}

.template-preview {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfcff;
  padding: 14px;
}

.preview-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.7fr) repeat(3, minmax(110px, 0.5fr));
  gap: 12px;
  align-items: start;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.preview-grid p,
.template-columns p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.mini-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

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

.template-columns h3 {
  font-size: 14px;
}

.amount-input {
  text-align: right;
}

.spaced {
  margin-top: 14px;
}

.compact-table {
  margin-top: 12px;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-weight: 700;
  white-space: nowrap;
}

.inline-check input {
  width: 16px;
  height: 16px;
}

.report-toolbar {
  display: grid;
  grid-template-columns: minmax(220px, 320px) minmax(260px, 1fr);
  gap: 12px;
  margin: 14px 0;
}

.report-toolbar label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.account-filter {
  position: relative;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  color: var(--ink);
}

.account-filter summary {
  min-width: 220px;
  padding: 10px 12px;
  cursor: pointer;
  list-style-position: inside;
  font-weight: 600;
}

.account-filter-options {
  position: absolute;
  z-index: 30;
  display: grid;
  gap: 6px;
  width: min(360px, 80vw);
  max-height: 320px;
  overflow-y: auto;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.account-filter-options label {
  display: flex;
  grid-template-columns: none;
  align-items: center;
  gap: 8px;
  color: var(--ink);
  font-weight: 500;
}

.account-filter-options input {
  width: 16px;
  min-height: 16px;
  margin: 0;
}

.management-table,
.gl-table {
  min-width: 1120px;
}

.management-table .tb-subtotal td {
  background: #f3f6fb;
  font-weight: 800;
  border-top: 2px solid var(--line);
}

:root[data-theme="dark"] .management-table .tb-subtotal td {
  background: #182235;
}

.report-caveat {
  margin-top: 10px;
}

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

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

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

th {
  color: var(--muted);
  background: #fafbfe;
  font-size: 12px;
  text-transform: uppercase;
}

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

.amount {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.table-control {
  width: 100%;
  min-width: 180px;
  min-height: 34px;
  padding: 6px 8px;
}

.statement {
  display: grid;
  gap: 2px;
}

.production-test-actions {
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
  margin: 14px 0;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fafc;
}

.production-summary {
  display: grid;
  gap: 8px;
  margin-bottom: 12px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.production-summary strong {
  font-size: 18px;
}

.compact-grid {
  gap: 10px;
  margin-bottom: 14px;
}

.status-tile {
  min-height: 82px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.status-tile span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.status-tile strong {
  display: block;
  margin-top: 6px;
  font-size: 20px;
}

.statement-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}

.tb-total td {
  border-top: 2px solid var(--ink);
  font-weight: 700;
}

.statement-row.total {
  margin-top: 6px;
  border-top: 2px solid var(--ink);
  border-bottom: 0;
  font-weight: 700;
}

.checklist {
  display: grid;
  gap: 10px;
}

.check-item {
  display: grid;
  grid-template-columns: 22px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 11px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.check-mark {
  width: 18px;
  height: 18px;
  border-radius: 4px;
  border: 2px solid var(--blue);
  margin-top: 1px;
}

.check-item.done .check-mark {
  background: var(--blue);
  box-shadow: inset 0 0 0 3px #ffffff;
}

.check-item p {
  margin-top: 3px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.pending-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

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

.pending-item p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.35;
}

.empty-state {
  padding: 14px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: #fbfcff;
}

.report-preview-card {
  align-self: start;
}

.report-preview {
  margin-top: 14px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #eef2f7;
  overflow-x: auto;
}

.preview-page {
  max-width: 760px;
  min-height: 440px;
  margin: 0 auto;
  padding: 34px 42px;
  background: #ffffff;
  border: 1px solid #cfd7e5;
  box-shadow: 0 12px 24px rgba(22, 31, 48, 0.12);
}

.preview-title {
  display: grid;
  gap: 5px;
  padding-bottom: 18px;
  border-bottom: 2px solid var(--ink);
  margin-bottom: 18px;
}

.preview-title strong {
  font-size: 20px;
}

.preview-title span {
  font-size: 17px;
  font-weight: 700;
}

.preview-title small,
.preview-note {
  color: var(--muted);
}

.preview-table {
  min-width: 0;
  width: 100%;
}

.preview-table td {
  padding: 11px 0;
  font-size: 14px;
}

.preview-table td:last-child {
  text-align: right;
  font-weight: 700;
}

.preview-table .preview-total td {
  border-top: 2px solid var(--ink);
  font-weight: 700;
}

.onboarding-card {
  border: 1px solid var(--blue);
  border-left: 4px solid var(--blue);
  margin-bottom: 18px;
  background: var(--blue-soft);
}

.onboarding-steps {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.onboarding-step {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.onboarding-step.done {
  opacity: 0.7;
}

.onboarding-num {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 13px;
  color: #ffffff;
  background: var(--blue);
}

.onboarding-step.done .onboarding-num {
  background: var(--green);
}

.onboarding-body strong {
  display: block;
}

.onboarding-body p {
  margin-top: 2px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.recon-overview {
  display: grid;
  gap: 14px;
}

.recon-actions {
  display: flex;
  align-items: end;
}

.recon-difference {
  display: grid;
  gap: 6px;
  padding: 8px 0;
}

.recon-difference strong {
  font-size: 30px;
  font-variant-numeric: tabular-nums;
}

.recon-ok {
  color: var(--green);
}

.recon-off {
  color: var(--red);
}

.alloc-progress {
  width: 160px;
  height: 10px;
  border-radius: 999px;
  background: #eef2f8;
  overflow: hidden;
}

.alloc-progress-fill {
  display: block;
  height: 100%;
  width: 0;
  border-radius: 999px;
  background: var(--blue);
  transition: width 280ms ease;
}

.alloc-progress-fill.complete {
  background: var(--green);
}

.alloc-hint {
  margin-top: -4px;
}

#allocationSearch {
  min-width: 220px;
}

.bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 12px;
  margin: 12px 0;
  padding: 12px 14px;
  border: 1px solid var(--blue);
  border-radius: 10px;
  background: var(--blue-soft);
}

.bulk-bar > strong {
  align-self: center;
}

.bulk-field {
  display: grid;
  gap: 5px;
  font-size: 11px;
}

.bulk-field select {
  min-width: 180px;
}

.select-col {
  width: 36px;
  text-align: center;
}

.select-col input {
  min-height: 0;
  width: 16px;
  height: 16px;
  cursor: pointer;
}

tr.row-selected td {
  background: var(--blue-soft);
}

:root[data-theme="dark"] tr.row-selected td {
  background: #1b2942;
}

.alloc-hint kbd {
  display: inline-block;
  padding: 1px 6px;
  border: 1px solid var(--line);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: #f8fafc;
  font-family: inherit;
  font-size: 12px;
  font-weight: 700;
  color: var(--ink);
}

.dash-overview {
  display: grid;
  gap: 14px;
}

.dash-charts {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 22px;
  margin-top: 14px;
}

.chart-title {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.02em;
  margin-bottom: 12px;
}

.bar-chart {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 132px minmax(0, 1fr) 96px;
  gap: 12px;
  align-items: center;
  font-size: 13px;
}

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

.bar-track {
  height: 14px;
  border-radius: 999px;
  background: #eef2f8;
  overflow: hidden;
}

.bar-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  transition: width 320ms ease;
}

.bar-revenue { background: var(--blue); }
.bar-expense { background: #e0a93a; }
.bar-profit { background: var(--green); }
.bar-loss { background: var(--red); }

.bar-value {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
}

.progress-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
}

.progress-head strong {
  font-size: 22px;
}

.progress-track {
  height: 16px;
  border-radius: 999px;
  background: #eef2f8;
  overflow: hidden;
}

.progress-fill {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--green);
  transition: width 320ms ease;
}

.progress-legend {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px 16px;
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
}

.progress-legend span {
  display: flex;
  align-items: center;
  gap: 7px;
}

.dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: none;
}

.dot-good { background: var(--green); }
.dot-warn { background: var(--amber); }
.dot-info { background: var(--blue); }
.dot-bad { background: var(--red); }

@media (max-width: 860px) {
  .dash-charts {
    grid-template-columns: 1fr;
  }
}

.toast {
  position: fixed;
  right: 18px;
  bottom: 18px;
  max-width: 340px;
  padding: 12px 14px;
  border-radius: 8px;
  background: var(--ink);
  color: #ffffff;
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms ease;
  pointer-events: none;
  font-size: 14px;
}

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

@media (max-width: 1120px) {
  .landing-panel {
    grid-template-columns: 1fr;
  }

  .metrics,
  .flow-steps,
  .intro-panel,
  .entity-menu-tiles,
  .grid.two,
  .asset-form,
  .mapping-grid,
  .rule-form,
  .account-form,
  .journal-form,
  .template-grid,
  .template-selector,
  .preview-grid,
  .template-columns,
  .pending-item {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .intro-steps {
    grid-column: 1 / -1;
  }

  .entity-menu-tiles {
    grid-column: 1 / -1;
  }
}

@media (max-width: 860px) {
  .app-header {
    grid-template-columns: 1fr;
    gap: 10px;
    align-items: stretch;
    padding: 10px 14px;
  }

  .brand {
    min-width: 0;
  }

  .main-menu {
    display: grid;
    min-width: 0;
  }

  .nav {
    display: none;
  }

  .nav button {
    min-width: max-content;
    font-size: 12px;
    padding: 8px 10px;
  }

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

  .content {
    padding: 14px;
  }

  .change-tray {
    top: 154px;
    align-items: flex-start;
    flex-direction: column;
    padding: 10px 14px;
  }

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

  .change-tray-actions .btn {
    flex: 1;
  }

  .setup-alert {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 640px) {
  .login-screen {
    padding: 12px;
  }

  .landing-copy,
  .login-card {
    padding: 18px;
  }

  .landing-copy h1 {
    font-size: 25px;
  }

  .brand-mark {
    width: 34px;
    height: 34px;
  }

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

  .brand span {
    font-size: 11px;
  }

  h1 {
    font-size: 23px;
  }

  .landing-steps,
  .metrics,
  .flow-steps,
  .intro-panel,
  .intro-steps,
  .entity-menu-tiles,
  .grid.two,
  .asset-form,
  .mapping-grid,
  .settings-grid,
  .settings-grid.note-grid,
  .rule-form,
  .account-form,
  .journal-form,
  .template-grid,
  .template-selector,
  .preview-grid,
  .template-columns,
  .pending-item {
    grid-template-columns: 1fr;
  }

  .preview-page {
    padding: 24px;
  }
}

/* Contextual help: hover tooltip + right-click popover */
[data-help] {
  cursor: help;
}
[data-help].btn,
[data-help] select,
[data-help] input,
.nav [data-help],
.metric[data-help] {
  cursor: inherit;
}

.help-tooltip {
  position: fixed;
  z-index: 1000;
  max-width: 280px;
  padding: 8px 11px;
  border-radius: 7px;
  background: #17202f;
  color: #ffffff;
  font-size: 12.5px;
  line-height: 1.42;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
  pointer-events: none;
}

.help-tooltip[hidden] {
  display: none;
}

.help-more-hint {
  display: block;
  margin-top: 5px;
  color: #aebfd6;
  font-size: 11px;
  font-weight: 700;
}

.help-popover {
  position: fixed;
  z-index: 1001;
  max-width: 320px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  box-shadow: var(--shadow);
}

.help-popover[hidden] {
  display: none;
}

.help-popover h4 {
  margin: 0 0 6px;
  font-size: 15px;
}

.help-popover p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.help-popover-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 12px;
}

/* Stack wide tables into labelled cards on small screens. */
@media (max-width: 720px) {
  .report-toolbar {
    grid-template-columns: 1fr;
  }

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

  .responsive-table thead {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
  }

  .responsive-table tr {
    display: block;
    margin: 0 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
  }

  .responsive-table td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    border: 0;
    border-bottom: 1px solid var(--line);
    text-align: right;
  }

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

  .responsive-table td::before {
    content: attr(data-label);
    font-weight: 700;
    font-size: 12px;
    color: var(--muted);
    text-transform: uppercase;
    text-align: left;
  }

  .responsive-table td .table-control {
    min-width: 0;
    max-width: 60%;
  }
}

:root[data-theme="dark"] {
  /* Slightly brighter muted text for AA contrast on dark surfaces. */
  --muted: #a7b4c8;
}

@media print {
  .app-header,
  .topbar,
  .section-switcher,
  .page-heading button,
  .top-actions,
  .topbar-status,
  .help-tooltip,
  .help-popover,
  .toast,
  .alloc-hint {
    display: none !important;
  }

  body {
    background: #ffffff;
  }

  .content {
    max-width: none;
    padding: 0;
  }

  .view {
    display: grid !important;
  }

  .view-panel[hidden] {
    display: block !important;
  }

  .card,
  .report-preview,
  .preview-page {
    box-shadow: none;
    border-color: #ccc;
    break-inside: avoid;
  }
}
