/* ============================================================================
   KAAI Memory Monitor Panel — CEO Dashboard
   memory-panel.css
   ============================================================================ */

/* ── Panel Layout ─────────────────────────────────────────────────────────── */
#panel-memory .panel-content {
    padding: 0;
}

.memory-tabs {
    display: flex;
    gap: 2px;
    border-bottom: 1px solid var(--border-color, #2a2a2a);
    background: var(--bg-secondary, #141414);
    padding: 0 16px;
    overflow-x: auto;
    flex-shrink: 0;
}

.mem-tab {
    padding: 10px 16px;
    cursor: pointer;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary, #888);
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: color .15s, border-color .15s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
}
.mem-tab:hover { color: var(--text-primary, #eee); }
.mem-tab.active {
    color: var(--accent, #7c6fcd);
    border-bottom-color: var(--accent, #7c6fcd);
}

.mem-tab-panel { display: none; padding: 16px; }
.mem-tab-panel.active { display: block; }

/* ── DB Cards Grid ────────────────────────────────────────────────────────── */
.db-cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.db-card {
    background: var(--bg-card, #1a1a1a);
    border: 1px solid var(--border-color, #2a2a2a);
    border-radius: 8px;
    padding: 14px 16px;
    position: relative;
    transition: border-color .15s;
}
.db-card:hover { border-color: var(--accent, #7c6fcd); }

.db-card-name {
    font-size: 13px;
    font-weight: 700;
    color: var(--accent, #7c6fcd);
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 8px;
}
.db-card-badge {
    font-size: 10px;
    padding: 2px 6px;
    border-radius: 10px;
    background: var(--accent-muted, #2e2b4a);
    color: var(--accent, #7c6fcd);
    font-weight: 600;
}
.db-card-size {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary, #eee);
    line-height: 1.2;
}
.db-card-meta {
    font-size: 11px;
    color: var(--text-muted, #555);
    margin-top: 4px;
}
.db-card-tables {
    margin-top: 10px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.db-table-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
    padding: 3px 0;
    border-bottom: 1px solid var(--border-subtle, #1e1e1e);
}
.db-table-row:last-child { border-bottom: none; }
.db-table-name { color: var(--text-secondary, #aaa); }
.db-table-count {
    font-weight: 600;
    color: var(--text-primary, #eee);
    background: var(--bg-secondary, #141414);
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 10px;
}

/* ── KPI Row ──────────────────────────────────────────────────────────────── */
.mem-kpi-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 10px;
    margin-bottom: 20px;
}
.mem-kpi {
    background: var(--bg-card, #1a1a1a);
    border: 1px solid var(--border-color, #2a2a2a);
    border-radius: 8px;
    padding: 12px 14px;
    text-align: center;
}
.mem-kpi-value {
    font-size: 24px;
    font-weight: 800;
    color: var(--accent, #7c6fcd);
    line-height: 1;
}
.mem-kpi-label {
    font-size: 10px;
    color: var(--text-muted, #555);
    margin-top: 4px;
    text-transform: uppercase;
    letter-spacing: .5px;
}

/* ── Charts Section ───────────────────────────────────────────────────────── */
.mem-charts-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}
@media (max-width: 900px) {
    .mem-charts-row { grid-template-columns: 1fr; }
}

.mem-chart-card {
    background: var(--bg-card, #1a1a1a);
    border: 1px solid var(--border-color, #2a2a2a);
    border-radius: 8px;
    padding: 14px 16px;
}
.mem-chart-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-secondary, #888);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: .5px;
}

/* Bar chart (CSS-only) */
.bar-chart { display: flex; flex-direction: column; gap: 6px; }
.bar-row {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 11px;
}
.bar-label {
    width: 110px;
    flex-shrink: 0;
    color: var(--text-secondary, #aaa);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    text-align: right;
}
.bar-track {
    flex: 1;
    background: var(--bg-secondary, #141414);
    border-radius: 3px;
    height: 14px;
    overflow: hidden;
}
.bar-fill {
    height: 100%;
    border-radius: 3px;
    background: var(--accent, #7c6fcd);
    transition: width .4s ease;
    min-width: 2px;
}
.bar-count {
    width: 50px;
    flex-shrink: 0;
    color: var(--text-primary, #eee);
    font-weight: 600;
    text-align: left;
}

/* Sparkline canvas */
.sparkline-canvas {
    width: 100%;
    height: 80px;
    display: block;
}

/* Growth chart canvas */
.growth-canvas {
    width: 100%;
    height: 120px;
    display: block;
}

/* ── Tag Cloud ────────────────────────────────────────────────────────────── */
.tag-cloud {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    padding: 4px 0;
}
.tag-pill {
    padding: 3px 10px;
    border-radius: 12px;
    background: var(--bg-secondary, #141414);
    border: 1px solid var(--border-color, #2a2a2a);
    color: var(--text-secondary, #aaa);
    font-size: 11px;
    cursor: pointer;
    transition: all .15s;
    white-space: nowrap;
}
.tag-pill:hover {
    background: var(--accent-muted, #2e2b4a);
    border-color: var(--accent, #7c6fcd);
    color: var(--accent, #7c6fcd);
}
.tag-pill.tag-lg { font-size: 14px; font-weight: 700; }
.tag-pill.tag-md { font-size: 12px; font-weight: 600; }
.tag-pill.tag-sm { font-size: 10px; }

/* ── Memory Browser Table ─────────────────────────────────────────────────── */
.mem-search-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}
.mem-search-bar input,
.mem-search-bar select {
    background: var(--bg-secondary, #141414);
    border: 1px solid var(--border-color, #2a2a2a);
    border-radius: 6px;
    padding: 7px 12px;
    color: var(--text-primary, #eee);
    font-size: 12px;
    outline: none;
    transition: border-color .15s;
}
.mem-search-bar input { flex: 1; min-width: 160px; }
.mem-search-bar input:focus,
.mem-search-bar select:focus { border-color: var(--accent, #7c6fcd); }

.mem-table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border-color, #2a2a2a);
    border-radius: 8px;
}
.mem-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 12px;
}
.mem-table th {
    background: var(--bg-secondary, #141414);
    color: var(--text-muted, #555);
    font-weight: 600;
    padding: 8px 12px;
    text-align: left;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: .4px;
    border-bottom: 1px solid var(--border-color, #2a2a2a);
    white-space: nowrap;
}
.mem-table td {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-subtle, #1a1a1a);
    color: var(--text-secondary, #aaa);
    vertical-align: top;
    max-width: 280px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.mem-table tr:hover td { background: var(--bg-hover, #1e1e1e); cursor: pointer; }
.mem-table tr:last-child td { border-bottom: none; }
.mem-table td.mono { font-family: monospace; font-size: 11px; }
.mem-table td.cell-id { color: var(--text-muted, #555); width: 50px; }

/* Type / layer badges */
.mem-type-badge {
    display: inline-block;
    padding: 2px 7px;
    border-radius: 10px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: .3px;
    white-space: nowrap;
}
.badge-code       { background: #1e3a2b; color: #4ade80; }
.badge-error      { background: #3a1e1e; color: #f87171; }
.badge-decision   { background: #2b2e1e; color: #facc15; }
.badge-learning   { background: #1e2b3a; color: #60a5fa; }
.badge-preference { background: #2e1e3a; color: #c084fc; }
.badge-default    { background: var(--bg-secondary, #141414); color: var(--text-muted, #666); }

.mem-priority-dot {
    display: inline-block;
    width: 8px; height: 8px;
    border-radius: 50%;
    margin-right: 4px;
}
.prio-1 { background: #ef4444; }
.prio-2 { background: #f97316; }
.prio-3 { background: #facc15; }
.prio-4 { background: #22c55e; }
.prio-5 { background: #3b82f6; }

/* Pagination */
.mem-pagination {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    justify-content: center;
    font-size: 12px;
}
.mem-pagination button {
    background: var(--bg-secondary, #141414);
    border: 1px solid var(--border-color, #2a2a2a);
    border-radius: 6px;
    padding: 5px 12px;
    color: var(--text-secondary, #aaa);
    cursor: pointer;
    font-size: 12px;
    transition: all .15s;
}
.mem-pagination button:hover:not(:disabled) {
    border-color: var(--accent, #7c6fcd);
    color: var(--accent, #7c6fcd);
}
.mem-pagination button:disabled { opacity: .35; cursor: not-allowed; }
.mem-pagination .page-info { color: var(--text-muted, #555); }

/* ── Detail Modal ─────────────────────────────────────────────────────────── */
.mem-detail-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.7);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.mem-detail-box {
    background: var(--bg-card, #1a1a1a);
    border: 1px solid var(--border-color, #2a2a2a);
    border-radius: 10px;
    max-width: 720px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    padding: 24px;
    position: relative;
}
.mem-detail-close {
    position: absolute;
    top: 12px; right: 14px;
    background: none;
    border: none;
    color: var(--text-muted, #555);
    font-size: 20px;
    cursor: pointer;
}
.mem-detail-close:hover { color: var(--text-primary, #eee); }
.mem-detail-field {
    margin-bottom: 12px;
}
.mem-detail-field label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted, #555);
    text-transform: uppercase;
    letter-spacing: .4px;
    display: block;
    margin-bottom: 4px;
}
.mem-detail-field .val {
    font-size: 13px;
    color: var(--text-primary, #eee);
    background: var(--bg-secondary, #141414);
    border-radius: 6px;
    padding: 8px 10px;
    font-family: monospace;
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 200px;
    overflow-y: auto;
}

/* ── Live Feed ────────────────────────────────────────────────────────────── */
.mem-live-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 10px;
}
.live-dot {
    width: 8px; height: 8px;
    border-radius: 50%;
    background: #22c55e;
    animation: pulse-live 1.5s infinite;
    flex-shrink: 0;
}
@keyframes pulse-live {
    0%,100% { opacity: 1; transform: scale(1); }
    50% { opacity: .4; transform: scale(.8); }
}
.live-feed-list {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 340px;
    overflow-y: auto;
    font-family: monospace;
    font-size: 11px;
}
.live-event {
    display: flex;
    gap: 8px;
    padding: 5px 8px;
    border-radius: 5px;
    background: var(--bg-secondary, #141414);
    border: 1px solid var(--border-subtle, #1e1e1e);
    align-items: flex-start;
    animation: slide-in .2s ease;
}
@keyframes slide-in {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: translateY(0); }
}
.live-event-db {
    flex-shrink: 0;
    padding: 1px 6px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 700;
}
.db-unified   { background: #2e2b4a; color: #7c6fcd; }
.db-braincell { background: #1e3a2b; color: #4ade80; }
.db-mother    { background: #3a1e1e; color: #f87171; }
.db-digest    { background: #2b2e1e; color: #facc15; }

.live-event-ts { color: var(--text-muted, #555); flex-shrink: 0; }
.live-event-label { color: var(--text-secondary, #aaa); flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.live-empty { color: var(--text-muted, #555); font-style: italic; text-align: center; padding: 20px; }

/* ── Integrity ────────────────────────────────────────────────────────────── */
.integrity-card {
    background: var(--bg-card, #1a1a1a);
    border: 1px solid var(--border-color, #2a2a2a);
    border-radius: 8px;
    padding: 14px 16px;
    margin-bottom: 10px;
}
.integrity-card-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--text-primary, #eee);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.integrity-ok   { color: #22c55e; }
.integrity-fail { color: #ef4444; }
.integrity-hash {
    font-family: monospace;
    font-size: 10px;
    color: var(--text-muted, #555);
    word-break: break-all;
    background: var(--bg-secondary, #141414);
    padding: 6px 8px;
    border-radius: 5px;
}

/* ── Section headers inside panels ───────────────────────────────────────── */
.mem-section-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--text-secondary, #888);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin: 20px 0 10px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--border-color, #2a2a2a);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.mem-section-title span { color: var(--text-muted, #555); font-weight: 400; font-size: 11px; letter-spacing: 0; }

/* Vector gauge */
.vector-gauge-wrap {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 0;
}
.vector-gauge-track {
    flex: 1;
    height: 18px;
    background: var(--bg-secondary, #141414);
    border-radius: 9px;
    overflow: hidden;
    position: relative;
}
.vector-gauge-fill {
    height: 100%;
    border-radius: 9px;
    background: linear-gradient(90deg, #7c6fcd, #a78bfa);
    transition: width .6s ease;
    position: relative;
}
.vector-gauge-fill::after {
    content: attr(data-pct) '%';
    position: absolute;
    right: 6px; top: 0;
    line-height: 18px;
    font-size: 10px;
    font-weight: 700;
    color: #fff;
}
.vector-gauge-label {
    font-size: 12px;
    color: var(--text-secondary, #aaa);
    white-space: nowrap;
}

/* ── Knowledge Base Tab ────────────────────────────────────────────────────── */
.kb-type-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 12px;
    margin-bottom: 20px;
}

.kb-type-card {
    background: var(--bg-card, #1a1a1a);
    border: 1px solid var(--border-color, #2a2a2a);
    border-radius: 8px;
    padding: 12px 14px;
    cursor: pointer;
    transition: border-color .15s, background .15s;
}
.kb-type-card:hover {
    background: var(--bg-hover, #222);
    border-color: var(--accent, #7c6fcd);
}

.kb-type-header {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
}
.kb-type-icon { font-size: 16px; flex-shrink: 0; }
.kb-type-name {
    font-size: 12px;
    font-weight: 700;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.kb-type-count {
    font-size: 11px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 10px;
    flex-shrink: 0;
}
.kb-type-latest {
    font-size: 10px;
    color: var(--text-muted, #555);
    margin-bottom: 6px;
}
.kb-type-samples {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.kb-sample {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    transition: background .1s;
}
.kb-sample:hover { background: var(--bg-secondary, #141414); }
.kb-sample-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 4px;
}
.kb-sample-text {
    font-size: 11px;
    color: var(--text-secondary, #aaa);
    line-height: 1.4;
    overflow: hidden;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
}

/* ── Learning & Analyst overview sections ───────────────────────────────── */
.mem-analyst-block {
    background: var(--card-bg, #1a1a2e);
    border: 1px solid var(--border-color, #2a2a3a);
    border-radius: 8px;
    padding: 10px 12px;
    margin-bottom: 8px;
}

.mem-analyst-section-label {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted, #666);
    text-transform: uppercase;
    letter-spacing: 0.6px;
    margin-bottom: 8px;
}

.mem-analyst-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 0;
    border-bottom: 1px solid rgba(255,255,255,0.04);
}

.mem-analyst-row:last-child { border-bottom: none; }

.mem-analyst-icon { font-size: 18px; flex-shrink: 0; }

.mem-analyst-body {
    flex: 1;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.mem-analyst-title {
    font-size: 12px;
    color: var(--text-primary, #e8e8f0);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.mem-analyst-meta {
    font-size: 10px;
    color: var(--text-muted, #666);
}

.mem-analyst-right {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 3px;
    min-width: 100px;
}

.mem-mini-badge {
    display: inline-block;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 10px;
    margin: 2px;
}

.mem-mini-bar-track {
    width: 90px;
    height: 4px;
    background: var(--border-color, #2a2a3a);
    border-radius: 2px;
    overflow: hidden;
}

.mem-mini-bar-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.3s;
}
