:root {
  --ink: #17201d;
  --muted: #66726e;
  --paper: #f3f4ef;
  --panel: #fffef9;
  --line: #d8dcd5;
  --line-strong: #bec6be;
  --accent: #c85832;
  --accent-soft: #f4ded4;
  --green: #1f7056;
  --green-soft: #dcece5;
  --blue: #315e78;
  --blue-soft: #e1ebf0;
  --yellow: #966516;
  --yellow-soft: #f4e9d4;
  --red: #8c3528;
  --shadow: 0 12px 40px rgba(31, 45, 40, .08);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body { margin: 0; min-width: 280px; color: var(--ink); background: var(--paper); font-family: Inter, "Segoe UI", sans-serif; }
button, input { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }
a { color: var(--blue); }
button:focus-visible, a:focus-visible, input:focus-visible, summary:focus-visible { outline: 3px solid rgba(200, 88, 50, .35); outline-offset: 2px; }
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 20; padding: 9px 12px; color: #fff; background: var(--ink); transform: translateY(-160%); }
.skip-link:focus { transform: translateY(0); }

.login-view { min-height: 100vh; padding: 28px 16px; display: grid; place-items: center; background: #1c2925; }
.login-card { width: min(430px, 100%); padding: clamp(24px, 5vw, 42px); background: var(--panel); border-top: 5px solid var(--accent); box-shadow: 0 24px 70px rgba(0, 0, 0, .28); }
.login-card h1 { margin: 9px 0 12px; font: 600 36px/1.05 Georgia, serif; }
.login-card p { color: var(--muted); line-height: 1.5; }
.login-card label { display: block; margin: 16px 0 6px; font-weight: 700; }
.login-card input { width: 100%; padding: 12px; border: 1px solid var(--line-strong); }
.login-card button { width: 100%; margin-top: 20px; padding: 12px; cursor: pointer; }
.form-error { padding: 10px; color: var(--red) !important; background: var(--accent-soft); }

.topbar { min-height: 132px; padding: 28px clamp(20px, 5vw, 72px); display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; color: #f8f5eb; background: #1c2925; border-bottom: 5px solid var(--accent); }
.topbar h1 { margin: 5px 0 0; font: 600 clamp(30px, 4vw, 48px)/1.05 Georgia, serif; }
.topbar p { margin: 9px 0 0; color: #bdc8c3; }
.topbar nav { display: flex; flex-wrap: wrap; gap: 10px; }
.topbar nav a { padding: 9px 14px; color: #fff; border: 1px solid #6b7773; border-radius: 5px; text-decoration: none; }
.topbar nav a:hover { background: rgba(255, 255, 255, .08); }
.account-nav { align-items: center; }
.account-nav span { color: #bdc8c3; font-size: 13px; }
.account-nav button { padding: 9px 14px; color: #fff; background: transparent; border: 1px solid #6b7773; border-radius: 5px; cursor: pointer; }

main { width: min(1720px, 100%); margin: 0 auto; padding: 24px clamp(14px, 4vw, 64px) 64px; }
.eyebrow { color: var(--accent); font-size: 11px; font-weight: 800; letter-spacing: .14em; }
.topbar .eyebrow { color: #e39a7d; }
h2 { margin: 3px 0 0; font: 600 25px/1.15 Georgia, serif; overflow-wrap: anywhere; }
h3 { margin: 3px 0 0; font: 600 21px/1.2 Georgia, serif; }
.muted { color: var(--muted); }

.app-status { min-height: 48px; margin-bottom: 16px; padding: 12px 16px; display: flex; align-items: center; gap: 10px; border-left: 4px solid var(--blue); background: var(--blue-soft); }
.app-status.error { border-color: var(--red); background: var(--accent-soft); }
.app-status button { margin-left: auto; padding: 7px 10px; border: 1px solid var(--line-strong); background: #fff; cursor: pointer; }
.spinner { width: 17px; height: 17px; flex: 0 0 auto; border: 2px solid #aebbb5; border-top-color: var(--green); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.metrics { display: grid; grid-template-columns: repeat(6, minmax(110px, 1fr)); gap: 10px; margin-bottom: 18px; }
.metric { min-width: 0; padding: 14px 16px; background: #e7e9e2; border-left: 3px solid #7c8984; }
.metric strong { display: block; font: 700 25px/1 Georgia, serif; }
.metric span { display: block; margin-top: 5px; color: var(--muted); font-size: 12px; overflow-wrap: anywhere; }
.metric.warn { background: var(--yellow-soft); border-color: var(--yellow); }

.workspace { display: grid; grid-template-columns: minmax(270px, 340px) minmax(0, 1fr); gap: 18px; }
.package-workspace { min-height: 720px; }
.panel { min-width: 0; background: var(--panel); border: 1px solid var(--line); box-shadow: var(--shadow); }
.sidebar, .content-panel, .objects-panel, .graph-panel { padding: 22px; }
.section-heading, .subheading { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 17px; }
.count { min-width: 32px; padding: 5px 8px; text-align: center; color: #fff; background: var(--ink); border-radius: 99px; font-size: 12px; }
.count.secondary { color: var(--ink); background: #e5e8e2; }
.search-label { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
input[type="search"] { width: 100%; padding: 11px 12px; background: #fff; border: 1px solid var(--line); border-radius: 4px; outline: none; }
input[type="search"]:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.list { margin-top: 13px; display: grid; gap: 7px; }
.list-item { width: 100%; min-width: 0; padding: 13px; text-align: left; border: 1px solid transparent; border-bottom-color: var(--line); background: transparent; cursor: pointer; }
.list-item:hover, .list-item.active { border-color: #c8cec7; background: #f4f1e9; }
.list-item.active { border-left: 4px solid var(--accent); }
.list-item strong, .list-item span, .list-item small { display: block; overflow-wrap: anywhere; }
.list-item span { margin-top: 5px; color: var(--muted); font-size: 12px; }
.list-item small { margin-top: 6px; color: #7d8783; font-size: 11px; }
.list-item-top { display: flex !important; align-items: flex-start; justify-content: space-between; gap: 8px; margin: 0 !important; color: var(--ink) !important; font-size: inherit !important; }
.list-item-top b { flex: 0 0 auto; padding: 3px 6px; color: var(--green); background: var(--green-soft); border-radius: 3px; font-size: 11px; }

.package-content[aria-busy="true"] { opacity: .65; }
.package-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.package-identity { min-width: 0; }
.package-head h2 { font-size: clamp(27px, 3vw, 38px); }
.package-head p { margin: 8px 0 0; overflow-wrap: anywhere; }
.current-block { flex: 0 0 auto; padding: 12px 15px; text-align: right; color: #fff; background: var(--green); border-radius: 5px; }
.current-block span, .current-block strong { display: block; }
.current-block span { font-size: 10px; text-transform: uppercase; letter-spacing: .08em; opacity: .8; }
.current-block strong { margin-top: 3px; font: 700 27px/1 Georgia, serif; }
.hero-actions, .compact-actions, .card-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.hero-actions { margin: 18px 0 12px; }
.button-link { display: inline-flex; min-height: 38px; padding: 9px 13px; align-items: center; justify-content: center; color: var(--ink); background: #fff; border: 1px solid var(--line-strong); border-radius: 4px; text-decoration: none; font-weight: 700; }
.button-link:hover { border-color: var(--green); }
.button-link.primary { color: #fff; background: var(--green); border-color: var(--green); }
.button-link.small { min-height: 31px; padding: 6px 9px; font-size: 12px; }
.button-link.disabled { color: #909995; background: #eff1ed; }
.text-link { padding: 5px; font-size: 12px; font-weight: 700; }
.contract-note { color: var(--muted); font-size: 11px; }

.summary-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 9px; margin-bottom: 24px; }
.summary-card { min-width: 0; padding: 13px; background: #f1f3ee; border-top: 3px solid #9baa9f; }
.summary-card strong, .summary-card span { display: block; overflow-wrap: anywhere; }
.summary-card strong { font: 700 19px/1.2 Georgia, serif; }
.summary-card span { margin-top: 5px; color: var(--muted); font-size: 11px; }

.package-detail-grid { display: grid; grid-template-columns: minmax(205px, 255px) minmax(0, 1fr); gap: 24px; align-items: start; }
.history-column { min-width: 0; }
.revision-detail { min-width: 0; padding-left: 24px; border-left: 1px solid var(--line); }
.revision-detail-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; min-height: 70px; }
.revision-detail-head h3 { font-size: 28px; }
.revision-detail-head p { margin: 6px 0 0; font-size: 12px; overflow-wrap: anywhere; }
.vertical-timeline { position: relative; display: grid; gap: 5px; }
.vertical-timeline::before { content: ""; position: absolute; top: 12px; bottom: 12px; left: 13px; width: 2px; background: #cad4ce; }
.timeline-entry { position: relative; width: 100%; min-width: 0; padding: 10px 8px 10px 33px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px; text-align: left; background: transparent; border: 1px solid transparent; cursor: pointer; }
.timeline-entry:hover { background: #f4f5f0; }
.timeline-entry.active { background: #eff5f1; border-color: #b7c9c0; }
.timeline-marker { position: absolute; left: 8px; width: 12px; height: 12px; background: var(--panel); border: 3px solid #8ca095; border-radius: 50%; z-index: 1; }
.timeline-entry.current .timeline-marker { background: var(--green); border-color: var(--green); box-shadow: 0 0 0 4px var(--green-soft); }
.timeline-body, .timeline-title, .timeline-body > span, .timeline-body small { display: block; min-width: 0; overflow-wrap: anywhere; }
.timeline-body > span:not(.timeline-title) { margin-top: 3px; color: var(--muted); font-size: 11px; }
.timeline-title { display: flex; align-items: center; gap: 5px; }
.timeline-title strong { font-size: 15px; }
.timeline-title b { padding: 2px 5px; color: var(--green); background: var(--green-soft); border-radius: 99px; font-size: 9px; text-transform: uppercase; }
.timeline-body small { margin-top: 4px; color: #7a8580; font-size: 10px; }
.timeline-index { color: #a3aba7; font: 700 11px Georgia, serif; }

.tabs { margin-top: 15px; display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--line); }
.tab { padding: 10px 12px; border: 0; border-bottom: 3px solid transparent; background: transparent; cursor: pointer; }
.tab.active { border-color: var(--accent); color: var(--accent); font-weight: 700; }
.tab-panel { min-width: 0; padding-top: 17px; }
.panel-intro { margin-bottom: 12px; padding: 12px 14px; display: flex; justify-content: space-between; gap: 12px; background: #eff1ec; border-left: 3px solid var(--blue); }
.panel-intro strong, .panel-intro span { display: block; }
.panel-intro span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.panel-intro b { align-self: center; font: 700 22px Georgia, serif; }

.file-card-list { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 280px), 1fr)); gap: 9px; }
.file-card { min-width: 0; padding: 13px; background: #fff; border: 1px solid var(--line); border-radius: 4px; }
.file-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.file-card-head > div { min-width: 0; }
.file-card-head strong { display: block; margin-top: 6px; overflow-wrap: anywhere; }
.file-type { display: inline-block; padding: 2px 5px; color: var(--blue); background: var(--blue-soft); border-radius: 2px; font-size: 9px; font-weight: 800; }
.file-facts { margin: 12px 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.file-facts div { min-width: 0; }
.file-facts .wide { grid-column: 1 / -1; }
.file-facts dt { color: var(--muted); font-size: 9px; text-transform: uppercase; letter-spacing: .08em; }
.file-facts dd { margin: 2px 0 0; font-size: 12px; overflow-wrap: anywhere; }
.file-facts code { font-size: 11px; }
.logical-key { margin: 9px 0; color: #84908b; font-size: 10px; overflow-wrap: anywhere; }
.state { display: inline-block; padding: 3px 7px; border-radius: 99px; font-size: 10px; font-weight: 800; text-transform: uppercase; }
.state.proposed { color: #8a5710; background: #f6e7ca; }
.state.confirmed, .state.inherited { color: var(--green); background: var(--green-soft); }
.state.rejected { color: var(--red); background: var(--accent-soft); }

.delta-list, .conflict-list, .event-list, .observation-list, .change-card-list { display: grid; gap: 8px; }
.delta-card { min-width: 0; padding: 11px 13px; display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 10px; border: 1px solid var(--line); background: #fff; }
.delta-card.upsert { border-left: 3px solid var(--green); }
.delta-card.remove { border-left: 3px solid var(--red); }
.delta-symbol { font: 700 25px/1 Georgia, serif; }
.delta-card strong, .delta-card span, .delta-card small { display: block; overflow-wrap: anywhere; }
.delta-card span:not(.delta-symbol) { margin-top: 3px; color: var(--muted); font-size: 11px; }
.delta-card small { margin-top: 4px; color: #8b9591; }
.change-summary { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 12px; }
.change-summary div { padding: 12px; background: #eff1ec; }
.change-summary strong, .change-summary span { display: block; }
.change-summary strong { font: 700 23px Georgia, serif; }
.change-summary span { margin-top: 4px; color: var(--muted); font-size: 10px; }
.placeholder-card, .alert-card, .success-card { margin-top: 10px; padding: 14px; border: 1px dashed #adb8b1; background: #f7f7f3; }
.placeholder-card strong, .placeholder-card p, .alert-card strong, .alert-card span, .success-card strong, .success-card span { display: block; }
.placeholder-card p { margin: 6px 0 0; color: var(--muted); font-size: 12px; }
.alert-card { border-style: solid; border-color: #dec38f; background: var(--yellow-soft); }
.alert-card span, .success-card span { margin-top: 5px; color: var(--muted); font-size: 11px; overflow-wrap: anywhere; }
.success-card { border-style: solid; border-color: #adcbc0; background: var(--green-soft); }
.conflict-card { min-width: 0; padding: 12px; border-left: 3px solid var(--yellow); background: #fff; }
.conflict-card strong, .conflict-card span { display: block; overflow-wrap: anywhere; }
.conflict-card span { margin: 5px 0 8px; color: var(--muted); font-size: 11px; }
.event-card { position: relative; min-width: 0; padding: 10px 10px 10px 30px; border-left: 1px solid #b7c2bc; }
.event-dot { position: absolute; left: -5px; top: 14px; width: 9px; height: 9px; background: var(--green); border-radius: 50%; }
.event-card strong, .event-card span, .event-card small { display: block; }
.event-card span { margin-top: 3px; color: var(--muted); font-size: 11px; }
.event-card small { margin-top: 2px; color: #8b9490; }
.inline-empty { min-height: 70px; padding: 18px; display: grid; place-items: center; gap: 3px; text-align: center; color: var(--muted); background: #f5f6f1; border: 1px dashed var(--line-strong); }
.inline-empty strong, .inline-empty span { display: block; }
.inline-loading { padding: 14px; display: flex; align-items: center; gap: 9px; color: var(--muted); }

.empty-state { min-height: 560px; display: grid; place-items: center; padding: 30px; color: var(--muted); text-align: center; }
.empty-state > div { max-width: 420px; }
.empty-state h2 { color: var(--ink); }
.empty-state p { line-height: 1.55; }
.empty-icon { display: block; margin-bottom: 12px; color: var(--accent); font: 700 42px Georgia, serif; }

.secondary-workspace { margin-top: 20px; border: 1px solid var(--line); background: #e9ece6; }
.secondary-workspace > summary { padding: 17px 20px; cursor: pointer; list-style-position: outside; }
.secondary-workspace > summary span { display: inline-grid; gap: 3px; margin-left: 5px; }
.secondary-workspace > summary small { color: var(--muted); font-weight: 400; }
.secondary-workspace[open] > summary { border-bottom: 1px solid var(--line); }
.document-workspace { padding: 18px; min-height: 620px; }
.document-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 15px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.document-head h2 { font-size: 29px; }
.revision-badge { padding: 11px 14px; color: #fff; background: var(--green); border-radius: 3px; font-weight: 800; }
.timeline { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 22px 4px 16px; }
.revision-node { display: flex; align-items: center; }
.revision-node button { min-width: 55px; height: 40px; color: var(--green); background: var(--green-soft); border: 2px solid var(--green); border-radius: 2px; font-weight: 800; cursor: pointer; }
.revision-node button.active { color: #fff; background: var(--green); }
.observation-card, .change-card { min-width: 0; padding: 13px; border: 1px solid var(--line); background: #fff; }
.observation-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.observation-card p { margin: 8px 0; overflow-wrap: anywhere; }
.observation-card > small { display: block; color: var(--muted); overflow-wrap: anywhere; }
.observation-foot { margin-top: 10px; display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px; color: var(--muted); font-size: 11px; }
.change-card > div { display: flex; align-items: flex-start; gap: 8px; }
.change-card strong { overflow-wrap: anywhere; }
.change-card > small { display: block; margin: 7px 0; color: var(--muted); }
.change-card pre { max-height: 240px; margin: 0; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; color: #45524d; font: 11px/1.45 ui-monospace, Consolas, monospace; }

.lower-grid { padding: 0 18px 18px; display: grid; grid-template-columns: 1.08fr .92fr; gap: 18px; }
.switch { color: var(--muted); font-size: 12px; white-space: nowrap; }
.object-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; margin-top: 14px; max-height: 310px; overflow: auto; }
.object-card { min-width: 0; padding: 12px; text-align: left; background: #f2f3ee; border: 1px solid var(--line); cursor: pointer; }
.object-card strong, .object-card span { display: block; overflow-wrap: anywhere; }
.object-card span { color: var(--muted); font-size: 11px; margin-top: 5px; }
.drawer { margin-top: 14px; padding: 16px; border-top: 3px solid var(--accent); background: #faf7ef; }
.occurrence { min-width: 0; margin: 12px 0; padding: 11px; border: 1px solid var(--line); background: #fff; overflow-wrap: anywhere; }
.occurrence blockquote { margin: 8px 0; color: #41504b; }
.actions { display: flex; flex-wrap: wrap; gap: 6px; }
.actions button { padding: 5px 9px; border: 1px solid var(--line); background: #fff; cursor: pointer; }
.actions button.primary { color: #fff; background: var(--green); border-color: var(--green); }
.graph-canvas { position: relative; min-height: 400px; overflow: hidden; background: linear-gradient(#f3f4ef 1px, transparent 1px), linear-gradient(90deg, #f3f4ef 1px, transparent 1px); background-size: 24px 24px; border: 1px solid var(--line); }
.graph-canvas svg { position: absolute; inset: 0; width: 100%; height: 100%; }
.graph-node-svg rect { fill: #fff; stroke-width: 3; rx: 5; }
.graph-node-svg text { fill: var(--ink); font-size: 13px; font-weight: 700; text-anchor: middle; dominant-baseline: middle; }
.graph-node-svg.document rect { stroke: var(--accent); }
.graph-node-svg.revision rect { stroke: var(--green); }
.graph-node-svg.component rect { stroke: var(--blue); }
.graph-node-svg.object rect { stroke: var(--yellow); rx: 24; }
.legend { color: var(--muted); font-size: 11px; }
.dot { display: inline-block; width: 9px; height: 9px; margin: 0 3px 0 10px; border: 2px solid; }
.dot.document { border-color: var(--accent); }
.dot.revision { border-color: var(--green); }
.dot.component { border-color: var(--blue); }
.dot.object { border-color: var(--yellow); border-radius: 50%; }
.toast { position: fixed; right: 20px; bottom: 20px; z-index: 10; max-width: min(360px, calc(100vw - 28px)); padding: 12px 16px; color: #fff; background: var(--ink); box-shadow: var(--shadow); opacity: 0; transform: translateY(12px); transition: .2s; pointer-events: none; }
.toast.visible { opacity: 1; transform: translateY(0); }

@media (max-width: 1180px) {
  .metrics { grid-template-columns: repeat(3, 1fr); }
  .summary-grid { grid-template-columns: repeat(2, 1fr); }
  .package-detail-grid { grid-template-columns: 210px minmax(0, 1fr); gap: 16px; }
  .revision-detail { padding-left: 16px; }
}

@media (max-width: 900px) {
  .workspace, .lower-grid { grid-template-columns: 1fr; }
  .package-workspace { min-height: 0; }
  .package-list { grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr)); }
  .package-detail-grid { grid-template-columns: 1fr; }
  .revision-detail { padding: 20px 0 0; border-left: 0; border-top: 1px solid var(--line); }
  .vertical-timeline::before { display: none; }
  .timeline-entry { padding-left: 13px; }
  .timeline-marker { display: none; }
  .empty-state { min-height: 220px; }
  .document-workspace, .lower-grid { padding: 14px; }
}

@media (max-width: 620px) {
  .topbar { min-height: 0; padding: 23px 18px; align-items: flex-start; flex-direction: column; }
  .topbar p { font-size: 13px; }
  main { padding: 14px 8px 46px; }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .metric { padding: 12px; }
  .sidebar, .content-panel, .objects-panel, .graph-panel { padding: 14px; }
  .package-head, .revision-detail-head, .document-head { flex-direction: column; }
  .current-block { width: 100%; text-align: left; }
  .hero-actions, .compact-actions { align-items: stretch; }
  .hero-actions .button-link, .compact-actions .button-link { flex: 1 1 130px; }
  .contract-note { width: 100%; }
  .summary-grid, .change-summary { grid-template-columns: 1fr 1fr; }
  .package-list, .vertical-timeline, .file-card-list { grid-template-columns: 1fr; }
  .tabs { gap: 0; }
  .tab { flex: 1 1 33%; padding: 9px 7px; font-size: 12px; }
  .panel-intro { align-items: flex-start; }
  .secondary-workspace > summary { padding: 14px; }
  .secondary-workspace > summary small { display: block; margin-top: 4px; }
  .graph-canvas { min-height: 330px; }
}

@media (max-width: 380px) {
  .metrics, .summary-grid, .change-summary { grid-template-columns: 1fr; }
  .tab { flex-basis: 50%; }
  .file-facts { grid-template-columns: 1fr; }
  .file-facts .wide { grid-column: auto; }
}

@media (prefers-reduced-motion: reduce) {
  * { scroll-behavior: auto !important; transition: none !important; }
  .spinner { animation-duration: 1.8s; }
}
