:root {
  --bg: #f6f8fa;
  --surface: #ffffff;
  --surface-soft: #f6f8fa;
  --surface-muted: #eef1f4;
  --line: #d0d7de;
  --line-strong: #afb8c1;
  --text: #1f2328;
  --muted: #59636e;
  --accent: #1f6f4a;
  --accent-dark: #17593b;
  --accent-soft: #eaf3ee;
  --blue: #0969da;
  --blue-soft: #ddf4ff;
  --amber: #9a6700;
  --amber-soft: #fff8c5;
  --red: #cf222e;
  --red-soft: #ffebe9;
  --shadow: 0 1px 0 rgba(31, 35, 40, 0.04);
  --focus: 0 0 0 3px rgba(9, 105, 218, 0.2);
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Malgun Gothic", Arial, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: 0;
}

body.locked .app-shell {
  filter: blur(2px);
  pointer-events: none;
  user-select: none;
}

button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.55; }

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

svg { flex: 0 0 auto; }

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

body.sidebar-collapsed .app-shell { grid-template-columns: 72px minmax(0, 1fr); }

.sidebar {
  position: sticky;
  top: 0;
  z-index: 20;
  height: 100vh;
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  overflow-y: auto;
  border-right: 1px solid var(--line);
  background: var(--surface);
}

.sidebar::-webkit-scrollbar { width: 8px; }
.sidebar::-webkit-scrollbar-thumb { border: 2px solid var(--surface); border-radius: 8px; background: var(--line); }
.sidebar-head { display: flex; align-items: center; gap: 6px; }
.sidebar-close { display: none !important; }

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 48px;
  padding: 4px 8px 14px;
}

.app-brand { width: 100%; border: 0; background: transparent; color: var(--text); text-align: left; }
.app-brand:hover { background: var(--surface-soft); border-radius: 6px; }

.brand-mark {
  width: 32px;
  height: 32px;
  display: grid;
  place-items: center;
  border-radius: 6px;
  background: var(--accent);
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
}

.brand strong, .brand span { display: block; }
.brand strong { font-size: 15px; }
.brand span { margin-top: 1px; color: var(--muted); font-size: 12px; }

.nav { display: grid; gap: 18px; padding-top: 8px; }
.nav-group { display: grid; gap: 2px; }
.nav-group-system { padding-top: 12px; border-top: 1px solid var(--line); }

.nav-label {
  padding: 0 10px 5px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.nav-button {
  width: 100%;
  min-height: 36px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  text-align: left;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.nav-button svg { width: 17px; height: 17px; color: var(--muted); }
.nav-button:hover { background: var(--surface-soft); }
.nav-button.active { border-color: #c7dfd1; background: var(--accent-soft); color: var(--accent-dark); font-weight: 600; }
.nav-button.active svg { color: var(--accent); }

body.sidebar-collapsed .sidebar { padding-right: 10px; padding-left: 10px; overflow-x: hidden; }
body.sidebar-collapsed .sidebar-head { justify-content: center; }
body.sidebar-collapsed .app-brand { width: 42px; justify-content: center; padding-right: 5px; padding-left: 5px; }
body.sidebar-collapsed .brand-copy,
body.sidebar-collapsed .nav-label,
body.sidebar-collapsed .nav-text { display: none; }
body.sidebar-collapsed .nav { gap: 7px; }
body.sidebar-collapsed .nav-group { justify-items: center; padding-top: 7px; border-top: 1px solid var(--line); }
body.sidebar-collapsed .nav-group:first-child { padding-top: 0; border-top: 0; }
body.sidebar-collapsed .nav-group-system { padding-top: 7px; }
body.sidebar-collapsed .nav-button { width: 42px; justify-content: center; padding: 0; }
body.sidebar-collapsed .nav-button.active { box-shadow: inset 3px 0 0 var(--accent); }

.sidebar-scrim { display: none; }

.main {
  min-width: 0;
  width: 100%;
  max-width: 1680px;
  margin: 0 auto;
  padding: 24px 28px 40px;
}

.topbar {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  padding-bottom: 16px;
  border-bottom: 1px solid var(--line);
}

.page-heading { min-width: 0; display: flex; align-items: center; gap: 10px; }
.menu-button { display: inline-flex !important; }

.eyebrow { margin: 0 0 2px; color: var(--muted); font-size: 12px; font-weight: 500; }
h1, h2 { margin: 0; letter-spacing: 0; }
h1 { font-size: 24px; line-height: 1.25; font-weight: 650; }
h2 { font-size: 16px; line-height: 1.4; font-weight: 650; }

.panel-subtitle { margin: 3px 0 0; color: var(--muted); font-size: 12px; }

.top-actions, .toolbar, .form-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.user-chip {
  min-height: 30px;
  display: inline-flex;
  align-items: center;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--muted);
  font-size: 12px;
  font-weight: 500;
}

.environment-badge {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  border: 1px solid #a7d5b9;
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 11px;
  font-weight: 600;
}

.environment-badge[hidden] { display: none; }
.environment-badge[data-environment="beta"] { border-color: #d4a72c66; background: var(--amber-soft); color: var(--amber); }
.login-panel > .environment-badge { justify-self: start; }

.login-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(31, 35, 40, 0.42);
}

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

.login-panel {
  width: min(380px, 100%);
  display: grid;
  gap: 14px;
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: 0 8px 24px rgba(31, 35, 40, 0.18);
}

.login-brand { padding: 0 0 12px; border-bottom: 1px solid var(--line); }
.login-message { min-height: 20px; margin: 0; color: var(--red); font-size: 12px; }
.google-login-hint { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.5; }
.login-divider { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.login-divider::before, .login-divider::after { height: 1px; flex: 1; background: var(--line); content: ""; }
.login-divider[hidden], .google-login-button[hidden], .google-login-hint[hidden], .login-password-fields[hidden] { display: none; }
.login-password-fields { display: grid; gap: 14px; }

.google-login-button {
  min-height: 40px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  font-weight: 600;
}

.google-login-button:hover { background: var(--surface-soft); }
.google-mark { color: #1a73e8; font-size: 16px; font-weight: 700; }
.table-subtext { margin-top: 2px; color: var(--muted); font-size: 12px; }

.primary-button, .ghost-button, .icon-button, .small-button {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 6px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
  transition: background 0.12s ease, border-color 0.12s ease;
}

.primary-button svg, .ghost-button svg { width: 16px; height: 16px; }
.primary-button { border-color: rgba(31, 35, 40, 0.15); background: var(--accent); color: #fff; box-shadow: var(--shadow); }
.primary-button:hover { background: var(--accent-dark); }
.ghost-button, .icon-button, .small-button { border-color: var(--line); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.ghost-button:hover, .icon-button:hover, .small-button:hover { background: var(--surface-soft); border-color: var(--line-strong); }
.button-link { text-decoration: none; }
.icon-button { width: 34px; padding: 0; }
.icon-button svg { width: 17px; height: 17px; }

.view { display: none; }
.view.active { display: grid; gap: 16px; }
.view-tabs { width: fit-content; display: flex; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-muted); }
.view-tab { min-height: 32px; display: inline-flex; align-items: center; gap: 7px; padding: 0 11px; border: 0; border-radius: 4px; background: transparent; color: var(--muted); font-weight: 600; }
.view-tab svg { width: 16px; height: 16px; }
.view-tab.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.billing-pane { display: grid; gap: 16px; }
.billing-pane[hidden] { display: none; }
.billing-estimate-only[hidden], .billing-invoice-only[hidden] { display: none; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.metric, .panel { border: 1px solid var(--line); border-radius: 6px; background: var(--surface); box-shadow: var(--shadow); }

.metric {
  min-height: 96px;
  display: grid;
  align-content: space-between;
  padding: 16px;
  border-left: 3px solid var(--accent);
}

.metric.warning { border-left-color: var(--amber); }
.metric.accent { border-left-color: var(--blue); }
.metric span { color: var(--muted); font-size: 12px; }
.metric strong { font-size: 25px; line-height: 1.2; font-weight: 650; }

.detail-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border-bottom: 1px solid var(--line); }
.detail-stats article { min-height: 76px; display: grid; align-content: center; gap: 4px; padding: 12px 16px; border-right: 1px solid var(--line); }
.detail-stats article:last-child { border-right: 0; }
.detail-stats span { color: var(--muted); font-size: 12px; font-weight: 600; }
.detail-stats strong { font-size: 21px; }

.split-grid { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(300px, 0.65fr); gap: 16px; }
.panel { overflow: hidden; }

.panel-head {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.table-wrap { width: 100%; overflow: auto; }
table { width: 100%; min-width: 760px; border-collapse: separate; border-spacing: 0; }
.split-grid table { min-width: 640px; }
th, td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; white-space: nowrap; }
th { position: sticky; top: 0; z-index: 1; background: var(--surface-soft); color: var(--muted); font-size: 12px; font-weight: 600; }
td { background: var(--surface); font-size: 13px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover td { background: #fbfcfd; }
.num { text-align: right; }
.amount-due { color: var(--red); font-weight: 650; }

.form-grid { display: grid; grid-template-columns: repeat(4, minmax(160px, 1fr)); gap: 13px; padding: 16px; }
.compact-form { border-bottom: 1px solid var(--line); background: var(--surface-soft); }
.calculation-note { align-self: end; min-height: 34px; display: flex; align-items: center; padding: 8px 10px; border: 1px solid var(--line); border-radius: 6px; background: var(--accent-soft); color: var(--accent-dark); font-size: 12px; font-weight: 600; }

label { display: grid; gap: 5px; color: var(--text); font-size: 12px; font-weight: 600; }
.field-help { color: var(--muted); font-size: 11px; font-weight: 400; }
input, select, textarea {
  width: 100%;
  min-height: 34px;
  padding: 6px 9px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
}

input::placeholder, textarea::placeholder { color: #8c959f; }
input:hover, select:hover, textarea:hover { border-color: #8c959f; }
textarea { resize: vertical; }
.wide { grid-column: span 2; }
.form-actions { grid-column: 1 / -1; justify-content: flex-end; padding-top: 2px; }
.check-row { min-height: 34px; display: flex; align-items: center; gap: 8px; align-self: end; }
.check-row input { width: 16px; min-height: 16px; }
.search { width: min(280px, 100%); }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.billing-counterparty-picker { display: grid; gap: 5px; }
.billing-counterparty-picker .field-help { min-height: 14px; }
.counterparty-registration-upload { grid-column: 1 / -1; display: grid; grid-template-columns: minmax(220px, 1fr) minmax(260px, 1.4fr) auto; align-items: end; gap: 10px; padding: 13px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface-soft); }
.counterparty-registration-upload strong, .counterparty-registration-upload span { display: block; }
.counterparty-registration-upload span { margin-top: 3px; color: var(--muted); font-size: 11px; font-weight: 400; }
.counterparty-registration-upload .counterparty-registration-picker { margin: 0; }
.counterparty-registration-upload > .field-help { grid-column: 1 / -1; min-height: 16px; margin: 0; }
.counterparty-registration-upload > .field-help.success { color: var(--accent-dark); font-weight: 600; }
.counterparty-registration-upload > .field-help.warning { color: #8a5b00; font-weight: 600; }
.counterparty-registration-current { grid-column: 1 / -1; min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); }
.counterparty-registration-current[hidden] { display: none; }
.counterparty-registration-current strong, .counterparty-registration-current span { display: block; }
.counterparty-registration-current span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.counterparties-table { min-width: 1180px; }

.service-material-editor {
  grid-column: 1 / -1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.service-material-head {
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
}

.service-material-head h3 { margin: 0; font-size: 14px; }
.service-material-head p { margin: 3px 0 0; color: var(--muted); font-size: 12px; }
.service-material-table { min-width: 820px; }
.service-material-table input, .service-material-table select { min-height: 32px; }
.service-material-table td { padding: 8px; background: var(--surface); }
.service-material-table .material-item { min-width: 220px; }
.service-material-table .material-quantity { min-width: 105px; }
.service-material-table .material-lot { min-width: 120px; }
.service-material-table .material-expiry { min-width: 140px; }
.service-material-table .icon-button { min-height: 32px; height: 32px; color: var(--red); box-shadow: none; }
.material-stock { color: var(--muted); font-size: 12px; }
.material-stock.low { color: var(--red); font-weight: 650; }

.service-photo-editor {
  grid-column: 1 / -1;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface-soft);
}

.service-photo-picker {
  min-height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 0 11px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  box-shadow: var(--shadow);
}

.service-photo-picker:hover { background: var(--surface-soft); }
.service-photo-picker svg { width: 16px; height: 16px; }
.service-photo-picker input { position: absolute; width: 1px; height: 1px; min-height: 1px; padding: 0; opacity: 0; pointer-events: none; }
.service-photo-fields { display: grid; grid-template-columns: minmax(140px, 0.35fr) 1fr; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.service-photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 10px; padding: 12px; background: var(--surface); }
.service-photo-card { min-width: 0; overflow: hidden; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); }
.service-photo-card.pending { border-style: dashed; }
.service-photo-card > a { display: block; }
.service-photo-card img { display: block; width: 100%; aspect-ratio: 4 / 3; object-fit: cover; background: var(--surface-muted); }
.service-photo-meta { min-height: 48px; display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 7px; padding: 7px; }
.service-photo-meta p { min-width: 0; margin: 0; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.service-photo-meta .icon-button { width: 30px; height: 30px; min-height: 30px; padding: 0; color: var(--red); box-shadow: none; }
.service-photo-empty { grid-column: 1 / -1; margin: 0; padding: 14px; color: var(--muted); text-align: center; }

.status, .tag {
  min-height: 22px;
  display: inline-flex;
  align-items: center;
  padding: 0 8px;
  border: 1px solid transparent;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 11px;
  font-weight: 600;
}

.status.good, .tag.in { border-color: #a7d5b9; background: var(--accent-soft); color: var(--accent-dark); }
.status.low, .tag.sale, .tag.field { border-color: #d4a72c66; background: var(--amber-soft); color: var(--amber); }
.status.empty, .tag.adjust { border-color: #ff818266; background: var(--red-soft); color: var(--red); }
.tag.order { border-color: #54aeff66; background: var(--blue-soft); color: var(--blue); }

.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.small-button { min-height: 28px; padding: 0 8px; font-size: 12px; }
a.small-button { text-decoration: none; }
.small-button.danger { color: var(--red); }

.bid-calculation {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  padding: 1px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--line);
  overflow: hidden;
}

.bid-calculation span { padding: 10px 12px; background: var(--surface-soft); color: var(--muted); font-size: 12px; }
.bid-calculation strong { display: block; margin-top: 2px; color: var(--text); font-size: 15px; }

.estimate-summary {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 1px;
  padding: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--line);
}

.estimate-summary span { padding: 10px 12px; background: var(--surface-soft); color: var(--muted); font-size: 12px; }
.estimate-summary strong { display: block; margin-top: 2px; color: var(--text); font-size: 14px; }
.estimate-summary span:last-child { background: var(--accent-soft); color: var(--accent-dark); }
.method-fieldset { min-width: 0; margin: 0; padding: 0; border: 0; }
.method-fieldset legend { margin-bottom: 5px; color: var(--text); font-size: 12px; font-weight: 600; }
.segmented-control { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2px; padding: 2px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-muted); }
.segmented-control label { display: block; cursor: pointer; }
.segmented-control input { position: absolute; width: 1px; min-height: 1px; opacity: 0; pointer-events: none; }
.segmented-control span { min-height: 30px; display: grid; place-items: center; padding: 0 9px; border-radius: 4px; color: var(--muted); font-size: 12px; font-weight: 600; }
.segmented-control input:checked + span { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.segmented-control input:focus-visible + span { outline: 2px solid var(--blue); outline-offset: 1px; }
.injection-cost-settings { grid-column: 1 / -1; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); }
#injectionDoseField[hidden], #injectionIntervalField[hidden], #injectionQuoteUnitPriceField[hidden] { display: none; }
.injection-cost-settings summary { padding: 10px 12px; color: var(--text); font-size: 12px; font-weight: 600; cursor: pointer; }
.injection-cost-settings .form-grid { border-top: 1px solid var(--line); }
.injection-tree-table { min-width: 920px; table-layout: fixed; }
.injection-tree-table th:first-child { width: 180px; }
.injection-tree-table th:last-child { width: 64px; }
.injection-tree-table td { padding: 7px 8px; }
.injection-tree-table input { min-height: 32px; }
.injection-tree-table .icon-button { min-height: 32px; height: 32px; color: var(--red); box-shadow: none; }
.injection-summary { display: grid; grid-template-columns: repeat(6, minmax(0, 1fr)); gap: 1px; padding: 1px; border-top: 1px solid var(--line); background: var(--line); }
.injection-summary span { min-width: 0; padding: 11px 12px; background: var(--surface-soft); color: var(--muted); font-size: 12px; }
.injection-summary strong { display: block; margin-top: 3px; overflow-wrap: anywhere; color: var(--text); font-size: 15px; }
.injection-summary span:last-child { background: var(--accent-soft); color: var(--accent-dark); }
.document-tabs { display: flex; flex-wrap: wrap; gap: 5px; }
.document-tabs .small-button { box-shadow: none; }
.document-tabs .small-button.active { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-dark); }
.injection-document { overflow: auto; padding: 18px; background: var(--surface-muted); }
.document-preview-table { width: min(1120px, 100%); min-width: 760px; margin: 0 auto; border: 1px solid #8c959f; border-collapse: collapse; background: #fff; box-shadow: var(--shadow); }
.document-preview-table td { min-width: 90px; padding: 8px 10px; border: 1px solid #8c959f; background: #fff; white-space: normal; }
.document-preview-table .document-title-row td { padding: 20px 10px; font-size: 20px; font-weight: 700; text-align: center; }
.archive-controls { display: grid; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--line); background: var(--surface-soft); }
.archive-search { display: grid; grid-template-columns: minmax(240px, 1fr) 160px auto; gap: 8px; }
.archive-search .search { width: 100%; max-width: none; }
.archive-breadcrumbs { min-height: 28px; display: flex; align-items: center; gap: 4px; overflow-x: auto; }
.archive-crumb { min-height: 28px; display: inline-flex; align-items: center; gap: 5px; flex: 0 0 auto; padding: 0 7px; border: 0; border-radius: 4px; background: transparent; color: var(--blue); font-size: 12px; }
.archive-crumb:hover { background: var(--blue-soft); }
.archive-crumb[aria-current="page"] { color: var(--text); font-weight: 600; pointer-events: none; }
.archive-separator { color: var(--muted); }
.archive-status { min-height: 38px; display: flex; align-items: center; padding: 8px 16px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.archive-connect { padding: 28px 16px; text-align: center; }
.archive-connect p { margin: 0 0 12px; color: var(--muted); }
.archive-table .archive-name-cell { max-width: 680px; white-space: normal; }
.archive-file-name { display: inline-flex; align-items: flex-start; gap: 8px; color: var(--text); font-weight: 600; text-align: left; }
.archive-file-name[href] { text-decoration: none; }
.archive-file-name svg { width: 17px; height: 17px; margin-top: 1px; color: var(--muted); }
button.archive-file-name { padding: 0; border: 0; background: transparent; }
button.archive-file-name:hover { color: var(--blue); }

.closing-period-bar {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 12px;
  padding: 16px 18px;
}
.closing-period-bar label { display: grid; gap: 6px; color: var(--muted); font-size: 12px; font-weight: 700; }
.closing-actions { display: flex; grid-column: 1 / -1; flex-wrap: wrap; gap: 8px; }
.closing-source-note { margin: 0; padding: 0 18px 16px; color: var(--amber); font-size: 12px; }
.closing-auto-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line); }
.closing-auto-grid article { min-height: 88px; padding: 16px; background: var(--surface); }
.closing-auto-grid span { display: block; color: var(--muted); font-size: 12px; }
.closing-auto-grid strong { display: block; margin-top: 5px; font-size: 20px; }
.closing-auto-grid small { color: var(--muted); }
.closing-income-table input,
.closing-segment-table input,
#closingExpensesTable input { min-width: 130px; text-align: right; }
.closing-derived { background: var(--surface-soft); font-weight: 700; }
.closing-operation-form { border-top: 0; }
.closing-checklist { display: grid; gap: 1px; background: var(--line); }
.closing-checklist article { display: grid; grid-template-columns: 32px minmax(160px, 1fr) auto; align-items: center; gap: 10px; padding: 12px 16px; background: var(--surface); }
.closing-checklist .closing-check-icon { display: grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 800; }
.closing-checklist article.warning .closing-check-icon { background: var(--amber-soft); color: var(--amber); }
.closing-checklist p { margin: 0; }
.closing-checklist small { color: var(--muted); }
.metric small { color: var(--muted); }
.tree-report-hero { overflow: hidden; }
.tree-report-controls { border-top: 1px solid var(--line); }
.tree-report-segments { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; padding: 18px; }
.tree-report-segment { padding: 18px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface-soft); }
.tree-report-segment header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.tree-report-segment h3 { margin: 0; font-size: 16px; }
.tree-report-segment .segment-value { display: block; margin-top: 14px; font-size: 25px; }
.tree-report-segment dl { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 14px 0 0; }
.tree-report-segment dl div { padding-top: 8px; border-top: 1px solid var(--line); }
.tree-report-segment dt { color: var(--muted); font-size: 11px; }
.tree-report-segment dd { margin: 3px 0 0; font-weight: 700; }
.tree-report-progress { height: 7px; margin-top: 12px; overflow: hidden; border-radius: 999px; background: var(--line); }
.tree-report-progress span { display: block; height: 100%; border-radius: inherit; background: var(--accent); }
.tree-report-client-list { display: grid; gap: 1px; background: var(--line); }
.tree-report-client-list article { display: grid; grid-template-columns: minmax(120px, 1fr) auto; gap: 8px; padding: 12px 16px; background: var(--surface); }
.tree-report-client-list small { grid-column: 1 / -1; color: var(--muted); }
.tree-report-narrative { display: grid; gap: 14px; padding: 16px; }
.tree-report-narrative article { padding-left: 12px; border-left: 3px solid var(--accent); }
.tree-report-narrative h3 { margin: 0 0 5px; font-size: 13px; }
.tree-report-narrative p { margin: 0; color: var(--muted); white-space: pre-wrap; }
.tree-report-empty { color: var(--muted); }
.archive-footer { display: flex; justify-content: center; padding: 12px; border-top: 1px solid var(--line); }
.archive-footer[hidden] { display: none; }
.contract-file-current { min-height: 42px; display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); }
.contract-file-current[hidden] { display: none; }
.contract-file-current strong, .contract-file-current span { display: block; }
.contract-file-current span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.module-placeholder { min-height: 240px; }
.module-placeholder .empty-state { display: grid; place-items: center; min-height: 180px; }

.alert-list { display: grid; gap: 8px; padding: 12px; }
.alert-item { padding: 10px 12px; border: 1px solid var(--line); border-left: 3px solid var(--amber); border-radius: 6px; background: #fffdf0; }
.alert-item strong, .alert-item span { display: block; }
.alert-item span { margin-top: 2px; color: var(--muted); font-size: 12px; }

.help-text { margin: 0 0 12px; color: var(--muted); line-height: 1.6; }
.import-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 0.6fr); gap: 16px; padding: 16px; }
#importText { margin-top: 12px; }
.sample-box { padding: 14px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; background: var(--surface-soft); }
.sample-box pre { margin: 12px 0 0; white-space: pre-wrap; line-height: 1.5; }

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 60;
  max-width: 360px;
  padding: 10px 13px;
  border: 1px solid #3d444d;
  border-radius: 6px;
  background: #24292f;
  color: #fff;
  box-shadow: 0 8px 24px rgba(31, 35, 40, 0.2);
  opacity: 0;
  transform: translateY(8px);
  pointer-events: none;
  transition: 0.16s ease;
}

.toast.show { opacity: 1; transform: translateY(0); }
.empty-state { padding: 24px; color: var(--muted); text-align: center; }
.g2b-search-status { margin: 0; padding: 10px 16px; border-bottom: 1px solid var(--line); color: var(--muted); font-size: 12px; }
.g2b-results-table .g2b-title-cell { min-width: 320px; white-space: normal; }
.g2b-results-table .g2b-title-cell small { color: var(--muted); }
.g2b-results-table .g2b-deadline { min-width: 142px; }
.g2b-results-table .g2b-qualification { min-width: 150px; white-space: normal; }
.g2b-results-table .g2b-qualification small { display: block; max-width: 220px; margin-top: 4px; color: var(--muted); line-height: 1.35; }
.qualification-status.eligible { border-color: #a7d5b9; background: var(--accent-soft); color: var(--accent-dark); }
.qualification-status.review { border-color: #d4a72c66; background: var(--amber-soft); color: var(--amber); }
.qualification-status.ineligible { border-color: #ff818266; background: var(--red-soft); color: var(--red); }
#bidQualificationForm label small { display: block; margin-top: 3px; color: var(--muted); font-weight: 400; }
.bid-result-filters { display: flex; flex-wrap: wrap; align-items: end; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.bid-result-filters > label:not(.check-row) { display: grid; gap: 4px; color: var(--muted); font-size: 12px; font-weight: 600; }
.bid-result-periods { align-self: end; }
.bid-results-table { min-width: 1320px; }
.bid-results-table td { vertical-align: top; white-space: normal; }
.bid-results-table td:nth-child(2) { min-width: 280px; }
.bid-results-table td:nth-child(4), .bid-results-table td:nth-child(5), .bid-results-table td:nth-child(6), .bid-results-table td:nth-child(7) { min-width: 145px; }
.bid-result-primary { font-weight: 700; }
.bid-result-secondary { display: block; margin-top: 3px; color: var(--muted); font-size: 11px; }

@media (max-width: 1180px) {
  .app-shell { grid-template-columns: 224px minmax(0, 1fr); }
  .main { padding: 22px 20px 36px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 860px) {
  body.sidebar-open { overflow: hidden; }
  .app-shell { display: block; }
  .sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: min(296px, 86vw);
    height: 100vh;
    box-shadow: 12px 0 32px rgba(31, 35, 40, 0.18);
    transform: translateX(-105%);
    visibility: hidden;
    transition: transform 0.18s ease;
  }
  body.sidebar-open .sidebar { transform: translateX(0); visibility: visible; }
  .sidebar-head { align-items: flex-start; }
  .sidebar-close { display: inline-flex !important; flex: 0 0 auto; margin-top: 5px; }
  body.sidebar-collapsed .sidebar { padding: 16px 12px; overflow-x: visible; }
  body.sidebar-collapsed .sidebar-head { justify-content: initial; }
  body.sidebar-collapsed .app-brand { width: 100%; justify-content: flex-start; padding: 4px 8px 14px; }
  body.sidebar-collapsed .brand-copy,
  body.sidebar-collapsed .nav-label,
  body.sidebar-collapsed .nav-text { display: block; }
  body.sidebar-collapsed .nav { gap: 18px; }
  body.sidebar-collapsed .nav-group { justify-items: stretch; padding-top: 0; border-top: 0; }
  body.sidebar-collapsed .nav-group-system { padding-top: 12px; border-top: 1px solid var(--line); }
  body.sidebar-collapsed .nav-button { width: 100%; justify-content: flex-start; padding: 0 10px; }
  body.sidebar-collapsed .nav-button.active { box-shadow: none; }
  .sidebar-scrim {
    position: fixed;
    inset: 0;
    z-index: 15;
    display: block;
    border: 0;
    background: rgba(31, 35, 40, 0.35);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.18s ease;
  }
  body.sidebar-open .sidebar-scrim { opacity: 1; pointer-events: auto; }
  .metric-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .injection-summary { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .split-grid, .import-layout { grid-template-columns: 1fr; }
  .closing-period-bar { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .closing-auto-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tree-report-segments { grid-template-columns: 1fr; }
  .counterparty-registration-upload { grid-template-columns: 1fr; align-items: stretch; }
  .counterparty-registration-upload > .field-help { grid-column: auto; }
}

@media (max-width: 640px) {
  .main { padding: 14px 12px 28px; }
  .topbar { align-items: flex-start; margin-bottom: 14px; padding-bottom: 12px; }
  .page-heading { align-items: flex-start; }
  .eyebrow { display: none; }
  h1 { padding-top: 3px; font-size: 20px; }
  .top-actions { justify-content: flex-end; }
  .user-chip { display: none; }
  .metric-grid { gap: 8px; }
  .metric { min-height: 82px; padding: 12px; }
  .metric strong { font-size: 21px; }
  .view.active { gap: 12px; }
  .panel-head { align-items: stretch; flex-direction: column; padding: 11px 12px; }
  .toolbar { width: 100%; }
  .toolbar > * { flex: 1 1 140px; }
  .search { width: 100%; max-width: none; }
  .form-grid { grid-template-columns: 1fr; padding: 12px; }
  .wide { grid-column: auto; }
  .service-material-head { align-items: stretch; flex-direction: column; }
  .service-material-head .ghost-button { width: 100%; }
  .service-photo-picker { width: 100%; }
  .service-photo-fields { grid-template-columns: 1fr; }
  .service-photo-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 10px; }
  .service-photo-meta { grid-template-columns: 1fr auto; }
  .service-photo-meta .tag { display: none; }
  .detail-stats { grid-template-columns: 1fr; }
  .detail-stats article { border-right: 0; border-bottom: 1px solid var(--line); }
  .detail-stats article:last-child { border-bottom: 0; }
  .bid-calculation { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .estimate-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .view-tabs { width: 100%; }
  .view-tabs { overflow-x: auto; }
  .view-tab { flex: 1 0 auto; justify-content: center; white-space: nowrap; }
  .injection-summary { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .injection-document { padding: 10px; }
  .archive-search { grid-template-columns: 1fr; }
  .closing-period-bar { grid-template-columns: 1fr; padding: 12px; }
  .closing-auto-grid { grid-template-columns: 1fr; }
  .closing-checklist article { grid-template-columns: 28px 1fr; }
  .closing-checklist article > :last-child { grid-column: 2; }
  .toast { right: 12px; bottom: 12px; left: 12px; max-width: none; }
}

.approval-dialog {
  width: min(560px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 24px 70px rgba(15, 23, 42, 0.28);
}

.approval-dialog::backdrop { background: rgba(15, 23, 42, 0.48); }
.approval-dialog form { display: grid; gap: 16px; padding-bottom: 18px; }
.approval-dialog .panel-head { border-bottom: 1px solid var(--line); }
.approval-comment-label { display: grid; gap: 8px; padding: 0 18px; font-weight: 700; }
.approval-comment-label textarea { width: 100%; resize: vertical; }
.approval-dialog .form-message { min-height: 20px; margin: 0; padding: 0 18px; color: var(--red); }
.approval-dialog .form-actions { padding: 0 18px; }
.approval-details { margin-top: 6px; color: var(--muted); }
.approval-details summary { cursor: pointer; font-size: 12px; font-weight: 700; }
.approval-details p { margin: 8px 0 0; white-space: pre-wrap; }
.approval-history { display: grid; gap: 4px; margin: 8px 0 0; padding-left: 18px; font-size: 12px; }

@media (max-width: 390px) {
  .environment-badge { display: none; }
  .primary-button, .ghost-button { padding: 0 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .app-shell, .sidebar, .sidebar-scrim { transition: none; }
}
