/* Timon Dashboard — Dark theme */

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-hover: #222632;
    --border: #2a2e3a;
    --text: #e4e6eb;
    --text-muted: #8b8fa3;
    --accent: #6366f1;
    --accent-hover: #818cf8;
    --green: #22c55e;
    --red: #ef4444;
    --orange: #f59e0b;
    --radius: 12px;
    --radius-sm: 8px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* Layout */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 32px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

header h1 {
    font-size: 20px;
    font-weight: 600;
}

.header-subtitle {
    font-size: 13px;
    color: var(--text-muted);
}

/* Status Bar */
.status-bar {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 14px 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 24px;
    flex-wrap: wrap;
}

.status-bar-group {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
}

.status-divider {
    width: 1px;
    height: 32px;
    background: var(--border);
}

.status-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 80px;
}

.status-item.kpi {
    align-items: center;
    min-width: 60px;
}

.status-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
}

.status-value {
    font-size: 13px;
    font-weight: 500;
}

.kpi-val {
    font-size: 18px;
    font-weight: 700;
    color: var(--accent);
}

.h-ok { color: var(--green); }
.h-err { color: var(--red); }
.h-pct { font-size: 11px; margin-left: 3px; color: var(--text-muted); }
.h-pct.h-err { color: var(--red); }

/* Sections */
.section {
    margin-bottom: 32px;
}

.section-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

/* Funnel Bar */
.funnel-bar {
    display: flex;
    height: 32px;
    border-radius: var(--radius-sm);
    overflow: hidden;
    margin-bottom: 8px;
}

.funnel-segment {
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 600;
    color: white;
    min-width: 2px;
    transition: width 0.3s;
}

.funnel-legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 13px;
    color: var(--text-muted);
}

.funnel-legend-item {
    display: flex;
    align-items: center;
    gap: 4px;
}

.funnel-legend-item b {
    color: var(--text);
}

.funnel-dot {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 3px;
}

/* Table */
.table-wrap {
    overflow-x: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th {
    text-align: left;
    padding: 12px 16px;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    font-weight: 500;
    white-space: nowrap;
}

th.sortable {
    cursor: pointer;
    user-select: none;
}

th.sortable:hover { color: var(--accent); }
th.sort-asc::after { content: ' ▲'; font-size: 10px; }
th.sort-desc::after { content: ' ▼'; font-size: 10px; }

td {
    padding: 10px 16px;
    border-bottom: 1px solid var(--border);
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface-hover); }

.td-date {
    font-size: 13px;
    color: var(--text-muted);
    white-space: nowrap;
}

.user-cell-name {
    font-weight: 500;
}

.user-cell-handle {
    font-size: 12px;
    color: var(--text-muted);
}

/* Status Badge */
.status-badge {
    display: inline-block;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 10px;
    color: white;
}

/* Enrichment Badge */
.enrichment-badge {
    display: inline-block;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    border: 1px solid var(--border);
}

.badge-full { background: rgba(34, 197, 94, 0.15); color: var(--green); border-color: rgba(34, 197, 94, 0.3); }
.badge-basic { background: rgba(245, 158, 11, 0.15); color: var(--orange); border-color: rgba(245, 158, 11, 0.3); }
.badge-none { background: var(--surface-hover); color: var(--text-muted); }
.badge-minimal { background: var(--surface-hover); color: var(--text-muted); }

/* Chat Link */
.chat-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
}

.chat-link:hover { color: var(--accent-hover); text-decoration: underline; }

/* Table Controls */
.table-controls {
    display: flex;
    gap: 8px;
    margin-left: auto;
}

.filter-select, .filter-input {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    padding: 6px 12px;
    font-size: 13px;
    outline: none;
}

.filter-select:focus, .filter-input:focus {
    border-color: var(--accent);
}

.filter-input { width: 160px; }

.filter-btn {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-muted);
    padding: 6px 12px;
    font-size: 13px;
    cursor: pointer;
}

.filter-btn:hover { border-color: var(--accent); color: var(--text); }

/* Cron Status */
.cron-details { width: 100%; }

.cron-toggle {
    cursor: pointer;
    user-select: none;
    list-style: none;
    padding: 8px 14px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: border-color 0.2s;
}

.cron-toggle:hover { border-color: var(--accent); }
.cron-toggle::-webkit-details-marker { display: none; }
.cron-toggle::marker { display: none; content: ''; }

.cron-badge {
    font-size: 12px;
    color: var(--green);
    margin-left: 8px;
    font-weight: 500;
}

.cron-badge.has-errors { color: var(--orange); }

.cron-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 10px;
}

.cron-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    flex-wrap: wrap;
}

.cron-status { font-size: 14px; font-weight: 700; min-width: 18px; text-align: center; }
.cron-ok { color: var(--green); }
.cron-err { color: var(--red); }
.cron-pending { color: var(--text-muted); }
.cron-name { font-weight: 500; min-width: 120px; flex-shrink: 0; }
.cron-schedule { font-size: 12px; color: var(--text-muted); }
.cron-dur { font-size: 11px; color: var(--text-muted); margin-left: auto; }
.cron-error { font-size: 11px; color: var(--red); width: 100%; padding-left: 28px; }

/* --- Conversation Page --- */

.conv-header {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
}

.back-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
}

.back-link:hover { color: var(--accent-hover); }

.conv-handle {
    font-size: 13px;
    color: var(--text-muted);
}

.conv-controls {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}

.msg-count {
    font-size: 13px;
    color: var(--text-muted);
    margin-left: auto;
}

/* Profile Card */
.profile-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 20px;
}

.profile-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

.profile-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.profile-toggle {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 0 4px;
}

.profile-toggle:hover { color: var(--accent); }

.profile-field {
    font-size: 13px;
    padding: 4px 0;
    line-height: 1.5;
}

.profile-key {
    font-weight: 600;
    color: var(--accent);
}

.profile-section {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.profile-section-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    margin-bottom: 4px;
}

.profile-section-body {
    font-size: 13px;
    line-height: 1.5;
    color: var(--text);
}

/* Chat Bubbles */
.chat-bubbles {
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px 0;
}

.chat-bubble {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 13px;
    line-height: 1.5;
    position: relative;
}

.bubble-left {
    align-self: flex-start;
    background: var(--surface);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.bubble-right {
    align-self: flex-end;
    background: rgba(34, 197, 94, 0.08);
    border: 1px solid rgba(34, 197, 94, 0.2);
    border-bottom-right-radius: 4px;
}

.bubble-error {
    border-color: rgba(239, 68, 68, 0.4) !important;
    background: rgba(239, 68, 68, 0.06) !important;
}

.bubble-media {
    border-color: rgba(99, 102, 241, 0.3);
}

.bubble-meta {
    display: flex;
    gap: 8px;
    align-items: center;
    margin-bottom: 2px;
    flex-wrap: wrap;
}

.bubble-who {
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
}

.bubble-right .bubble-who {
    color: var(--green);
}

.bubble-time {
    font-size: 10px;
    color: var(--text-muted);
    font-family: 'SF Mono', 'Fira Code', monospace;
}

.bubble-text {
    white-space: pre-wrap;
    word-break: break-word;
}

.bubble-media-tag {
    font-size: 10px;
    color: var(--accent);
    background: rgba(99, 102, 241, 0.1);
    padding: 1px 6px;
    border-radius: 4px;
}

.bubble-error-tag {
    font-size: 10px;
    color: var(--red);
    background: rgba(239, 68, 68, 0.1);
    padding: 1px 6px;
    border-radius: 4px;
}

.chat-date-separator {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    padding: 12px 0 4px;
    font-weight: 500;
}

/* Login */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}

.login-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 40px;
    width: 360px;
}

.login-box h2 {
    margin-bottom: 24px;
    text-align: center;
}

.login-box input {
    width: 100%;
    padding: 12px 16px;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text);
    font-size: 14px;
    margin-bottom: 16px;
    outline: none;
}

.login-box input:focus {
    border-color: var(--accent);
}

.btn {
    width: 100%;
    padding: 12px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: background 0.2s;
}

.btn:hover { background: var(--accent-hover); }

.empty {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
    font-size: 14px;
}

/* Responsive */
@media (max-width: 768px) {
    .container { padding: 16px; }
    .status-bar { flex-direction: column; gap: 12px; }
    .status-divider { width: 100%; height: 1px; }
    .chat-bubble { max-width: 90%; }
    .table-controls { flex-direction: column; width: 100%; }
    .filter-input { width: 100%; }
    .section-title { flex-direction: column; align-items: flex-start; }
    .conv-header { flex-wrap: wrap; }
}
