:root {
    --bg-dark: #080c17;
    --card-bg: #111827;
    --card-border: rgba(255, 255, 255, 0.08);
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --accent: #10b981;
    --accent-glow: rgba(16, 185, 129, 0.25);
    --warning: #f59e0b;
    --danger: #ef4444;
    --text-main: #f9fafb;
    --text-muted: #9ca3af;
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', system-ui, -apple-system, sans-serif; }

body {
    background-color: var(--bg-dark);
    color: var(--text-main);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    background-image: radial-gradient(circle at 50% 0%, rgba(59, 130, 246, 0.08), transparent 60%);
}

header {
    background-color: rgba(17, 24, 39, 0.8);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--card-border);
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 50;
}

.brand {
    font-size: 1.3rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: #60a5fa;
    letter-spacing: -0.02em;
}

.badge-owner {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.2), rgba(5, 150, 105, 0.3));
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.4);
    font-size: 0.72rem;
    padding: 0.25rem 0.6rem;
    border-radius: 6px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

nav {
    display: flex;
    gap: 0.5rem;
    background: rgba(17, 24, 39, 0.6);
    padding: 0.75rem 2rem;
    border-bottom: 1px solid var(--card-border);
    flex-wrap: wrap;
}

nav a {
    color: var(--text-muted);
    text-decoration: none;
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s ease;
}

nav a.active, nav a:hover {
    color: #ffffff;
    background: var(--primary);
    box-shadow: 0 4px 12px rgba(59, 130, 246, 0.3);
}

main {
    flex: 1;
    padding: 2rem;
    max-width: 1300px;
    margin: 0 auto;
    width: 100%;
}

h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
    color: #f9fafb;
    letter-spacing: -0.02em;
}

p { color: var(--text-muted); margin-bottom: 1.5rem; line-height: 1.5; }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    display: block;
    margin: 0 0 1.5rem 0;
}

.metric-title { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.08em; font-weight: 600; }
.metric-val { font-size: 2.2rem; font-weight: 700; margin-top: 0.4rem; color: var(--text-main); letter-spacing: -0.03em; }

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
    font-size: 0.9rem;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    overflow: hidden;
}

th, td {
    padding: 0.85rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--card-border);
}

th { color: var(--text-muted); font-weight: 600; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; background: rgba(255,255,255,0.02); }

.status-pill {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.3rem 0.75rem;
    border-radius: 9999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.status-succeeded { background: rgba(16, 185, 129, 0.15); color: #34d399; border: 1px solid rgba(16, 185, 129, 0.3); }

input, select, button {
    padding: 0.6rem 1rem;
    background: #1f2937;
    color: #ffffff;
    border: 1px solid var(--card-border);
    border-radius: 8px;
    font-size: 0.9rem;
    outline: none;
    transition: all 0.2s ease;
}

input:focus, select:focus { border-color: var(--primary); box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.2); }

button, .btn {
    background: var(--primary);
    color: white;
    border: none;
    padding: 0.6rem 1.2rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 600;
    transition: all 0.2s ease;
    box-shadow: 0 2px 8px rgba(59, 130, 246, 0.25);
}

button:hover, .btn:hover { background: var(--primary-hover); transform: translateY(-1px); }

code, .secret { font-family: 'JetBrains Mono', monospace; font-size: 0.85rem; background: rgba(255, 255, 255, 0.06); padding: 0.2rem 0.4rem; border-radius: 4px; color: #93c5fd; }

/* Login Box Styling */
.login-box {
    max-width: 420px;
    margin: 4rem auto;
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 2.5rem;
    box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.login-box label {
    display: block;
    margin-bottom: 1.25rem;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.login-box input {
    width: 100%;
    margin-top: 0.4rem;
}

.login-box button {
    width: 100%;
    margin-top: 1rem;
    padding: 0.75rem;
    font-size: 0.95rem;
}

.alert-danger {
    background: rgba(239, 68, 68, 0.15);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #f87171;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 1.5rem;
    font-size: 0.9rem;
}

/* Lab Studio Tab Bar */
.lab-tabs {
    display: flex;
    gap: 0.5rem;
    border-bottom: 1px solid var(--card-border);
    margin-bottom: 1.5rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
}

.lab-tab-btn {
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-muted);
    border: 1px solid var(--card-border);
    padding: 0.65rem 1.25rem;
    border-radius: 10px;
    cursor: pointer;
    font-size: 0.88rem;
    font-weight: 600;
    transition: all 0.2s ease;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    white-space: nowrap;
}

.lab-tab-btn:hover {
    color: #ffffff;
    background: rgba(255, 255, 255, 0.08);
}

.lab-tab-btn.active {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.3), rgba(37, 99, 235, 0.4));
    color: #ffffff;
    border-color: rgba(59, 130, 246, 0.6);
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.25);
}

.lab-tab-content {
    display: none;
}

.lab-tab-content.active {
    display: block;
}

/* Canvas Toolbar Controls */
.canvas-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.4);
    padding: 0.5rem 0.75rem;
    border-radius: 8px 8px 0 0;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-bottom: none;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.tool-group {
    display: flex;
    gap: 0.35rem;
    align-items: center;
}

.tool-btn {
    background: rgba(255, 255, 255, 0.08);
    color: #e5e7eb;
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    font-size: 0.78rem;
    cursor: pointer;
    font-weight: 500;
    transition: all 0.15s ease;
}

.tool-btn:hover, .tool-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary-hover);
}

/* Interactive Canvas Viewport */
.canvas-viewport {
    position: relative;
    overflow: hidden;
    height: 520px;
    background: #040812;
    border-radius: 0 0 8px 8px;
    border: 1px solid rgba(255, 255, 255, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: grab;
}

.canvas-viewport:active {
    cursor: grabbing;
}

canvas#ocr_canvas {
    transition: filter 0.2s ease;
    transform-origin: center center;
}

/* Line Item Syncing */
.line-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.45rem 0.75rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    font-size: 0.84rem;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.15s ease;
}

.line-item:hover, .line-item.active {
    background: rgba(59, 130, 246, 0.18);
    border-color: rgba(59, 130, 246, 0.4);
}

/* Timeline Components */
.timeline {
    position: relative;
    padding-left: 1.5rem;
    border-left: 2px solid rgba(255, 255, 255, 0.1);
    margin: 1rem 0;
}

.timeline-node {
    position: relative;
    margin-bottom: 1.25rem;
}

.timeline-node::before {
    content: '';
    position: absolute;
    left: -1.95rem;
    top: 0.25rem;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid var(--bg-dark);
}

.timeline-node.status-ok::before { background: #34d399; }
.timeline-node.status-active::before { background: #f59e0b; box-shadow: 0 0 8px #f59e0b; }
.timeline-node.status-warning::before { background: #ef4444; }
.timeline-node.status-info::before { background: #60a5fa; }

.timeline-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 600;
}

.timeline-title {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text-main);
    margin-top: 0.15rem;
}

.timeline-desc {
    font-size: 0.82rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

/* Badges & Metrics */
.badge-math-pass {
    background: rgba(16, 185, 129, 0.15);
    color: #34d399;
    border: 1px solid rgba(16, 185, 129, 0.4);
    padding: 0.6rem 1rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.badge-math-fail {
    background: rgba(239, 68, 68, 0.15);
    color: #f87171;
    border: 1px solid rgba(239, 68, 68, 0.4);
    padding: 0.6rem 1rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* A credential page that does not say whose credential it is asks the operator
   to store a secret for a client they cannot see named. Stated above the key
   itself, before the "store this now" instruction they are about to follow. */
.key-owner {
    margin: 0 0 0.5rem;
    font-size: 0.92rem;
    color: var(--text-muted);
}

.key-owner code {
    color: #93c5fd;
}

/* The third state. Deliberately NEUTRAL, not green and not red: the check was
   declined because a component the receipt prints could not be read, and that
   is a declared gap rather than either a pass or an accusation. Colouring it
   green would be the exact lie this state exists to stop; colouring it red
   would be the false positive it exists to stop. */
.badge-math-unknown {
    background: rgba(148, 163, 184, 0.14);
    color: #cbd5e1;
    border: 1px solid rgba(148, 163, 184, 0.38);
    padding: 0.6rem 1rem;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.tax-line-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.82rem;
}

.tax-line-table caption {
    text-align: left;
    color: var(--text-muted);
    font-size: 0.78rem;
    padding-bottom: 0.35rem;
}

.tax-line-table th,
.tax-line-table td {
    text-align: left;
    padding: 0.3rem 0.5rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.07);
}

/* The Lab's layout columns.
   These used to be inline `grid-template-columns` declarations, which no media
   query can override without !important -- so on a 390px phone the upload
   panel's fixed 280px second column pushed the document 85px wider than the
   viewport and the "Run OCR" button sat off-screen. A form the user has to
   scroll sideways to reach is a form they do not complete. Measured by
   tests/browser/lab.spec.js, which asserts zero horizontal overflow at 390px. */
.lab-grid-upload { grid-template-columns: 1fr 280px; }
.lab-grid-inspector { grid-template-columns: 1fr 420px; }
.lab-grid-halves { grid-template-columns: 1fr 1fr; }
.lab-grid-quarters { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 860px) {
    .lab-grid-upload,
    .lab-grid-inspector,
    .lab-grid-halves {
        grid-template-columns: 1fr;
    }
    .lab-grid-quarters {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .lab-grid-quarters {
        grid-template-columns: 1fr;
    }
}

.tax-state-read { color: #34d399; }
.tax-state-unreadable { color: #fbbf24; }
.tax-state-absent { color: #94a3b8; }

.field-card {
    background: rgba(0, 0, 0, 0.25);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 0.85rem;
    transition: transform 0.15s ease;
}

.field-card:hover {
    border-color: rgba(59, 130, 246, 0.4);
}

/* Premium operations surfaces */
.eyebrow {
    display: block;
    margin-bottom: 0.65rem;
    color: #8fb7ff;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.16em;
    text-transform: uppercase;
}

.ops-hero,
.runbook-hero {
    position: relative;
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 2rem;
    margin-bottom: 1.5rem;
    padding: 2.25rem;
    overflow: hidden;
    border: 1px solid rgba(121, 158, 255, 0.18);
    border-radius: 22px;
    background:
        radial-gradient(circle at 85% 15%, rgba(90, 130, 246, 0.22), transparent 34%),
        linear-gradient(135deg, rgba(18, 29, 52, 0.98), rgba(9, 15, 29, 0.98));
    box-shadow: 0 26px 70px rgba(0, 0, 0, 0.28);
}

.ops-hero::after,
.runbook-hero::after {
    position: absolute;
    right: -80px;
    bottom: -130px;
    width: 270px;
    height: 270px;
    border: 1px solid rgba(130, 168, 255, 0.16);
    border-radius: 50%;
    content: "";
}

.ops-hero h1,
.runbook-hero h1 {
    max-width: 760px;
    margin-bottom: 0.7rem;
    font-size: clamp(2rem, 4vw, 3.4rem);
    line-height: 1.02;
    letter-spacing: -0.055em;
}

.ops-hero p,
.runbook-hero p {
    max-width: 720px;
    margin: 0;
    font-size: 1rem;
}

.btn-secondary {
    position: relative;
    z-index: 1;
    flex: 0 0 auto;
    color: #dce8ff;
    text-decoration: none;
    background: rgba(255, 255, 255, 0.055);
    border: 1px solid rgba(146, 177, 255, 0.23);
    box-shadow: none;
}

.btn-secondary:hover {
    color: #fff;
    background: rgba(96, 145, 255, 0.16);
}

.ops-verdict {
    --verdict-rgb: 156, 168, 188;
    --verdict-color: #aeb9ca;
    position: relative;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 1.15rem;
    align-items: center;
    margin-bottom: 1rem;
    padding: 1.35rem 1.5rem;
    overflow: hidden;
    border: 1px solid rgba(var(--verdict-rgb), 0.2);
    border-radius: 18px;
    background:
        linear-gradient(100deg, rgba(var(--verdict-rgb), 0.11), transparent 42%),
        rgba(13, 21, 36, 0.92);
    box-shadow:
        inset 0 1px 0 rgba(255, 255, 255, 0.035),
        0 18px 45px rgba(0, 0, 0, 0.18);
}

.ops-verdict::after {
    position: absolute;
    right: 12%;
    bottom: -90px;
    width: 190px;
    height: 150px;
    border-radius: 50%;
    background: rgba(var(--verdict-rgb), 0.08);
    filter: blur(34px);
    content: "";
    pointer-events: none;
}

.ops-verdict-ok {
    --verdict-rgb: 78, 224, 173;
    --verdict-color: #4ee0ad;
}

.ops-verdict-safe {
    --verdict-rgb: 121, 168, 255;
    --verdict-color: #90b5ff;
}

.ops-verdict-warn {
    --verdict-rgb: 248, 190, 97;
    --verdict-color: #f8be61;
}

.ops-verdict-bad {
    --verdict-rgb: 255, 124, 134;
    --verdict-color: #ff7c86;
}

.ops-verdict-mark {
    display: grid;
    width: 3rem;
    height: 3rem;
    place-items: center;
    border: 1px solid rgba(var(--verdict-rgb), 0.32);
    border-radius: 14px;
    color: var(--verdict-color);
    background: rgba(var(--verdict-rgb), 0.1);
    box-shadow: 0 0 28px rgba(var(--verdict-rgb), 0.12);
}

.ops-verdict-mark span {
    width: 0.7rem;
    height: 0.7rem;
    border: 2px solid currentColor;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 16px currentColor;
}

.ops-verdict-copy {
    position: relative;
    z-index: 1;
}

.ops-verdict-copy .eyebrow {
    margin-bottom: 0.35rem;
    color: var(--verdict-color);
}

.ops-verdict-copy h2 {
    margin-bottom: 0.35rem;
    font-size: 1.35rem;
    letter-spacing: -0.03em;
}

.ops-verdict-copy p {
    max-width: 760px;
    margin: 0;
    font-size: 0.87rem;
}

.ops-verdict-action {
    position: relative;
    z-index: 1;
    display: grid;
    justify-items: end;
    gap: 0.55rem;
    min-width: 180px;
}

.ops-verdict-action > span {
    padding: 0.35rem 0.7rem;
    border: 1px solid rgba(var(--verdict-rgb), 0.24);
    border-radius: 999px;
    color: var(--verdict-color);
    background: rgba(var(--verdict-rgb), 0.08);
    font-size: 0.71rem;
    font-weight: 750;
    letter-spacing: 0.055em;
    text-transform: uppercase;
}

.ops-verdict-action a {
    color: #b8c8e5;
    font-size: 0.78rem;
    font-weight: 650;
    text-decoration: none;
}

.ops-verdict-action a:hover { color: #fff; }

.ops-safe-boundary {
    display: grid;
    gap: 0.35rem;
    margin: 1.2rem 0;
    padding: 1rem;
    border: 1px solid rgba(121, 168, 255, 0.2);
    border-radius: 16px;
    background: linear-gradient(135deg, rgba(121, 168, 255, 0.1), rgba(16, 22, 35, 0.42));
}

.ops-safe-boundary strong { color: #eef4ff; }
.ops-safe-boundary span { color: var(--muted); line-height: 1.55; }

.client-hero { margin-bottom: 1rem; }

.onboarding-rail {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.75rem;
    margin: 0 0 1.25rem;
}

.onboarding-rail article {
    display: flex;
    gap: 0.85rem;
    align-items: center;
    min-width: 0;
    padding: 1rem;
    border: 1px solid rgba(159, 176, 205, 0.14);
    border-radius: 18px;
    background:
        linear-gradient(145deg, rgba(255, 255, 255, 0.045), transparent 58%),
        rgba(14, 19, 31, 0.78);
    box-shadow: 0 16px 38px rgba(0, 0, 0, 0.18);
}

.onboarding-rail article > span {
    display: grid;
    place-items: center;
    flex: 0 0 2.35rem;
    height: 2.35rem;
    border: 1px solid rgba(78, 224, 173, 0.28);
    border-radius: 999px;
    color: #6ee7b7;
    background: rgba(78, 224, 173, 0.08);
    font-size: 0.75rem;
    font-weight: 800;
    letter-spacing: 0.08em;
}

.onboarding-rail div { display: grid; gap: 0.2rem; min-width: 0; }
.onboarding-rail strong { color: #f3f7ff; }
.onboarding-rail small { color: var(--muted); line-height: 1.4; }

.client-alert {
    display: flex;
    gap: 0.45rem;
    align-items: baseline;
    margin-bottom: 1rem;
    padding: 0.9rem 1rem;
    border-radius: 14px;
}

.client-create { margin-bottom: 1rem; }

.client-create-form {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.9rem;
}

.client-create-form label {
    display: grid;
    gap: 0.42rem;
    color: #dbe6f7;
    font-size: 0.82rem;
    font-weight: 700;
}

.client-create-form label small {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 500;
    line-height: 1.45;
}

.client-field-wide { grid-column: span 3; }

.client-create-submit {
    grid-column: span 3;
    display: flex;
    gap: 1rem;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.15rem;
    padding-top: 1rem;
    border-top: 1px solid rgba(159, 176, 205, 0.12);
}

.client-create-submit span {
    max-width: 56rem;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.55;
}

.client-create-submit strong { color: #eef4ff; }

.client-actions,
.client-verify-form {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    align-items: center;
}

.client-verify-form input {
    min-width: 13rem;
}

.key-reveal-hero {
    border-color: rgba(52, 211, 153, 0.28);
    background:
        radial-gradient(circle at 86% 20%, rgba(52, 211, 153, 0.12), transparent 29%),
        linear-gradient(135deg, rgba(15, 23, 42, 0.97), rgba(16, 38, 52, 0.96));
}

.key-reveal-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.55fr) minmax(18rem, 0.85fr);
    gap: 1rem;
    margin-top: 1rem;
}

.key-secret-panel,
.key-next-panel {
    min-width: 0;
}

.key-once-badge {
    color: #fbbf24;
    border: 1px solid rgba(251, 191, 36, 0.34);
    background: rgba(251, 191, 36, 0.08);
    border-radius: 999px;
    padding: 0.35rem 0.7rem;
    font-size: 0.74rem;
    font-weight: 700;
    white-space: nowrap;
}

.key-secret-panel .secret {
    margin-top: 1.2rem;
    padding: 1.1rem 1.2rem;
    overflow-x: auto;
    border: 1px solid rgba(52, 211, 153, 0.35);
    border-radius: 12px;
    background: rgba(2, 6, 23, 0.9);
    box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.02);
}

.key-secret-panel .secret code {
    color: #6ee7b7;
    font-size: 0.95rem;
    white-space: nowrap;
}

.key-copy-row {
    display: flex;
    align-items: center;
    gap: 0.9rem;
    margin-top: 0.8rem;
}

.key-facts {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.8rem;
    margin: 1.4rem 0 0;
    padding-top: 1.2rem;
    border-top: 1px solid var(--card-border);
}

.key-facts div {
    min-width: 0;
}

.key-facts dt {
    color: var(--text-muted);
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.key-facts dd {
    margin: 0.35rem 0 0;
}

.key-next-panel h2 {
    margin: 0.35rem 0 1rem;
}

.key-next-list {
    display: grid;
    gap: 0.9rem;
    padding: 0;
    margin: 0;
    list-style: none;
}

.key-next-list li {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 0.75rem;
    align-items: start;
}

.key-next-list li > span {
    display: grid;
    place-items: center;
    width: 2rem;
    height: 2rem;
    border: 1px solid rgba(96, 165, 250, 0.34);
    border-radius: 50%;
    color: #93c5fd;
    font: 700 0.72rem/1 'JetBrains Mono', monospace;
}

.key-next-list strong,
.key-next-list small {
    display: block;
}

.key-next-list small {
    color: var(--text-muted);
    line-height: 1.45;
    margin-top: 0.15rem;
}

.key-return {
    display: inline-block;
    margin-top: 1.3rem;
}

.ops-metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 0.85rem;
    margin-bottom: 1rem;
}

.ops-metric {
    min-height: 156px;
    padding: 1.25rem;
    border: 1px solid rgba(255, 255, 255, 0.075);
    border-radius: 16px;
    background: linear-gradient(145deg, rgba(20, 30, 50, 0.9), rgba(13, 20, 35, 0.96));
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
}

.ops-metric-accent {
    border-color: rgba(71, 215, 166, 0.18);
    background: linear-gradient(145deg, rgba(16, 49, 49, 0.72), rgba(12, 25, 34, 0.96));
}

.ops-label {
    display: block;
    margin-bottom: 1.1rem;
    color: #8290a8;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.09em;
    text-transform: uppercase;
}

.ops-metric strong {
    display: flex;
    align-items: center;
    min-height: 2.15rem;
    font-size: 1.35rem;
    letter-spacing: -0.025em;
}

.ops-metric strong i {
    width: 0.55rem;
    height: 0.55rem;
    margin-right: 0.55rem;
    border-radius: 50%;
    background: currentColor;
    box-shadow: 0 0 16px currentColor;
}

.ops-metric small {
    display: block;
    margin-top: 0.75rem;
    color: #7f8ca2;
    font-size: 0.76rem;
    line-height: 1.4;
}

.state-ok { color: #4ee0ad; }
.state-busy { color: #79a8ff; }
.state-warn { color: #f8be61; }
.state-bad { color: #ff7c86; }
.state-muted { color: #9ca8bc; }

.ops-notice {
    display: flex;
    gap: 1rem;
    margin: 1rem 0 1.5rem;
    padding: 1.1rem 1.25rem;
    border: 1px solid rgba(112, 151, 245, 0.17);
    border-radius: 14px;
    background: rgba(41, 67, 119, 0.13);
}

.ops-notice-icon {
    display: grid;
    flex: 0 0 2rem;
    width: 2rem;
    height: 2rem;
    place-items: center;
    border: 1px solid rgba(123, 162, 255, 0.28);
    border-radius: 10px;
    color: #91b4ff;
    background: rgba(74, 119, 226, 0.12);
}

.ops-notice strong { color: #edf3ff; }
.ops-notice p { margin: 0.3rem 0 0; font-size: 0.88rem; }

.ops-layout {
    display: grid;
    grid-template-columns: minmax(0, 1.7fr) minmax(300px, 0.7fr);
    gap: 1rem;
    align-items: start;
    margin-bottom: 1rem;
}

.ops-layout > * { min-width: 0; }

.ops-panel {
    margin: 0 0 1rem;
    padding: 1.35rem;
    border: 1px solid rgba(255, 255, 255, 0.075);
    border-radius: 18px;
    background: rgba(15, 23, 39, 0.88);
    box-shadow: 0 18px 45px rgba(0, 0, 0, 0.16);
}

.ops-panel h2 {
    margin-bottom: 0.4rem;
    font-size: 1.25rem;
    letter-spacing: -0.025em;
}

.ops-panel-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1rem;
}

.ops-search {
    display: flex;
    gap: 0.5rem;
}

.ops-search input { min-width: 220px; }
.panel-copy { margin: 0 0 1.1rem; font-size: 0.86rem; }

.ops-command-form {
    display: grid;
    gap: 0.8rem;
}

.ops-command-form label {
    color: #aab5c7;
    font-size: 0.76rem;
    font-weight: 650;
    letter-spacing: 0.02em;
}

.ops-command-form input,
.ops-command-form select {
    width: 100%;
    margin-top: 0.38rem;
}

.table-shell {
    margin-top: 1rem;
    overflow-x: auto;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
}

.table-shell table {
    margin: 0;
    border: 0;
    border-radius: 0;
}

.table-shell tbody tr:last-child td { border-bottom: 0; }
.muted, .ops-caption { color: #8390a5; }
.ops-caption { font-size: 0.76rem; }

.empty-state {
    padding: 2rem;
    color: #8895a9;
    text-align: center;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.runbook-hero {
    display: block;
    padding-top: 4.25rem;
}

.back-link {
    position: absolute;
    top: 1.4rem;
    left: 2.25rem;
    z-index: 1;
    color: #9ebdff;
    font-size: 0.82rem;
    text-decoration: none;
}

.runbook-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1rem;
}

.runbook-step {
    display: flex;
    gap: 1.1rem;
    min-height: 170px;
    padding: 1.35rem;
    border: 1px solid rgba(255, 255, 255, 0.075);
    border-radius: 18px;
    background: linear-gradient(145deg, rgba(18, 28, 47, 0.92), rgba(11, 18, 31, 0.96));
}

.runbook-step > span {
    flex: 0 0 auto;
    color: #75a2ff;
    font: 600 0.78rem/1.4 'JetBrains Mono', monospace;
}

.runbook-step h2 { margin-bottom: 0.5rem; font-size: 1.05rem; }
.runbook-step p { margin: 0; font-size: 0.87rem; }

/* Job proof ledger: canonical OCR first, advisory AI second */
.detail-heading,
.section-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 1.25rem;
}

.detail-heading {
    margin-bottom: 1.5rem;
    padding: 0.3rem 0;
}

.detail-heading h1 { margin-bottom: 0.35rem; font-size: clamp(2rem, 4vw, 3.25rem); }
.detail-lede, .section-intro { max-width: 760px; margin: 0; }
.section-heading h2 { margin: 0.15rem 0 0; font-size: 1.45rem; letter-spacing: -0.025em; }

.job-facts {
    position: relative;
    overflow: hidden;
    border-color: rgba(116, 158, 255, 0.15);
    background:
        linear-gradient(145deg, rgba(18, 29, 49, 0.96), rgba(11, 17, 29, 0.98));
}

.job-facts::before {
    position: absolute;
    inset: 0 auto 0 0;
    width: 3px;
    content: "";
    background: linear-gradient(#75a2ff, rgba(117, 162, 255, 0));
}

.fact-strip {
    display: grid;
    grid-template-columns: repeat(6, minmax(0, 1fr));
    gap: 1px;
    margin-top: 1.25rem;
    overflow: hidden;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.055);
}

.fact-strip > div {
    min-width: 0;
    padding: 0.95rem;
    background: rgba(8, 13, 24, 0.78);
}

.fact-strip dt,
.technical-grid dt {
    color: #77869d;
    font-size: 0.67rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.fact-strip dd,
.technical-grid dd {
    margin-top: 0.35rem;
    overflow-wrap: anywhere;
    color: #edf3ff;
    font-size: 0.84rem;
}

.ocr-facts,
.insight-section {
    margin-top: 2rem;
}

.confidence-badge,
.insight-health,
.field-status,
.reason-code {
    display: inline-flex;
    align-items: center;
    width: fit-content;
    padding: 0.35rem 0.65rem;
    border: 1px solid rgba(119, 161, 255, 0.22);
    border-radius: 999px;
    color: #a9c2ff;
    background: rgba(70, 112, 211, 0.1);
    font: 650 0.7rem/1.2 'JetBrains Mono', monospace;
}

.field-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.85rem;
    margin-top: 1.25rem;
}

.field-card {
    min-width: 0;
    padding: 1.1rem;
    border: 1px solid rgba(255, 255, 255, 0.075);
    border-radius: 14px;
    background: linear-gradient(145deg, rgba(16, 25, 42, 0.9), rgba(10, 16, 28, 0.94));
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.14);
}

.field-card-topline {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
}

.field-card h3 {
    min-width: 0;
    color: #9caac0;
    font-size: 0.75rem;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.field-status { padding: 0.25rem 0.5rem; color: #8ea7d9; font-size: 0.62rem; }
.field-value { margin: 1rem 0 0.75rem; overflow-wrap: anywhere; color: #f4f7ff; font-size: 1.2rem; font-weight: 680; }
.field-value small { color: #8392a9; font-size: 0.68rem; font-weight: 600; }

.confidence-meter {
    height: 4px;
    overflow: hidden;
    border-radius: 99px;
    background: rgba(255, 255, 255, 0.07);
}

.confidence-meter span {
    display: block;
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #477de8, #4ee0ad);
}

.confidence-copy { margin: 0.45rem 0 0; color: #77869c; font-size: 0.68rem; }

.next-action-card {
    display: grid;
    grid-template-columns: minmax(190px, 0.5fr) minmax(0, 1fr);
    gap: 1.25rem;
    margin-top: 1rem;
    padding: 1.1rem 1.25rem;
    border: 1px solid rgba(92, 142, 255, 0.16);
    border-radius: 14px;
    background: rgba(48, 82, 155, 0.09);
}

.next-action-card p { margin: 0; }
.next-action-card strong { color: #b8ccff; font: 600 0.82rem/1.4 'JetBrains Mono', monospace; }

.technical-details {
    margin-top: 0.85rem;
    border: 1px solid rgba(255, 255, 255, 0.07);
    border-radius: 12px;
    background: rgba(7, 12, 22, 0.42);
}

.technical-details summary {
    padding: 0.85rem 1rem;
    color: #9eabc0;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 650;
}

.technical-details > :not(summary) { margin: 0; padding: 0 1rem 1rem; }
.technical-list { display: grid; gap: 0.55rem; list-style: none; }
.ocr-text { max-height: 320px; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; color: #b8c5d9; font: 0.78rem/1.65 'JetBrains Mono', monospace; }

.insight-advisory {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 1rem;
    margin-top: 1.25rem;
    padding: 1.3rem;
    border: 1px solid rgba(112, 153, 255, 0.2);
    border-radius: 18px;
    background:
        radial-gradient(circle at 0 0, rgba(78, 128, 239, 0.17), transparent 48%),
        linear-gradient(145deg, rgba(22, 35, 61, 0.94), rgba(11, 18, 31, 0.98));
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.2);
}

.insight-sigil {
    display: grid;
    width: 2.8rem;
    height: 2.8rem;
    place-items: center;
    border: 1px solid rgba(124, 164, 255, 0.3);
    border-radius: 14px;
    color: #a8c1ff;
    background: rgba(70, 112, 211, 0.13);
    box-shadow: inset 0 0 24px rgba(93, 139, 245, 0.1);
}

.insight-summary { max-width: 900px; margin: 0; color: #edf3ff; font-size: clamp(1.05rem, 2vw, 1.3rem); line-height: 1.6; }

.insight-layout {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.9rem;
    margin-top: 0.9rem;
}

.insight-layout > * { min-width: 0; }

.insight-panel {
    min-width: 0;
    padding: 1.2rem;
    border: 1px solid rgba(255, 255, 255, 0.075);
    border-radius: 16px;
    background: rgba(13, 21, 36, 0.88);
}

.insight-panel h3,
.recommended-message h3 {
    margin: 0.2rem 0 1rem;
    color: #f0f4fb;
    font-size: 1.05rem;
}

.reliable-panel { border-color: rgba(78, 224, 173, 0.15); }
.uncertainty-panel { border-color: rgba(248, 190, 97, 0.17); }

.insight-list { display: grid; gap: 0.75rem; list-style: none; }
.insight-list li { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 0.7rem; }
.insight-list p { margin: 0; color: #dbe3f0; font-size: 0.88rem; }
.insight-list small { display: block; margin-top: 0.3rem; overflow-wrap: anywhere; color: #718198; font: 0.66rem/1.5 'JetBrains Mono', monospace; }

.list-mark {
    display: grid;
    width: 1.4rem;
    height: 1.4rem;
    place-items: center;
    border-radius: 50%;
    color: #4ee0ad;
    background: rgba(78, 224, 173, 0.1);
    font-size: 0.7rem;
    font-weight: 800;
}

.uncertainty-panel .list-mark { color: #f8be61; background: rgba(248, 190, 97, 0.1); }

.recommended-message {
    display: grid;
    gap: 0.8rem;
    margin-top: 0.9rem;
    padding: 1.25rem;
    border: 1px solid rgba(122, 162, 255, 0.24);
    border-radius: 18px;
    background: rgba(53, 87, 165, 0.1);
}

.recommended-message blockquote {
    margin: 0;
    padding: 1rem 1.1rem;
    overflow-wrap: anywhere;
    border-left: 3px solid #75a2ff;
    border-radius: 0 10px 10px 0;
    color: #f4f7ff;
    background: rgba(5, 10, 20, 0.42);
    font-size: 1rem;
    line-height: 1.65;
}

.message-actions { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.sr-status { color: #8fa0b8; font-size: 0.75rem; }

.technical-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 0.8rem;
}

.insight-state {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr);
    gap: 1rem;
    margin-top: 2rem;
    padding: 1.3rem;
    border: 1px solid rgba(255, 255, 255, 0.09);
    border-radius: 18px;
    background: rgba(16, 24, 40, 0.88);
}

.insight-state h2 { margin: 0.2rem 0 0.45rem; font-size: 1.15rem; }
.insight-state p { margin-bottom: 0; }
.insight-state-rejected { border-color: rgba(248, 190, 97, 0.2); background: rgba(98, 64, 18, 0.1); }

.state-icon {
    display: grid;
    width: 2.4rem;
    height: 2.4rem;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    color: #a8b5c9;
}

.empty-result h2,
.empty-result h3 { margin-bottom: 0.4rem; }

button:focus-visible,
.btn:focus-visible,
a:focus-visible,
summary:focus-visible {
    outline: 3px solid rgba(117, 162, 255, 0.72);
    outline-offset: 3px;
}

@media (max-width: 1080px) {
    .fact-strip { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
    .detail-heading,
    .section-heading { align-items: flex-start; flex-direction: column; }
    .fact-strip,
    .field-grid,
    .insight-layout,
    .technical-grid,
    .next-action-card { grid-template-columns: minmax(0, 1fr); }
    .field-card,
    .insight-panel,
    .recommended-message,
    .insight-advisory,
    .insight-state { min-width: 0; }
    .message-actions { align-items: stretch; flex-direction: column; }
    .message-actions button { width: 100%; }
    .reason-code { max-width: 100%; overflow-wrap: anywhere; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}

@media (max-width: 980px) {
    .ops-metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .ops-layout { grid-template-columns: 1fr; }
    .key-reveal-layout { grid-template-columns: 1fr; }
    .client-create-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .client-field-wide,
    .client-create-submit { grid-column: span 2; }
}

@media (max-width: 680px) {
    header {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 0.75rem;
        padding: 0.85rem 1rem;
    }
    .brand {
        min-width: 0;
        flex-wrap: wrap;
        gap: 0.4rem;
        font-size: 1rem;
        line-height: 1.2;
    }
    .badge-owner {
        padding: 0.2rem 0.4rem;
        font-size: 0.58rem;
    }
    header button { padding: 0.5rem 0.7rem; }
    nav {
        flex-wrap: nowrap;
        gap: 0.35rem;
        padding: 0.65rem 1rem;
        overflow-x: auto;
        overscroll-behavior-x: contain;
        scrollbar-width: thin;
    }
    nav a {
        flex: 0 0 auto;
        padding: 0.55rem 0.75rem;
    }
    main { padding: 1rem; }
    .ops-hero { display: block; padding: 1.5rem; }
    .ops-hero .btn { display: inline-block; margin-top: 1.2rem; }
    .ops-verdict { grid-template-columns: auto minmax(0, 1fr); padding: 1.2rem; }
    .ops-verdict-action {
        grid-column: 1 / -1;
        justify-items: start;
        min-width: 0;
        padding-left: 4.15rem;
    }
    .ops-metrics, .runbook-grid { grid-template-columns: 1fr; }
    .onboarding-rail,
    .client-create-form { grid-template-columns: 1fr; }
    .client-field-wide,
    .client-create-submit { grid-column: span 1; }
    .client-create-submit {
        display: grid;
        justify-items: stretch;
    }
    .key-copy-row { align-items: stretch; flex-direction: column; }
    .key-facts { grid-template-columns: 1fr; }
    .client-create-submit .btn { width: 100%; }
    .client-alert { display: grid; }
    .ops-panel-head { display: block; }
    .ops-search {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        width: 100%;
        margin-top: 1rem;
    }
    .ops-search input { min-width: 0; width: 100%; }
}

/* Facturación panel — the copy affordance.
   Small and inline, because it sits INSIDE a table cell beside the value it
   copies. Sized to the 44px touch target on coarse pointers: the person most
   likely to use this is standing in a shop holding the ticket. */
.errand-copy {
    background: transparent;
    border: 1px solid rgba(148, 163, 184, 0.35);
    color: #cbd5e1;
    padding: 0.05rem 0.35rem;
    margin-left: 0.35rem;
    font-size: 0.8rem;
    line-height: 1.4;
    border-radius: 5px;
    cursor: pointer;
}
.errand-copy:hover {
    background: rgba(148, 163, 184, 0.18);
    color: #f8fafc;
    transform: none;
}
@media (pointer: coarse) {
    .errand-copy { min-width: 44px; min-height: 44px; }
}
