/* ===================================================================
   Agent Demo — Happy Robots Light Theme
   =================================================================== */

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

:root {
    /* Colors — HR light palette */
    --bg: #FFFFFF;
    --surface: #FAFAFA;
    --surface-2: #F5F5F5;
    --border: #E5E5E5;
    --text: #1A1A1A;
    --text-muted: #666666;
    --accent: #0066CC;
    --accent-hover: #005F9F;
    --accent-dim: rgba(0, 102, 204, 0.08);
    --success: #10B981;
    --success-dim: rgba(16, 185, 129, 0.08);
    --warning: #F59E0B;
    --warning-dim: rgba(245, 158, 11, 0.08);
    --error: #DC2626;
    --purple: #8B5CF6;
    --purple-dim: rgba(139, 92, 246, 0.08);

    /* Typography — HR font stacks */
    --font-mono: 'SF Mono', 'Cascadia Code', 'Fira Code', monospace;
    --font-sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    --font-serif: Georgia, 'Times New Roman', serif;

    /* Spacing tokens */
    --space-xxs: 0.75rem;
    --space-xs: 1rem;
    --space-sm: 1.5rem;
    --space-md: 2rem;
    --space-lg: 3rem;
    --space-xl: 4rem;

    /* Transition tokens — HR timing */
    --transition-default: all 200ms ease;
    --transition-subtle: all 150ms ease;
    --transition-button: all 300ms ease;

    /* Shadows — HR elevation */
    --shadow-subtle: 0px 1px 2px rgba(15, 23, 42, 0.08);
    --shadow-card: 0px 8px 24px rgba(15, 23, 42, 0.08);

    /* Border radius */
    --radius-sm: 4px;
    --radius-md: 8px;
}

body {
    font-family: var(--font-sans);
    background: var(--bg);
    color: var(--text);
    line-height: 1.7;
    min-height: 100vh;
}

/* ---- Header — HR serif heading, light weight ---- */
header {
    display: flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.75rem;
    padding: 0.4rem var(--space-xs);
    border-bottom: 1px solid var(--border);
}

header h1 {
    font-family: var(--font-serif);
    font-size: 1.25rem;
    font-weight: 300;
    letter-spacing: -0.015em;
}

.subtitle {
    color: var(--text-muted);
    font-style: italic;
    font-size: 0.75rem;
    line-height: 1;
}

/* ---- Three-panel layout ---- */
main {
    display: grid;
    grid-template-columns: 280px 1fr 320px;
    gap: 0;
    height: calc(100vh - 40px);
}

.panel {
    padding: 0.75rem;
    overflow-y: auto;
    border-right: 1px solid var(--border);
    scrollbar-width: none;
}

.panel::-webkit-scrollbar {
    display: none;
}

.panel:last-child {
    border-right: none;
}

/* Panel headings — HR eyebrow style */
.panel h2 {
    font-family: var(--font-sans);
    font-size: 0.8125rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    padding-bottom: 0.35rem;
    border-bottom: 1px solid var(--border);
}

/* ---- Setup Panel ---- */
.setup-group {
    margin-bottom: 0.6rem;
}

/* Labels — HR eyebrow convention */
.setup-group label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.setup-group small {
    display: block;
    color: var(--text-muted);
    font-size: 0.75rem;
    margin-top: 0.2rem;
    line-height: 1.4;
    letter-spacing: 0.01em;
}

/* Input — HR form pattern */
#api-key {
    width: 100%;
    padding: 0.5rem 0.6rem;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-family: var(--font-mono);
    font-size: 0.875rem;
    outline: none;
    transition: var(--transition-default);
}

#api-key:focus {
    border-color: var(--accent);
    background: rgba(0, 102, 204, 0.05);
}

/* ---- Info box — HR card pattern ---- */
.info-box {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.6rem 0.75rem;
    margin-top: 0.6rem;
    transition: var(--transition-default);
}

.info-box:hover {
    border-color: var(--text-muted);
    box-shadow: var(--shadow-subtle);
}

.info-box h3 {
    font-size: 0.8125rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-muted);
    margin-bottom: 0.3rem;
}

.info-box ol {
    padding-left: 1.2rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.info-box ol li {
    margin-bottom: 0.1rem;
}

.info-box p {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.3rem;
}

.inbox-preview {
    padding-left: 1.2rem;
    font-size: 0.8125rem;
    color: var(--text-muted);
    line-height: 1.4;
}

.inbox-preview li {
    margin-bottom: 0.1rem;
}

/* ---- Buttons — HR slide-fill pattern ---- */
.btn {
    display: inline-block;
    padding: 0.4rem 0.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.875rem;
    font-weight: 400;
    cursor: pointer;
    width: 100%;
    text-align: center;
    position: relative;
    overflow: hidden;
    z-index: 1;
    transition: var(--transition-button);
}

.btn::before {
    content: '';
    position: absolute;
    inset: 0;
    z-index: -1;
    transition: transform 300ms ease;
}

.btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

/* Primary button — HR blue + slide-fill + lift */
.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.btn-primary::before {
    background: rgba(255, 255, 255, 0.12);
    transform: translateX(-100%);
}

.btn-primary:hover:not(:disabled) {
    transform: translateY(-1px);
    background: var(--accent-hover);
}

.btn-primary:hover:not(:disabled)::before {
    transform: translateX(0);
}

/* Secondary button — HR border-darken + slide-fill + lift */
.btn-secondary {
    background: var(--bg);
    color: var(--text);
}

.btn-secondary::before {
    background: rgba(0, 0, 0, 0.03);
    transform: translateX(-100%);
}

.btn-secondary:hover:not(:disabled) {
    border-color: var(--text-muted);
    transform: translateY(-1px);
}

.btn-secondary:hover:not(:disabled)::before {
    transform: translateX(0);
}

/* Focus ring — HR pattern */
.btn:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
}

/* ---- Timeline Panel ---- */
#timeline-panel {
    background: var(--surface);
}

.timeline {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.empty-state {
    text-align: center;
    padding: var(--space-lg) var(--space-xs);
    color: var(--text-muted);
}

.empty-icon {
    font-size: 2.5rem;
    margin-bottom: 0.5rem;
}

.empty-sub {
    font-size: 0.8125rem;
    margin-top: 0.25rem;
}

/* ---- Timeline cards — HR card pattern ---- */
.card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    overflow: hidden;
    animation: cardIn 0.3s ease-out;
    transition: var(--transition-default);
}

.card:hover {
    border-color: var(--text-muted);
    box-shadow: var(--shadow-subtle);
}

@keyframes cardIn {
    from { opacity: 0; transform: translateY(10px); }
    to   { opacity: 1; transform: translateY(0); }
}

.card-header {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.35rem 0.6rem;
    font-size: 0.75rem;
    font-weight: 500;
    border-bottom: 1px solid var(--border);
}

.card-header .iteration-badge {
    background: var(--accent-dim);
    color: var(--accent);
    padding: 0.1rem 0.4rem;
    border-radius: 999px;
    font-size: 0.625rem;
    font-family: var(--font-mono);
}

.card-body {
    padding: 0.4rem 0.6rem;
    font-size: 0.8125rem;
    line-height: 1.5;
}

/* Card variants */
.card.reasoning .card-header { color: var(--text-muted); }

.card.tool-call .card-header { color: var(--warning); }
.card.tool-call { border-color: var(--warning-dim); }

.card.tool-result .card-header { color: var(--success); }
.card.tool-result { border-color: var(--success-dim); }

.card.server-side .card-header { color: var(--purple); }
.card.server-side { border-color: var(--purple-dim); }

.card.draft .card-header { color: var(--accent); }
.card.draft { border-color: var(--accent-dim); }

.card.loop-marker .card-header {
    color: var(--text-muted);
    border-bottom: none;
    font-size: 0.6875rem;
}
.card.loop-marker {
    background: transparent;
    border: 1px dashed var(--border);
}

.card.agent-start .card-header { color: var(--accent); }
.card.agent-done .card-header { color: var(--success); }
.card.agent-error .card-header { color: var(--error); }
.card.agent-error { border-color: rgba(220, 38, 38, 0.15); }

/* Rendered markdown inside cards */
.card-body ol,
.card-body ul {
    padding-left: 1.2rem;
    margin: 0.2rem 0;
}

.card-body ol li,
.card-body ul li {
    margin-bottom: 0.15rem;
}

/* Code blocks inside cards */
.card-body pre {
    background: var(--surface-2);
    padding: 0.3rem 0.5rem;
    border-radius: var(--radius-sm);
    overflow-x: auto;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    white-space: pre-wrap;
    word-break: break-word;
    margin-top: 0.3rem;
    line-height: 1.4;
}

/* ---- Draft email card ---- */
.draft-email {
    background: var(--surface-2);
    border-radius: var(--radius-sm);
    padding: 0.5rem 0.6rem;
    margin-top: 0.3rem;
}

.draft-email .field {
    margin-bottom: 0.3rem;
}

/* Draft field labels — HR eyebrow */
.draft-email .field-label {
    font-size: 0.6875rem;
    font-weight: 500;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.12em;
}

.draft-email .field-value {
    font-size: 0.8125rem;
}

.draft-email .body {
    white-space: pre-wrap;
    padding-top: 0.3rem;
    border-top: 1px solid var(--border);
    margin-top: 0.3rem;
    font-size: 0.8125rem;
    line-height: 1.5;
}

/* ---- Email list in tool result ---- */
.email-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.email-item {
    background: var(--surface-2);
    padding: 0.35rem 0.5rem;
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--accent-dim);
    transition: var(--transition-default);
}

.email-item:hover {
    border-left-color: var(--accent);
    box-shadow: var(--shadow-subtle);
}

.email-item .from {
    font-weight: 500;
    font-size: 0.75rem;
}

.email-item .subject {
    font-size: 0.75rem;
    color: var(--accent);
}

.email-item .snippet {
    font-size: 0.6875rem;
    color: var(--text-muted);
    margin-top: 0.1rem;
    line-height: 1.4;
}

/* ---- Search results ---- */
.search-results {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.search-item {
    background: var(--surface-2);
    padding: 0.5rem;
    border-radius: var(--radius-sm);
    border-left: 3px solid var(--purple-dim);
    transition: var(--transition-default);
}

.search-item:hover {
    border-left-color: var(--purple);
    box-shadow: var(--shadow-subtle);
}

.search-item .title {
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--purple);
}

.search-item .url {
    font-size: 0.6875rem;
    color: var(--text-muted);
    word-break: break-all;
}

/* ---- Spinner ---- */
.spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid var(--border);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
    margin-right: 0.4rem;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---- Education Panel — HR card + eyebrow patterns ---- */
.edu-section {
    padding: 0.5rem 0.6rem;
    margin-bottom: 0.25rem;
    border-radius: var(--radius-sm);
    border: 1px solid transparent;
    transition: var(--transition-default);
    opacity: 0.6;
}

.edu-section:hover {
    opacity: 0.85;
    border-color: var(--border);
    box-shadow: var(--shadow-subtle);
}

.edu-section.active {
    opacity: 1;
    background: var(--surface-2);
    border-color: var(--accent-dim);
}

.edu-section.seen {
    opacity: 0.8;
}

.edu-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.edu-number {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: var(--border);
    color: var(--text-muted);
    font-size: 0.6875rem;
    font-weight: 500;
    flex-shrink: 0;
    transition: var(--transition-default);
}

.edu-section.active .edu-number {
    background: var(--accent);
    color: #fff;
}

/* Education headings — HR H3: sans-serif, weight 400 */
.edu-section h3 {
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 500;
    letter-spacing: -0.01em;
}

.edu-section p {
    font-size: 0.8125rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
    line-height: 1.5;
}

.edu-section.active p {
    color: var(--text);
}

.edu-section code {
    background: var(--surface-2);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.6875rem;
}

.edu-code {
    margin-top: 0.3rem;
}

.edu-code pre {
    background: var(--surface-2);
    padding: 0.35rem 0.5rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.6875rem;
    line-height: 1.35;
    overflow-x: auto;
    border: 1px solid var(--border);
}

/* ---- Education panel buttons ---- */
.post-deep-dive-btns {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    margin-top: 0.5rem;
}

.post-deep-dive-btns .btn {
    width: 100%;
}

/* ==================================================================
   Deep Dive Modal
   ================================================================== */

/* Full-screen overlay — HR modal: fade + scale */
.deep-dive-overlay {
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    animation: overlayIn 200ms ease;
}

@keyframes overlayIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1); }
}

.deep-dive-modal {
    position: relative;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    width: 90vw;
    max-width: 72vw;
    height: 92vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding: 1rem 1.5rem 0.75rem;
    animation: modalIn 200ms ease;
    box-shadow: var(--shadow-card);
}


.dd-close {
    position: absolute;
    top: var(--space-xxs);
    right: var(--space-xs);
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.5rem;
    cursor: pointer;
    line-height: 1;
    padding: 0.25rem;
    transition: var(--transition-subtle);
}

.dd-close:hover {
    color: var(--text);
}

/* Title — HR H3: sans-serif, 1.5rem, weight 400 */
.deep-dive-title {
    font-family: var(--font-sans);
    font-size: 1.25rem;
    font-weight: 400;
    letter-spacing: -0.01em;
    color: var(--text);
    margin-bottom: 0.4rem;
    padding-bottom: 0.4rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

/* Body text — fills remaining space, scrolls only if needed */
.deep-dive-body {
    flex: 1;
    overflow-y: auto;
    scrollbar-width: none;
    font-size: 0.8125rem;
    line-height: 1.55;
    color: var(--text);
    padding-right: 0.25rem;
}

.deep-dive-body::-webkit-scrollbar {
    display: none;
}

.deep-dive-body > p {
    margin-bottom: 0.35rem;
    color: var(--text-muted);
}

.deep-dive-body > p strong {
    color: var(--text);
}

.deep-dive-body ul {
    padding-left: 1.2rem;
    margin-bottom: 0.35rem;
}

.deep-dive-body ul li {
    margin-bottom: 0.15rem;
    color: var(--text-muted);
    font-size: 0.8125rem;
}

.deep-dive-body ul li strong {
    color: var(--text);
}

/* H4 — section headers */
.deep-dive-body h4 {
    font-family: var(--font-sans);
    font-size: 1rem;
    font-weight: 500;
    color: var(--accent);
    margin-top: 0.4rem;
    margin-bottom: 0.2rem;
}

.deep-dive-body pre {
    background: var(--surface-2);
    padding: 0.35rem 0.5rem;
    border-radius: var(--radius-sm);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    line-height: 1.4;
    overflow-x: auto;
    margin-bottom: 0.35rem;
    border: 1px solid var(--border);
}

.deep-dive-body code {
    background: var(--surface-2);
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    font-family: var(--font-mono);
    font-size: 0.75rem;
}

.deep-dive-body em {
    color: var(--text-muted);
    font-size: 0.8125rem;
}

/* Links — HR underline-fill animation */
.deep-dive-body a {
    color: var(--accent);
    text-decoration: underline;
    text-decoration-color: rgba(0, 102, 204, 0.3);
    text-underline-offset: 2px;
    transition: text-decoration-color 300ms ease;
}

.deep-dive-body a:hover {
    text-decoration-color: var(--accent);
}

.deep-dive-body a:focus-visible {
    outline: none;
    box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent);
    border-radius: 2px;
}

/* Two-column layout */
.dd-columns {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-top: 0.35rem;
    margin-bottom: 0.35rem;
}

.dd-col h4:first-child {
    margin-top: 0;
}

.dd-col p {
    font-size: 0.8125rem;
    margin-bottom: 0.3rem;
    color: var(--text-muted);
}

.dd-col p strong {
    color: var(--text);
}

/* Content cards — HR card pattern with hover */
.dd-card {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 0.4rem 0.55rem;
    margin-bottom: 0.35rem;
    font-size: 0.8125rem;
    line-height: 1.5;
    color: var(--text-muted);
    transition: var(--transition-default);
}

.dd-card:hover {
    border-color: var(--text-muted);
    box-shadow: var(--shadow-subtle);
}

.dd-card h4 {
    margin-top: 0 !important;
    margin-bottom: 0.15rem;
    font-size: 0.875rem;
}

.dd-card p {
    margin-bottom: 0.15rem;
    font-size: 0.8125rem;
}

.dd-card em {
    font-size: 0.75rem;
}

.dd-card strong {
    color: var(--text);
}

.dd-card code {
    font-size: 0.75rem;
}

/* Key idea callout */
.deep-dive-key-idea {
    background: var(--accent-dim);
    border-left: 3px solid var(--accent);
    padding: 0.4rem 0.6rem;
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    margin-top: 0.4rem;
    font-size: 0.8125rem;
    color: var(--text);
    line-height: 1.5;
}

/* Nav bar — pinned to bottom */
.deep-dive-nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.5rem;
    padding-top: 0.4rem;
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

.deep-dive-nav .btn {
    width: auto;
    min-width: 100px;
}

/* Page indicator — HR eyebrow */
.dd-indicator {
    font-size: 0.8125rem;
    font-weight: 500;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
    font-family: var(--font-mono);
}

/* ---- Responsive ---- */
@media (max-width: 1024px) {
    main {
        grid-template-columns: 1fr;
        height: auto;
    }
    .panel {
        border-right: none;
        border-bottom: 1px solid var(--border);
        max-height: 60vh;
    }
    #education-panel {
        max-height: none;
    }
}

/* ---- Debug log panel (left sidebar) ---- */
#debug-log {
    position: fixed;
    top: 40px;
    left: 0;
    bottom: 0;
    width: 280px;
    overflow-y: auto;
    background: var(--surface);
    border-right: 2px solid var(--warning);
    font-family: var(--font-mono);
    font-size: 0.75rem;
    padding: 0.5rem;
    z-index: 100;
    color: var(--text-muted);
    scrollbar-width: none;
}

#debug-log::-webkit-scrollbar {
    display: none;
}

#debug-log .log-line {
    padding: 0.1rem 0;
    border-bottom: 1px solid var(--border);
}

#debug-log .log-line.error { color: var(--error); }
#debug-log .log-line.event { color: var(--success); }
#debug-log .log-line.info { color: var(--text-muted); }

#debug-toggle {
    position: fixed;
    bottom: 8px;
    left: 8px;
    z-index: 101;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 0.3rem 0.6rem;
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    cursor: pointer;
    font-family: var(--font-mono);
    transition: var(--transition-default);
}

#debug-toggle:hover {
    border-color: var(--text-muted);
}

#debug-log.hidden { display: none; }
#debug-log:not(.hidden) ~ main { margin-left: 280px; }
