:root {
  color-scheme: light;
  --bg: #f5efe7;
  --surface: #fffaf3;
  --surface-soft: #fbf3ea;
  --text: #231f20;
  --muted: #756960;
  --line: #e4d4bf;
  --accent: #e77f27;
  --accent-dark: #bc6b25;
  --gold: #c4a37b;
  --cream: #f1ddc2;
  --danger: #a94335;
  --warn: #e77f27;
  --ok: #5f7d49;
  --map: #5c5557;
  --shadow: 0 14px 32px rgba(35, 31, 32, 0.1);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

@keyframes fade-up {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(135deg, rgba(231, 127, 39, 0.08), transparent 32%),
    var(--bg);
  color: var(--text);
}

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

.auth-page {
  background:
    linear-gradient(135deg, rgba(231, 127, 39, 0.18), transparent 34%),
    linear-gradient(315deg, rgba(196, 163, 123, 0.2), transparent 32%),
    var(--bg);
}

.auth-shell {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 22px;
}

.auth-card {
  display: grid;
  grid-template-columns: minmax(0, 1.08fr) minmax(320px, 0.92fr);
  gap: 34px;
  width: min(920px, 100%);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 34px;
  box-shadow: 0 18px 44px rgba(22, 33, 45, 0.12);
  animation: fade-up 420ms ease both;
}

.auth-brand,
.login-form {
  display: grid;
  align-content: center;
  gap: 16px;
}

.auth-logo {
  width: min(360px, 100%);
  height: auto;
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.auth-brand h1 {
  margin: 0;
  font-size: clamp(2rem, 6vw, 3.4rem);
  line-height: 0.96;
}

.auth-brand p:not(.eyebrow) {
  margin: 0;
  color: var(--muted);
  line-height: 1.55;
}

.login-form div {
  display: grid;
  gap: 6px;
}

.form-error {
  border: 1px solid #f0b8b5;
  border-radius: 8px;
  background: #fff0ef;
  color: var(--danger);
  padding: 11px 12px;
  font-weight: 700;
}

.full-button {
  width: 100%;
}

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

.sidebar {
  position: sticky;
  top: 0;
  width: 280px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  min-height: 100vh;
  border-right: 1px solid var(--line);
  background: #231f20;
  padding: 22px;
  flex-shrink: 0;
}

  .workspace {
    flex: 1;
    display: grid;
    align-content: start;
    gap: 16px;
    padding: 26px;
    animation: fade-up 360ms ease both;
  }

  /* Mobile only: hamburger toggle */
  .sidebar-toggle {
    display: none; /* Hidden on desktop */
  }

  /* Mobile: start collapsed */
  .sidebar.collapsed .nav-tabs,
  .sidebar.collapsed .logout-link {
    display: none;
  }

  .sidebar-toggle {
    appearance: none;
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 8px;
  }

  .sidebar-toggle:hover {
    background: var(--accent);
    color: white;
  }

  .sidebar-toggle:focus-visible {
    outline: 3px solid rgba(231, 127, 39, 0.4);
    outline-offset: 2px;
  }

.brand-block {
  display: grid;
  grid-template-columns: 44px 1fr;
  gap: 12px;
  align-items: center;
}

.brand-logo,
.upload-icon {
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  color: #fffaf3;
  font-weight: 900;
}

.brand-logo {
  width: 44px;
  height: 44px;
}

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

.brand-block strong {
  color: #fffaf3;
}

.brand-block span {
  color: var(--cream);
  font-size: 0.86rem;
}

.nav-tabs {
  display: grid;
  gap: 8px;
}

.nav-tab,
.logout-link {
  display: inline-flex;
  align-items: center;
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: #d7c4ad;
  cursor: pointer;
  padding: 0 12px;
  text-align: left;
  font-weight: 800;
  text-decoration: none;
  transition: background 160ms ease, color 160ms ease, transform 160ms ease;
}

.nav-tab.active,
.nav-tab:hover,
.logout-link:hover {
  background: rgba(231, 127, 39, 0.14);
  color: #fffaf3;
}

.nav-tab:hover,
.logout-link:hover {
  transform: translateX(2px);
}

.logout-link {
  margin-top: auto;
}

.workspace {
  display: grid;
  align-content: start;
  gap: 16px;
  padding: 26px;
  animation: fade-up 360ms ease both;
}

.topbar,
.panel-head,
.group-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--accent-dark);
  font-size: 0.78rem;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(2rem, 5vw, 3.4rem);
  line-height: 0.96;
}

.page-subtitle {
  max-width: 680px;
  margin-top: 10px;
  color: var(--muted);
  line-height: 1.5;
}

h2 {
  font-size: 1.15rem;
}

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

button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 0 16px;
  cursor: pointer;
  font-weight: 800;
  transition: transform 150ms ease, box-shadow 150ms ease, border-color 150ms ease, background 150ms ease;
}

button:hover {
  transform: translateY(-1px);
}

button:active {
  transform: translateY(0);
}

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

.primary-button {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 8px 18px rgba(231, 127, 39, 0.24);
}

.ghost-button {
  border-color: var(--line);
  background: #fff;
  color: var(--text);
}

.upload-grid,
.toolbar,
.summary-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.view-panel > .upload-grid,
.view-panel > .summary-grid,
.view-panel > .insight-strip,
.view-panel > .toolbar {
  margin: 16px;
}

.view-panel > .upload-grid,
.view-panel > .summary-grid {
  margin-bottom: 0;
}

.drop-zone {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-areas: "icon title" "icon meta";
  gap: 2px 14px;
  align-items: center;
  min-height: 112px;
  border: 2px dashed #aebdcc;
  border-radius: 8px;
  background: var(--surface);
  padding: 20px;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition:
    border-color 160ms ease,
    background 160ms ease,
    transform 160ms ease;
}

.drop-zone:hover,
.drop-zone.dragging {
  border-color: var(--accent);
  background: #fff4e8;
  transform: translateY(-1px);
}

.drop-zone.ready {
  border-style: solid;
  border-color: var(--ok);
  background: #eef5e8;
}
.drop-zone.ready:hover {
  border-color: var(--ok);
  background: #e6f0dd;
}
.drop-zone.ready .drop-title {
  color: #3e5a30;
}
.drop-zone.ready .drop-title::before {
  content: "✓ ";
  font-weight: 900;
}
.drop-zone.ready .drop-meta {
  color: #4a6b39;
}

.drop-zone input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
}

.upload-icon {
  grid-area: icon;
  width: 48px;
  height: 48px;
}

.drop-title {
  grid-area: title;
  font-weight: 900;
}

.drop-meta {
  grid-area: meta;
  color: var(--muted);
  overflow-wrap: anywhere;
}

.toolbar {
  grid-template-columns: 1fr 220px 220px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px;
}

.toolbar div {
  display: grid;
  gap: 6px;
}

label,
.metric-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  color: var(--text);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 3px solid rgba(231, 127, 39, 0.16);
}

input,
select {
  min-height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 230px;
  resize: vertical;
  padding: 12px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.84rem;
}

textarea.invalid {
  border-color: var(--danger);
  background: #fff7f7;
}

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

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

.metric,
.view-panel,
.insight-strip {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  animation: fade-up 260ms ease both;
}

.metric {
  display: grid;
  gap: 7px;
  padding: 16px;
  min-height: 112px;
}

.metric strong {
  font-size: 2rem;
  line-height: 1;
}

.metric small {
  color: var(--muted);
  font-weight: 700;
}

.insight-strip {
  border-left: 4px solid var(--accent);
  padding: 14px 16px;
  color: #3d3430;
  line-height: 1.45;
}

.view-panel {
  display: none;
  overflow: hidden;
}

.view-panel.active {
  display: block;
  animation: fade-up 240ms ease both;
}

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

.panel-head p {
  margin-top: 4px;
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
  max-height: 62vh;
  background:
    linear-gradient(90deg, #fffaf3 30%, rgba(255, 250, 243, 0)),
    linear-gradient(90deg, rgba(255, 250, 243, 0), #fffaf3 70%) 100% 0,
    radial-gradient(farthest-side at 0 50%, rgba(35, 31, 32, 0.14), rgba(35, 31, 32, 0)),
    radial-gradient(farthest-side at 100% 50%, rgba(35, 31, 32, 0.14), rgba(35, 31, 32, 0)) 100% 0;
  background-attachment: local, local, scroll, scroll;
  background-repeat: no-repeat;
  background-size:
    40px 100%,
    40px 100%,
    14px 100%,
    14px 100%;
}

.report-group {
  min-width: 820px;
}

.group-head {
  position: sticky;
  top: 0;
  z-index: 3;
  border-bottom: 1px solid var(--line);
  background: #f4e5d3;
  padding: 12px 16px;
}

.group-head span {
  color: var(--muted);
  font-weight: 800;
}

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

th,
td {
  border-bottom: 1px solid #e8eef3;
  padding: 11px 14px;
  text-align: left;
  vertical-align: top;
}

th {
  position: sticky;
  top: 45px;
  z-index: 2;
  background: #fff7ed;
  color: #5b4b41;
  font-size: 0.78rem;
  text-transform: uppercase;
}

td {
  font-size: 0.92rem;
}

tbody tr:hover {
  background: #fff4e8;
}

.variance-positive {
  color: var(--warn);
  font-weight: 900;
}

.variance-negative {
  color: var(--danger);
  font-weight: 900;
}

.variance-neutral {
  color: var(--ok);
  font-weight: 900;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 0 9px;
  font-size: 0.74rem;
  font-weight: 900;
  white-space: nowrap;
}

.status-over {
  background: #fff0df;
  color: var(--warn);
}

.status-under {
  background: #fff0ef;
  color: var(--danger);
}

.status-balanced {
  background: #eff5e8;
  color: var(--ok);
}

.status-map {
  background: #eee8e3;
  color: var(--map);
}

.overview-layout {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.simple-overview {
  display: grid;
  grid-template-columns: minmax(280px, 0.9fr) minmax(320px, 1.1fr);
  gap: 14px;
  padding: 16px;
}

.next-step-card {
  display: grid;
  align-content: start;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 18px;
}

.next-step-card p {
  color: var(--muted);
  line-height: 1.45;
}

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

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

.chart-card,
.mini-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 14px;
  transition: box-shadow 160ms ease, transform 160ms ease;
}

.chart-card {
  display: grid;
  gap: 12px;
  min-height: 292px;
}

.chart-card.wide {
  grid-column: span 2;
}

.chart-card div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
}

.chart-card span {
  color: var(--muted);
  font-weight: 800;
  white-space: nowrap;
}

.chart-card canvas {
  max-height: 220px;
}

.mini-card h3 {
  margin-bottom: 10px;
}

.mini-card p {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  border-top: 1px solid var(--line);
  padding: 10px 0;
  color: #3d3430;
  line-height: 1.35;
}

.mini-card b {
  white-space: nowrap;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
  padding: 16px;
}

.settings-card {
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 12px;
}

.settings-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 4px;
}

.settings-card-head p {
  margin-top: 4px;
  color: var(--muted);
}

.settings-card span {
  color: var(--text);
  font-weight: 900;
}

.settings-card.wide {
  grid-column: 1 / -1;
}

.manager-list {
  display: grid;
  gap: 10px;
  max-height: min(85vh, 1100px);
  overflow: auto;
  padding-right: 4px;
}

.manager-row {
  display: grid;
  grid-template-columns: 1.2fr 1.5fr 1.2fr 160px 120px auto;
  gap: 12px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 14px 16px;
  animation: fade-up 220ms ease both;
  transition: box-shadow 160ms ease, transform 160ms ease;
}

.metric:hover,
.mini-card:hover,
.next-step-card:hover,
.settings-card:hover,
.manager-row:hover {
  box-shadow: 0 18px 38px rgba(35, 31, 32, 0.13);
}

.mini-card:hover,
.next-step-card:hover,
.manager-row:hover {
  transform: translateY(-1px);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 1ms !important;
    transition-duration: 1ms !important;
    scroll-behavior: auto !important;
  }
}

.manager-row.dependency-row {
  grid-template-columns: 1.4fr 1.2fr 140px 110px auto;
}

.manager-row label {
  display: grid;
  gap: 5px;
}

.manager-row label span {
  color: var(--muted);
  font-size: 0.76rem;
}

.danger-button {
  border-color: #efc4bc;
  background: #fff0ef;
  color: var(--danger);
}

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

.empty-state {
  display: grid;
  place-items: center;
  min-height: 240px;
  padding: 24px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 960px) {
  .app-shell {
    flex-direction: column;
  }

  .sidebar {
    position: static;
    width: 100%;
    min-height: auto;
    height: auto;
  }

  /* Mobile only: show hamburger toggle */
  .sidebar-toggle {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--surface-soft);
    color: var(--text);
    cursor: pointer;
    margin-bottom: 12px;
    position: sticky;
    top: 0;
    z-index: 10;
    font-size: 1.4rem;
  }

  .sidebar-toggle:hover {
    background: var(--accent);
    color: white;
  }

  .sidebar-toggle:focus-visible {
    outline: 3px solid rgba(231, 127, 39, 0.4);
    outline-offset: 2px;
  }

  /* Mobile: start collapsed */
  .sidebar.collapsed {
    height: auto;
  }

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

  .logout-link {
    margin-top: 0;
  }

  .toolbar,
  .summary-grid,
  .compact-summary,
  .simple-overview,
  .chart-grid,
  .card-grid,
  .settings-grid,
  .manager-row,
  .manager-row.dependency-row {
    grid-template-columns: 1fr;
  }

  .chart-card.wide {
    grid-column: auto;
  }

  .topbar,
  .panel-head {
    align-items: stretch;
    flex-direction: column;
  }
}

@media (max-width: 720px) {
  .workspace {
    padding: 16px;
  }

  .auth-card,
  .upload-grid {
    grid-template-columns: 1fr;
  }

  .auth-card {
    padding: 24px;
  }
}

/* ===== Mobile-First Enhancements ===== */

/* Skip link for keyboard accessibility */
.skip-link {
  position: absolute;
  top: -40px;
  left: 0;
  background: var(--accent);
  color: white;
  padding: 8px 12px;
  z-index: 1000;
  transition: top 160ms ease;
  text-decoration: none;
  font-weight: 700;
  font-size: 0.85rem;
}

.skip-link:focus {
  top: 0;
  outline: 3px solid rgba(255,255,255,0.4);
}

/* Prevent horizontal scroll */
html, body {
  overflow-x: hidden;
  width: 100%;
}

/* Ensure form inputs are readable on mobile (prevents iOS zoom) */
input:not([type="search"]),
select,
textarea {
  font-size: 16px !important;
}

/* Better touch targets */
@media (max-width: 480px) {
  button,
  input,
  select,
  textarea,
  .nav-tab,
  .logout-link,
  .drop-zone {
    min-height: 48px;
  }

  .drop-zone {
    min-height: 130px;
  }

  .actions {
    flex-direction: column;
  }

  .actions button {
    width: 100%;
  }

  .topbar > div:first-child {
    margin-bottom: 8px;
  }
}

/* Upload zone touch improvements */
.drop-zone {
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

.drop-zone input {
  pointer-events: none;
}

/* Table scrolling on mobile */
.table-wrap {
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  margin: 0 0 16px;
  border-radius: 0 0 8px 8px;
}

/* Scrollbar styling for mobile */
.table-wrap::-webkit-scrollbar {
  height: 8px;
}

.table-wrap::-webkit-scrollbar-track {
  background: transparent;
}

.table-wrap::-webkit-scrollbar-thumb {
  background: var(--accent);
  border-radius: 4px;
}

/* Focus visible for accessibility */
*:focus-visible {
  outline: 3px solid rgba(231, 127, 39, 0.4);
  outline-offset: 2px;
}

/* Prevent iOS text size adjustment */
html {
  -webkit-text-size-adjust: 100%;
}

/* Safe area insets for notched devices */
@supports (padding-top: env(safe-area-inset-top)) {
  .sidebar {
    padding-top: calc(22px + env(safe-area-inset-top));
  }

  .workspace {
    padding-top: calc(26px + env(safe-area-inset-top));
  }

  .auth-shell {
    padding-top: calc(22px + env(safe-area-inset-top));
    padding-bottom: calc(22px + env(safe-area-inset-bottom));
  }
}

/* Prevent zoom on double-tap */
@media (hover: none) and (pointer: coarse) {
  a, button {
    touch-action: manipulation;
  }
}

/* Improved mobile navigation */
@media (max-width: 480px) {
  .nav-tabs {
    grid-template-columns: 1fr;
  }

  .nav-tab {
    text-align: left;
  }
}

/* Ensure charts are responsive */
.chart-card canvas {
  max-width: 100%;
}

/* Mobile-friendly tables */
@media (max-width: 600px) {
  table {
    font-size: 0.85rem;
  }

  th, td {
    padding: 10px 6px;
  }
}

/* Smaller headings on mobile dashboard */
@media (max-width: 480px) {
  .topbar h1 {
    font-size: 1.4rem !important;
  }

  .topbar p.eyebrow {
    font-size: 0.7rem !important;
  }

  .topbar button {
    font-size: 0.85rem;
    padding: 0 14px;
  }

  .panel-head h2 {
    font-size: 1rem !important;
  }

  .panel-head p {
    font-size: 0.85rem;
  }

  .drop-title {
    font-size: 0.95rem;
  }

  .drop-meta {
    font-size: 0.8rem;
  }
}

/* Desktop font size adjustments */
.topbar h1 {
  font-size: 2rem !important;
}

.topbar p.eyebrow {
  font-size: 0.75rem !important;
}

.topbar button {
  font-size: 0.85rem !important;
  padding: 0 14px !important;
}

.panel-head h2 {
  font-size: 1rem !important;
}

.panel-head p {
  font-size: 0.9rem !important;
}

.upload-grid .drop-title {
  font-size: 0.95rem !important;
}

.upload-grid .drop-meta {
  font-size: 0.85rem !important;
}

.audit-name-control {
  display: grid;
  gap: 6px;
  width: min(360px, 100%);
}

.step-kicker {
  color: var(--accent-dark);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
}

.small-button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 0.78rem;
  white-space: nowrap;
}

.history-list {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.history-card {
  display: grid;
  grid-template-columns: minmax(240px, 1.3fr) minmax(260px, 1fr) auto;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 14px;
}

.history-card h3 {
  margin-top: 8px;
  font-size: 1rem;
}

.history-card p,
.history-card small {
  color: var(--muted);
}

.history-card small {
  grid-column: 1 / -1;
  font-weight: 700;
}

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

.history-stats span {
  display: grid;
  gap: 2px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 10px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.history-stats strong {
  color: var(--text);
  font-size: 1.1rem;
}

.settings-shell {
  display: grid;
  gap: 16px;
  padding: 16px;
}

.settings-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 12px;
}

.settings-tab {
  min-height: 38px;
  border-color: var(--line);
  background: var(--surface);
  color: var(--muted);
}

.settings-tab.active,
.settings-tab:hover {
  border-color: var(--accent);
  background: #fff4e8;
  color: var(--text);
}

.settings-section {
  display: none;
}

.settings-section.active {
  display: block;
}

.stock-row,
.recipe-row {
  grid-template-columns: minmax(260px, 1.6fr) minmax(160px, 0.9fr) minmax(90px, 0.4fr) auto;
  align-items: center;
}

.category-row {
  grid-template-columns: minmax(180px, 0.7fr) minmax(280px, 1.3fr) auto;
}

.hidden-row {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.manager-row strong,
.manager-row small {
  display: block;
}

.manager-row small {
  margin-top: 4px;
  color: var(--muted);
  line-height: 1.35;
}

.row-label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 900;
  text-transform: uppercase;
}

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

.app-dialog {
  width: min(560px, calc(100vw - 32px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  padding: 0;
  box-shadow: 0 24px 70px rgba(35, 31, 32, 0.26);
}

.app-dialog::backdrop {
  background: rgba(35, 31, 32, 0.38);
}

.app-dialog form {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.app-dialog header,
.app-dialog footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.app-dialog label {
  display: grid;
  gap: 6px;
}

.app-dialog label span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.app-dialog footer {
  justify-content: flex-end;
  border-top: 1px solid var(--line);
  padding-top: 14px;
}

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

.icon-button {
  width: 38px;
  min-height: 38px;
  padding: 0;
  font-size: 1.2rem;
}

@media (max-width: 960px) {
  .history-card,
  .stock-row,
  .recipe-row,
  .category-row {
    grid-template-columns: 1fr;
  }

  .row-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 640px) {
  .history-stats,
  .form-grid {
    grid-template-columns: 1fr;
  }

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

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

.kpi-card {
  display: grid;
  gap: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  padding: 14px;
}

.kpi-label {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.kpi-value {
  color: var(--text);
  font-size: 1.35rem;
  font-weight: 800;
}

.kpi-warning {
  color: #b03a2e;
}

.variance-panels {
  display: grid;
  gap: 18px;
}

.variance-section {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-soft);
  overflow: hidden;
}

.variance-title {
  margin: 0;
  padding: 12px 16px;
  font-size: 0.85rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 1px solid var(--line);
}

.variance-title.variance-high {
  background: rgba(176, 58, 46, 0.18);
  color: #b03a2e;
  border-left: 5px solid #b03a2e;
}

.variance-title.variance-medium {
  background: rgba(212, 166, 54, 0.22);
  color: #8a6914;
  border-left: 5px solid #d4a636;
}

.variance-title.variance-low {
  background: rgba(95, 125, 73, 0.18);
  color: #3e5a30;
  border-left: 5px solid #5f7d49;
}

.variance-title.variance-map {
  background: rgba(92, 85, 87, 0.16);
  color: #5c5557;
  border-left: 5px solid #5c5557;
}

.variance-body {
  max-height: 520px;
  overflow: auto;
}

.variance-body .table-wrap {
  max-height: none;
}

.audit-flow {
  display: grid;
  gap: 16px;
}

.step {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.step.hidden {
  display: none;
}

.step.locked {
  opacity: 0.45;
  filter: grayscale(0.5);
  pointer-events: none;
}

.step-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.step-body {
  padding: 18px;
  display: grid;
  gap: 14px;
}

.step-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface-soft);
}

.form-row {
  display: grid;
  gap: 6px;
}

.form-row label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.form-row input {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

.drop-zone.locked {
  opacity: 0.5;
  pointer-events: none;
  filter: grayscale(0.3);
}

.step {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.step.hidden {
  display: none;
}

.drop-zone.locked {
  opacity: 0.5;
  pointer-events: none;
  filter: grayscale(0.3);
}

.step-header {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.step-num {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-weight: 900;
  font-size: 0.9rem;
}

.step-body {
  padding: 18px;
  display: grid;
  gap: 14px;
}

.step-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  padding: 12px 18px;
  border-top: 1px solid var(--line);
  background: var(--surface-soft);
}

.form-row {
  display: grid;
  gap: 6px;
}

.form-row label {
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.form-row input {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

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

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

/* Toast notifications */
.toast-host {
  position: fixed;
  right: 20px;
  bottom: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 2000;
  pointer-events: none;
}
.toast {
  min-width: 220px;
  max-width: 360px;
  padding: 12px 16px;
  border-radius: 10px;
  background: #2c2622;
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 14px 34px rgba(35, 31, 32, 0.28);
  opacity: 0;
  transform: translateY(12px);
  transition: opacity 200ms ease, transform 200ms ease;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
.toast-success { background: #2f6f43; }
.toast-error { background: #a23030; }
.toast-info { background: #355074; }

/* Save-audit card on the results step */
.save-bar {
  margin-top: 18px;
  padding: 22px 18px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface);
  display: grid;
  gap: 16px;
  justify-items: center;
  text-align: center;
}
.save-bar-field {
  display: grid;
  gap: 6px;
  width: 100%;
  max-width: 460px;
}
.save-bar-field label {
  font-weight: 600;
  color: var(--text);
  font-size: 0.9rem;
}
.save-bar-field .req { color: #c0392b; }
.save-bar-field input {
  padding: 11px 13px;
  border: 1px solid var(--line);
  border-radius: 9px;
  font-size: 1rem;
}
.save-bar-field input:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
.save-bar-field input.invalid {
  border-color: #c0392b;
  background: #fff5f4;
}
.save-bar .step-footer {
  padding: 0;
  border: 0;
}

/* Print -> Save as PDF: isolate the results report */
@media print {
  /* Kill animations/transforms/sticky that cause overlapping text in the PDF. */
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    transform: none !important;
    position: static !important;
    box-shadow: none !important;
  }
  .sidebar,
  .topbar,
  .skip-link,
  .toast-host,
  .save-bar,
  .nav-tabs,
  .step-footer,
  .step.hidden { display: none !important; }
  .app-shell { display: block; }
  .workspace { padding: 0; }
  .view-panel:not(.active) { display: none !important; }
  body { background: #fff; }
  /* Expand every scroll container so the whole report flows onto the PDF. */
  html,
  body,
  .app-shell,
  .workspace,
  .view-panel,
  .view-panel.active,
  .audit-flow,
  .step,
  .step.active,
  .step-body,
  .variance-panels,
  .variance-body,
  .variance-body .table-wrap,
  .manager-list {
    height: auto !important;
    max-height: none !important;
    overflow: visible !important;
  }
  tr,
  .report-group,
  .variance-section,
  .kpi-card { page-break-inside: avoid; }
  /* Force wide tables to fit the printable page width (no horizontal clipping). */
  .variance-body table,
  .report-group table {
    min-width: 0 !important;
    width: 100% !important;
    table-layout: fixed;
    font-size: 9px;
  }
  .variance-body th,
  .variance-body td,
  .report-group th,
  .report-group td {
    padding: 4px 5px;
    word-break: break-word;
    overflow-wrap: anywhere;
  }
  th { position: static !important; }
}

/* In-app confirm modal */
.confirm-dialog {
  width: min(420px, calc(100vw - 32px));
}
.confirm-box {
  display: grid;
  gap: 12px;
  padding: 20px;
}
.confirm-box h3 {
  margin: 0;
  font-size: 1.1rem;
}
.confirm-box p {
  margin: 0;
  color: var(--muted);
  line-height: 1.5;
}
.confirm-box footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 4px;
}

/* Variance colour cue shown on the table (not in the title text) */
.variance-section.section-over .variance-body { border-top: 3px solid #b03a2e; }
.variance-section.section-under .variance-body { border-top: 3px solid #d4a636; }
.variance-section.section-map .variance-body { border-top: 3px solid #5c5557; }
.variance-section.section-balanced .variance-body { border-top: 3px solid #5f7d49; }

/* Keep wide variance tables readable on screen: scroll instead of clipping */
.variance-body table {
  min-width: 560px;
}

/* ============================================================
   UX polish: motion + per-section colour layering
   (the prefers-reduced-motion block above neutralises animation)
   ============================================================ */
@keyframes panel-in {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: none; }
}
@keyframes pop-in {
  0% { opacity: 0; transform: translateY(8px) scale(.985); }
  100% { opacity: 1; transform: none; }
}

/* Tab panels fade/slide in on switch */
.view-panel.active { animation: panel-in 260ms cubic-bezier(.22,.61,.36,1) both; }

/* Smooth, tactile interactions */
.nav-tab,
.primary-button,
.ghost-button,
.danger-button,
.small-button,
.kpi-card,
.settings-card,
.history-card,
.drop-zone { transition: transform 160ms ease, box-shadow 180ms ease, background 160ms ease, border-color 160ms ease; }
.primary-button:hover,
.ghost-button:hover,
.danger-button:hover { transform: translateY(-1px); }
.primary-button:active,
.ghost-button:active,
.danger-button:active { transform: translateY(0); }
.nav-tab.active { box-shadow: inset 3px 0 0 var(--accent); }
.drop-zone:hover { border-color: var(--accent); background: #fff6ec; }

/* KPI cards: distinct colour accent + staggered entrance + hover lift */
.kpi-card { border-top: 3px solid var(--line); }
.kpi-grid .kpi-card:nth-child(1) { border-top-color: var(--gold); }
.kpi-grid .kpi-card:nth-child(2) { border-top-color: var(--accent); }
.kpi-grid .kpi-card:nth-child(3) { border-top-color: var(--accent-dark); }
.kpi-grid .kpi-card:nth-child(4) { border-top-color: var(--map); }
.kpi-grid .kpi-card:nth-child(5) { border-top-color: var(--danger); }
.kpi-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.view-panel.active .kpi-card { animation: pop-in 360ms ease both; }
.view-panel.active .kpi-card:nth-child(2) { animation-delay: .04s; }
.view-panel.active .kpi-card:nth-child(3) { animation-delay: .08s; }
.view-panel.active .kpi-card:nth-child(4) { animation-delay: .12s; }
.view-panel.active .kpi-card:nth-child(5) { animation-delay: .16s; }

/* Variance result sections animate in, slightly staggered */
.view-panel.active .variance-section { animation: pop-in 380ms ease both; }
.view-panel.active .variance-section.section-under { animation-delay: .05s; }
.view-panel.active .variance-section.section-map { animation-delay: .1s; }
.view-panel.active .variance-section.section-balanced { animation-delay: .15s; }

/* Settings: give each stacked section its own colour layer to differentiate */
[data-settings-section="stock"] .settings-card { border-left: 4px solid var(--accent); background: linear-gradient(180deg, #fff6ec 0, var(--surface-soft) 70px); }
[data-settings-section="recipes"] .settings-card { border-left: 4px solid var(--ok); background: linear-gradient(180deg, #f1f6ec 0, var(--surface-soft) 70px); }
[data-settings-section="categories"] .settings-card { border-left: 4px solid var(--gold); background: linear-gradient(180deg, #f8f1e6 0, var(--surface-soft) 70px); }
.settings-section { animation: panel-in 280ms ease both; }
[data-settings-section="recipes"] { animation-delay: .06s; }
[data-settings-section="categories"] { animation-delay: .12s; }

/* Dialogs ease in */
.app-dialog[open] { animation: pop-in 200ms ease both; }

/* Audit progress stepper — clear "where am I" + smooth step arrival */
.stepper {
  position: relative;
  display: flex;
  list-style: none;
  margin: 0 0 26px;
  padding: 20px 0 0;
}
/* Single track line behind all the dots (robust, always aligned) */
.stepper::before {
  content: "";
  position: absolute;
  top: 38px;
  left: 9%;
  right: 9%;
  height: 3px;
  background: var(--line);
  z-index: 0;
}
.stepper-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  position: relative;
  z-index: 1;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  text-align: center;
}
.stepper-dot {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface);
  border: 2px solid var(--line);
  color: var(--muted);
  font-weight: 800;
  font-size: 0.95rem;
  position: relative;
  z-index: 1;
  transition: transform 220ms ease, background 220ms ease, border-color 220ms ease, color 220ms ease, box-shadow 220ms ease;
}
.stepper-label { margin-top: 8px; }
.stepper-item.current { color: var(--text); }
.stepper-item.current .stepper-dot {
  border-color: var(--accent);
  background: #fff4e8;
  color: var(--accent-dark);
  transform: scale(1.12);
  box-shadow: 0 0 0 4px rgba(231, 127, 39, 0.14);
}
.stepper-item.done { color: var(--ok); }
.stepper-item.done .stepper-dot {
  background: var(--ok);
  border-color: var(--ok);
  color: transparent;
  transform: none;
  box-shadow: none;
}
.stepper-item.done .stepper-dot::after {
  content: "✓";
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: #fff;
  font-size: 1rem;
}
@keyframes step-in {
  from { opacity: 0; transform: translateX(18px); }
  to { opacity: 1; transform: none; }
}
.step.active.step-enter { animation: step-in 340ms cubic-bezier(.22, .61, .36, 1) both; }
@media (max-width: 560px) {
  .stepper-label { display: none; }
}
