:root {
    --bg: #F6F3EC;
    --panel: #FBF9F4;
    --raised: #F4F1EA;
    --line: #E3DED2;
    --text: #14161C;
    --muted: #6B6F7B;
    --accent: #3F6B0F;
    --high: #D32F2F;
    --medium: #F57C00;
    --low: #1976D2;
    
    --radius: 14px;
    
    --font-display: 'Lora', ui-serif, Georgia, serif;
    --font-ui: 'Manrope', system-ui, sans-serif;
    --font-mono: 'Fira Code', ui-monospace, monospace;
    
    --ease-out: cubic-bezier(0.2, 0.8, 0.2, 1);
}

[data-theme="dark"] {
    --bg: #0A0B0F;
    --panel: #101218;
    --raised: #161922;
    --line: #232733;
    --text: #ECEEF3;
    --muted: #8C93A6;
    --accent: #B6F25A;
    --high: #FF5D73;
    --medium: #FFB020;
    --low: #6EA8FF;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    padding: 0;
    background-color: var(--bg);
    color: var(--text);
    font-family: var(--font-ui);
    font-size: 15px;
    line-height: 1.6;
    overflow-x: hidden;
    transition: background-color 0.3s var(--ease-out), color 0.3s var(--ease-out);
}

/* Ambient Background */
.app-bg-glow {
    position: fixed;
    top: 0; left: 0; right: 0; height: 100vh;
    pointer-events: none;
    z-index: -1;
    background-image: 
        radial-gradient(circle at 50% -10%, color-mix(in srgb, var(--accent) 6%, transparent) 0%, transparent 60%),
        radial-gradient(var(--line) 1px, transparent 1px);
    background-size: 100% 100%, 24px 24px;
    opacity: 0.8;
}

/* Typography Utilities */
.mono { font-family: var(--font-mono); letter-spacing: 0.04em; }
.text-muted { color: var(--muted); }
.uppercase { text-transform: uppercase; }
.tracking { letter-spacing: 0.06em; font-size: 11px; font-weight: 500; }

/* Scrollbars */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--muted); }

::selection {
    background-color: color-mix(in srgb, var(--accent) 25%, transparent);
    color: var(--text);
}

/* Buttons & Inputs */
button {
    font-family: inherit;
    color: inherit;
    transition: all 0.2s var(--ease-out);
}
button:focus-visible, input:focus-visible, textarea:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

.icon-btn {
    background: transparent;
    border: 1px solid transparent;
    border-radius: 8px;
    width: 32px; height: 32px;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer; color: var(--muted);
}
.icon-btn:hover { background: var(--raised); color: var(--text); }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 0 16px; height: 36px;
    border-radius: 8px; font-weight: 500; font-size: 14px;
    cursor: pointer; border: 1px solid transparent;
}
.primary-btn {
    background: var(--text); color: var(--bg);
}
.primary-btn:hover { opacity: 0.9; transform: translateY(-1px); }
.secondary-btn {
    background: var(--raised); border-color: var(--line); color: var(--text);
}
.secondary-btn:hover { background: var(--line); }
.ghost-btn {
    display: inline-flex; align-items: center; gap: 6px;
    background: transparent; color: var(--muted);
    padding: 6px 12px; border-radius: 6px; cursor: pointer; font-size: 14px;
}
.ghost-btn:hover { background: var(--raised); color: var(--text); }

.kbd {
    font-family: var(--font-mono); font-size: 11px;
    padding: 2px 6px; border-radius: 4px;
    background: var(--raised); border: 1px solid var(--line);
    color: var(--muted);
}
.primary-btn .kbd { background: color-mix(in srgb, var(--bg) 20%, transparent); border: none; color: inherit; opacity: 0.8; }

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.04), 0 4px 20px rgba(0,0,0,0.02);
}

/* Header */
.topbar {
    display: flex; justify-content: space-between; align-items: center;
    padding: 16px 24px; position: relative; z-index: 10;
}
.logo {
    display: flex; align-items: center; gap: 8px;
    font-weight: 500; font-size: 15px; letter-spacing: -0.02em;
}
.logo-icon { color: var(--text); }
[data-theme="dark"] .logo-icon { color: var(--text); }

/* Phases */
.phase { display: none; opacity: 0; transform: translateY(10px); transition: opacity 0.4s var(--ease-out), transform 0.4s var(--ease-out); }
.phase.active { display: block; opacity: 1; transform: translateY(0); }

/* Phase 1: Compose */
.compose-container {
    max-width: 720px; margin: 8vh auto 0; padding: 0 24px;
    position: relative; z-index: 2; text-align: center;
}
.display-title {
    font-family: var(--font-display);
    font-size: clamp(48px, 6vw, 64px);
    line-height: 1.02; margin: 0 0 16px 0; font-weight: 400;
}
.subtitle {
    font-size: 17px; color: var(--muted); margin: 0 auto 48px; max-width: 500px;
}

.compose-panel {
    position: relative; text-align: left; overflow: hidden;
    display: flex; flex-direction: column;
}
#text-input {
    width: 100%; height: 280px; padding: 24px;
    background: transparent; border: none; color: var(--text);
    font-family: var(--font-ui); font-size: 15px; resize: none;
    line-height: 1.6;
}
.compose-footer {
    display: flex; justify-content: space-between; align-items: center;
    padding: 12px 16px; border-top: 1px solid var(--line);
    background: var(--raised);
}
.compose-actions-left { display: flex; align-items: center; gap: 16px; }

/* Segmented Control */
.lang-segmented {
    display: inline-flex; background: var(--line); padding: 2px; border-radius: 6px;
}
.lang-segmented label { cursor: pointer; }
.lang-segmented input { display: none; }
.lang-segmented span {
    display: inline-block; padding: 4px 10px; font-size: 13px; font-weight: 500;
    border-radius: 4px; color: var(--muted); transition: all 0.2s;
}
.lang-segmented input:checked + span { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,0.05); }

/* D&D Overlay */
.drop-overlay {
    position: absolute; inset: 0; background: color-mix(in srgb, var(--panel) 90%, transparent);
    backdrop-filter: blur(4px); z-index: 10; display: none;
    align-items: center; justify-content: center;
    border: 2px dashed var(--accent); border-radius: var(--radius);
}
.drop-overlay.dragover { display: flex; }
.drop-content { text-align: center; color: var(--accent); font-weight: 500; display: flex; flex-direction: column; align-items: center; gap: 12px; }

/* Samples & Trust */
.samples {
    display: flex; justify-content: center; gap: 12px; margin-top: 24px;
}
.sample-chip {
    background: var(--panel); border: 1px solid var(--line); border-radius: 20px;
    padding: 6px 14px; font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; gap: 8px;
    cursor: pointer;
}
.sample-chip:hover { border-color: var(--muted); }
.trust-labels {
    display: flex; justify-content: center; align-items: center; gap: 16px; margin-top: 48px;
    font-family: var(--font-mono); font-size: 11px; color: var(--muted);
}
.trust-labels .dot { opacity: 0.5; }
.trust-labels span { display: flex; align-items: center; gap: 6px; }

/* Skeleton bg */
.skeleton-doc {
    position: absolute; top: 20%; left: 50%; transform: translateX(-50%);
    width: 600px; height: 500px; border: 1px solid var(--line); border-radius: 8px;
    background: var(--panel); z-index: 1; opacity: 0.4;
    padding: 40px; pointer-events: none; mask-image: linear-gradient(to bottom, black 0%, transparent 100%);
    -webkit-mask-image: linear-gradient(to bottom, black 0%, transparent 100%);
}
.skel-line { height: 12px; background: var(--line); border-radius: 4px; margin-bottom: 16px; }
.w-40 { width: 40%; } .w-80 { width: 80%; } .w-90 { width: 90%; } .w-70 { width: 70%; } .w-100 { width: 100%; } .w-30 { width: 30%; }
.h1 { height: 24px; margin-bottom: 32px; } .h2 { height: 18px; } .mt { margin-top: 32px; }
.scan-line {
    position: absolute; top: 0; left: 0; right: 0; height: 1px; background: var(--accent);
    box-shadow: 0 0 10px var(--accent); animation: scan 4s linear infinite;
}
@keyframes scan { 0% { top: 0; opacity: 0; } 10% { opacity: 1; } 90% { opacity: 1; } 100% { top: 100%; opacity: 0; } }

/* PHASE 2 & 3: Live Analysis */
#phase-analysis {
    padding: 0 24px 24px; max-width: 1400px; margin: 0 auto;
    display: flex; flex-direction: column; height: calc(100vh - 72px);
}

.graph-container {
    height: 180px; position: relative; margin-bottom: 24px;
    transition: height 0.4s var(--ease-out); flex-shrink: 0;
}
.graph-container.collapsed { height: 48px; cursor: pointer; overflow: hidden; }
.graph-legend {
    position: absolute; bottom: 0; right: 0; display: flex; gap: 16px;
    font-family: var(--font-mono); font-size: 11px; color: var(--muted);
}
.legend-item { display: flex; align-items: center; gap: 6px; }
.legend-circle { width: 8px; height: 8px; border-radius: 50%; border: 1px solid var(--muted); }
.legend-circle.code { border-radius: 2px; }

/* SVG Graph internal classes */
.node circle, .node rect { fill: var(--panel); stroke: var(--line); stroke-width: 1.5; transition: all 0.3s; }
.node text.label { fill: var(--text); font-family: var(--font-mono); font-size: 11px; text-anchor: middle; }
.node text.count { fill: var(--muted); font-family: var(--font-mono); font-size: 9px; text-anchor: middle; font-weight: 500; }
.edge path { fill: none; stroke: var(--line); stroke-width: 1.5; transition: stroke 0.3s, stroke-dashoffset 0.3s; }
.edge.active path { stroke: var(--accent); stroke-dasharray: 4 4; animation: dash-flow 1s linear infinite; }
.edge.done path { stroke: var(--accent); stroke-dasharray: none; opacity: 0.4; }
.node.active circle, .node.active rect { stroke: var(--accent); filter: drop-shadow(0 0 4px color-mix(in srgb, var(--accent) 40%, transparent)); }
.node.done circle, .node.done rect { stroke: var(--muted); }
.node.done text.count { fill: var(--accent); }
@keyframes dash-flow { to { stroke-dashoffset: -8; } }

/* Review Header */
.review-header { flex-shrink: 0; margin-bottom: 24px; animation: slide-down 0.4s var(--ease-out); }
@keyframes slide-down { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }
.review-title-row { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 16px; }
.verdict-sentence { font-family: var(--font-display); font-size: 40px; margin: 0; font-weight: 400; line-height: 1.1; }
.score-meter-container { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; }
.score-number { font-size: 32px; font-weight: 500; line-height: 1; color: var(--text); }
.score-ticks { display: flex; gap: 2px; height: 12px; }
.score-tick { width: 6px; background: var(--line); border-radius: 1px; transition: background 0.2s; }
.score-tick.filled.high { background: var(--high); }
.score-tick.filled.medium { background: var(--medium); }
.score-tick.filled.low { background: var(--low); }

.review-controls { display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid var(--line); padding-bottom: 16px; }
.severity-filters { display: flex; gap: 8px; }
.chip {
    background: transparent; border: 1px solid var(--line); border-radius: 16px; padding: 4px 12px;
    font-size: 13px; font-weight: 500; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; color: var(--muted);
}
.chip.active { background: var(--panel); border-color: var(--muted); color: var(--text); }
.pip { width: 8px; height: 8px; border-radius: 50%; }
.pip.high { background: var(--high); } .pip.medium { background: var(--medium); } .pip.low { background: var(--low); }
.review-actions { display: flex; gap: 12px; }
.search-box { display: flex; align-items: center; gap: 8px; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 0 12px; height: 32px; }
.search-box input { border: none; background: transparent; color: var(--text); font-family: var(--font-ui); font-size: 13px; outline: none; width: 120px; }
.search-box svg { color: var(--muted); }

/* Columns */
.analysis-columns {
    display: flex; gap: 24px; flex: 1; min-height: 0;
}
.doc-panel { flex: 6; overflow: hidden; position: relative; display: flex; }
.doc-content {
    flex: 1; overflow-y: auto; padding: 32px 48px;
    font-family: var(--font-display); font-size: 19px; line-height: 1.8;
    max-width: 80ch; margin: 0 auto; scroll-behavior: smooth;
}
.doc-clause { position: relative; margin-bottom: 1.5em; padding-left: 48px; }
.doc-clause.hanging { padding-left: 0; }
.clause-number {
    position: absolute; left: 0; top: 0.4em; font-family: var(--font-mono); font-size: 12px; color: var(--muted);
}
.doc-clause h3 { font-family: var(--font-ui); font-size: 15px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text); margin: 0 0 0.5em; padding-left: 48px; }
.highlight { border-bottom: 2px solid transparent; cursor: pointer; transition: background 0.2s; border-radius: 2px; }
.highlight.high { border-color: var(--high); } .highlight.medium { border-color: var(--medium); } .highlight.low { border-color: var(--low); }
.highlight:hover, .highlight.active { background: color-mix(in srgb, currentColor 10%, transparent); }

.heat-minimap { width: 16px; background: var(--raised); border-left: 1px solid var(--line); position: relative; cursor: pointer; }
.heat-tick { position: absolute; left: 0; right: 0; height: 2px; opacity: 0.8; }
.heat-tick.high { background: var(--high); } .heat-tick.medium { background: var(--medium); } .heat-tick.low { background: var(--low); }

/* Findings Feed */
.findings-panel { flex: 4; display: flex; flex-direction: column; border: 1px solid var(--line); border-radius: var(--radius); background: var(--bg); overflow: hidden; }
.findings-header { display: flex; justify-content: space-between; align-items: center; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--panel); }
.status-indicator { display: flex; align-items: center; gap: 8px; }
.live-dot { width: 14px; height: 14px; border-radius: 50%; border: 2px solid color-mix(in srgb, var(--accent) 30%, transparent); border-top-color: var(--accent); animation: spin 1s linear infinite; }
@keyframes spin { 100% { transform: rotate(360deg); } }

.findings-list { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.finding-card {
    background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 16px;
    animation: slide-in 0.28s var(--ease-out); cursor: pointer; transition: transform 0.2s, border-color 0.2s;
    position: relative; overflow: hidden;
}
.finding-card::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: transparent; }
.finding-card.high::before { background: var(--high); } .finding-card.medium::before { background: var(--medium); } .finding-card.low::before { background: var(--low); }
.finding-card:hover, .finding-card.selected { transform: translateX(-4px); border-color: var(--muted); }
@keyframes slide-in { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

.fc-header { display: flex; justify-content: space-between; margin-bottom: 8px; align-items: flex-start; }
.fc-title { font-weight: 500; font-size: 15px; margin: 0; line-height: 1.4; color: var(--text); }
.fc-clause-chip { font-family: var(--font-mono); font-size: 11px; background: var(--raised); padding: 2px 6px; border-radius: 4px; color: var(--muted); }
.fc-desc { font-size: 13px; color: var(--muted); margin: 0 0 12px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.fc-status { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; padding: 4px 8px; border-radius: 12px; background: var(--raised); color: var(--text); }
.fc-status.reviewing { animation: shimmer 2s infinite linear; background: linear-gradient(90deg, var(--raised) 0%, var(--panel) 50%, var(--raised) 100%); background-size: 200% 100%; color: var(--muted); }
@keyframes shimmer { to { background-position: -200% 0; } }

/* Rejected */
.rejected-group { padding: 0 16px 16px; }
.rejected-toggle { width: 100%; text-align: left; background: transparent; border: 1px dashed var(--line); border-radius: 8px; padding: 8px 12px; font-size: 13px; color: var(--muted); cursor: pointer; display: flex; align-items: center; gap: 8px; }
.rejected-toggle svg { transition: transform 0.2s; }
.rejected-toggle[aria-expanded="true"] svg { transform: rotate(180deg); }
.rejected-list { display: none; margin-top: 8px; flex-direction: column; gap: 8px; }
.rejected-list.open { display: flex; }
.finding-card.rejected { opacity: 0.6; filter: grayscale(1); }
.finding-card.rejected .fc-title { text-decoration: line-through; }

/* Slide Over Detail */
.slide-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); backdrop-filter: blur(2px); z-index: 100; opacity: 0; pointer-events: none; transition: opacity 0.3s; display: flex; justify-content: flex-end; }
.slide-overlay.open { opacity: 1; pointer-events: auto; }
.slide-panel { width: 480px; max-width: 100vw; background: var(--panel); border-left: 1px solid var(--line); height: 100%; transform: translateX(100%); transition: transform 0.3s var(--ease-out); display: flex; flex-direction: column; box-shadow: -4px 0 24px rgba(0,0,0,0.1); }
.slide-overlay.open .slide-panel { transform: translateX(0); }
.slide-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 24px; border-bottom: 1px solid var(--line); }
.slide-kbd-hints { display: flex; gap: 8px; }
.slide-content { padding: 24px; overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 24px; }

.detail-quote { font-family: var(--font-display); font-size: 17px; line-height: 1.6; padding: 16px; background: var(--raised); border-radius: 8px; border-left: 2px solid var(--accent); }
.detail-section h4 { font-size: 12px; font-family: var(--font-mono); text-transform: uppercase; color: var(--muted); margin: 0 0 8px; letter-spacing: 0.05em; }
.detail-section p { margin: 0; font-size: 14px; color: var(--text); }

.counter-clause-box {
    background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 16px;
    border-left: 3px solid var(--accent); position: relative;
}
.counter-clause-box p { font-family: var(--font-display); font-size: 16px; margin: 0 0 16px; color: var(--text); }
.counter-clause-box .copy-btn { position: absolute; top: 12px; right: 12px; }

/* Toasts */
.toast-container { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 1000; pointer-events: none; }
.toast { background: var(--text); color: var(--bg); padding: 8px 16px; border-radius: 20px; font-size: 13px; font-weight: 500; animation: toast-up 0.3s var(--ease-out), toast-down 0.3s 3s forwards; box-shadow: 0 4px 12px rgba(0,0,0,0.1); }
@keyframes toast-up { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }
@keyframes toast-down { to { opacity: 0; transform: translateY(10px); } }

@media (max-width: 1100px) {
    .analysis-columns { flex-direction: column; }
    .doc-panel, .findings-panel { height: 500px; flex: none; }
}
@media (max-width: 600px) {
    .slide-panel { width: 100vw; }
}
