:root {
  /* Color tokens */
  --ink: #17201f;
  --muted: #667370;
  --line: #d9e2de;
  --panel: #ffffff;
  --surface: #f4f7f4;
  --brand: #0b3f8f;
  --brand-2: #087d2b;
  --brand-red: #e71920;
  --accent: #f4c95d;
  --danger: #c94c4c;
  --warn: #bd7f2d;
  --ok: #2e7d57;
  --info: #3a6ea5;
  --shadow: 0 16px 42px rgba(29, 44, 41, 0.1);

  /* Material 3 design tokens */
  /* Color tints (used for focus rings, hover states, soft fills) */
  --brand-tint: #e8eef9;
  --brand-tint-strong: #d4e0f3;
  --brand-on: #0b3f8f;
  --danger-tint: #fdecec;
  --ok-tint: #e2f3ea;
  --warn-tint: #fdf1d8;
  --info-tint: #e6eff9;

  /* Spacing scale (4px grid) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;

  /* Radius scale */
  --radius-xs: 4px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 24px;
  --radius-pill: 999px;

  /* Elevation (Material 3 levels) */
  --elev-0: none;
  --elev-1: 0 1px 2px rgba(11, 63, 143, 0.08), 0 1px 3px rgba(11, 63, 143, 0.10);
  --elev-2: 0 1px 2px rgba(11, 63, 143, 0.10), 0 2px 6px rgba(11, 63, 143, 0.10);
  --elev-3: 0 4px 8px rgba(11, 63, 143, 0.10), 0 1px 3px rgba(11, 63, 143, 0.08);
  --elev-4: 0 6px 12px rgba(11, 63, 143, 0.12), 0 2px 4px rgba(11, 63, 143, 0.08);
  --elev-modal: 0 12px 24px rgba(11, 63, 143, 0.16), 0 4px 8px rgba(11, 63, 143, 0.10);

  /* Motion */
  --motion-fast: 120ms cubic-bezier(0.2, 0, 0, 1);
  --motion-med:  200ms cubic-bezier(0.2, 0, 0, 1);
  --motion-slow: 320ms cubic-bezier(0.2, 0, 0, 1);

  /* Typography */
  --font-sans: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-display: "Roboto Flex", Inter, ui-sans-serif, system-ui, sans-serif;

  /* Focus ring */
  --focus-ring: 0 0 0 3px rgba(11, 63, 143, 0.20);
  --focus-ring-danger: 0 0 0 3px rgba(201, 76, 76, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  overflow: hidden;
  background: var(--surface);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

.inline-input {
  min-width: 138px;
  min-height: 34px;
  padding: 6px 8px;
  font-size: 12px;
}

button {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  width: 100%;
  max-width: 100vw;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  position: relative;
  height: 100vh;
  padding: 22px 18px;
  background: #0b3274;
  color: #f7fbf9;
  overflow-y: auto;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 56px;
  margin-bottom: 22px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 50px;
  height: 50px;
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.16);
}

.brand-mark img {
  width: 40px;
  height: 40px;
  object-fit: contain;
}

.mark-blue {
  fill: var(--brand);
}

.mark-red {
  fill: var(--brand-red);
}

.mark-green {
  fill: var(--brand-2);
}

.mark-white {
  fill: #ffffff;
}

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

.brand span {
  color: #bad0ca;
  font-size: 12px;
}

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

.nav-button {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 44px;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: #dce9e5;
  text-align: left;
}

.nav-button:hover,
.nav-button.active {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.14);
  color: #ffffff;
}

.nav-icon {
  text-align: center;
  font-weight: 800;
}

.nav-badge {
  padding: 2px 7px;
  border-radius: 999px;
  background: rgba(244, 201, 93, 0.18);
  color: #ffe4a0;
  font-size: 11px;
}

.main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 100%;
  height: 100vh;
  overflow: hidden;
  padding: 0;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 0;
  padding: 24px 24px 18px;
  background: rgba(244, 247, 244, 0.96);
  border-bottom: 1px solid rgba(217, 226, 222, 0.78);
  box-shadow: 0 10px 28px rgba(29, 44, 41, 0.06);
  z-index: 20;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand-2);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0;
}

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

h1 {
  margin-bottom: 0;
  font-size: clamp(26px, 3vw, 38px);
  letter-spacing: 0;
}

h2 {
  margin-bottom: 14px;
  font-size: 20px;
}

h3 {
  margin-bottom: 8px;
  font-size: 15px;
}

.top-actions {
  display: flex;
  align-items: flex-end;
  gap: 10px;
}

.company-switcher {
  height: 36px;
  padding: 0 28px 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3e%3cpath fill='none' stroke='%230b3f8f' stroke-width='1.6' d='M1 1l4 4 4-4'/%3e%3c/svg%3e") no-repeat right 10px center;
  color: var(--ink);
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  max-width: 220px;
}

.company-switcher:focus {
  outline: 2px solid var(--brand);
  outline-offset: 1px;
}

.icon-button,
.primary,
.secondary,
.ghost {
  min-height: 40px;
  border-radius: 8px;
  border: 1px solid var(--line);
  padding: 0 14px;
  background: #ffffff;
  color: var(--ink);
  font-weight: 700;
}

.icon-button {
  width: 42px;
  padding: 0;
  font-size: 20px;
}

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

.secondary {
  background: #eef5f2;
  border-color: #c9d8d3;
  color: #153d36;
}

.ghost {
  background: transparent;
}

.content {
  display: grid;
  gap: 18px;
  flex: 1 1 auto;
  min-width: 0;
  max-width: 100%;
  overflow: auto;
  padding: 18px 24px 24px;
}

.portal-hero {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 18px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.portal-hero h2 {
  margin: 0 0 8px;
  font-size: 34px;
}

.portal-hero p {
  max-width: 780px;
  margin-bottom: 0;
  color: var(--muted);
}

.portal-status {
  display: grid;
  gap: 4px;
  min-width: 150px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
}

.portal-status strong {
  font-size: 24px;
}

.portal-status span {
  color: var(--muted);
  font-size: 12px;
}

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

.portal-card {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 16px;
  min-height: 320px;
  padding: 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: var(--shadow);
}

.portal-card.ready {
  border-color: rgba(11, 63, 143, 0.28);
  box-shadow: 0 18px 44px rgba(11, 63, 143, 0.12);
}

.portal-card-icon {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 8px;
  background: #0b3274;
  color: #ffffff;
  font-weight: 900;
}

.portal-card-title {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  margin-bottom: 8px;
}

.portal-card h3 {
  margin: 0;
  font-size: 24px;
}

.portal-card strong {
  display: block;
  margin-bottom: 10px;
}

.portal-card p {
  color: var(--muted);
}

.portal-roadmap {
  margin-bottom: 0;
}

.panel {
  min-width: 0;
  max-width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 14px;
  padding: 18px 18px 0;
}

.panel-header p {
  margin: 3px 0 0;
  color: var(--muted);
}

.panel-body {
  min-width: 0;
  max-width: 100%;
  padding: 18px;
}

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

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

.grid.two {
  grid-template-columns: minmax(0, 1.2fr) minmax(320px, 0.8fr);
}

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

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

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

.metric-label,
.metric-note {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.metric-value {
  display: block;
  margin: 10px 0 8px;
  font-size: 28px;
  letter-spacing: 0;
}

.ai-kpi-grid {
  margin-bottom: 14px;
}

.ai-summary {
  display: grid;
  gap: 12px;
}

.ai-summary h3 {
  margin: 0;
}

.ai-summary ul {
  margin: 0;
  padding-left: 18px;
}

.ai-summary li {
  margin-bottom: 8px;
}

.ai-report-card {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
}

.ai-report-card span {
  color: var(--muted);
}

.ai-chat {
  display: grid;
  gap: 14px;
}

.ai-chat-output {
  display: grid;
  gap: 10px;
  max-height: 420px;
  overflow-y: auto;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
}

.ai-message {
  max-width: 920px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.ai-message.user {
  justify-self: end;
  background: #e5eff9;
}

.ai-message.agent {
  justify-self: start;
}

.ai-message p,
.ai-message ul {
  margin: 6px 0 0;
}

.ai-prompt-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.ai-chat-input {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: contain;
}

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

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

th {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0;
}

.shipment-ref {
  display: inline-block;
  white-space: nowrap;
  min-width: max-content;
}

.stacked {
  display: grid;
  gap: 6px;
}

.subsection {
  margin-top: 18px;
}

.subsection h3 {
  margin: 0 0 8px;
}

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

.mini-field {
  display: grid;
  grid-template-columns: 84px minmax(110px, 1fr);
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.mini-field input {
  min-height: 34px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  font: inherit;
}

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

.status,
.pill {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 12px;
  font-weight: 800;
}

.status.ok,
.pill.ok {
  background: #dff2e7;
  color: var(--ok);
}

.status.warn,
.pill.warn {
  background: #fff1d2;
  color: var(--warn);
}

.status.danger,
.pill.danger {
  background: #fde3e3;
  color: var(--danger);
}

.status.info,
.pill.info {
  background: #e5eff9;
  color: var(--info);
}

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

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

.step-dot {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #edf3f0;
  color: var(--muted);
  font-weight: 900;
}

.timeline-step.done .step-dot {
  background: var(--brand);
  color: #ffffff;
}

.timeline-step.current {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

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

.field {
  display: grid;
  gap: 6px;
}

.field.compact {
  min-width: 170px;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  background: #ffffff;
  color: var(--ink);
}

textarea {
  min-height: 86px;
  resize: vertical;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.planning-choice-panel {
  display: grid;
  gap: 14px;
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.planning-select select {
  min-height: 48px;
  font-weight: 700;
}

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

.planning-option-detail > div {
  min-height: 74px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
}

.planning-option-detail span {
  display: block;
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.planning-option-detail strong {
  display: block;
  color: var(--ink);
  font-size: 16px;
}

.process-strip {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 10px;
  margin: 16px 0;
}

.process-strip > div {
  min-height: 96px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f8fbfa;
}

.process-strip strong,
.process-strip span {
  display: block;
}

.process-strip strong {
  margin-bottom: 6px;
  color: var(--ink);
  font-size: 14px;
}

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

.trace-actions {
  display: grid;
  gap: 8px;
  min-width: 210px;
}

.upload-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.route-price-note {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  color: var(--muted);
  font-size: 12px;
}

.section-title-row {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 14px;
  margin: 20px 0 12px;
}

.section-title-row p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.order-lines {
  display: grid;
  gap: 12px;
}

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

.line-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

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

.bar-row {
  display: grid;
  grid-template-columns: 92px 1fr 96px;
  gap: 10px;
  align-items: center;
  min-height: 28px;
  font-size: 13px;
}

.bar-row.project-bar {
  grid-template-columns: minmax(140px, 220px) 1fr 120px;
}

.bar-row.compact {
  grid-template-columns: minmax(120px, 1fr) 48px;
}

.chart-note {
  margin: -2px 0 16px 0;
  color: var(--muted);
  font-size: 12px;
  padding-left: 150px;
}

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

.bar-fill {
  height: 100%;
  border-radius: inherit;
  background: var(--brand-2);
}

.bar-fill.cost {
  background: var(--warn);
}

.bar-fill.util {
  background: var(--info);
}

.kanban {
  display: grid;
  grid-template-columns: repeat(4, minmax(220px, 1fr));
  gap: 12px;
  overflow-x: auto;
}

.lane {
  min-height: 260px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfa;
}

.lane h3 {
  padding: 12px;
  border-bottom: 1px solid var(--line);
}

.shipment-card {
  margin: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.shipment-card strong,
.shipment-card span {
  display: block;
}

.shipment-card span {
  color: var(--muted);
  font-size: 12px;
}

.driver-view {
  display: grid;
  gap: 14px;
}

.driver-hero {
  display: grid;
  gap: 14px;
  padding: 18px;
  border-radius: 8px;
  background: var(--brand);
  color: #ffffff;
}

.driver-hero p {
  color: #cfe4df;
}

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

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

.empty-state {
  padding: 24px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(12, 24, 22, 0.45);
}

.modal {
  width: min(980px, 100%);
  max-height: min(760px, 92vh);
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.22);
}

.success-toast {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 80;
  padding: 14px 18px;
  border-radius: 8px;
  background: var(--ok);
  color: #ffffff;
  box-shadow: 0 18px 44px rgba(0, 0, 0, 0.2);
  font-weight: 800;
}

.trouble-agent {
  position: fixed;
  right: 22px;
  bottom: 22px;
  z-index: 70;
}

.trouble-agent-button {
  width: 62px;
  height: 62px;
  border: 0;
  border-radius: 50%;
  background: #ffffff;
  color: #ffffff;
  box-shadow: 0 18px 44px rgba(11, 63, 143, 0.32);
  font-size: 20px;
  font-weight: 900;
  cursor: pointer;
  display: grid;
  place-items: center;
  padding: 8px;
}

.trouble-agent-button img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.trouble-agent-panel {
  position: absolute;
  right: 0;
  bottom: 76px;
  width: min(420px, calc(100vw - 32px));
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
  box-shadow: 0 24px 70px rgba(17, 29, 27, 0.2);
}

.trouble-agent-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.trouble-agent-panel p,
.trouble-agent-note {
  color: var(--muted);
}

.trouble-agent-form {
  display: grid;
  gap: 12px;
}

/* ──────────────────────────────────────────────────────────────────────
   Material 3 component layer
   Applied across ERP forms + modals. Non-destructive — older classes
   (`.primary`, `.secondary`, `.ghost`, `.button`, `.field`, `.pill`)
   remain valid. New pages should prefer the `.btn*` / `.md-field` /
   `.md-modal*` variants below.
   ────────────────────────────────────────────────────────────────────── */

/* Buttons (Material 3: filled / filled-tonal / outlined / text) */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--brand);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.1px;
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color var(--motion-fast),
    box-shadow var(--motion-fast),
    color var(--motion-fast),
    border-color var(--motion-fast),
    transform var(--motion-fast);
  white-space: nowrap;
  user-select: none;
}

.btn:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.btn:active {
  transform: translateY(1px);
}

.btn:disabled,
.btn[aria-disabled="true"] {
  opacity: 0.5;
  cursor: not-allowed;
  pointer-events: none;
}

/* Filled — primary action (blue) */
.btn-filled {
  background: var(--brand);
  color: #ffffff;
  box-shadow: var(--elev-1);
}
.btn-filled:hover {
  background: #0a3579;
  box-shadow: var(--elev-2);
}
.btn-filled.danger { background: var(--danger); }
.btn-filled.danger:hover { background: #b54040; }
.btn-filled.ok    { background: var(--ok); }
.btn-filled.ok:hover { background: #266b4a; }

/* Filled tonal — softer filled */
.btn-tonal {
  background: var(--brand-tint);
  color: var(--brand-on);
}
.btn-tonal:hover { background: var(--brand-tint-strong); }

/* Outlined */
.btn-outlined {
  background: transparent;
  border-color: var(--line);
  color: var(--ink);
}
.btn-outlined:hover {
  background: rgba(11, 63, 143, 0.05);
  border-color: var(--brand);
  color: var(--brand);
}
.btn-outlined.danger { color: var(--danger); border-color: var(--danger); }
.btn-outlined.danger:hover { background: var(--danger-tint); }

/* Text — lowest emphasis */
.btn-text {
  background: transparent;
  color: var(--brand);
  padding: 0 12px;
}
.btn-text:hover { background: rgba(11, 63, 143, 0.06); }

/* Icon-only square */
.btn-icon {
  width: 40px;
  min-height: 40px;
  padding: 0;
  border-radius: 50%;
}

/* Size modifiers */
.btn-sm { min-height: 32px; padding: 0 14px; font-size: 12.5px; }
.btn-lg { min-height: 48px; padding: 0 26px; font-size: 15px; }

/* Block button (full width) */
.btn-block { width: 100%; }

/* Backwards-compat aliases — keep old markup working but route to M3 styles */
.button,
.icon-button,
.primary,
.secondary,
.ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 20px;
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--brand);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition:
    background-color var(--motion-fast),
    box-shadow var(--motion-fast),
    color var(--motion-fast),
    border-color var(--motion-fast);
}

.button:focus-visible,
.icon-button:focus-visible,
.primary:focus-visible,
.secondary:focus-visible,
.ghost:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

.icon-button {
  width: 42px;
  padding: 0;
  border-radius: 50%;
  font-size: 18px;
}

.primary {
  background: var(--brand);
  color: #ffffff;
  box-shadow: var(--elev-1);
}
.primary:hover {
  background: #0a3579;
  box-shadow: var(--elev-2);
}

.secondary {
  background: var(--brand-tint);
  color: var(--brand-on);
  border-color: transparent;
}
.secondary:hover {
  background: var(--brand-tint-strong);
}

.ghost {
  background: transparent;
  color: var(--ink);
  padding: 0 12px;
}
.ghost:hover { background: rgba(11, 63, 143, 0.06); }

/* Old "outline" class (used by logout link & action buttons) */
.outline {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius-pill);
  background: transparent;
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background-color var(--motion-fast), border-color var(--motion-fast), color var(--motion-fast);
}
.outline:hover {
  background: rgba(11, 63, 143, 0.05);
  border-color: var(--brand);
  color: var(--brand);
}
.outline.danger {
  color: var(--danger);
  border-color: var(--danger);
}
.outline.danger:hover {
  background: var(--danger-tint);
}
.outline:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* ─── Form fields (Material 3 outlined text field) ─────────────────── */
.md-field {
  display: grid;
  gap: 6px;
  margin: 0;
}

.md-field-label {
  color: var(--ink);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.1px;
}

.md-field-label .required {
  color: var(--danger);
  margin-left: 2px;
}

.md-field-hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
}

.md-field-error {
  color: var(--danger);
  font-size: 12px;
  font-weight: 500;
}

.md-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-4);
}

@media (max-width: 680px) {
  .md-row { grid-template-columns: 1fr; }
}

/* Inputs / select / textarea — softer, focused ring */
input,
select,
textarea {
  width: 100%;
  min-height: 44px;
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #ffffff;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.4;
  transition: border-color var(--motion-fast), box-shadow var(--motion-fast);
}

input::placeholder,
textarea::placeholder {
  color: #8a9893;
}

input:hover:not(:disabled),
select:hover:not(:disabled),
textarea:hover:not(:disabled) {
  border-color: #b8c7c1;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--focus-ring);
}

input[type="file"] {
  padding: 8px 12px;
  min-height: auto;
  background: var(--brand-tint);
}

textarea {
  min-height: 92px;
  resize: vertical;
}

/* Checkbox group container (used in modals) */
.md-checkbox-group {
  display: grid;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: #fafcfa;
}

.md-checkbox {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 4px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-xs);
  transition: background-color var(--motion-fast);
}

.md-checkbox:hover {
  background: rgba(11, 63, 143, 0.04);
}

.md-checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  min-height: auto;
  padding: 0;
  margin: 0;
  cursor: pointer;
  accent-color: var(--brand);
}

/* Error alert / banner */
.md-alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  background: var(--danger-tint);
  color: #882b2b;
  font-size: 13px;
  font-weight: 500;
  margin-bottom: var(--space-4);
}

/* ─── Modal (Material 3 dialog) ─────────────────────────────────────── */
.md-modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: var(--space-4);
  background: rgba(8, 14, 13, 0.50);
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
  animation: md-fade-in var(--motion-med) both;
}

@keyframes md-fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}

@keyframes md-pop-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.md-modal {
  width: min(520px, 100%);
  max-height: min(85vh, 720px);
  display: flex;
  flex-direction: column;
  border-radius: var(--radius-lg);
  background: var(--panel);
  box-shadow: var(--elev-modal);
  overflow: hidden;
  animation: md-pop-in var(--motion-med) both;
}

.md-modal-md { width: min(640px, 100%); }
.md-modal-lg { width: min(820px, 100%); }

.md-modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-5) var(--space-6) var(--space-3);
}

.md-modal-title {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.1px;
}

.md-modal-close {
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  transition: background-color var(--motion-fast), color var(--motion-fast);
}
.md-modal-close:hover {
  background: rgba(11, 63, 143, 0.08);
  color: var(--ink);
}

.md-modal-body {
  padding: var(--space-3) var(--space-6) var(--space-5);
  overflow-y: auto;
}

.md-modal-body > form > .md-stack:last-child,
.md-modal-body form > .md-stack:last-child {
  margin-bottom: 0;
}

.md-modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-6) var(--space-5);
  border-top: 1px solid var(--line);
  background: #fafcfa;
}

/* ─── Stack helper (used inside modals for vertical rhythm) ──────────── */
.md-stack {
  display: grid;
  gap: var(--space-4);
  margin-bottom: var(--space-4);
}

.md-stack-tight {
  display: grid;
  gap: var(--space-2);
}

/* ─── Table polish (row hover + sticky-ish header feel) ─────────────── */
table tbody tr {
  transition: background-color var(--motion-fast);
}
table tbody tr:hover {
  background: rgba(11, 63, 143, 0.03);
}

table th {
  background: #f7f9f7;
  border-bottom: 1px solid var(--line);
}

/* Pills — add blue / purple / teal / gray / etc. colors used by AR/AP/CA
   pages so they don't fall back to unknown modifiers. */
.pill.blue   { background: var(--info-tint);  color: var(--info); }
.pill.purple { background: #ece4fb;          color: #5b21b6; }
.pill.teal   { background: #d4f1ec;          color: #0d7066; }
.pill.gray   { background: #e6ecea;          color: #4b5752; }
.pill.brand  { background: var(--brand-tint); color: var(--brand); }

/* Inline action buttons inside table cells (Edit / Delete) */
.row-actions {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.row-actions form { display: inline; }
.row-actions button,
.row-actions .button,
.row-actions .outline {
  min-height: 30px;
  padding: 0 12px;
  font-size: 12px;
  border-radius: var(--radius-pill);
}

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

  .sidebar {
    position: static;
    height: auto;
    padding: 14px;
  }

  .module-nav {
    grid-auto-flow: column;
    grid-auto-columns: minmax(170px, 1fr);
    overflow-x: auto;
  }

  .grid.metrics,
  .grid.two,
  .grid.three,
  .grid.four,
  .portal-grid,
  .form-grid,
  .planning-option-detail,
  .process-strip {
    grid-template-columns: 1fr 1fr;
  }
}

@media (max-width: 680px) {
  .main {
    padding: 14px;
  }

  .topbar,
  .panel-header,
  .section-title-row {
    display: grid;
  }

  .top-actions,
  .grid.metrics,
  .grid.two,
  .grid.three,
  .grid.four,
  .portal-hero,
  .portal-grid,
  .form-grid,
  .planning-option-detail,
  .process-strip {
    grid-template-columns: 1fr;
    width: 100%;
  }

  .module-nav {
    grid-auto-columns: minmax(148px, 1fr);
  }

  .nav-button {
    grid-template-columns: 24px 1fr;
  }

  .nav-badge {
    display: none;
  }

  .metric-value {
    font-size: 24px;
  }

  .timeline-step {
    grid-template-columns: 30px 1fr;
  }

  .timeline-step .pill {
    grid-column: 2;
    justify-self: start;
  }
}

/* Mobile Card View for Tables */
@media (max-width: 768px) {
  .md-table.mobile-cards,
  .md-table.mobile-cards tbody,
  .md-table.mobile-cards tr,
  .md-table.mobile-cards td {
    display: block;
    width: 100%;
  }
  
  .md-table.mobile-cards thead {
    display: none;
  }
  
  .md-table.mobile-cards tr {
    background: #fff;
    margin-bottom: 16px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  }
  
  .md-table.mobile-cards td {
    border: none;
    padding: 8px 0;
    position: relative;
    padding-left: 40%;
    text-align: right;
  }
  
  .md-table.mobile-cards td::before {
    content: attr(data-label);
    position: absolute;
    left: 0;
    width: 35%;
    padding-right: 10px;
    white-space: nowrap;
    text-align: left;
    font-weight: 600;
    color: var(--muted);
    font-size: 0.85rem;
  }
}
