/* Quality Manager Portal — professional manufacturing-quality theme. */
:root {
  --navy: #0f2238; --navy-2: #16314f; --steel: #3b4a5c;
  --bg: #f3f5f8; --surface: #ffffff; --surface-2: #f8fafc; --border: #d8dee6; --border-strong: #b9c3cf;
  --text: #1b2430; --muted: #5b6878;
  --accent: #1d5fd1; --accent-ink: #ffffff; --accent-soft: #e8f0fd;
  --ok: #1f7a3e; --ok-soft: #e6f4ea; --warn: #8a5300; --warn-soft: #fff4e5; --warn-line: #e3a23b;
  --bad: #b42318; --bad-soft: #fdecea; --ai: #6b3fc8; --ai-soft: #f1ebfd;
  --radius: 8px; --shadow: 0 1px 2px rgba(15, 34, 56, .06), 0 2px 8px rgba(15, 34, 56, .05);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  --sidebar: 248px;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: var(--font); font-size: 14.5px; line-height: 1.45; color: var(--text); background: var(--bg); }
a { color: var(--accent); }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0 0 .2rem; line-height: 1.25; }
h2 { font-size: 1.05rem; margin: 0 0 .6rem; }
h3 { font-size: .95rem; margin: .4rem 0; }
p { margin: .35rem 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid #7aa7f0; outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.skip-link { position: absolute; left: -9999px; top: 0; background: #fff; padding: .5rem 1rem; z-index: 100; }
.skip-link:focus { left: 1rem; top: .5rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.nowrap { white-space: nowrap; }
.ok-text { color: var(--ok); } .warn-text { color: var(--warn); } .bad-text { color: var(--bad); font-weight: 600; }
.overdue { color: var(--bad); font-weight: 600; }

/* ---------- shell ---------- */
.demo-banner { display: flex; flex-wrap: wrap; gap: .3rem .8rem; align-items: center; justify-content: center; padding: .4rem 1rem; background: #fff1c2; color: #5a4300; border-bottom: 1px solid #e8cf7a; font-size: .85rem; text-align: center; }
.demo-banner strong { letter-spacing: .06em; }
.shell { display: flex; min-height: calc(100vh - 34px); }
.sidebar { width: var(--sidebar); flex: 0 0 var(--sidebar); background: var(--navy); color: #d6deea; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow-y: auto; }
.brand { display: flex; gap: .7rem; align-items: center; padding: 1rem 1rem .8rem; color: #fff; text-decoration: none; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.brand:hover { text-decoration: none; }
.brand-mark svg { width: 34px; height: 34px; display: block; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-text small { color: #9fb0c6; font-size: .75rem; }
.nav-list { list-style: none; margin: .6rem 0; padding: 0 .5rem; }
.nav-list a { display: flex; gap: .65rem; align-items: center; padding: .52rem .7rem; border-radius: 6px; color: #d6deea; text-decoration: none; font-size: .92rem; }
.nav-list a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav-list a.active { background: var(--navy-2); color: #fff; box-shadow: inset 3px 0 0 #50c878; }
.ni { width: 1.2rem; text-align: center; opacity: .85; }
.nav-sep { height: 1px; background: rgba(255, 255, 255, .08); margin: .5rem .4rem; }
.sidebar-foot { margin-top: auto; padding: 1rem; font-size: .74rem; color: #8ea0b8; border-top: 1px solid rgba(255, 255, 255, .08); }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: .8rem; padding: .6rem 1.4rem; background: var(--surface); border-bottom: 1px solid var(--border); position: sticky; top: 0; z-index: 20; }
.menu-btn { display: none; }
.global-search { flex: 1; max-width: 520px; }
.global-search input { width: 100%; padding: .48rem .75rem; border: 1px solid var(--border); border-radius: 6px; background: var(--surface-2); }
.agenda-bell { position: relative; text-decoration: none; font-size: 1.15rem; padding: .2rem .45rem; border-radius: 8px; border: 1px solid var(--border); background: var(--surface-2); }
.agenda-bell:hover { text-decoration: none; border-color: var(--accent); }
.bell-count:empty { display: none; }
.bell-count { position: absolute; top: -7px; right: -8px; min-width: 19px; height: 19px; padding: 0 5px; border-radius: 999px; background: var(--bad); color: #fff; font-size: .7rem; font-weight: 700; display: grid; place-items: center; }
.page-actions select { padding: .45rem .6rem; border: 1px solid var(--border-strong); border-radius: 6px; background: #fff; font-size: .88rem; }
.agenda-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.agenda-routine { grid-row: span 2; }
.card-bad { border-top: 4px solid var(--bad); }
.agenda-kind { display: inline-block; font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--steel); background: #eef1f5; border-radius: 4px; padding: 0 .35rem; }
.routine { list-style: none; margin: 0; padding: 0; }
.routine li { padding: .55rem 0; border-top: 1px solid #edf0f4; }
.routine li:first-child { border-top: 0; }
.routine-label { display: flex; gap: .55rem; align-items: flex-start; font-weight: 600; cursor: pointer; }
.routine-label input { width: 18px; height: 18px; margin-top: .1rem; flex: 0 0 auto; }
.routine li.done .routine-label span { text-decoration: line-through; color: var(--muted); font-weight: 400; }
.routine .li-meta { margin-left: 1.7rem; }
.routine-tools { margin-left: 1.7rem; display: flex; gap: .8rem; }
.routine-mini { list-style: none; padding: 0; margin: .2rem 0; font-size: .88rem; }
.routine-mini li.done { color: var(--muted); text-decoration: line-through; }
.reminder h3 { margin-top: .8rem; }
@media (max-width: 900px) { .agenda-grid { grid-template-columns: minmax(0, 1fr); } }
.ai-pill { font-size: .78rem; padding: .25rem .6rem; border-radius: 999px; border: 1px solid var(--border); white-space: nowrap; }
.ai-pill.on { background: var(--ai-soft); color: var(--ai); border-color: #cdb9f3; }
.ai-pill.off { background: var(--warn-soft); color: var(--warn); border-color: #f0cf9c; }
.user-switch { display: flex; flex-direction: column; font-size: .72rem; color: var(--muted); }
.user-switch select { font-size: .85rem; padding: .25rem .4rem; border: 1px solid var(--border); border-radius: 6px; background: #fff; max-width: 260px; }
#view { padding: 1.3rem 1.5rem 3rem; outline: none; max-width: 1500px; width: 100%; }
.loading { padding: 2rem; }

/* ---------- headings ---------- */
.page-head { display: flex; flex-wrap: wrap; gap: 1rem; justify-content: space-between; align-items: flex-start; margin-bottom: 1rem; }
.page-actions { display: flex; flex-wrap: wrap; gap: .45rem; align-items: center; }
.kicker { font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.head-meta { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; font-size: .88rem; color: var(--muted); margin-top: .25rem; }
.crumbs { font-size: .85rem; color: var(--muted); margin-bottom: .4rem; }
.section-title { margin: 1.4rem 0 .6rem; }
.section-row { display: flex; flex-wrap: wrap; gap: .6rem; justify-content: space-between; align-items: center; }
.save-state { font-size: .8rem; color: var(--muted); }
.save-state.unsaved { color: var(--warn); font-weight: 600; }
.demo-tag { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: #7a6510; background: #fff6d6; border: 1px solid #ecd98c; border-radius: 4px; padding: 0 .3rem; vertical-align: middle; }

/* ---------- buttons ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .35rem; padding: .48rem .9rem; border-radius: 6px; border: 1px solid transparent; cursor: pointer; font-weight: 600; font-size: .88rem; text-decoration: none; white-space: nowrap; line-height: 1.2; }
.btn:hover { text-decoration: none; filter: brightness(.96); }
.btn:disabled, .btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: #fff; color: var(--text); border-color: var(--border-strong); }
.btn-secondary.active { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-danger { background: #fff; color: var(--bad); border-color: #e6a8a2; }
.btn-ai { background: var(--ai); color: #fff; }
.btn-sm { padding: .3rem .6rem; font-size: .8rem; }
.icon-btn { background: transparent; border: 1px solid transparent; border-radius: 6px; cursor: pointer; padding: .25rem .5rem; font-size: 1rem; line-height: 1; }
.icon-btn:hover { background: var(--surface-2); border-color: var(--border); }
.icon-btn.sm { font-size: .78rem; padding: .2rem .38rem; }
.icon-btn.danger { color: var(--bad); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: .15rem 0; font-size: .85rem; text-decoration: underline; }
.link-btn.danger { color: var(--bad); }
.menu-wrap { position: relative; }
.menu { position: absolute; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(15, 34, 56, .16); min-width: 230px; z-index: 30; padding: .3rem; }
.menu button { display: block; width: 100%; text-align: left; background: none; border: 0; padding: .5rem .7rem; border-radius: 6px; cursor: pointer; }
.menu button:hover, .menu button:focus { background: var(--surface-2); }

/* ---------- badges ---------- */
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .74rem; font-weight: 600; border: 1px solid transparent; white-space: nowrap; vertical-align: middle; }
.badge-ok { background: var(--ok-soft); color: var(--ok); border-color: #b5dcc1; }
.badge-warn { background: var(--warn-soft); color: var(--warn); border-color: #f0cf9c; }
.badge-bad { background: var(--bad-soft); color: var(--bad); border-color: #f1b9b3; }
.badge-info { background: var(--accent-soft); color: var(--accent); border-color: #bcd1f6; }
.badge-draft, .badge-muted { background: #eef1f5; color: var(--steel); border-color: #d5dbe3; }
.badge-ai { background: var(--ai-soft); color: var(--ai); border-color: #cdb9f3; }

/* ---------- banners ---------- */
.banner { border: 1px solid var(--border); border-left-width: 4px; border-radius: 6px; padding: .6rem .85rem; margin: 0 0 .9rem; background: var(--surface); font-size: .9rem; }
.banner ul { margin: .3rem 0 .2rem 1.1rem; padding: 0; }
.banner-info { border-left-color: var(--accent); background: #f5f8fe; }
.banner-warn { border-left-color: var(--warn-line); background: var(--warn-soft); }
.banner-bad { border-left-color: var(--bad); background: var(--bad-soft); }
.banner-ok { border-left-color: var(--ok); background: var(--ok-soft); }
.banner-ai { border-left-color: var(--ai); background: var(--ai-soft); }

/* ---------- panels, cards ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.kpi { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem 1rem; box-shadow: var(--shadow); color: var(--text); text-decoration: none; display: block; border-top: 4px solid var(--border-strong); }
.kpi-link:hover { text-decoration: none; border-color: var(--accent); }
.kpi-n { font-size: 1.8rem; font-weight: 700; line-height: 1.1; }
.kpi-l { font-size: .82rem; color: var(--muted); }
.kpi-bad { border-top-color: var(--bad); } .kpi-bad .kpi-n { color: var(--bad); }
.kpi-warn { border-top-color: var(--warn-line); }
.kpi-ok { border-top-color: var(--ok); }
.small-kpis .kpi { border-top-width: 1px; }
.dash-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 1rem; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); outline: none; }
.card:focus { box-shadow: 0 0 0 3px #bcd1f6; }
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: .5rem; }
.count { display: inline-block; min-width: 1.5rem; text-align: center; font-size: .78rem; background: #eef1f5; border-radius: 999px; padding: 0 .4rem; color: var(--steel); }
.card-list { list-style: none; margin: 0; padding: 0; }
.card-list li { padding: .5rem 0; border-top: 1px solid #edf0f4; }
.card-list li:first-child { border-top: 0; }
.li-meta { font-size: .8rem; color: var(--muted); margin-top: .1rem; }
.empty-inline { padding: .5rem 0; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: .8rem; margin-bottom: 1rem; }
.tpl-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); display: flex; flex-direction: column; }
.tpl-card p { color: var(--muted); font-size: .85rem; flex: 1; }
.tpl-icon { font-size: 1.5rem; width: 2.4rem; height: 2.4rem; display: grid; place-items: center; background: var(--accent-soft); color: var(--accent); border-radius: 8px; }
.tpl-actions { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-top: .4rem; }
.empty { text-align: center; padding: 2rem 1rem; color: var(--muted); }
.empty h3 { color: var(--text); }
.empty-icon { font-size: 2rem; opacity: .4; }
.progress { position: relative; height: 18px; min-width: 110px; background: #eef1f5; border-radius: 999px; overflow: hidden; }
.progress-bar { height: 100%; background: linear-gradient(90deg, #4f8de8, var(--accent)); }
.progress span { position: absolute; inset: 0; display: grid; place-items: center; font-size: .72rem; font-weight: 600; color: var(--text); }

/* ---------- forms ---------- */
.filters { display: grid; grid-template-columns: repeat(auto-fill, minmax(165px, 1fr)); gap: .5rem .7rem; align-items: end; margin-bottom: .6rem; }
.filter-reset { justify-content: flex-end; }
.field { display: flex; flex-direction: column; gap: .2rem; min-width: 0; }
.field > label, .label { font-size: .8rem; font-weight: 600; color: var(--steel); }
.field input, .field select, .field textarea, .grid input, .grid select, .grid textarea, .chat textarea, .inline-form input, .fw-row input, .fb-list input, .side-panel select, .unclear-cell input[type=text] {
  width: 100%; padding: .42rem .55rem; border: 1px solid var(--border-strong); border-radius: 6px; background: #fff; min-width: 0;
}
.field textarea { resize: vertical; }
.field input:disabled, .field select:disabled, .field textarea:disabled, .grid input:disabled, .grid select:disabled, .grid textarea:disabled, .fw-row input:disabled, .fb-list input:disabled {
  background: var(--surface-2); color: var(--text); border-color: #e3e7ed; opacity: 1; -webkit-text-fill-color: var(--text);
}
.field-full { grid-column: 1 / -1; }
.field-help { font-size: .78rem; color: var(--muted); }
.field-error { color: var(--bad); font-size: .8rem; min-height: 0; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--bad); }
.req { color: var(--bad); }
.form-section { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); padding: .8rem 1rem 1rem; margin: 0 0 1rem; box-shadow: var(--shadow); min-width: 0; }
.form-section > legend { font-weight: 700; padding: 0 .4rem; color: var(--navy); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: .7rem .9rem; }
.field-label-row { display: flex; justify-content: space-between; align-items: baseline; }
.check { display: inline-flex; gap: .35rem; align-items: flex-start; font-size: .88rem; }
.check input { margin-top: .2rem; }
.checks { border: 0; padding: 0; margin: 0; min-width: 0; }
.checks-row { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; }
.check-col { display: flex; flex-direction: column; gap: .3rem; max-height: 260px; overflow: auto; padding: .3rem 0; }
.inline-form { display: flex; gap: .4rem; margin: .4rem 0; max-width: 520px; }
.seg { display: flex; flex-wrap: wrap; gap: 1rem; }

/* ---------- tables ---------- */
.table-scroll { overflow-x: auto; }
table { border-collapse: collapse; width: 100%; }
.data th, .data td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid #e9edf2; vertical-align: top; }
[hidden] { display: none !important; }
.data thead th .nocase { text-transform: none; }
.data thead th { font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); background: var(--surface-2); position: sticky; top: 0; }
.data tbody tr:hover { background: #fafbfd; }
.data.compact td, .data.compact th { padding: .32rem .5rem; font-size: .85rem; }
.matrix td { text-align: center; }
.grid { font-size: .85rem; }
.grid th { background: var(--navy); color: #fff; font-weight: 600; font-size: .76rem; padding: .4rem .45rem; text-align: left; white-space: nowrap; }
.grid td { border: 1px solid #e3e7ed; padding: .22rem; vertical-align: top; }
.grid input, .grid select, .grid textarea { padding: .3rem .4rem; font-size: .85rem; }
.grid select { min-width: 104px; }
.ppap-grid td:nth-child(3) select { min-width: 150px; }
.ppap-grid td:nth-child(4) select { min-width: 120px; }
.grid td.computed { text-align: center; vertical-align: middle; background: var(--surface-2); }
.row-tools { white-space: nowrap; width: 1%; }
.empty-row { text-align: center; padding: 1rem !important; }
.table-actions { margin-top: .4rem; }
.grid tr.sel td { background: #fff8db; }
.el-missing td:first-child { box-shadow: inset 4px 0 0 var(--bad); }
.el-inprogress td:first-child { box-shadow: inset 4px 0 0 var(--warn-line); }
.el-complete td:first-child { box-shadow: inset 4px 0 0 var(--ok); }
.el-na td:first-child { box-shadow: inset 4px 0 0 #9aa5b3; }
tr.flash td { animation: flash 1.2s; }
@keyframes flash { 0%, 60% { background: #fff1c2; } 100% { background: transparent; } }
.evidence .ev { display: flex; gap: .3rem; align-items: center; flex-wrap: wrap; font-size: .82rem; margin-bottom: .2rem; }
.ppap-grid td:nth-child(2) { min-width: 200px; } .ppap-grid td:nth-child(5) { min-width: 220px; } .ppap-grid td:nth-child(6) { min-width: 220px; }

/* ---------- editor layout ---------- */
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 320px; gap: 1rem; align-items: start; }
.editor-side { position: sticky; top: 64px; display: flex; flex-direction: column; gap: .8rem; max-height: calc(100vh - 80px); overflow-y: auto; }
.side-panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .8rem .9rem; box-shadow: var(--shadow); }
.side-panel h2 { font-size: .92rem; text-transform: uppercase; letter-spacing: .04em; color: var(--steel); }
.issues { outline: none; }
.issue-list { list-style: none; padding: 0; margin: .2rem 0; font-size: .85rem; }
.issue-list li { padding: .3rem .4rem .3rem 1.4rem; position: relative; border-radius: 4px; margin-bottom: .2rem; }
.issue-list li::before { position: absolute; left: .35rem; top: .3rem; font-weight: 700; }
.issue-error { background: var(--bad-soft); } .issue-error::before { content: '!'; color: var(--bad); }
.issue-warn { background: var(--warn-soft); } .issue-warn::before { content: '△'; color: var(--warn); font-size: .75rem; }
.issue-info { background: #f2f5f9; } .issue-info::before { content: 'i'; color: var(--steel); }
.issue-list a { color: inherit; }
.stepper { display: flex; list-style: none; padding: 0; margin: 0 0 .6rem; counter-reset: s; flex-wrap: wrap; gap: .25rem; }
.stepper li { flex: 1; min-width: 70px; font-size: .74rem; text-align: center; padding: .3rem .2rem; background: #eef1f5; color: var(--muted); border-radius: 4px; }
.stepper li.done { background: var(--ok-soft); color: var(--ok); }
.stepper li.current { background: var(--accent); color: #fff; font-weight: 700; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: .2rem .7rem; margin: 0; font-size: .86rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.kv-grid { grid-template-columns: max-content 1fr max-content 1fr; }
.trail { list-style: none; padding: 0; margin: 0; font-size: .84rem; }
.trail li { padding: .4rem 0; border-top: 1px solid #edf0f4; }
.trail li:first-child { border-top: 0; }
.link-list { list-style: none; padding: 0; margin: 0 0 .5rem; font-size: .86rem; }
.link-list li { display: flex; gap: .3rem; align-items: center; flex-wrap: wrap; padding: .2rem 0; }

/* ---------- special widgets ---------- */
.fivewhy { display: flex; flex-direction: column; gap: .45rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: .7rem; }
.fw-row { display: grid; grid-template-columns: 90px 1fr; gap: .5rem; align-items: start; }
.fw-label { font-weight: 700; font-size: .82rem; padding-top: .45rem; color: var(--navy); }
.fw-prompt { margin-bottom: .1rem; }
.fw-root .fw-label { color: var(--ok); }
.fb-cols { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: .6rem; margin: .5rem 0; }
.fb-col { background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; padding: .5rem; }
.fb-col h4 { margin: 0 0 .3rem; font-size: .82rem; color: var(--navy); }
.fb-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: .25rem; }
.fb-list li { display: flex; gap: .2rem; }
.fishbone-diagram, .flow-diagram { margin-top: .6rem; border: 1px solid var(--border); border-radius: 6px; background: #fff; overflow-x: auto; }
.fishbone-svg { width: 100%; min-width: 640px; height: auto; display: block; }
.flow-svg { width: 100%; max-width: 760px; height: auto; display: block; }
.gallery { display: flex; flex-wrap: wrap; gap: .7rem; }
.photo { margin: 0; width: 220px; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; background: #fff; }
.photo-img { width: 100%; height: 150px; object-fit: contain; background: #eef1f5; display: block; }
.photo figcaption { padding: .35rem; display: flex; flex-direction: column; gap: .2rem; }
.photo-add { width: 220px; min-height: 150px; border: 2px dashed var(--border-strong); border-radius: 6px; background: var(--surface-2); color: var(--muted); cursor: pointer; font-weight: 600; }
.photo-add:hover { border-color: var(--accent); color: var(--accent); }
.img-cell { display: flex; flex-direction: column; gap: .2rem; align-items: flex-start; }
.thumb-sm { width: 100px; height: 70px; object-fit: contain; background: #eef1f5; border-radius: 4px; }

/* ---------- documents & chat ---------- */
.docs-layout { display: grid; grid-template-columns: minmax(0, 1fr) 380px; gap: 1rem; align-items: start; }
.docs-right { position: sticky; top: 64px; }
.dropzone { border: 2px dashed var(--border-strong); border-radius: var(--radius); padding: 1rem; text-align: center; color: var(--muted); background: var(--surface); margin-bottom: .8rem; cursor: pointer; }
.dropzone.over, .dropzone:hover { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.upload-list { display: flex; flex-direction: column; gap: .7rem; margin-top: .6rem; max-height: 55vh; overflow: auto; }
.upload-item { border: 1px solid var(--border); border-radius: 6px; padding: .6rem .8rem; }
.upload-item legend { font-weight: 600; font-size: .85rem; padding: 0 .3rem; }
.chat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: .9rem 1rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .4rem; }
.chat-head { display: flex; justify-content: space-between; align-items: center; }
.chat-head h2 { margin: 0; }
.chat-scope { display: flex; flex-wrap: wrap; gap: .3rem .8rem; align-items: center; }
.chat-scope select { padding: .2rem .3rem; border: 1px solid var(--border); border-radius: 5px; }
.chat-log { min-height: 160px; max-height: 52vh; overflow-y: auto; display: flex; flex-direction: column; gap: .55rem; padding: .4rem; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; }
.msg { padding: .55rem .7rem; border-radius: 8px; font-size: .9rem; max-width: 100%; overflow-wrap: anywhere; }
.msg-q { background: var(--accent); color: #fff; align-self: flex-end; max-width: 88%; }
.msg-q .msg-who { color: #dbe7fb; }
.msg-a { background: #fff; border: 1px solid var(--border); }
.msg-a.not-found { border-color: #f0cf9c; background: #fffaf2; }
.msg-who { font-size: .72rem; color: var(--muted); margin-bottom: .25rem; }
.quote { margin: .35rem 0; padding: .35rem .6rem; border-left: 3px solid var(--accent); background: #f6f9fe; font-size: .86rem; }
.quote footer { font-size: .76rem; margin-top: .2rem; }
.cites ol { margin: .2rem 0 .3rem 1.1rem; padding: 0; font-size: .85rem; }
.cite { font-size: .8rem; }
.chat-form { display: flex; gap: .4rem; align-items: stretch; }
.chat-form textarea { resize: vertical; min-height: 44px; }
.chips { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; }
.chip { border: 1px solid var(--border-strong); background: #fff; border-radius: 999px; padding: .15rem .55rem; font-size: .76rem; cursor: pointer; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.spinner { display: inline-block; width: .85rem; height: .85rem; border: 2px solid #c8d3e2; border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.preview-img { max-width: 100%; max-height: 640px; display: block; margin: 0 auto; background: #fff; }
.preview-pdf { width: 100%; height: 640px; border: 0; }
.pages { display: flex; flex-direction: column; gap: .6rem; margin-bottom: .8rem; }
.page-text { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: .6rem .8rem; }
.page-text.target { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.page-body { white-space: pre-wrap; font-size: .87rem; }
mark { background: #ffe58a; padding: 0 .1rem; }
.summary ul { margin: .3rem 0 .4rem 1.1rem; padding: 0; }
.summary li { margin-bottom: .3rem; }
.compare-head { display: grid; grid-template-columns: 1fr 1fr; gap: .8rem; }
.diff-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .5rem; }
.diff { background: var(--surface); border: 1px solid var(--border); border-radius: 6px; padding: .5rem .7rem; }
.diff-kind { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
del { background: #fde2df; color: #8a1c13; text-decoration: line-through; }
ins { background: #dcf1e2; color: #145a2c; text-decoration: none; }

/* ---------- drawing review ---------- */
.review { display: grid; grid-template-columns: minmax(0, 1fr); gap: 1rem; align-items: start; }
@media (min-width: 1750px) { .review { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } .review-left { position: sticky; top: 64px; } }
.doc-title { min-width: 220px; }
.viewer-tools { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin-bottom: .4rem; }
.legend { display: inline-flex; align-items: center; gap: .3rem; color: var(--muted); margin-left: auto; }
.lg { display: inline-block; width: 12px; height: 12px; border-radius: 50%; border: 2px solid; background: #fff; }
.lg-conf { border-color: var(--ok); } .lg-unconf { border-color: var(--bad); } .lg-unclear { border-color: #c27a00; border-style: dashed; }
.viewer { border: 1px solid var(--border); border-radius: 6px; background: #e9edf2; overflow: auto; max-height: 72vh; }
.stage { position: relative; width: 100%; user-select: none; touch-action: none; }
.stage.adding { cursor: crosshair; }
.stage-img { width: 100%; display: block; background: #fff; }
.balloon { position: absolute; transform: translate(-50%, -50%); width: 28px; height: 28px; border-radius: 50%; border: 2.5px solid var(--bad); background: #fff; color: var(--navy); font-weight: 700; font-size: .78rem; cursor: grab; padding: 0; display: grid; place-items: center; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); }
.balloon.confirmed { border-color: var(--ok); }
.balloon.unclear { border-color: #c27a00; border-style: dashed; background: #fff4e5; }
.balloon.sel { box-shadow: 0 0 0 4px rgba(29, 95, 209, .45); z-index: 2; }
.balloon:active { cursor: grabbing; }
.char-grid td { vertical-align: middle; }
.char-grid select { min-width: 92px; }
.char-grid th { position: sticky; top: 0; z-index: 1; }
.unclear-cell { min-width: 150px; }
.unclear-cell input[type=text] { margin-top: .2rem; font-size: .8rem; }
.conf-cell { min-width: 120px; }
.csr-block { border-top: 1px solid #edf0f4; padding: .5rem 0; }

/* ---------- modal & toast ---------- */
.modal-overlay { position: fixed; inset: 0; background: rgba(15, 34, 56, .45); display: grid; place-items: center; z-index: 50; padding: 1rem; }
.modal { background: #fff; border-radius: 10px; width: min(560px, 100%); max-height: calc(100vh - 2rem); display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0, 0, 0, .3); }
.modal-wide { width: min(980px, 100%); }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: .8rem 1rem; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; font-size: 1.05rem; }
.modal-body { padding: 1rem; overflow-y: auto; }
.modal-actions { display: flex; justify-content: flex-end; gap: .5rem; padding: .7rem 1rem; border-top: 1px solid var(--border); background: var(--surface-2); border-radius: 0 0 10px 10px; }
#toast-root { pointer-events: none; position: fixed; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; gap: .5rem; z-index: 60; max-width: min(420px, calc(100vw - 2rem)); }
.toast { background: var(--navy); color: #fff; padding: .65rem .9rem; border-radius: 8px; box-shadow: 0 8px 24px rgba(0, 0, 0, .25); font-size: .88rem; transition: opacity .3s, transform .3s; border-left: 4px solid #7aa7f0; }
.toast-ok { border-left-color: #50c878; } .toast-bad { border-left-color: #ff6b5e; } .toast-warn { border-left-color: #f2b544; }
.toast.out { opacity: 0; transform: translateY(8px); }

/* ---------- responsive ---------- */
@media (max-width: 1180px) {
  .editor, .docs-layout, .review { grid-template-columns: minmax(0, 1fr); }
  .editor-side, .docs-right, .review-left { position: static; max-height: none; }
  .dash-grid { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .sidebar { position: fixed; left: 0; top: 0; z-index: 40; transform: translateX(-100%); transition: transform .2s; box-shadow: 8px 0 24px rgba(0, 0, 0, .25); }
  body.nav-open .sidebar { transform: none; }
  .menu-btn { display: inline-block; }
  #view { padding: 1rem .8rem 3rem; }
  .topbar { padding: .5rem .8rem; flex-wrap: wrap; }
  .user-switch { order: 3; width: 100%; flex-direction: row; align-items: center; gap: .4rem; }
  .kv-grid { grid-template-columns: max-content 1fr; }
  .compare-head { grid-template-columns: 1fr; }
  .filters { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .fw-row { grid-template-columns: 1fr; }
  .fw-label { padding-top: 0; }
}

/* ---------- print ---------- */
#print-root { display: none; }
@media print {
  @page { margin: 14mm; }
  body { background: #fff; font-size: 10.5pt; }
  .demo-banner, .shell, #modal-root, #toast-root { display: none !important; }
  #print-root { display: block; }
  .print-doc { position: relative; }
  .print-watermark { position: fixed; top: 40%; left: 0; right: 0; text-align: center; font-size: 64pt; font-weight: 800; color: rgba(180, 35, 24, .12); transform: rotate(-30deg); z-index: 0; }
  .print-head { display: flex; justify-content: space-between; border-bottom: 2px solid #0f2238; margin-bottom: 6pt; }
  .print-kicker { font-size: 8.5pt; text-transform: uppercase; color: #555; }
  .print-head h1 { font-size: 15pt; }
  .print-org { font-size: 8.5pt; color: #555; }
  .print-notice { border: 1px solid #e3a23b; background: #fff4e5; padding: 4pt 6pt; font-size: 9pt; }
  .print-meta, .print-kv, .print-table { width: 100%; border-collapse: collapse; margin: 4pt 0 8pt; font-size: 8.5pt; }
  .print-meta th, .print-meta td, .print-kv th, .print-kv td, .print-table th, .print-table td { border: 1px solid #999; padding: 2pt 4pt; text-align: left; vertical-align: top; }
  .print-meta th, .print-kv th { background: #f0f2f5; width: 18%; }
  .print-table th { background: #0f2238; color: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .print-doc h2 { font-size: 11.5pt; margin: 10pt 0 3pt; color: #0f2238; }
  .print-doc h3 { font-size: 9.5pt; }
  .print-diagram svg { width: 100%; height: auto; max-height: 120mm; }
  .print-images { display: flex; flex-wrap: wrap; gap: 6pt; }
  .print-images figure { margin: 0; width: 48%; }
  .print-img { width: 100%; max-height: 70mm; object-fit: contain; }
  .print-foot { font-size: 8pt; color: #555; margin-top: 10pt; border-top: 1px solid #999; padding-top: 3pt; }
  section { break-inside: avoid-page; }
}

/* ---------- capability studies ---------- */
.kpi-link { font: inherit; text-align: left; cursor: pointer; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.cap-filters > summary { cursor: pointer; margin-bottom: .5rem; }
.cap-steps { display: flex; flex-wrap: wrap; gap: .35rem; margin: 0 0 1rem; }
.cap-step { display: inline-flex; align-items: center; gap: .4rem; border: 1px solid var(--border-strong); background: #fff; border-radius: 999px; padding: .38rem .8rem; font-weight: 600; font-size: .85rem; cursor: pointer; color: var(--text); }
.cap-step:hover { border-color: var(--accent); }
.cap-step.current { background: var(--accent); color: #fff; border-color: var(--accent); }
.cap-step.current .muted { color: #dbe7fb; }
.cap-step-mark { display: inline-grid; place-items: center; width: 1.2rem; height: 1.2rem; border-radius: 50%; background: #eef1f5; color: var(--steel); font-size: .75rem; }
.cap-step.done .cap-step-mark { background: var(--ok); color: #fff; }
.cap-step.current .cap-step-mark { background: #fff; color: var(--accent); }
.cap-next { display: flex; justify-content: flex-end; margin: .5rem 0 1rem; }
.cap-concls { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: .7rem; margin-bottom: 1rem; }
.cap-concl { background: var(--surface); border: 1px solid var(--border); border-top: 5px solid var(--border-strong); border-radius: var(--radius); padding: .7rem .9rem; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: .25rem; align-items: flex-start; }
.cap-concl-val { font-size: 1.35rem; font-weight: 700; }
.cap-ok { border-top-color: var(--ok); } .cap-warn { border-top-color: var(--warn-line); } .cap-bad { border-top-color: var(--bad); } .cap-muted { border-top-color: #b9c3cf; }
.cap-grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 1rem; }
.cap-grid2 .panel { margin-bottom: 0; }
.cap-grid2 + * { margin-top: 1rem; }
.data tbody tr.muted td { color: var(--muted); }
.cap-method summary { cursor: pointer; font-weight: 600; margin-top: .6rem; }
.method-list { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: .78rem; padding-left: 1.4rem; }
.method-list li { margin-bottom: .2rem; }
.check-list { list-style: none; margin: 0; padding: 0; }
.check-item { display: flex; gap: .6rem; padding: .5rem 0; border-top: 1px solid #edf0f4; }
.check-item:first-child { border-top: 0; }
.check-item ul { margin: .2rem 0 0 1rem; padding: 0; }
.check-icon { flex: 0 0 1.5rem; height: 1.5rem; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #fff; font-size: .8rem; }
.check-ok .check-icon { background: var(--ok); } .check-warn .check-icon { background: var(--warn-line); } .check-bad .check-icon { background: var(--bad); } .check-muted .check-icon { background: #9aa5b3; }
.cap-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(460px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.cap-fig { margin: 0; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); padding: .4rem; box-shadow: var(--shadow); min-width: 0; }
.cap-fig.wide { grid-column: 1 / -1; }
.cap-fig figcaption { padding: .2rem .4rem; }
.cap-chart { width: 100%; height: auto; display: block; }
.cap-chart [data-tip]:focus { outline: 2px solid var(--accent); }
.chart-tip { position: fixed; z-index: 70; pointer-events: none; background: var(--navy); color: #fff; font-size: .8rem; padding: .45rem .6rem; border-radius: 6px; box-shadow: 0 6px 18px rgba(0,0,0,.25); max-width: 300px; }
.chart-tip strong { display: block; margin-bottom: .1rem; }
.cap-data input { min-width: 70px; }
.cap-data input[type=datetime-local] { min-width: 170px; }
.cap-data input.num { text-align: right; min-width: 90px; font-variant-numeric: tabular-nums; }
.cap-data input.invalid { border-color: var(--bad); background: var(--bad-soft); }
.cap-data input.out-spec { border-color: var(--bad); background: #fde2df; color: var(--bad); font-weight: 700; }
.cap-data input.outlier { border-color: var(--warn-line); background: var(--warn-soft); }
.cap-data tr.excluded td { background: #f6f7f9; }
.cap-data tr.excluded input { text-decoration: line-through; color: var(--muted); }
.cap-data-wrap { max-height: 70vh; overflow: auto; }
.cap-data thead th { position: sticky; top: 0; z-index: 1; }
.inc-cell { min-width: 140px; }
.cap-ai-text { width: 100%; font-family: inherit; font-size: .9rem; line-height: 1.5; padding: .6rem; border: 1px solid var(--border-strong); border-radius: 6px; }
.logo-preview { width: 56px; height: 56px; object-fit: contain; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.cap-report-head { display: flex; gap: .8rem; align-items: center; margin-bottom: .5rem; }
.cap-compare tr.diff-row td { background: #fff4e5; font-weight: 600; }
.cap-link-form { flex-wrap: wrap; max-width: none; }
.cap-link-form select { max-width: 360px; }
.import-preview { margin-top: .6rem; }
@media (max-width: 900px) { .cap-charts, .cap-grid2 { grid-template-columns: minmax(0, 1fr); } }

/* ---------- Capability Sixpack ---------- */
.spx-settings > summary { cursor: pointer; padding: .2rem 0; }
.spx-settings[open] > summary { margin-bottom: .6rem; }
.spx-tests { border: 1px solid var(--border); border-radius: var(--radius); padding: .5rem .8rem; display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: .2rem .8rem; }
.spx-tests legend { font-weight: 600; padding: 0 .3rem; }
.spx-tests p { grid-column: 1 / -1; margin: .2rem 0 0; }
.spx-nn { border-top: 1px dashed var(--border); padding-top: .6rem; }
.spx-report { padding: 1rem 1.1rem; }
.spx-head { display: flex; align-items: center; gap: .9rem; border-bottom: 3px solid var(--navy); padding-bottom: .5rem; margin-bottom: .6rem; }
.spx-logo { width: 46px; height: 46px; object-fit: contain; }
.spx-title { flex: 1; min-width: 0; }
.spx-title h2 { margin: 0; font-size: 1.35rem; color: var(--navy); }
.spx-company { font-weight: 700; color: var(--steel); font-size: .9rem; }
.spx-stamp { font-weight: 800; font-size: .85rem; letter-spacing: .04em; border: 2px solid; border-radius: 6px; padding: .3rem .6rem; text-align: center; }
.spx-stamp-ok { color: var(--ok); border-color: var(--ok); background: var(--ok-soft); }
.spx-stamp-draft { color: var(--bad); border-color: var(--bad); background: var(--bad-soft); }
.spx-fields { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0; margin: 0 0 .6rem; border: 1px solid var(--border); border-radius: 6px; overflow: hidden; font-size: .8rem; }
.spx-fields > div { display: flex; gap: .4rem; padding: .22rem .45rem; border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); min-width: 0; }
.spx-fields dt { flex: 0 0 7.4rem; color: var(--muted); font-weight: 600; }
.spx-fields dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.spx-unstable { font-size: .95rem; }
.spx-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .55rem; }
.spx-cell { margin: 0; border: 1px solid var(--border); border-radius: 6px; padding: .3rem; background: #fff; min-width: 0; }
.spx-cell figcaption { font-size: .78rem; font-weight: 700; color: var(--steel); padding: 0 .2rem .2rem; }
.spx-cell .spx-empty { padding: 2rem 1rem; text-align: center; }
.spx-chart { width: 100%; height: auto; display: block; }
.spx-foot { margin-top: .6rem; border-top: 1px solid var(--border); padding-top: .4rem; }
.spx-foot p { margin: .25rem 0; }
.spx-interp { font-family: var(--font); }
@media (max-width: 900px) {
  .spx-grid { grid-template-columns: minmax(0, 1fr); }
  .spx-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 520px) {
  .spx-fields { grid-template-columns: minmax(0, 1fr); }
  .spx-head { flex-wrap: wrap; }
}
@media print {
  .print-sixpack .spx-report { border: 0; box-shadow: none; padding: 0; }
  .print-sixpack .spx-fields { font-size: 7pt; grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .print-sixpack .spx-fields > div { padding: 1pt 3pt; }
  .print-sixpack .spx-fields dt { flex-basis: 5.6rem; }
  .print-sixpack .spx-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 3pt; }
  .print-sixpack .spx-cell { break-inside: avoid; padding: 1pt; }
  .print-sixpack .spx-cell figcaption { display: none; }
  .print-sixpack .spx-foot { font-size: 6.5pt; }
  .print-sixpack .spx-head h2 { font-size: 13pt; }
  .print-sixpack .banner { padding: 2pt 5pt; font-size: 8pt; margin: 2pt 0; }
  .print-sixpack .spx-stamp-ok, .print-sixpack .spx-stamp-draft { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.spx-links .inline-form { flex-wrap: wrap; }
.spx-links .inline-form select { flex: 1 1 14rem; min-width: 0; max-width: 100%; }
