/* ==========================================================================
   The Cornmill Intelligencer — Newsroom Visualiser
   Broadsheet aesthetic with live agent activity
   ========================================================================== */

@import url('https://fonts.googleapis.com/css2?family=Playfair+Display:wght@400;700;900&family=Libre+Baskerville:ital,wght@0,400;0,700;1,400&family=Inter:wght@400;500;600&display=swap');

:root {
    /* Broadsheet palette */
    --paper:        #E6E4DF;
    --paper-light:  #F0EEED;
    --ink:          #2A2118;
    --ink-light:    #6B5E52;
    --accent:       #7A2518;
    --rule:         #B8AD98;
    --rule-dark:    #8A7E6E;
    --surface:      #FFFFFF;
    --surface-warm: #FAF8F5;

    /* Agent colors — match SwiftUI system colors */
    --agent-blue:   #007AFF;
    --agent-purple: #AF52DE;
    --agent-pink:   #FF2D55;
    --agent-red:    #FF3B30;
    --agent-orange: #FF9500;
    --agent-yellow: #FFCC00;
    --agent-green:  #34C759;
    --agent-teal:   #5AC8FA;
    --agent-cyan:   #32ADE6;
    --agent-indigo: #5856D6;
    --agent-gray:   #8E8E93;

    /* Desk states */
    --state-active: #3D6B4A;
    --state-idle:   #B8AD98;
}

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

body {
    background: var(--paper);
    color: var(--ink);
    font-family: 'Libre Baskerville', Georgia, 'Times New Roman', serif;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ==========================================================================
   Masthead
   ========================================================================== */

.masthead {
    text-align: center;
    padding: 0 24px;
    background: var(--paper-light);
}

.masthead-rule {
    height: 3px;
    background: var(--ink);
    margin: 0 -24px;
}

.masthead-rule.thin {
    height: 1px;
    background: var(--rule-dark);
}

.masthead-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 0 4px;
}

.masthead-title {
    font-family: 'Playfair Display', Georgia, serif;
    font-weight: 900;
    font-size: 2.4rem;
    letter-spacing: 0.02em;
    color: var(--ink);
}

.masthead-left,
.masthead-right {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--ink-light);
    min-width: 140px;
}

.masthead-right { text-align: right; }

.edition-label {
    background: var(--accent);
    color: white;
    padding: 2px 8px;
    font-weight: 600;
    font-size: 0.65rem;
    letter-spacing: 0.15em;
}

.masthead-subtitle {
    font-family: 'Libre Baskerville', Georgia, serif;
    font-style: italic;
    font-size: 0.85rem;
    color: var(--ink-light);
    padding: 4px 0 8px;
}

.queue-count {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-weight: 500;
    font-size: 0.65rem;
    background: var(--ink-light);
    color: white;
    margin-right: 6px;
    font-variant-numeric: tabular-nums;
}

.connection-status {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-weight: 500;
    font-size: 0.65rem;
}

.connection-status.connected {
    background: var(--state-active);
    color: white;
}

.connection-status.disconnected {
    background: var(--accent);
    color: white;
}

/* View switcher removed — single unified view */

/* ==========================================================================
   Newsroom Floor
   ========================================================================== */

.newsroom {
    flex: 1;
    padding: 20px 24px;
    overflow-y: auto;
}

.newsroom-floor {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
    max-width: 1400px;
    margin: 0 auto;
}

.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--ink-light);
    font-style: italic;
}

.empty-state .hint {
    margin-top: 16px;
    font-size: 0.8rem;
    font-style: normal;
}

.empty-state code {
    display: inline-block;
    margin-top: 8px;
    padding: 6px 12px;
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: 4px;
    font-family: 'SF Mono', Menlo, monospace;
    font-size: 0.75rem;
    color: var(--accent);
}

/* ==========================================================================
   Agent Desk
   ========================================================================== */

.agent-desk {
    background: var(--surface);
    border: 1px solid var(--rule);
    border-radius: 0;
    overflow: hidden;
    transition: border-color 0.3s, box-shadow 0.3s, opacity 1.5s, max-height 1.5s;
    position: relative;
    opacity: 1;
    max-height: 500px;
}

.agent-desk.desk-departing {
    opacity: 0.2;
    max-height: 60px;
    overflow: hidden;
}

.agent-desk.active {
    border-color: var(--agent-color, var(--rule-dark));
    box-shadow: 0 2px 12px rgba(0,0,0,0.08);
}

/* Desk nameplate */
.desk-nameplate {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px 14px;
    border-bottom: 2px solid var(--agent-color, var(--rule));
    background: var(--surface-warm);
}

.desk-lamp {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--state-idle);
    transition: background 0.3s, box-shadow 0.3s;
    flex-shrink: 0;
}

.agent-desk.active .desk-lamp {
    background: var(--state-active);
    box-shadow: 0 0 8px rgba(61, 107, 74, 0.5);
}

.desk-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    border: 1.5px solid var(--agent-color, var(--rule));
    flex-shrink: 0;
}

.desk-name-group {
    flex: 1;
    min-width: 0;
}

.desk-name {
    font-family: 'Inter', -apple-system, sans-serif;
    font-weight: 600;
    font-size: 0.85rem;
    color: var(--ink);
}

.desk-instance {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.68rem;
    color: var(--ink-light);
    font-style: italic;
    margin-top: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.desk-role {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--ink-light);
}

/* Desk activity area */
.desk-activity {
    padding: 12px 14px;
    min-height: 80px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.activity-current {
    display: flex;
    align-items: flex-start;
    gap: 8px;
}

.activity-icon {
    font-size: 1.2rem;
    flex-shrink: 0;
    width: 24px;
    text-align: center;
    line-height: 1.4;
}

.activity-text {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.78rem;
    color: var(--ink);
    line-height: 1.4;
    flex: 1;
}

.activity-text.idle {
    color: var(--ink-light);
    font-style: italic;
}

/* Tool badges — inline tags for tool names */
.tool-badge,
.tool-badge-sm {
    display: inline-block;
    font-family: 'Inter', -apple-system, sans-serif;
    font-weight: 500;
    background: var(--agent-color, var(--ink-light));
    color: white;
    border-radius: 3px;
    vertical-align: baseline;
}

.tool-badge {
    font-size: 0.72rem;
    padding: 1px 7px;
}

.tool-badge-sm {
    font-size: 0.62rem;
    padding: 0px 5px;
}

.tool-badge.done,
.tool-badge-sm.done {
    background: var(--state-active);
}

.tool-badge.fail,
.tool-badge-sm.fail {
    background: var(--accent);
}

.tool-badge.delegate,
.tool-badge-sm.delegate {
    background: var(--agent-color, #5856D6);
    opacity: 0.9;
}

.tool-desc {
    display: block;
    font-size: 0.7rem;
    color: var(--ink-light);
    margin-top: 2px;
    font-style: italic;
}

.tool-duration {
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.65rem;
    color: var(--ink-light);
    margin-left: 6px;
    font-variant-numeric: tabular-nums;
}

/* Narrative — agent inner monologue */
.activity-narrative {
    display: none;
    font-family: 'Libre Baskerville', Georgia, serif;
    font-style: italic;
    font-size: 0.72rem;
    color: var(--ink-light);
    line-height: 1.5;
    padding: 6px 10px;
    margin-top: 2px;
    background: var(--surface-warm);
    border-left: 2px solid var(--agent-color, var(--rule));
    border-radius: 0 4px 4px 0;
}

/* Typing animation */
.typing-indicator {
    display: none;
    gap: 3px;
    align-items: center;
    padding: 4px 0;
}

.agent-desk.active .typing-indicator.show {
    display: inline-flex;
}

.typing-dot {
    width: 4px;
    height: 4px;
    border-radius: 50%;
    background: var(--agent-color, var(--ink-light));
    animation: typingBounce 1.2s infinite;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-4px); opacity: 1; }
}

/* Desk log — mini activity history */
.desk-log {
    border-top: 1px solid var(--rule);
    padding: 8px 14px;
    max-height: 120px;
    overflow-y: auto;
}

.desk-log::-webkit-scrollbar {
    width: 4px;
}

.desk-log::-webkit-scrollbar-thumb {
    background: var(--rule);
    border-radius: 2px;
}

.log-entry {
    display: flex;
    align-items: baseline;
    gap: 6px;
    padding: 2px 0;
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.68rem;
    color: var(--ink-light);
    line-height: 1.3;
}

.log-time {
    font-variant-numeric: tabular-nums;
    flex-shrink: 0;
    opacity: 0.6;
    min-width: 48px;
}

.log-icon {
    flex-shrink: 0;
    width: 14px;
    text-align: center;
    font-size: 0.7rem;
}

.log-msg {
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* New log entry flash */
.log-entry.new {
    animation: logFlash 1.5s ease-out;
}

@keyframes logFlash {
    0% { background: rgba(122, 37, 24, 0.08); }
    100% { background: transparent; }
}

/* ==========================================================================
   Activity Ticker
   ========================================================================== */

.ticker-bar {
    display: flex;
    align-items: center;
    background: var(--ink);
    color: var(--paper-light);
    height: 32px;
    overflow: hidden;
    flex-shrink: 0;
}

.ticker-label {
    font-family: 'Inter', -apple-system, sans-serif;
    font-weight: 600;
    font-size: 0.65rem;
    letter-spacing: 0.15em;
    text-transform: uppercase;
    background: var(--accent);
    color: white;
    padding: 0 12px;
    height: 100%;
    display: flex;
    align-items: center;
    flex-shrink: 0;
}

.ticker-feed {
    flex: 1;
    overflow: hidden;
    white-space: nowrap;
    font-family: 'Inter', -apple-system, sans-serif;
    font-size: 0.72rem;
    padding: 0 16px;
    display: flex;
    align-items: center;
    gap: 24px;
}

.ticker-waiting {
    color: var(--rule);
    font-style: italic;
}

.ticker-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    animation: tickerSlideIn 0.4s ease-out;
    flex-shrink: 0;
}

.ticker-item .ticker-agent {
    font-weight: 600;
}

.ticker-item .ticker-sep {
    color: var(--rule-dark);
    margin: 0 4px;
}

@keyframes tickerSlideIn {
    from { opacity: 0; transform: translateX(40px); }
    to   { opacity: 1; transform: translateX(0); }
}

/* ==========================================================================
   Responsive
   ========================================================================== */

@media (max-width: 600px) {
    .masthead-title { font-size: 1.4rem; }
    .masthead-left, .masthead-right { display: none; }
    .newsroom-floor { grid-template-columns: 1fr; }
}
