/* Sol redesign layer — unified enterprise UI, responsive workflow and review states */
:root {
  --ink: #0a1d32;
  --ink-2: #30465f;
  --ink-3: #5d7188;
  --bg: #f2f6fa;
  --brand: #064e86;
  --brand-2: #0876bd;
  --accent: #009ba3;
  --line: #d8e3ed;
  --line-soft: #e8eef4;
  --r-lg: 16px;
  --r-md: 11px;
  --shadow-1: 0 1px 2px rgba(5,30,54,.04), 0 9px 24px rgba(5,30,54,.055);
  --shadow-2: 0 2px 8px rgba(5,30,54,.08), 0 22px 52px rgba(5,30,54,.12);
  --font-num: "Segoe UI Variable", "SF Pro Display", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
}
html { scroll-padding-top: 20px; }
body {
  font-family: "Segoe UI Variable", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  background:
    radial-gradient(900px 420px at 92% -12%, rgba(8,118,189,.10), transparent 62%),
    radial-gradient(720px 360px at -8% 108%, rgba(0,155,163,.07), transparent 64%),
    var(--bg);
}
button, input, select, textarea { font: inherit; }
button:disabled { cursor: not-allowed; opacity: .58; box-shadow: none !important; transform: none !important; }
[hidden] { display: none !important; }
.skip-link {
  position: fixed; z-index: 200; left: 16px; top: -80px; padding: 10px 14px;
  border-radius: 10px; color: #fff; background: var(--brand); box-shadow: var(--shadow-2);
}
.skip-link:focus { top: 14px; }
.sr-only {
  position: absolute !important; width: 1px !important; height: 1px !important; padding: 0 !important;
  margin: -1px !important; overflow: hidden !important; clip: rect(0,0,0,0) !important; white-space: nowrap !important; border: 0 !important;
}

/* Case management: per-row actions, recycle view and revision history */
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; }
.row-actions .btn { white-space: nowrap; }
.btn.btn-danger { border-color: #e3b4b0; color: #a3312a; }
.btn.btn-danger:hover { background: #fdf1f0; border-color: #cf6a62; }
.page-tools .btn.on { border-color: var(--brand); background: var(--brand); color: #fff; }
.own-tag { color: var(--ink-3); font-size: 10.5px; }
.deleted-banner {
  display: flex; flex-wrap: wrap; gap: 12px; align-items: center; justify-content: space-between;
  margin: 0 0 18px; padding: 12px 14px; border: 1px solid #e3b4b0; border-radius: 12px;
  background: #fdf1f0; color: #7d2620;
}
.deleted-banner > div { display: grid; gap: 2px; min-width: 0; }
.deleted-banner b { font-size: 13px; }
.deleted-banner span { font-size: 12px; }
.deleted-banner em { font-size: 12px; font-style: normal; color: #a3312a; }
.revision-current > td { background: #eef6fb; font-weight: 650; }

/* Spec file import entry point */
.spec-import-label {
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; justify-content: space-between;
}
.spec-import-label .btn { text-transform: none; letter-spacing: 0; }
.spec-import-note { margin-bottom: 16px; }

/* Login */
.auth-panel { max-width: 980px; min-height: 590px; grid-template-columns: 1.08fr .92fr; border-radius: 28px; }
.auth-hero { isolation: isolate; background: #062e52; padding: 52px 48px; }
.auth-hero::before { background: linear-gradient(108deg, rgba(4,35,64,.92), rgba(4,56,92,.55) 58%, rgba(0,123,140,.18)); z-index: -1; }
.auth-hero::after { content: ""; position: absolute; inset: 0; z-index: -2; background: linear-gradient(180deg, transparent 40%, rgba(2,26,49,.5)); }
.auth-visual { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; opacity: .84; z-index: -3; }
.auth-hero-content { display: grid; align-content: start; }
.auth-hero .hero-title { max-width: 390px; font-size: clamp(30px, 4vw, 42px); letter-spacing: -.7px; }
.auth-hero .hero-sub { max-width: 410px; color: rgba(255,255,255,.84); }
.auth-form { padding: 50px 46px; }

/* Global shell */
.sidebar { width: 220px; background: linear-gradient(180deg, #06365f 0%, #064e7d 68%, #075b91 100%); border-right: 1px solid rgba(255,255,255,.09); }
.side-brand.text-brand { min-height: 82px; gap: 12px; }
.side-brand.text-brand > img { width: 34px; height: 34px; border-radius: 10px; box-shadow: 0 6px 18px rgba(1,25,49,.28); }
.side-brand.text-brand div b { font-size: 15px; letter-spacing: .2px; }
.nav a { min-height: 46px; border-radius: 11px; }
.nav .ico { width: 21px; height: 21px; display: grid; place-items: center; }
.nav .ico svg { width: 20px; height: 20px; }
.main { width: 100%; max-width: 1440px; margin: 0 auto; padding: 28px clamp(22px, 3vw, 44px) 72px; }
.page-head { margin-bottom: 18px; }
.page-head h1 { font-size: clamp(23px, 2.4vw, 30px); letter-spacing: -.4px; }
.page-head .sub { max-width: 760px; font-size: 13.5px; }
.page-tools { display: flex; gap: 8px; }
.page-tools .btn { min-height: 40px; padding: 8px 14px; }
.card { border-color: #e2e9f0; box-shadow: var(--shadow-1); }
.card-h { min-height: 62px; }
.card-h h3 { letter-spacing: .1px; }

/* Quotation flow */
.estimate-scope-note {
  display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 12px;
  margin: 0 0 16px; padding: 11px 14px; border: 1px solid #cfe0ed; border-radius: 12px;
  color: #37546d; background: linear-gradient(100deg, #f4f9fd, #f4fbfb); font-size: 12.5px;
}
.estimate-scope-note b { color: var(--brand); white-space: nowrap; }
.estimate-scope-note em { color: #517083; font-size: 11px; font-style: normal; white-space: nowrap; }
.workflow-stepper { border-color: #d5e1eb; background: rgba(231,239,246,.9); }
.workflow-step { min-height: 46px; }
.workflow-step.on { box-shadow: 0 3px 10px rgba(5,45,80,.1); }
.quote-step-card { overflow: hidden; }
.quote-step-card .card-h { flex-wrap: wrap; }
.step-summary { margin-left: auto; color: var(--ink-3); font-size: 11.5px; font-weight: 700; text-align: right; }
.step-toggle {
  min-width: 58px; min-height: 32px; padding: 5px 10px; border: 1px solid var(--line); border-radius: 999px;
  color: var(--brand); background: #fff; font-size: 11.5px; font-weight: 800;
}
.quote-step-card.is-collapsed .card-b { display: none; }
.quote-step-card.is-collapsed .card-h { border-bottom: 0; }
.ptype-row { grid-template-columns: repeat(auto-fit, minmax(90px, 1fr)); }
.ptype { min-height: 82px; padding: 12px 8px 10px; }
.ptype .ic { width: 26px; height: 26px; margin: 0 auto; color: #47708f; display: grid; }
.ptype .ic svg { width: 100%; height: 100%; }
.ptype.on .ic { color: var(--brand); }
.region-chip .flag {
  min-width: 28px; min-height: 23px; display: inline-grid; place-items: center; padding: 2px 5px;
  border-radius: 6px; color: #fff; background: var(--brand); font-family: var(--font-num); font-size: 9px; letter-spacing: .6px;
}
.case-meta-grid .field { margin-bottom: 0; }
.quote-live-summary { transition: border-color .18s, box-shadow .18s, opacity .18s, transform .18s; }
.quote-live-summary.is-stale { border-color: #d79a3a; box-shadow: 0 8px 30px rgba(138,87,7,.16); }
.quote-live-summary.is-stale .live-total { background: #fff8eb; }
.live-calc-shortcut { display: none; }
.dirty-notice {
  margin-top: 20px; padding: 13px 14px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  border: 1px solid #ebc77e; border-radius: 12px; background: #fff8e8; color: #70500d;
}
.dirty-notice > div { display: grid; gap: 2px; }
.dirty-notice b { font-size: 13px; }
.dirty-notice span { font-size: 12px; }
.dirty-notice .btn-primary { width: auto; flex: none; }
.draft-notice {
  margin: 0 0 18px; padding: 11px 14px; display: flex; align-items: center; justify-content: space-between; gap: 16px;
  border: 1px solid #bcd9ce; border-radius: 12px; background: #f0f9f4; color: #1d5d3e;
}
.draft-notice > div { display: grid; gap: 2px; min-width: 0; }
.draft-notice b { font-size: 13px; }
.draft-notice span { font-size: 12px; color: #2c6b4c; }
.draft-notice .btn { flex: none; }
.result-stale { opacity: .62; filter: saturate(.55); transition: opacity .18s, filter .18s; }

/* Result hierarchy */
.result-overview .card-b { display: grid; gap: 16px; }
.result-grand { margin-top: 0; }
.result-grand .hrs b { font-family: var(--font-num); font-size: 20px; }
.estimate-review {
  display: grid; grid-template-columns: minmax(220px,.75fr) minmax(0,1.6fr); gap: 18px; align-items: center;
  padding: 15px 16px; border: 1px solid #cde5da; border-left: 4px solid var(--ok); border-radius: 12px; background: #f3fbf7;
}
.estimate-review.needs-review { border-color: #edd7a8; border-left-color: #c48116; background: #fff9ed; }
.estimate-review > div:first-child { display: grid; gap: 2px; }
.estimate-review small { color: var(--ink-3); font-size: 9.5px; font-weight: 900; letter-spacing: 1.2px; }
.estimate-review strong { color: #155c3e; font-size: 17px; }
.estimate-review.needs-review strong { color: #8a5707; }
.estimate-review span { color: var(--ink-2); font-size: 11.5px; }
.review-meta { display: grid; grid-template-columns: repeat(3,minmax(0,1fr)); gap: 8px; }
.review-meta span { padding: 8px 10px; border: 1px solid rgba(105,130,150,.16); border-radius: 9px; background: rgba(255,255,255,.72); overflow-wrap: anywhere; }
.review-meta b { display: block; margin-top: 2px; color: var(--ink); font-size: 11.5px; }
.standards-disclaimer { display: grid; gap: 3px; padding: 12px 14px; border-left: 3px solid #6c8ba4; border-radius: 8px; background: #f5f8fb; }
.standards-disclaimer b { color: #31536e; font-size: 12px; }
.standards-disclaimer span { color: var(--ink-3); font-size: 11.5px; line-height: 1.55; }
.result-detail-card summary { cursor: pointer; list-style: none; justify-content: space-between; }
.result-detail-card summary::-webkit-details-marker { display: none; }
.result-detail-card summary > div { display: flex; align-items: baseline; gap: 10px; }
.detail-summary-meta { color: var(--ink-3); font: 800 11.5px/1 var(--font-num); }
.result-detail-card .table-wrap:focus-visible, .quote-kpi-bar:focus-visible { outline: 3px solid rgba(8,118,189,.25); outline-offset: 2px; }
table.detail caption { text-align: left; }
.detail-reason { color: var(--ink-3); }
.ptcrb-host-summary { display: none; }
.ptcrb-host-summary div { min-width: 0; }
.ptcrb-host-summary small, .ptcrb-host-summary span { display: block; color: #587086; font-size: 9px; }
.ptcrb-host-summary b { display: block; color: #073b66; font-size: 15px; white-space: nowrap; }
.ptcrb-host-summary button {
  min-height: 42px; padding: 7px 11px; border: 0; border-radius: 10px;
  background: #0b5fad; color: #fff; font-weight: 850;
}

@media (min-width: 1240px) {
  .quote-step-card .card-b { padding: 24px 26px 26px; }
  .ptype-row { grid-template-columns: repeat(7, minmax(90px,1fr)); }
}

@media (max-width: 980px) {
  .auth-panel { grid-template-columns: 1fr; max-width: 480px; }
  .sidebar { width: 100%; height: auto; position: sticky; top: 0; z-index: 50; display: grid; grid-template-columns: 1fr auto; background: #063e6d; }
  .side-brand { grid-column: 1; min-height: 56px !important; padding: 10px 16px; border-bottom: 0; }
  .side-brand.text-brand > img { width: 31px; height: 31px; }
  .side-user { grid-column: 2; grid-row: 1; border-top: 0; padding: 8px 12px; }
  .nav { grid-column: 1 / -1; display: flex; gap: 6px; padding: 7px 10px 9px; border-top: 1px solid rgba(255,255,255,.1); }
  .nav a { min-height: 40px; padding: 8px 11px; }
  .main { padding: 20px 16px 72px; }
  .estimate-scope-note { grid-template-columns: auto 1fr; }
  .estimate-scope-note em { grid-column: 2; }
  .case-meta-grid { grid-template-columns: 1fr 1fr; }
  .case-meta-grid > :last-child { grid-column: 1 / -1; }
  .estimate-review { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  body.quote-workspace { padding-bottom: 96px; }
  .sidebar { position: sticky; }
  .side-brand.text-brand div small, .side-user-info { display: none; }
  .side-user { gap: 6px; }
  .side-user .avatar { width: 30px; height: 30px; }
  .side-user button { padding: 5px 8px; }
  .lang-switch.compact { display: none; }
  .nav { overscroll-behavior-x: contain; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { font-size: 12px; white-space: nowrap; }
  .nav .ico { width: 17px; height: 17px; }
  .nav .ico svg { width: 17px; height: 17px; }
  .main { padding: 16px 10px 48px; }
  .page-head { gap: 12px; }
  .page-head h1 { font-size: 23px; }
  /* Three tools no longer fit on one narrow row; wrap instead of squeezing labels. */
  .page-tools { width: 100%; flex-wrap: wrap; }
  .page-tools .btn { flex: 1 1 128px; min-width: 0; }
  .estimate-scope-note { grid-template-columns: 1fr; gap: 5px; padding: 10px 12px; }
  .estimate-scope-note em { grid-column: auto; white-space: normal; }
  .workflow-stepper {
    margin-bottom: 12px;
    -webkit-mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 30px), transparent 100%);
    mask-image: linear-gradient(90deg, transparent 0, #000 14px, #000 calc(100% - 30px), transparent 100%);
  }
  .workflow-step { flex-basis: 112px; }
  .quote-live-summary {
    position: fixed; z-index: 70; top: auto; bottom: 8px; left: 8px; right: 8px; margin: 0;
    height: 68px; min-height: 68px; max-height: 68px;
    grid-template-columns: 64px 64px minmax(0,1fr); border-radius: 14px; box-shadow: 0 12px 38px rgba(5,34,60,.22);
  }
  .quote-live-summary > .live-kpi:nth-child(3), .quote-live-summary > .live-kpi:nth-child(4) { display: none; }
  .quote-live-summary > .live-kpi.risk { display: block !important; }
  body.result-summary-in-view .quote-live-summary {
    opacity: 0; visibility: hidden; pointer-events: none; transform: translateY(12px);
  }
  .live-kpi, .live-total { padding: 10px 9px 9px; }
  .live-kpi small, .live-total small { font-size: 8.5px; }
  .live-kpi b { font-size: 12px; }
  .live-total { display: grid; grid-template-columns: 1fr auto; grid-template-rows: auto auto auto; column-gap: 8px; }
  .live-total small, .live-total b, .live-total em { min-width: 0; }
  .live-total b { font-size: 15px; }
  .live-total em { max-width: 170px; font-size: 9.5px; }
  .live-calc-shortcut { grid-column: 2; grid-row: 1 / span 3; display: block; align-self: center; min-height: 42px; padding: 7px 11px; border: 0; border-radius: 10px; color: #fff; background: var(--brand); font-size: 12px; font-weight: 900; }
  .card-h { min-height: 56px; padding: 14px 13px; gap: 8px; }
  .card-h .right { display: none; }
  .step-summary { width: calc(100% - 64px); margin-left: 34px; text-align: left; order: 3; font-size: 10.5px; }
  .step-toggle { margin-left: auto; }
  .card-b { padding: 15px 13px; }
  .case-meta-grid, .g2, .g3, .g4 { grid-template-columns: 1fr; }
  .case-meta-grid > :last-child { grid-column: auto; }
  .ptype-row { grid-template-columns: repeat(2,minmax(0,1fr)); gap: 8px; }
  .ptype { min-height: 72px; }
  .region-chip { flex: 1 1 calc(50% - 6px); justify-content: center; padding: 9px 10px; font-size: 12px; }
  .dirty-notice { align-items: stretch; flex-direction: column; }
  .dirty-notice .btn-primary { width: 100%; }
  .draft-notice { align-items: stretch; flex-direction: column; }
  .draft-notice .btn { width: 100%; }
  .deleted-banner { align-items: stretch; flex-direction: column; }
  .row-actions .btn { flex: 1 1 auto; justify-content: center; }
  .spec-import-label { justify-content: flex-start; }
  .spec-import-label .btn { width: 100%; }
  .result-grand { padding: 18px; }
  .result-grand .amt { font-size: 29px; }
  .estimate-review { padding: 13px; }
  .review-meta { grid-template-columns: 1fr; }
  .result-grid { grid-template-columns: 1fr; }
  .result-detail-card summary > div { display: grid; gap: 5px; }
  .result-detail-card .card-b { padding: 10px; }
  table.detail, table.detail tbody, table.detail tr, table.detail td { display: block; width: 100%; }
  table.detail thead { display: none; }
  table.detail tbody { display: grid; gap: 10px; }
  table.detail tr { padding: 10px; border: 1px solid var(--line-soft); border-radius: 11px; background: #fff; box-shadow: 0 3px 10px rgba(7,39,68,.035); }
  table.detail td, table.detail tbody tr:nth-child(even) td { display: grid; grid-template-columns: 88px minmax(0,1fr); gap: 9px; padding: 5px 3px; border: 0; background: transparent; text-align: left !important; overflow-wrap: anywhere; }
  table.detail td::before { content: attr(data-label); color: var(--ink-3); font-size: 10px; font-weight: 800; letter-spacing: .3px; }
  table.detail td.num { font-family: inherit; }
  .table-wrap { overflow: visible; }
  .auth-wrap { align-items: center; min-height: 100svh; }
  .ptcrb-host-summary:not([hidden]) {
    position: fixed; z-index: 72; right: 8px; bottom: 8px; left: 8px;
    display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 9px;
    min-height: 68px; padding: 8px 10px; border: 1px solid #88c7cf; border-radius: 14px;
    background: linear-gradient(135deg, #f3fbff, #e8f8f6); box-shadow: 0 12px 38px rgba(5,34,60,.22);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

@media print {
  .skip-link, .estimate-scope-note, .dirty-notice, .draft-notice, .spec-import-note, .step-toggle, .standards-disclaimer { display: none !important; }
  .spec-import-label .btn, .si-backdrop { display: none !important; }
  .result-details:not([open]) > :not(summary) { display: block !important; }
  body.print-stale-blocked #resultArea > * { display: none !important; }
  body.print-stale-blocked #resultArea::before {
    content: "STALE RESULT — 輸入內容已變更，請重新試算後再列印。";
    display: block; margin: 24px 0; padding: 18px; border: 2px solid #9b6500;
    color: #663f00; background: #fff8e8; font-size: 18px; font-weight: 800;
  }
  body:not(.print-stale-blocked) .result-stale { opacity: 1; filter: none; }
}
