/* Spyglass v2 — KIgulls Designsprache */
/* Don't Panic */

/* Self-hosted Fonts */
@font-face {
    font-family: "Cormorant Garamond";
    src: url("/static/fonts/CormorantGaramond-Light.woff2") format("woff2");
    font-weight: 300;
    font-display: swap;
}
@font-face {
    font-family: "Cormorant Garamond";
    src: url("/static/fonts/CormorantGaramond-Regular.woff2") format("woff2");
    font-weight: 400;
    font-display: swap;
}
@font-face {
    font-family: "IBM Plex Mono";
    src: url("/static/fonts/IBMPlexMono-Light.woff2") format("woff2");
    font-weight: 300;
    font-display: swap;
}
@font-face {
    font-family: "IBM Plex Mono";
    src: url("/static/fonts/IBMPlexMono-Regular.woff2") format("woff2");
    font-weight: 400;
    font-display: swap;
}

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

:root {
    /* KIgulls Palette */
    --bg:          #08090f;
    --bg-raised:   #0f1018;
    --bg-surface:  #141520;
    --border:      #1e2030;
    --text:        #a0a4b4;
    --text-bright: #cdd0da;
    --text-dim:    #404560;

    /* Gold */
    --accent:      #c4984c;
    --accent-dim:  rgba(196, 152, 76, 0.15);
    --accent-glow: rgba(196, 152, 76, 0.4);

    /* Red Rising — Agent-Farben */
    --gold:   #c4984c;
    --gray:   #808080;
    --orange: #c49050;
    --green:  #5a9a5a;
    --yellow: #c4c050;
    --white:  #cdd0da;
    --violet: #9a5a9a;
    --blue:   #5a7a9a;
    --silver: #a0a4b4;
    --copper: #b87333;
    --red:    #c45050;

    /* Typo */
    --serif: "Cormorant Garamond", Georgia, serif;
    --mono:  "IBM Plex Mono", Menlo, monospace;
}

body {
    font-family: var(--mono);
    font-weight: 300;
    background: var(--bg);
    color: var(--text);
    height: 100dvh;
    overflow: hidden;
    font-size: 0.85rem;
    display: flex;
    flex-direction: column;
}

/* ── Header ── */
.header {
    padding: 0.6rem 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 0.8rem;
    flex-shrink: 0;
}
.header h1 {
    font-family: var(--serif);
    color: var(--text-bright);
    font-size: 1.3rem;
    font-weight: 300;
    letter-spacing: 0.06em;
}
.header h1 .ki { color: var(--accent); font-weight: 400; }
.header .status { font-size: 0.75rem; }
.status-dot {
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 50%;
    margin-right: 4px;
}
.status-connected .status-dot {
    background: var(--accent);
    box-shadow: 0 0 6px var(--accent-glow);
    animation: pulse 2s ease-in-out infinite;
}
.status-disconnected .status-dot { background: var(--red); }
.status-connected { color: var(--accent); }
.status-disconnected { color: var(--red); }
.token-counter {
    font-size: 0.7rem;
    color: var(--text-dim);
    margin-left: auto;
}

/* ── Main Content ── */
.view-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    padding-bottom: 4rem; /* Platz fuer Tab Bar */
}

/* ── Tab Bar ── */
.tab-bar {
    position: fixed;
    bottom: 0;
    left: 0; right: 0;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0.5rem 0;
    background: var(--bg-raised);
    border-top: 1px solid var(--border);
    z-index: 100;
    flex-shrink: 0;
}
.tab-bar.hidden { display: none; }
.tab-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    text-decoration: none;
    color: var(--text-dim);
    font-size: 0.6rem;
    font-family: var(--mono);
    padding: 0.2rem 0.8rem;
    transition: color 0.2s;
}
.tab-item:hover { color: var(--text); }
.tab-item.active { color: var(--accent); }
.tab-icon { font-size: 1.1rem; }

/* ── Login ── */
.login-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100dvh;
    gap: 1.5rem;
}
.login-title {
    font-family: var(--serif);
    font-weight: 300;
    font-size: 1.6rem;
    color: var(--text-bright);
}
.login-title .ki { color: var(--accent); font-weight: 400; }
.login-field {
    width: 280px;
    background: var(--bg-raised);
    color: var(--text-bright);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 0.6rem 0.8rem;
    font-size: 0.85rem;
    font-family: var(--mono);
    font-weight: 300;
    text-align: center;
}
.login-field:focus {
    outline: none;
    border-color: var(--accent);
}
.login-field.error {
    border-color: var(--red);
    animation: flash-red 0.4s;
}
.login-btn {
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid rgba(196, 152, 76, 0.3);
    padding: 0.5rem 2rem;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.85rem;
    font-family: var(--mono);
    font-weight: 400;
    transition: all 0.2s;
}
.login-btn:hover {
    background: var(--accent);
    color: var(--bg);
    border-color: var(--accent);
}

/* ── Pulse View ── */
.agent-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.agent-dot {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.3rem;
    padding: 0.8rem 1rem;
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    min-width: 100px;
    transition: border-color 0.2s;
    text-decoration: none;
    color: inherit;
}
.agent-dot:hover { border-color: var(--text-dim); }
.agent-dot .dot {
    width: 10px; height: 10px;
    border-radius: 50%;
    animation: pulse 2s ease-in-out infinite;
}
.agent-dot .dot.dead { animation: none; opacity: 0.3; }
.agent-dot .name {
    font-size: 0.8rem;
    font-weight: 400;
    color: var(--text-bright);
}
.agent-dot .age {
    font-size: 0.65rem;
    color: var(--text-dim);
}

.section-label {
    padding: 0.4rem 0;
    color: var(--text-dim);
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-weight: 400;
    margin-bottom: 0.5rem;
}

/* ── Result Cards (Pulse + Agent-Detail) ── */
.result-card {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.8rem 1rem;
    margin-bottom: 0.5rem;
    animation: fadeIn 0.3s ease-in;
}
.result-card.severity-CRIT { border-left: 3px solid var(--red); }
.result-card.severity-WARN { border-left: 3px solid var(--orange); }
.result-card.severity-INFO { border-left: 3px solid var(--green); }
.result-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 0.4rem;
    font-size: 0.75rem;
    color: var(--text-dim);
}
.result-header .agent-name { color: var(--accent); font-weight: 400; }
.result-body {
    white-space: pre-wrap;
    line-height: 1.5;
    font-size: 0.8rem;
}

/* ── Escalation Cards ── */
.escalation-card {
    background: var(--bg-raised);
    border: 1px solid var(--red);
    border-radius: 4px;
    padding: 0.8rem 1rem;
    margin-bottom: 0.5rem;
    animation: fadeIn 0.3s ease-in;
}
.escalation-card .action-btn {
    margin-top: 0.5rem;
    font-size: 0.7rem;
    color: var(--accent);
    cursor: pointer;
    background: none;
    border: 1px solid var(--accent-dim);
    padding: 0.2rem 0.6rem;
    border-radius: 3px;
}

/* ── Flow Trace ── */
.flow-controls {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 0.8rem;
    flex-wrap: wrap;
}
.filter-toggle {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 0.65rem;
    color: var(--text-dim);
    cursor: pointer;
    user-select: none;
}
.filter-toggle.off { opacity: 0.4; text-decoration: line-through; }
.filter-dot {
    width: 8px; height: 8px;
    border-radius: 2px;
    display: inline-block;
}
.agent-filter {
    margin-left: auto;
    background: var(--bg-surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 0.2rem 0.4rem;
    font-size: 0.65rem;
    font-family: var(--mono);
}
.pause-btn {
    margin-left: 0.3rem;
    background: var(--bg-surface);
    color: var(--text-dim);
    border: 1px solid var(--border);
    padding: 0.2rem 0.6rem;
    border-radius: 3px;
    font-size: 0.7rem;
    font-family: var(--mono);
    cursor: pointer;
}
.pause-btn.paused { color: var(--accent); border-color: var(--accent); }

.trace-card {
    background: var(--bg-raised);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.3rem;
    font-size: 0.75rem;
    animation: fadeIn 0.2s ease-in;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.4rem;
    align-items: start;
}
.trace-route {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    flex-wrap: wrap;
}
.trace-source { color: var(--text); font-weight: 400; }
.trace-arrow { color: var(--text-dim); }
.trace-target { font-weight: 400; }
.trace-detail {
    color: var(--text-dim);
    font-size: 0.65rem;
    margin-top: 0.15rem;
    white-space: pre-wrap;
    max-height: 80px;
    overflow-y: auto;
}
.trace-time { color: var(--text-dim); font-size: 0.65rem; white-space: nowrap; }

/* Flow Trace — Topic-Farben */
.trace-card.topic-tasks { border-left: 3px solid var(--orange); }
.trace-card.topic-tasks .trace-target { color: var(--orange); }
.trace-card.topic-results { border-left: 3px solid var(--green); }
.trace-card.topic-results .trace-target { color: var(--green); }
.trace-card.topic-prompts { border-left: 3px solid var(--blue); }
.trace-card.topic-prompts .trace-target { color: var(--blue); }
.trace-card.topic-responses { border-left: 3px solid #D5E8F0; }
.trace-card.topic-responses .trace-target { color: #D5E8F0; }
.trace-card.topic-activity { border-left: 3px solid var(--violet); }
.trace-card.topic-activity .trace-target { color: var(--violet); }
.trace-card.topic-poison { border-left: 3px solid var(--red); }
.trace-card.topic-poison .trace-target { color: var(--red); }
.trace-card.topic-inbox { border-left: 3px solid var(--accent); }
.trace-card.topic-inbox .trace-target { color: var(--accent); }
.trace-card.topic-heartbeat { border-left: 3px solid #2a2d3a; opacity: 0.5; }
.trace-card.topic-heartbeat .trace-target { color: var(--text-dim); }

/* Flow filter hide classes */
.hide-tasks .topic-tasks,
.hide-prompts .topic-prompts,
.hide-responses .topic-responses,
.hide-results .topic-results,
.hide-activity .topic-activity,
.hide-poison .topic-poison,
.hide-inbox .topic-inbox,
.hide-heartbeat .topic-heartbeat { display: none; }

/* Agent filter */
#flow-trace.agent-filtered .trace-card { display: none; }
#flow-trace.agent-filtered .trace-card.agent-match { display: grid; }

/* Routing-Korrelation */
.trace-card[data-routing-id] { position: relative; cursor: pointer; }
.trace-card.routing-active {
    border-color: var(--accent);
    box-shadow: 0 0 8px var(--accent-dim);
}
.trace-card.routing-dim { opacity: 0.25; }

/* ── Costs View ── */
.cost-bar-row {
    display: flex;
    align-items: center;
    gap: 0.8rem;
    margin-bottom: 0.4rem;
    font-size: 0.8rem;
}
.cost-bar-label {
    width: 80px;
    text-align: right;
    color: var(--text);
    font-weight: 400;
}
.cost-bar-track {
    flex: 1;
    height: 12px;
    background: var(--bg-surface);
    border-radius: 2px;
    overflow: hidden;
}
.cost-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s;
}
.cost-bar-value {
    width: 120px;
    font-size: 0.7rem;
    color: var(--text-dim);
}

/* ── Send View ── */
.send-textarea {
    width: 100%;
    min-height: 80px;
    background: var(--bg-raised);
    color: var(--text-bright);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 0.6rem;
    font-size: 0.8rem;
    font-family: var(--mono);
    font-weight: 300;
    resize: vertical;
}
.send-textarea:focus { outline: none; border-color: var(--accent); }
.send-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}
.send-select {
    background: var(--bg-raised);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 3px;
    padding: 0.35rem 0.5rem;
    font-size: 0.75rem;
    font-family: var(--mono);
}
.send-btn {
    background: var(--accent-dim);
    color: var(--accent);
    border: 1px solid rgba(196, 152, 76, 0.3);
    padding: 0.4rem 1rem;
    border-radius: 3px;
    cursor: pointer;
    font-size: 0.8rem;
    font-family: var(--mono);
    font-weight: 400;
    transition: all 0.2s;
}
.send-btn:hover {
    background: var(--accent);
    color: var(--bg);
}

/* ── Routing Chain Panel ── */
.chain-panel {
    position: fixed;
    bottom: 3.5rem;
    right: 1rem;
    width: 260px;
    max-height: 50vh;
    overflow-y: auto;
    background: var(--bg-surface);
    border: 1px solid var(--accent);
    border-radius: 4px;
    padding: 0.8rem;
    z-index: 200;
    animation: fadeIn 0.2s ease-in;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
}
.chain-panel .chain-close {
    position: absolute;
    top: 0.4rem;
    right: 0.6rem;
    color: var(--text-dim);
    cursor: pointer;
    font-size: 0.9rem;
    background: none;
    border: none;
}
.chain-header {
    font-size: 0.7rem;
    color: var(--accent);
    font-weight: 400;
    margin-bottom: 0.6rem;
    padding-right: 1.5rem;
}
.chain-hop {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.75rem;
    padding: 0.3rem 0;
}
.chain-agent {
    color: var(--text-bright);
    font-weight: 400;
    min-width: 60px;
}
.chain-action {
    color: var(--text-dim);
    flex: 1;
}
.chain-time {
    color: var(--text-dim);
    font-size: 0.65rem;
}
.chain-connector {
    text-align: center;
    color: var(--text-dim);
    font-size: 0.6rem;
    line-height: 1;
}
.chain-empty {
    font-size: 0.75rem;
    color: var(--text-dim);
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: var(--bg); }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }

/* ── Animations ── */
@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes flash-red {
    0%, 100% { border-color: var(--red); }
    50% { border-color: var(--border); }
}

/* ── Responsive ── */
@media (max-width: 600px) {
    .header h1 { font-size: 1.1rem; }
    .agent-grid { gap: 0.5rem; }
    .agent-dot { min-width: 80px; padding: 0.5rem; }
    .view-container { padding: 0.6rem; padding-bottom: 4rem; }
}
