/* Contract Date Calculator — compact UI fit for a typical laptop (1366×768).
   No outer scrolling; only inner panes scroll. */

:root {
    --primary: #2563eb;
    --primary-dark: #1e40af;
    --success: #16a34a;
    --warning: #d97706;
    --error: #dc2626;
    --info: #0891b2;
    --decision: #7c3aed;
    --condition: #059669;
    --action: #2563eb;
    --section: #64748b;

    --bg: #f1f5f9;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #e2e8f0;
    --border-strong: #cbd5e1;
    --text: #0f172a;
    --text-muted: #64748b;
    --text-faint: #94a3b8;

    --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
    --shadow: 0 2px 8px rgba(15, 23, 42, 0.08);

    --radius: 6px;
    --radius-sm: 4px;

    --header-h: 44px;
    --sidebar-w: 360px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 13px;
    line-height: 1.45;
}

/* ----- App shell ----- */
.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
}

.app-header {
    height: var(--header-h);
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    flex-shrink: 0;
}

.app-header-title strong {
    font-size: 14px;
    font-weight: 700;
    color: var(--text);
}

.app-header-sub {
    margin-left: 8px;
    color: var(--text-muted);
    font-size: 12px;
}

.app-header-nav a {
    color: var(--primary);
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
}
.app-header-nav a:hover { text-decoration: underline; }

.app-body {
    flex: 1;
    display: grid;
    grid-template-columns: var(--sidebar-w) 1fr;
    overflow: hidden;
    min-height: 0;
}

/* ----- Sidebar ----- */
.sidebar {
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    min-height: 0;
}

.sidebar-form {
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.form-block {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px 12px;
}

.form-block h3 {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 8px;
}
.grid-2:last-child { margin-bottom: 0; }

.field { display: flex; flex-direction: column; }

.field label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 3px;
}

.field input[type="text"],
.field input[type="date"],
.field select,
.field textarea {
    width: 100%;
    padding: 5px 7px;
    font-size: 12px;
    border: 1px solid var(--border-strong);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
    transition: border-color 0.1s ease, box-shadow 0.1s ease;
}

.field textarea {
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    resize: vertical;
    min-height: 54px;
    font-size: 11px;
    line-height: 1.35;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
}

.field-checkbox { justify-content: flex-end; }
.checkbox-label {
    display: flex !important;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text);
    cursor: pointer;
    font-weight: 500;
    margin-bottom: 0 !important;
    padding: 5px 0;
}
.checkbox-label input { width: auto !important; margin: 0; cursor: pointer; }

.btn-primary {
    width: 100%;
    padding: 9px 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.1s ease;
}
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: translateY(1px); }

/* ----- Demo cases (collapsed by default; below the form) ----- */
.demo-cases {
    margin: 0 12px 12px;
    background: rgba(124, 58, 237, 0.05);
    border: 1px solid rgba(124, 58, 237, 0.2);
    border-radius: var(--radius);
}

.demo-cases > summary {
    cursor: pointer;
    padding: 8px 12px;
    font-weight: 600;
    color: var(--decision);
    font-size: 12px;
    user-select: none;
    list-style: none;
}
.demo-cases > summary::-webkit-details-marker { display: none; }
.demo-cases > summary::before {
    content: '▶';
    display: inline-block;
    margin-right: 6px;
    font-size: 9px;
    transition: transform 0.15s ease;
}
.demo-cases[open] > summary::before { transform: rotate(90deg); }

.demo-cases-body {
    padding: 0 12px 10px;
    border-top: 1px solid rgba(124, 58, 237, 0.15);
}

.demo-category { margin-top: 10px; }
.demo-category-name {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 4px;
}
.demo-list { list-style: none; padding: 0; margin: 0; }
.demo-list li { margin-bottom: 2px; }
.demo-link {
    display: block;
    padding: 4px 6px;
    color: var(--primary);
    text-decoration: none;
    font-size: 12px;
    border-radius: var(--radius-sm);
    line-height: 1.35;
}
.demo-link:hover { background: rgba(124, 58, 237, 0.08); text-decoration: none; }

/* ----- Main results ----- */
.results {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-height: 0;
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 32px;
    text-align: center;
    color: var(--text-muted);
}
.empty-icon { font-size: 48px; margin-bottom: 12px; opacity: 0.7; }
.empty-state h2 { font-size: 18px; font-weight: 600; color: var(--text); margin-bottom: 8px; }
.empty-state p { max-width: 460px; margin-bottom: 6px; }
.empty-state .muted { font-size: 12px; color: var(--text-faint); }

/* Result strip at top */
.result-strip {
    display: grid;
    grid-auto-flow: column;
    grid-auto-columns: minmax(140px, 1fr);
    gap: 8px;
    padding: 10px 14px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.result-box {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 8px 10px;
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.result-box.start { border-left: 3px solid var(--success); }
.result-box.end { border-left: 3px solid var(--error); }
.result-box.path.addon { border-left: 3px solid var(--decision); }
.result-box.path.rule { border-left: 3px solid var(--action); }
.result-box.doctype { border-left: 3px solid var(--warning); }

.result-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: 2px;
}
.result-value {
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: 18px;
    font-weight: 700;
    color: var(--text);
    line-height: 1.1;
}
.result-value-sm {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    line-height: 1.2;
}
.result-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Tabs */
.tabs {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0 14px;
    flex-shrink: 0;
}
.tab {
    background: none;
    border: none;
    padding: 10px 14px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    transition: color 0.1s, border-color 0.1s;
    display: flex;
    align-items: center;
    gap: 6px;
}
.tab:hover { color: var(--text); }
.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.tab .badge {
    background: var(--border);
    color: var(--text-muted);
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 700;
}
.tab.active .badge { background: var(--primary); color: white; }

.tab-panel {
    display: none;
    flex: 1;
    overflow-y: auto;
    padding: 14px 18px;
    min-height: 0;
}
.tab-panel.active { display: block; }

.panel-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 12px;
    gap: 12px;
    flex-wrap: wrap;
}
.panel-head h3 {
    font-size: 13px;
    font-weight: 700;
    color: var(--text);
}
.muted {
    font-size: 11px;
    color: var(--text-muted);
}
code {
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    background: var(--surface-2);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 11px;
    border: 1px solid var(--border);
}

/* JSON payload */
.json-payload {
    background: #0f172a;
    color: #e2e8f0;
    padding: 12px 14px;
    border-radius: var(--radius);
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: 12px;
    line-height: 1.5;
    overflow-x: auto;
    white-space: pre;
    border: 1px solid #1e293b;
    margin-bottom: 10px;
}

.fallback-warning {
    background: rgba(217, 119, 6, 0.08);
    border-left: 3px solid var(--warning);
    border-radius: var(--radius-sm);
    padding: 8px 12px;
    margin-bottom: 10px;
    font-size: 12px;
    color: var(--text);
}
.fallback-warning strong { display: block; margin-bottom: 4px; color: var(--warning); }
.fallback-warning ul { margin: 0 0 0 18px; padding: 0; }
.fallback-warning li {
    margin-bottom: 2px;
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: 11px;
}

.payload-inputs > summary {
    cursor: pointer;
    padding: 6px 10px;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    user-select: none;
}
.payload-inputs > summary:hover { background: var(--bg); }
.payload-inputs pre {
    margin-top: 6px;
    padding: 8px 10px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: 11px;
    overflow-x: auto;
}

/* Pipeline stages */
.pipeline-stage {
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-left: 3px solid var(--decision);
    border-radius: var(--radius);
    padding: 10px 12px;
    margin-bottom: 8px;
    position: relative;
}
.pipeline-stage::before {
    content: '↓';
    position: absolute;
    left: 16px;
    bottom: -10px;
    color: var(--text-faint);
    font-size: 12px;
    line-height: 1;
}
.pipeline-stage:last-child {
    border-left-color: var(--success);
}
.pipeline-stage:last-child::before { display: none; }

.pipeline-stage-header {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 10px;
    flex-wrap: wrap;
    margin-bottom: 6px;
}
.pipeline-stage-name {
    font-weight: 700;
    color: var(--text);
    font-size: 12px;
}
.pipeline-stage-where {
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: 10px;
    color: var(--text-faint);
}
.pipeline-stage-row {
    font-size: 12px;
    margin-bottom: 3px;
    line-height: 1.4;
}
.pipeline-stage-row.notes {
    margin-top: 4px;
    padding-top: 4px;
    border-top: 1px dashed var(--border);
    color: var(--text-muted);
    font-size: 11px;
}
.pipeline-stage-row .mono {
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    background: var(--surface);
    border: 1px solid var(--border);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 11px;
}
.pipeline-stage-row.dates {
    display: flex;
    gap: 14px;
    margin-top: 5px;
    padding: 5px 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    flex-wrap: wrap;
}
.pipeline-date { display: flex; align-items: center; gap: 5px; }
.pipeline-date-label {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    font-weight: 700;
}
.pipeline-date-value {
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-weight: 700;
    color: var(--text);
    font-size: 12px;
}

/* Execution flow */
.execution-flow { display: flex; flex-direction: column; gap: 4px; }

.log-entry {
    background: var(--surface-2);
    border-left: 3px solid var(--border-strong);
    border-radius: var(--radius-sm);
    padding: 6px 10px;
    font-size: 12px;
}
.log-entry.info       { border-left-color: var(--info);     background: rgba(8, 145, 178, 0.05); }
.log-entry.decision   { border-left-color: var(--decision); background: rgba(124, 58, 237, 0.05); }
.log-entry.condition  { border-left-color: var(--condition);background: rgba(5, 150, 105, 0.05); }
.log-entry.action     { border-left-color: var(--action);   background: rgba(37, 99, 235, 0.05); }
.log-entry.warning    { border-left-color: var(--warning);  background: rgba(217, 119, 6, 0.05); }
.log-entry.error      { border-left-color: var(--error);    background: rgba(220, 38, 38, 0.05); }
.log-entry.success    { border-left-color: var(--success);  background: rgba(22, 163, 74, 0.05); }
.log-entry.section    { border-left-color: var(--section);  background: rgba(100, 116, 139, 0.08); font-weight: 600; }

.log-header { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 3px; }
.log-type {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 1px 5px;
    border-radius: 3px;
    color: white;
    background: var(--section);
}
.log-entry.info .log-type      { background: var(--info); }
.log-entry.decision .log-type  { background: var(--decision); }
.log-entry.condition .log-type { background: var(--condition); }
.log-entry.action .log-type    { background: var(--action); }
.log-entry.warning .log-type   { background: var(--warning); }
.log-entry.error .log-type     { background: var(--error); }
.log-entry.success .log-type   { background: var(--success); }

.log-timestamp {
    font-size: 10px;
    color: var(--text-faint);
    font-family: 'SF Mono', Menlo, Consolas, monospace;
}
.log-message {
    font-size: 12px;
    color: var(--text);
    line-height: 1.4;
    word-break: break-word;
}

.log-variables { margin-top: 4px; }
.log-variables > summary {
    cursor: pointer;
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    padding: 2px 6px;
    background: var(--surface);
    border-radius: 3px;
    user-select: none;
    display: inline-block;
}
.log-variables > summary:hover { background: var(--bg); }
.log-variables pre {
    margin-top: 4px;
    padding: 6px 8px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: 'SF Mono', Menlo, Consolas, monospace;
    font-size: 11px;
    overflow-x: auto;
    line-height: 1.4;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Scrollbars */
.sidebar::-webkit-scrollbar,
.tab-panel::-webkit-scrollbar {
    width: 8px;
    height: 8px;
}
.sidebar::-webkit-scrollbar-track,
.tab-panel::-webkit-scrollbar-track { background: transparent; }
.sidebar::-webkit-scrollbar-thumb,
.tab-panel::-webkit-scrollbar-thumb {
    background: var(--border-strong);
    border-radius: 4px;
}
.sidebar::-webkit-scrollbar-thumb:hover,
.tab-panel::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* Compact mode for shorter viewports */
@media (max-height: 720px) {
    .sidebar-form { gap: 8px; padding: 10px; }
    .form-block { padding: 8px 10px; }
    .form-block h3 { margin-bottom: 6px; }
    .grid-2 { gap: 6px; margin-bottom: 6px; }
    .result-strip { padding: 8px 12px; }
    .tab-panel { padding: 10px 14px; }
}

/* Wider sidebar accommodation on narrow screens */
@media (max-width: 1100px) {
    :root { --sidebar-w: 320px; }
}

/* ============================================================
   "Why not?" explainer — expected vs. actual doctype decision
   ============================================================ */
.badge-warn {
    background: var(--warning) !important;
    color: #fff !important;
}

.whynot-verdict {
    border-radius: var(--radius);
    padding: 14px 16px;
    margin-bottom: 16px;
    border: 1px solid var(--border-strong);
    background: var(--bg);
}
.whynot-verdict.diff {
    border-color: var(--warning);
    background: #fffbeb;
}
.whynot-verdict.ok {
    border-color: var(--success);
    background: #f0fdf4;
}
.whynot-outcome {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    font-size: 14px;
}
.whynot-chip {
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    background: var(--surface);
    border: 1px solid var(--border);
}
.whynot-chip.expected { border-left: 3px solid var(--info); }
.whynot-chip.actual { border-left: 3px solid var(--decision); }
.whynot-arrow { font-size: 18px; font-weight: 700; color: var(--text-muted); }

.whynot-note { font-size: 13px; margin: 8px 0; }

.whynot-decisive {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    border: 1px solid var(--warning);
    background: #fffbeb;
    border-radius: var(--radius);
    padding: 12px 14px;
    margin-bottom: 16px;
}
.whynot-decisive-label {
    font-weight: 700;
    color: var(--warning);
    white-space: nowrap;
}
.whynot-decisive-body { font-size: 13px; line-height: 1.5; }
.whynot-decisive-body .muted { margin: 6px 0 0; }

.whynot-section { margin-bottom: 16px; }
.whynot-section h4 {
    margin: 0 0 8px;
    font-size: 13px;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--text-muted);
}
.whynot-cases { margin: 0 0 8px 18px; padding: 0; font-size: 13px; line-height: 1.6; }

.whynot-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.whynot-table th,
.whynot-table td {
    text-align: left;
    padding: 6px 8px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
.whynot-table th {
    color: var(--text-muted);
    font-weight: 600;
    background: var(--bg);
}
.whynot-table .whynot-num { text-align: center; font-variant-numeric: tabular-nums; }
.whynot-fail { color: var(--error); }
.whynot-fail .muted { color: var(--text-faint); }
