:root {
  --bg: #0a0b14;
  --card: #141621;
  --card-hover: #1a1d2e;
  --border: #232636;
  --text: #e0e3ed;
  --muted: #6b7088;
  --green: #3ddc84;
  --yellow: #f5c518;
  --orange: #ff9f43;
  --red: #ff5b5b;
  --blue: #4dabf7;
  --purple: #b197fc;
  --radius: 10px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); padding: 16px; max-width: 1200px; margin: 0 auto; }
#app { display: flex; flex-direction: column; gap: 14px; }

/* Header */
.header { display: flex; justify-content: space-between; align-items: center; }
.header-left { display: flex; align-items: center; gap: 10px; }
.header h1 { font-size: 1.3rem; }
.header-right { display: flex; align-items: center; gap: 8px; }
.live-badge { background: var(--red); color: #fff; padding: 2px 8px; border-radius: 10px; font-size: 0.7rem; font-weight: 700; animation: pulse 2s infinite; }
@keyframes pulse { 0%,100%{opacity:1} 50%{opacity:0.5} }
.muted-sm { color: var(--muted); font-size: 0.8rem; }

/* Buttons */
.btn { background: var(--card); border: 1px solid var(--border); color: var(--text); padding: 7px 14px; border-radius: 7px; cursor: pointer; font-size: 0.82rem; transition: all 0.15s; }
.btn:hover { background: var(--card-hover); border-color: var(--blue); }
.btn-primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn-primary:hover { opacity: 0.85; }
.btn-danger { color: var(--red); }
.btn-sm { padding: 5px 10px; font-size: 0.78rem; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* API Bar */
.api-bar { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; }
.api-bar-left, .api-bar-right { display: flex; align-items: center; gap: 8px; }
.select { background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 5px 10px; border-radius: 6px; font-size: 0.82rem; cursor: pointer; }
.switch-status { font-size: 0.8rem; }

/* Filter Bar */
.filter-bar { display: flex; align-items: center; gap: 8px; padding: 0 4px; }
.filter-btn { background: transparent; border: 1px solid var(--border); color: var(--muted); padding: 5px 14px; border-radius: 20px; cursor: pointer; font-size: 0.78rem; transition: all 0.15s; }
.filter-btn:hover { color: var(--text); }
.filter-btn.active { background: var(--blue); border-color: var(--blue); color: #fff; }

/* Provider Cards */
.providers-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(340px, 1fr)); gap: 12px; }
.provider-card { background: var(--card); border: 2px solid var(--border); border-radius: var(--radius); padding: 16px; cursor: pointer; transition: all 0.2s; }
.provider-card:hover { background: var(--card-hover); }
.provider-card.selected { border-color: var(--blue); box-shadow: 0 0 0 1px var(--blue); }
.provider-card h3 { font-size: 0.95rem; margin-bottom: 10px; display: flex; align-items: center; gap: 6px; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }
.status-green { background: var(--green); }
.status-yellow { background: var(--yellow); }
.status-warning { background: var(--orange); }
.status-critical { background: var(--red); animation: pulse 1.5s infinite; }

.metric { display: flex; justify-content: space-between; font-size: 0.82rem; padding: 3px 0; }
.metric .label { color: var(--muted); }
.metric .val { font-weight: 600; }
.metric .val.warn { color: var(--orange); }
.metric .val.crit { color: var(--red); }
.metric .val.ok { color: var(--green); }

.bar-wrap { width: 100%; height: 7px; background: var(--bg); border-radius: 4px; overflow: hidden; margin-top: 8px; }
.bar-fill { height: 100%; border-radius: 4px; transition: width 0.5s ease; }

/* Charts */
.charts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 768px) { .charts { grid-template-columns: 1fr; } }
.chart-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.chart-card h3 { font-size: 0.85rem; margin-bottom: 8px; }

/* Sections */
.section { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.section h3 { font-size: 0.9rem; margin-bottom: 10px; }

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
th { text-align: left; padding: 6px 8px; color: var(--muted); font-weight: 600; font-size: 0.72rem; text-transform: uppercase; border-bottom: 1px solid var(--border); }
td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
tbody tr:hover { background: rgba(255,255,255,0.025); }

.tag { display: inline-block; padding: 1px 7px; border-radius: 4px; font-size: 0.7rem; font-weight: 600; }
.tag-official { background: rgba(77,171,247,0.18); color: var(--blue); }
.tag-avello { background: rgba(177,151,252,0.18); color: var(--purple); }

/* Pagination */
.pagination { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 10px; }

/* Modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.65); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal.hidden { display: none; }
.modal-content { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 22px; width: 90%; max-width: 480px; }
.modal-content h3 { margin-bottom: 6px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 14px; }
.form-field { margin-bottom: 10px; }
.form-field label { display: block; font-size: 0.78rem; color: var(--muted); margin-bottom: 3px; }
.form-field input { width: 100%; background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 7px 10px; border-radius: 6px; font-size: 0.82rem; }

.convo-card { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 14px; margin-bottom: 10px; }
.convo-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.convo-header .time { font-size: 0.78rem; color: var(--muted); }
.convo-user { background: rgba(77,171,247,0.08); border-left: 3px solid var(--blue); padding: 8px 12px; border-radius: 6px; margin-bottom: 8px; font-size: 0.85rem; white-space: pre-wrap; word-break: break-word; max-height: 200px; overflow-y: auto; }
.convo-assistant { background: rgba(177,151,252,0.08); border-left: 3px solid var(--purple); padding: 8px 12px; border-radius: 6px; font-size: 0.85rem; white-space: pre-wrap; word-break: break-word; max-height: 400px; overflow-y: auto; }
.convo-meta { display: flex; gap: 12px; font-size: 0.75rem; color: var(--muted); margin-top: 6px; }
.convo-meta .tag { cursor: default; }
#convo-modal .modal-content { max-width: 700px; max-height: 80vh; overflow-y: auto; }
#convo-modal-body { margin-bottom: 12px; }
.convo-full-user { background: rgba(77,171,247,0.08); border-left: 3px solid var(--blue); padding: 12px 16px; border-radius: 8px; margin-bottom: 12px; font-size: 0.88rem; white-space: pre-wrap; word-break: break-word; }
.convo-full-ai { background: rgba(177,151,252,0.08); border-left: 3px solid var(--purple); padding: 12px 16px; border-radius: 8px; font-size: 0.88rem; white-space: pre-wrap; word-break: break-word; }
.convo-full-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; }
.convo-search-bar { display: flex; gap: 8px; margin-bottom: 10px; }
.search-input { flex: 1; background: var(--bg); border: 1px solid var(--border); color: var(--text); padding: 7px 12px; border-radius: 7px; font-size: 0.82rem; }
.search-input:focus { outline: none; border-color: var(--blue); }
#cost-display { color: var(--green); font-weight: 600; }
.copy-btn { background: transparent; border: 1px solid var(--border); color: var(--muted); padding: 3px 8px; border-radius: 5px; cursor: pointer; font-size: 0.72rem; margin-left: 8px; }
.copy-btn:hover { color: var(--blue); border-color: var(--blue); }
.tips-section { border-left: 3px solid var(--green); }
.tip-card { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 10px 14px; margin-bottom: 8px; font-size: 0.82rem; }
.tip-card .tip-icon { margin-right: 6px; }
.tip-card strong { color: var(--green); }
.tip-savings { color: var(--green); font-weight: 600; }

/* Stats Summary */
.stats-summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 10px; }
.stat-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stat-card .stat-icon { font-size: 1.3rem; }
.stat-card .stat-val { font-size: 1.4rem; font-weight: 700; color: var(--text); }
.stat-card .stat-label { font-size: 0.72rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.stats-summary.hidden { display: none; }

/* Icon button */
.icon-btn { font-size: 1rem; padding: 4px 8px; line-height: 1; }

/* Light theme */
body.light-theme { --bg: #f5f6fa; --card: #fff; --card-hover: #f0f1f5; --border: #e0e3ed; --text: #1a1d2e; --muted: #6b7088; }
body.light-theme th { color: var(--muted); }
body.light-theme .tag-official { background: rgba(77,171,247,0.12); }
body.light-theme .tag-avello { background: rgba(177,151,252,0.12); }
body.light-theme .convo-user { background: rgba(77,171,247,0.06); }
body.light-theme .convo-assistant { background: rgba(177,151,252,0.06); }
body.light-theme .convo-full-user { background: rgba(77,171,247,0.06); }
body.light-theme .convo-full-ai { background: rgba(177,151,252,0.06); }
body.light-theme .tip-card { background: var(--card-hover); }
body.light-theme .select { background: var(--card); }
body.light-theme .form-field input { background: var(--card-hover); }
body.light-theme .search-input { background: var(--card); }

/* Available Models Grid */
.models-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 12px; }
.provider-models { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px; }
.provider-models h4 { font-size: 0.85rem; margin-bottom: 8px; }
.model-list { display: flex; flex-direction: column; gap: 4px; }
.model-item { display: flex; align-items: center; gap: 6px; padding: 4px 8px; background: var(--card); border-radius: 4px; font-size: 0.78rem; border: 1px solid var(--border); }
.model-item.model-current { border-color: var(--green); background: rgba(61,220,132,0.08); }
.model-icon { font-size: 0.7rem; }


/* Conversation Session UI */
.convo-title { font-size: 0.88rem; font-weight: 600; color: var(--text); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.convo-session-meta { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; font-size: 0.75rem; flex-wrap: wrap; }
.convo-session-info { display: flex; align-items: center; gap: 6px; margin-bottom: 12px; font-size: 0.78rem; }
.convo-modal-nav { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border); }
.convo-modal-title { font-size: 0.95rem; font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; }
.convo-turns-container { max-height: 50vh; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.convo-turn { border: 1px solid var(--border); border-radius: 8px; padding: 12px; background: var(--bg); }
.convo-turn-header { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.turn-num { font-size: 0.72rem; font-weight: 700; color: var(--blue); background: rgba(77,171,247,0.12); padding: 2px 8px; border-radius: 4px; }
.convo-search-bar { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; align-items: center; }
#convo-search-info { min-width: 80px; }

/* Light theme additions */
body.light-theme .convo-turn { background: var(--card-hover); }
body.light-theme .convo-title { color: var(--text); }
