:root {
  --bg: #f4f7f8;
  --surface: #ffffff;
  --surface-alt: #f8fafb;
  --ink: #172329;
  --muted: #63737b;
  --line: #dbe4e7;
  --line-strong: #c6d3d7;
  --brand: #0f5f5b;
  --brand-strong: #0a4542;
  --brand-soft: #e2f1ef;
  --accent: #bc8a3c;
  --danger: #a63d45;
  --danger-soft: #fbe9eb;
  --warning: #9a6614;
  --warning-soft: #fff4da;
  --success: #2f6e4f;
  --success-soft: #e6f4ec;
  --info: #315f83;
  --info-soft: #e8f1f8;
  --shadow: 0 12px 30px rgba(31, 55, 62, .08);
  --radius: 16px;
  --radius-sm: 9px;
  --sidebar: 248px;
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--bg); }
body { margin: 0; min-height: 100vh; color: var(--ink); background: var(--bg); font: 15px/1.5 Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-strong); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
img { display: block; max-width: 100%; }
small { color: var(--muted); }
code, .mono { font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace; font-size: .9em; }
.break-all { word-break: break-all; }
.muted { color: var(--muted); }
.text-danger { color: var(--danger) !important; }
.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; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: var(--sidebar) minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 24px; padding: 24px 18px; background: #10282b; color: #dbe9e9; z-index: 20; }
.brand { display: flex; align-items: center; gap: 12px; color: #fff; padding: 0 8px 14px; border-bottom: 1px solid rgba(255,255,255,.12); }
.brand:hover { color: #fff; }
.brand img { width: 42px; height: 42px; }
.brand span { display: grid; line-height: 1.15; }
.brand strong { font-size: 18px; letter-spacing: .02em; }
.brand small { color: #9fc1bf; font-size: 12px; margin-top: 4px; text-transform: uppercase; letter-spacing: .12em; }
.nav { display: grid; gap: 4px; }
.nav-link { display: flex; align-items: center; min-height: 40px; padding: 9px 12px; border-radius: 9px; color: #bcd0d1; font-weight: 600; transition: background .15s ease, color .15s ease; }
.nav-link:hover { color: #fff; background: rgba(255,255,255,.08); }
.nav-link.active { color: #fff; background: #1d5553; box-shadow: inset 3px 0 #e5b45f; }
.sidebar-footer { margin-top: auto; display: grid; gap: 5px; }
.sidebar-footer small { color: #84a5a6; padding: 12px; line-height: 1.55; }

.main-column { min-width: 0; }
.topbar { position: sticky; top: 0; z-index: 15; display: flex; align-items: center; gap: 16px; height: 76px; padding: 14px clamp(20px, 3vw, 42px); background: rgba(244,247,248,.94); backdrop-filter: blur(14px); border-bottom: 1px solid rgba(198,211,215,.8); }
.global-search { flex: 1; display: flex; max-width: 830px; }
.global-search input { width: 100%; min-width: 0; height: 46px; border: 1px solid var(--line-strong); border-right: 0; border-radius: 12px 0 0 12px; background: var(--surface); padding: 0 16px; color: var(--ink); outline: none; }
.global-search input:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15,95,91,.12); }
.global-search button { border: 0; border-radius: 0 12px 12px 0; background: var(--brand); color: #fff; font-weight: 700; padding: 0 20px; }
.status-pill { margin-left: auto; white-space: nowrap; padding: 8px 11px; border-radius: 999px; background: var(--success-soft); color: var(--success); font-size: 12px; font-weight: 800; }
.icon-button { width: 42px; height: 42px; border: 1px solid var(--line); background: var(--surface); border-radius: 10px; }
.mobile-only { display: none; }

.content { padding: 30px clamp(20px, 3vw, 42px) 60px; max-width: 1800px; margin: 0 auto; }
.page-header { display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; margin-bottom: 24px; }
.page-header h1 { margin: 0; font-size: clamp(28px, 3vw, 42px); line-height: 1.12; letter-spacing: -.035em; }
.page-header p:not(.eyebrow) { margin: 8px 0 0; max-width: 760px; color: var(--muted); }
.eyebrow { margin: 0 0 7px !important; color: var(--brand); font-size: 12px; font-weight: 850; letter-spacing: .14em; text-transform: uppercase; }
.detail-header { align-items: center; }
.actions { display: flex; align-items: center; justify-content: flex-end; gap: 9px; flex-wrap: wrap; }
.actions form { margin: 0; }

.button { display: inline-flex; align-items: center; justify-content: center; min-height: 42px; padding: 9px 16px; border: 1px solid var(--line-strong); border-radius: 10px; background: var(--surface); color: var(--ink); font-weight: 750; line-height: 1.2; text-align: center; transition: transform .1s ease, box-shadow .15s ease, border-color .15s ease; }
.button:hover { color: var(--brand); border-color: var(--brand); box-shadow: 0 4px 14px rgba(31,55,62,.08); }
.button:active { transform: translateY(1px); }
.button.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.button.primary:hover { background: var(--brand-strong); color: #fff; }
.button.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.button.danger:hover { color: #fff; filter: brightness(.92); }
.button.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.button.small { min-height: 34px; padding: 6px 11px; border-radius: 8px; font-size: 13px; }
.button.full { width: 100%; }

.alert { margin: 0 0 22px; padding: 13px 16px; border-radius: 11px; border: 1px solid; font-weight: 650; }
.alert.success { background: var(--success-soft); color: var(--success); border-color: #bddfc9; }
.alert.danger { background: var(--danger-soft); color: var(--danger); border-color: #efc3c8; }

.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.panel + .panel { margin-top: 20px; }
.panel-header { display: flex; justify-content: space-between; align-items: center; gap: 20px; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.panel-header h2 { margin: 0; font-size: 19px; letter-spacing: -.015em; }
.panel-header p { margin: 3px 0 0; color: var(--muted); font-size: 13px; }
.panel-header > a { font-weight: 750; font-size: 13px; }
.stack { display: grid; align-content: start; gap: 20px; }
.stack > .panel { margin-top: 0; }
.two-column { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(320px, .75fr); gap: 24px; align-items: start; }
.two-column.wide-left { grid-template-columns: minmax(0, 1.65fr) minmax(340px, .7fr); }
.lower-grid { margin-top: 24px; }

.kpi-grid { display: grid; grid-template-columns: repeat(6, minmax(145px, 1fr)); gap: 14px; margin-bottom: 24px; }
.kpi-card { display: grid; min-height: 142px; padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); box-shadow: 0 7px 20px rgba(31,55,62,.05); }
.kpi-card:hover { color: var(--ink); border-color: #a9c3c2; transform: translateY(-1px); }
.kpi-card span { color: var(--muted); font-weight: 750; font-size: 13px; }
.kpi-card strong { align-self: end; font-size: 35px; letter-spacing: -.04em; }
.kpi-card small { margin-top: 3px; }
.kpi-card.warning-card { border-color: #e9cf94; background: #fffaf0; }

.summary-strip { display: grid; grid-template-columns: repeat(5, 1fr); margin: 0 0 24px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.summary-strip > div { padding: 17px 20px; border-right: 1px solid var(--line); }
.summary-strip > div:last-child { border-right: 0; }
.summary-strip span { display: block; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .08em; font-weight: 750; }
.summary-strip strong { display: block; margin-top: 4px; font-size: 20px; }

.filter-panel { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 14px; margin-bottom: 18px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: 0 5px 15px rgba(31,55,62,.04); }
.filter-panel input[type="search"] { flex: 1 1 260px; }
.filter-panel select { max-width: 270px; }
input, select, textarea { width: 100%; border: 1px solid var(--line-strong); border-radius: 9px; background: #fff; color: var(--ink); padding: 10px 11px; outline: none; }
input, select { min-height: 42px; }
textarea { resize: vertical; line-height: 1.5; }
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15,95,91,.11); }
input[type="checkbox"] { width: 17px; height: 17px; min-height: 0; accent-color: var(--brand); }
.check-control { display: inline-flex; width: auto; align-items: center; gap: 7px; color: var(--muted); white-space: nowrap; }
.check-control.in-form { min-height: 42px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: var(--surface-alt); color: var(--ink); }
.check-control.danger-zone { color: var(--danger); border-color: #efc3c8; background: var(--danger-soft); }

.form-page { padding: 24px; }
.form-page.narrow { max-width: 980px; margin: 0 auto; }
.form-section + .form-section { margin-top: 28px; padding-top: 26px; border-top: 1px solid var(--line); }
.form-section h2 { margin: 0 0 16px; font-size: 20px; }
.form-stack, .form-section { display: grid; gap: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
label { display: grid; gap: 6px; color: #3d4d54; font-size: 13px; font-weight: 750; }
.form-hint { margin: 0; color: var(--muted); font-size: 13px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 30px; padding-top: 20px; border-top: 1px solid var(--line); }
.upload-form { margin-top: 18px; padding-top: 18px; border-top: 1px solid var(--line); }
.safety-note { padding: 14px 16px; border-left: 4px solid var(--warning); border-radius: 8px; background: var(--warning-soft); color: #6d4b13; }
.danger-panel { border-color: #ecc3c7; }
.danger-panel .panel-header { background: var(--danger-soft); }

.table-panel { padding: 0; }
.table-wrap { width: 100%; overflow-x: auto; }
.table-wrap.tall { max-height: 680px; overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th { padding: 12px 14px; background: var(--surface-alt); color: var(--muted); border-bottom: 1px solid var(--line); text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .075em; white-space: nowrap; }
td { padding: 14px; border-bottom: 1px solid #e7edef; vertical-align: top; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcfc; }
td > span, td > strong, td > a { display: block; }
td small { display: block; margin-top: 4px; max-width: 420px; }
.table-title { color: var(--ink); font-weight: 800; }
.table-title:hover { color: var(--brand); }
.blocked-row { background: #fff8f8; }
.wrap-text { white-space: normal; }
.bulk-actions { display: flex; align-items: center; gap: 9px; padding: 12px 14px; border-bottom: 1px solid var(--line); background: var(--surface-alt); }

.badge { display: inline-flex; align-items: center; width: fit-content; padding: 4px 8px; border-radius: 999px; font-size: 11px; font-weight: 850; line-height: 1.25; }
.badge.neutral { color: #58686f; background: #edf1f2; }
.badge.info { color: var(--info); background: var(--info-soft); }
.badge.success { color: var(--success); background: var(--success-soft); }
.badge.warning { color: var(--warning); background: var(--warning-soft); }
.badge.danger { color: var(--danger); background: var(--danger-soft); }

.stack-list { display: grid; }
.stack-item { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; padding: 14px 20px; color: var(--ink); border-bottom: 1px solid var(--line); }
.stack-item:last-child { border-bottom: 0; }
.stack-item:hover { background: var(--surface-alt); color: var(--ink); }
.stack-item.static:hover { background: transparent; }
.stack-item span { min-width: 0; }
.stack-item strong, .stack-item small { display: block; }
.stack-item .right { max-width: 55%; text-align: right; }

.highlight-box { margin: 20px; padding: 18px; border-radius: 11px; background: var(--brand-soft); }
.highlight-box > strong { color: var(--brand); }
.highlight-box p { margin: 7px 0 0; white-space: pre-wrap; }
.card-list { display: grid; }
.contact-card { display: flex; justify-content: space-between; gap: 20px; padding: 15px 20px; border-bottom: 1px solid var(--line); color: var(--ink); }
.contact-card:last-child { border-bottom: 0; }
.contact-card:hover { color: var(--ink); background: var(--surface-alt); }
.contact-card strong, .contact-card span, .contact-card small { display: block; }
.contact-card span { color: #46575e; margin: 2px 0; }
.contact-meta { text-align: right; }
.contact-meta .badge { margin-left: auto; }

.timeline { padding: 10px 22px 20px; }
.timeline.compact { padding-top: 16px; }
.timeline.large { padding-top: 22px; }
.timeline-item { position: relative; display: grid; grid-template-columns: 15px 1fr; gap: 12px; padding: 11px 0; }
.timeline-item:not(:last-child)::before { content: ""; position: absolute; left: 6px; top: 27px; bottom: -9px; width: 2px; background: var(--line); }
.timeline-dot { width: 13px; height: 13px; margin-top: 5px; border-radius: 50%; background: var(--brand); border: 3px solid var(--brand-soft); box-shadow: 0 0 0 1px var(--brand); z-index: 1; }
.timeline-item strong { font-size: 14px; }
.timeline-item p { margin: 4px 0; white-space: pre-wrap; color: #3b4c53; }
.timeline-item small { display: block; }

.message-list { display: grid; }
.message-list > a { display: grid; grid-template-columns: 31px minmax(0,1fr) auto; align-items: center; gap: 12px; padding: 13px 18px; color: var(--ink); border-bottom: 1px solid var(--line); }
.message-list > a:last-child { border-bottom: 0; }
.message-list > a:hover { background: var(--surface-alt); }
.message-list strong, .message-list small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.message-list time { color: var(--muted); font-size: 12px; white-space: nowrap; }
.direction { display: grid; place-items: center; width: 29px; height: 29px; border-radius: 50%; font-weight: 900; }
.direction.in { background: var(--success-soft); color: var(--success); }
.direction.out { background: var(--info-soft); color: var(--info); }

.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 0; margin: 0; }
.detail-grid.one-col { grid-template-columns: 1fr; }
.detail-field { padding: 13px 20px; border-bottom: 1px solid var(--line); }
.detail-field:last-child { border-bottom: 0; }
.detail-field dt { color: var(--muted); font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .07em; }
.detail-field dd { margin: 4px 0 0; white-space: pre-wrap; }
.prose { padding: 20px; }
.prose h3 { margin: 0 0 5px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.prose h3:not(:first-child) { margin-top: 18px; }
.prose p { margin: 0; white-space: pre-wrap; }
.external-link { display: block; margin: 16px 20px 20px; font-weight: 750; }

.status-box { padding: 15px; border-radius: 10px; margin-bottom: 15px; }
.status-box.ready { background: var(--success-soft); color: var(--success); }
.status-box.blocked { background: var(--danger-soft); color: var(--danger); }
.status-box strong, .status-box p { display: block; margin: 0; }
.status-box p { margin-top: 5px; }

.document-list { display: grid; }
.document-list > a { display: grid; padding: 12px 20px; color: var(--ink); border-bottom: 1px solid var(--line); }
.document-list > a:hover { background: var(--surface-alt); }
.document-list > .muted { padding: 16px 20px; }

.bar-list { display: grid; padding: 10px 20px 20px; }
.bar-list a { display: grid; grid-template-columns: minmax(170px, 1.5fr) minmax(100px, 2fr) 38px; align-items: center; gap: 12px; padding: 8px 0; color: var(--ink); }
.bar-list progress { width: 100%; height: 8px; border: 0; border-radius: 999px; overflow: hidden; background: var(--brand-soft); }
.bar-list progress::-webkit-progress-bar { background: var(--brand-soft); border-radius: 999px; }
.bar-list progress::-webkit-progress-value { background: var(--brand); border-radius: 999px; }
.bar-list progress::-moz-progress-bar { background: var(--brand); border-radius: 999px; }
.bar-list strong { text-align: right; }
.source-panel .detail-field { padding-left: 22px; padding-right: 22px; }

.template-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 16px; }
.template-card { display: grid; min-height: 290px; padding: 20px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.template-card:hover { color: var(--ink); border-color: #a7c2c0; transform: translateY(-1px); }
.template-card-top { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-size: 12px; }
.template-card h2 { margin: 20px 0 9px; font-size: 18px; }
.template-card p { margin: 0; color: #46575e; white-space: pre-wrap; }
.template-card footer { align-self: end; display: grid; gap: 3px; margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line); }
.template-card footer span { color: var(--muted); font-size: 12px; }

.mail-preview { max-height: 470px; overflow: auto; margin: 0; padding: 20px; white-space: pre-wrap; font: 14px/1.6 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--surface-alt); }
.email-paper { padding: 0; }
.email-meta { display: grid; gap: 8px; padding: 20px 24px; border-bottom: 1px solid var(--line); }
.email-meta > div { display: grid; grid-template-columns: 95px 1fr; gap: 12px; }
.email-meta span { color: var(--muted); }
.email-body { padding: 28px; white-space: pre-wrap; font-family: Georgia, "Times New Roman", serif; line-height: 1.7; }
.linked-record { display: grid; margin: 14px 20px; padding: 14px; border-radius: 9px; background: var(--brand-soft); color: var(--brand-strong); }
.linked-record small { margin-top: 3px; }

.issue-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 16px; }
.issue-card { display: grid; padding: 20px; border: 1px solid var(--line); border-left: 4px solid var(--warning); border-radius: 12px; background: var(--surface); box-shadow: var(--shadow); }
.issue-card.resolved { opacity: .68; border-left-color: var(--success); }
.issue-card header, .research-card header { display: flex; justify-content: space-between; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.issue-card h2 { margin: 14px 0 7px; font-size: 18px; }
.issue-card p { margin: 0; }
.issue-card aside { margin-top: 14px; padding: 12px; border-radius: 8px; background: var(--surface-alt); }
.issue-card aside strong { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .06em; }
.issue-card footer { display: flex; justify-content: space-between; align-items: center; gap: 15px; margin-top: 17px; padding-top: 14px; border-top: 1px solid var(--line); }

.research-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 16px; }
.research-card { padding: 19px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); box-shadow: var(--shadow); }
.research-card h2 { margin: 14px 0 3px; font-size: 18px; }
.research-card > p { margin: 0 0 15px; color: var(--muted); }
.research-card dl { margin: 0; display: grid; gap: 8px; }
.research-card dl > div { display: grid; grid-template-columns: minmax(100px,.8fr) minmax(0,1.2fr); gap: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.research-card dt { color: var(--muted); font-size: 12px; }
.research-card dd { margin: 0; overflow-wrap: anywhere; }

.legacy-list { display: grid; }
.legacy-list details { border-bottom: 1px solid var(--line); }
.legacy-list details:last-child { border-bottom: 0; }
.legacy-list summary { display: flex; justify-content: space-between; padding: 15px 20px; cursor: pointer; }
.legacy-list details[open] summary { background: var(--surface-alt); }
.legacy-list dl { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); margin: 0; padding: 15px 20px 22px; gap: 9px 20px; }
.legacy-list dl > div { display: grid; grid-template-columns: 150px 1fr; gap: 10px; padding: 6px 0; border-bottom: 1px solid #edf1f2; }
.legacy-list dt { color: var(--muted); font-size: 12px; }
.legacy-list dd { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }

.file-list { display: grid; }
.file-list a { display: flex; justify-content: space-between; gap: 20px; padding: 14px 20px; color: var(--ink); border-bottom: 1px solid var(--line); }
.file-list a:last-child { border-bottom: 0; }
.file-list a:hover { background: var(--surface-alt); }
.file-list strong, .file-list small { display: block; }

.rule-list { margin: 0; padding: 18px 24px 22px 40px; }
.rule-list li { padding: 4px 0; }
.search-results { display: grid; gap: 12px; }
.search-results > a { display: grid; grid-template-columns: auto 1fr; align-items: start; gap: 14px; padding: 18px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); color: var(--ink); box-shadow: 0 5px 15px rgba(31,55,62,.04); }
.search-results > a:hover { border-color: #a7c2c0; color: var(--ink); }
.search-results h2 { margin: 0; font-size: 18px; }
.search-results p { margin: 2px 0 6px; color: var(--muted); }
.search-results small { color: #46575e; }
.search-results mark { padding: 0 2px; background: #ffeba8; }

.empty-state { padding: 35px 20px; color: var(--muted); text-align: center; }
.pagination { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 15px; margin-top: 20px; color: var(--muted); }
.pagination a:last-child { text-align: right; }
.error-page { display: grid; place-items: center; min-height: 60vh; text-align: center; }
.error-page > strong { font-size: 80px; color: var(--brand-soft); line-height: 1; }
.error-page h1 { margin: 10px 0 0; font-size: 34px; }
.error-page p { max-width: 600px; color: var(--muted); }

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

@media (max-width: 1020px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; left: 0; transform: translateX(-105%); width: var(--sidebar); transition: transform .2s ease; box-shadow: 12px 0 30px rgba(0,0,0,.2); }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .mobile-only { display: inline-grid; place-items: center; }
  .status-pill { display: none; }
  .two-column, .two-column.wide-left { grid-template-columns: 1fr; }
  .topbar { padding-left: 18px; padding-right: 18px; }
  .content { padding-left: 18px; padding-right: 18px; }
}

@media (max-width: 720px) {
  .topbar { height: auto; min-height: 70px; }
  .global-search button { padding: 0 12px; }
  .page-header { align-items: flex-start; flex-direction: column; }
  .actions { justify-content: flex-start; }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0,1fr)); }
  .kpi-card { min-height: 125px; }
  .summary-strip { grid-template-columns: repeat(2,1fr); }
  .summary-strip > div { border-bottom: 1px solid var(--line); }
  .form-grid, .form-grid.three { grid-template-columns: 1fr; }
  .template-grid, .research-grid, .issue-grid { grid-template-columns: 1fr; }
  .filter-panel { align-items: stretch; }
  .filter-panel > * { max-width: none !important; width: 100%; }
  .contact-card, .stack-item { flex-direction: column; }
  .contact-meta, .stack-item .right { max-width: none; text-align: left; }
  .contact-meta .badge { margin-left: 0; }
  .message-list > a { grid-template-columns: 31px minmax(0,1fr); }
  .message-list time { grid-column: 2; }
  .detail-grid { grid-template-columns: 1fr; }
  .legacy-list dl { grid-template-columns: 1fr; }
  .legacy-list dl > div { grid-template-columns: 1fr; }
  .bar-list a { grid-template-columns: 1fr 50px; }
  .bar-list progress { grid-row: 2; grid-column: 1 / -1; }
}

/* V1.1 navigation, auth and drill-down controls */
.top-back { white-space: nowrap; }
.logout-form { margin: 0; }
.signed-in { display: grid; gap: 2px; padding: 10px 12px; margin-bottom: 8px; border-radius: 9px; background: rgba(255,255,255,.06); }
.signed-in strong { color: #fff; font-size: 13px; }
.signed-in small { color: rgba(255,255,255,.65); }
.action-menu { position: relative; }
.action-menu > summary { list-style: none; cursor: pointer; }
.action-menu > summary::-webkit-details-marker { display: none; }
.action-menu-popover { position: absolute; z-index: 20; right: 0; top: calc(100% + 8px); min-width: 320px; max-width: 440px; padding: 7px; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); box-shadow: 0 18px 50px rgba(17,36,43,.18); }
.action-menu-popover a { display: grid; gap: 2px; padding: 11px 12px; border-radius: 8px; color: var(--ink); }
.action-menu-popover a:hover { background: var(--surface-alt); color: var(--ink); }
.action-menu-popover small { color: var(--muted); }
.selected-contact { border-left: 4px solid var(--brand); }
.selected-row { outline: 2px solid var(--brand); outline-offset: -2px; }
.summary-strip.compact { margin: 8px 0 0; box-shadow: none; }
.compact-list { margin-top: 12px; }
.clickable-timeline { color: var(--ink); text-decoration: none; }
.clickable-timeline:hover { background: var(--surface-alt); color: var(--ink); }
.clickable-card { display: block; color: var(--ink); text-decoration: none; }
.clickable-card:hover { color: var(--ink); border-color: #a7c2c0; transform: translateY(-1px); }
.panel-actions { padding: 0 20px 20px; }
.user-actions { display: grid; gap: 12px; min-width: 280px; padding: 14px 0; }
.danger-button { border-color: #c56a6a !important; color: #9c3535 !important; }
.auth-body { margin: 0; min-height: 100vh; background: linear-gradient(135deg, #eef4f4, #f8f9f7); }
.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: 28px; }
.auth-card { width: min(100%, 460px); padding: 32px; border: 1px solid var(--line); border-radius: 18px; background: var(--surface); box-shadow: 0 24px 70px rgba(31,55,62,.14); }
.auth-card.wide { width: min(100%, 680px); }
.auth-card h1 { margin: 5px 0 8px; }
.auth-card > p { color: var(--muted); }
.auth-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 28px; }
.auth-brand img { width: 44px; height: 44px; }
.auth-brand div { display: grid; }
.auth-brand strong { font-size: 20px; }
.auth-brand small { color: var(--muted); }
@media (max-width: 720px) { .top-back { order: 2; } .action-menu-popover { position: fixed; left: 18px; right: 18px; top: auto; min-width: 0; } }

/* Server V2 additions */
.status-pill.server { background: #e7f6f0; color: #145b46; border-color: #b8dfd0; }
.autosave-status { display:inline-flex; align-items:center; min-height:2rem; padding:.35rem .7rem; border-radius:999px; font-size:.85rem; background:#f1f4f7; color:#43505b; }
.autosave-status[data-kind="saved"] { background:#e7f6f0; color:#145b46; }
.autosave-status[data-kind="working"] { background:#fff4db; color:#735100; }
.autosave-status[data-kind="warning"] { background:#fff4db; color:#735100; }
.autosave-status[data-kind="error"] { background:#fde8e8; color:#8d1e1e; }
dialog { border:0; border-radius:18px; padding:0; width:min(680px,calc(100vw - 2rem)); box-shadow:0 24px 80px rgba(0,0,0,.25); }
dialog::backdrop { background:rgba(15,26,36,.48); }
.dialog-card { padding:1.4rem; }
.phone-choice { display:flex; justify-content:space-between; gap:1rem; align-items:center; padding:.9rem 0; border-bottom:1px solid #e3e8ec; }
.phone-choice:last-child { border-bottom:0; }
.lease-warning { padding:1rem; background:#fff4db; border:1px solid #efd99b; border-radius:12px; }
.selected-contact-panel { border:2px solid var(--accent,#c27545); }
.server-note { border-left:4px solid #28745e; padding:.85rem 1rem; background:#eef8f4; border-radius:0 10px 10px 0; }
.inline-form { display:flex; gap:.6rem; align-items:end; flex-wrap:wrap; }
.inline-form label { min-width:12rem; }
.code-note { white-space:pre-wrap; font-family:ui-monospace,SFMono-Regular,Consolas,monospace; background:#f6f7f9; padding:1rem; border-radius:10px; }
.phone-choice > div { display:flex; flex-direction:column; gap:.15rem; min-width:0; }
.phone-choice > div small { display:block; color:var(--muted,#667784); }

/* Server V2.1 integrated Parallelchat functionality */
.full { grid-column: 1 / -1; }
.lower-grid.three { display:grid; grid-template-columns:repeat(3,minmax(0,1fr)); gap:20px; }
.alert.warning { background:var(--warning-soft); color:#6d4b13; border-color:#efd99b; }
.safety-note code, .rule-list code { font-family:ui-monospace,SFMono-Regular,Consolas,monospace; }
.file-list > .empty-state { border-bottom:0; }
.template-card code { overflow-wrap:anywhere; }
details > summary { cursor:pointer; }
td details { min-width:220px; }
td details summary { color:var(--brand); font-weight:750; }
@media (max-width:1020px) { .lower-grid.three { grid-template-columns:1fr; } }

/* Browser V2.1 DIRECTSTART FIX2: filter, follow-up and validation controls */
.filter-panel.filter-grid {
  display: grid;
  grid-template-columns: minmax(280px, 2fr) repeat(3, minmax(180px, 1fr));
  align-items: end;
  gap: 14px;
}
.filter-panel.filter-grid label { min-width: 0; }
.filter-panel.filter-grid input,
.filter-panel.filter-grid select { width: 100%; }
.filter-search { min-width: 0; }
.filter-actions {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.button.disabled,
.button[aria-disabled="true"] {
  opacity: .45;
  pointer-events: none;
  cursor: default;
}
.organization-nav {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 18px;
}
.organization-nav .nav-position {
  color: var(--muted);
  font-size: .9rem;
  font-weight: 700;
}
.follow-up-panel { margin-bottom: 24px; }
.follow-up-form { padding: 0 22px 22px; }
.follow-up-form .inline-form { align-items: center; }
.validation-panel { margin-bottom: 20px; }
.validation-panel.validation-ok { border-left: 4px solid var(--success); }
.validation-panel.validation-blocked { border-left: 4px solid var(--danger); }
.validation-reasons { margin: 10px 0 0; padding-left: 20px; }
.validation-reasons li + li { margin-top: 5px; }
.blocked-card {
  background: #fff8f8;
  border-left: 4px solid var(--danger);
}
.tag-line {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-top: 12px;
}
label small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-weight: 500;
  line-height: 1.35;
}
.form-help {
  color: var(--muted);
  font-size: .9rem;
  line-height: 1.45;
}
@media (max-width: 1180px) {
  .filter-panel.filter-grid { grid-template-columns: repeat(2, minmax(220px, 1fr)); }
}
@media (max-width: 720px) {
  .filter-panel.filter-grid { grid-template-columns: 1fr; }
  .filter-actions { grid-column: 1; }
  .organization-nav { align-items: stretch; }
  .organization-nav .button { flex: 1 1 auto; text-align: center; }
  .organization-nav .nav-position { width: 100%; text-align: center; }
}

/* Browser V2.1 DIRECTSTART FIX3: wide mail reading and live-mail controls */
.email-paper-wide {
  width: 100%;
  max-width: none;
  min-width: 0;
  overflow: visible;
}
.email-paper-wide .email-meta,
.email-paper-wide .email-body {
  box-sizing: border-box;
  width: 100%;
  max-width: none;
}
.email-paper-wide .email-body {
  min-height: 420px;
  overflow-x: auto;
  overflow-wrap: anywhere;
  word-break: normal;
  background: #fff;
}
.mail-settings-form { padding-top: 22px; }
button:disabled,
.button:disabled {
  cursor: not-allowed;
  opacity: .55;
}

/* FIX3: auth brand link */
.auth-brand-link {
  color: inherit;
  text-decoration: none;
  border-radius: 12px;
}
.auth-brand-link:hover,
.auth-brand-link:focus-visible {
  outline: 3px solid rgba(92, 61, 125, .18);
  outline-offset: 5px;
}

/* Browser V2.1 DIRECTSTART FIX6: organization creation and transparent send workspace */
.approved-row { background: #f1faf6; }
.approved-row:hover { background: #e8f6ef; }

.mail-send-workspace {
  display: grid;
  grid-template-columns: minmax(210px, .48fr) minmax(470px, 1.45fr) minmax(310px, .9fr);
  gap: 20px;
  align-items: start;
  margin-top: 24px;
}
.mail-send-workspace > .panel { margin-top: 0; }
.mail-action-body { padding: 20px 22px 22px; }
.mail-test-panel .mail-action-body { display: grid; gap: 16px; }
.mail-test-panel .panel-header { padding-bottom: 16px; }
.mail-send-panel { border-color: var(--line-strong); }
.mail-send-panel .panel-header { background: var(--surface); }
.pending-send-count {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 2px 16px;
  padding: 14px 16px;
  border: 1px solid #b9d9cd;
  border-radius: 11px;
  background: var(--success-soft);
  color: var(--success);
}
.pending-send-count span { font-size: 12px; font-weight: 850; letter-spacing: .06em; text-transform: uppercase; }
.pending-send-count strong { grid-row: 1 / span 2; grid-column: 2; font-size: 30px; line-height: 1; }
.pending-send-count small { color: inherit; }
.approved-recipient-scroll { max-height: 365px; overflow: auto; }
.approved-recipient-item {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: flex-start;
  padding: 13px 16px;
  border-bottom: 1px solid var(--line);
  color: var(--ink);
}
.approved-recipient-item:last-child { border-bottom: 0; }
.approved-recipient-item:hover { color: var(--ink); background: var(--surface-alt); }
.approved-recipient-item span:first-child { min-width: 0; }
.approved-recipient-item strong,
.approved-recipient-item small { display: block; }
.compact-empty { padding: 20px; }
@media (max-width: 1320px) {
  .mail-send-workspace { grid-template-columns: minmax(210px, .45fr) minmax(440px, 1.55fr); }
  .approved-recipient-panel { grid-column: 1 / -1; }
  .approved-recipient-scroll { max-height: 280px; }
}
@media (max-width: 900px) {
  .mail-send-workspace { grid-template-columns: 1fr; }
  .approved-recipient-panel { grid-column: auto; }
}

/* Server V2.2.3: Excel-only data bridge */
.data-count-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
  padding: 20px 22px 24px;
}
.data-count {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface-alt);
}
.data-count span { min-width: 0; overflow-wrap: anywhere; color: var(--muted); }
.data-count strong { font-size: 1.1rem; }
.duplicate-table td { vertical-align: top; }
.duplicate-table td:first-child { width: 46px; text-align: center; }
.duplicate-match { margin-bottom: 10px; padding-bottom: 10px; border-bottom: 1px solid var(--line); }
.duplicate-match:last-child { margin-bottom: 0; padding-bottom: 0; border-bottom: 0; }
.duplicate-actions { display: flex; flex-wrap: wrap; gap: 10px; padding: 18px 22px 22px; border-top: 1px solid var(--line); }

/* Structured diagnostics for deployment and Excel operations */
.diagnostic-alert { display: grid; gap: .8rem; }
.diagnostic-title { display: flex; flex-wrap: wrap; gap: .55rem .9rem; align-items: baseline; }
.diagnostic-title strong { letter-spacing: .02em; }
.diagnostic-grid { display: grid; gap: .55rem; margin: 0; }
.diagnostic-grid > div { display: grid; grid-template-columns: minmax(7rem, 9rem) 1fr; gap: .65rem; }
.diagnostic-grid dt { font-weight: 700; }
.diagnostic-grid dd { margin: 0; min-width: 0; overflow-wrap: anywhere; }
.diagnostic-grid code { font-size: .9em; white-space: normal; }
@media (max-width: 640px) { .diagnostic-grid > div { grid-template-columns: 1fr; gap: .15rem; } }
