/* ============================================================
   ClearLLM — Dark/Light Theme + Sidebar + Two-Column Layout
   ============================================================ */

/* ---- Dark theme (default) ---- */
:root, [data-theme="dark"] {
    --bg-primary: #0a0c10;
    --bg-secondary: #0f1218;
    --bg-card: #151921;
    --bg-input: #1a1f2b;
    --bg-hover: #1e2433;
    --border: #232938;
    --border-light: #2a3146;
    --border-focus: #4f6df5;
    --text-primary: #e4e8f1;
    --text-secondary: #8b92a8;
    --text-muted: #555e78;
    --accent: #4f6df5;
    --accent-hover: #6381f7;
    --accent-glow: rgba(79, 109, 245, 0.12);
    --accent-soft: rgba(79, 109, 245, 0.08);
    --success: #22c55e;
    --success-glow: rgba(34, 197, 94, 0.1);
    --warning: #f59e0b;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --shadow: 0 1px 4px rgba(0,0,0,0.25);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.35);
    --modal-bg: rgba(0,0,0,0.6);
}

/* ---- Light theme ---- */
[data-theme="light"] {
    --bg-primary: #f0f2f5;
    --bg-secondary: #ffffff;
    --bg-card: #ffffff;
    --bg-input: #f5f7fa;
    --bg-hover: #e8ecf2;
    --border: #d5dae4;
    --border-light: #c8cfdc;
    --border-focus: #4f6df5;
    --text-primary: #1a1d27;
    --text-secondary: #555e78;
    --text-muted: #8b92a8;
    --accent: #4259e0;
    --accent-hover: #3448c9;
    --accent-glow: rgba(66, 89, 224, 0.1);
    --accent-soft: rgba(66, 89, 224, 0.06);
    --success: #16a34a;
    --success-glow: rgba(22, 163, 74, 0.08);
    --warning: #d97706;
    --danger: #dc2626;
    --danger-hover: #b91c1c;
    --shadow: 0 1px 4px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --modal-bg: rgba(0,0,0,0.3);
}

/* ---- Tokens ---- */
:root {
    --sidebar-width: 260px;
    --topbar-height: 52px;
    --radius: 10px;
    --radius-sm: 6px;
    --radius-xs: 4px;
    --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;
    --transition: 0.2s ease;
}

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

html {
    font-size: 14px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    line-height: 1.6;
    overflow: hidden;
    transition: background var(--transition), color var(--transition);
}

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
    width: var(--sidebar-width);
    height: 100vh;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    flex-shrink: 0;
    overflow-y: auto;
    position: fixed;
    left: 0;
    top: 0;
    z-index: 200;
    transition: background var(--transition), border-color var(--transition);
}

.sidebar-top { padding: 1.25rem; display: flex; flex-direction: column; gap: 1.25rem; }
.sidebar-bottom { padding: 1rem 1.25rem; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 0.75rem; }
.sidebar-bottom-actions { display: flex; flex-direction: column; gap: 0.25rem; }

.brand { display: flex; align-items: center; gap: 0.6rem; padding-bottom: 1rem; border-bottom: 1px solid var(--border); }
.brand-icon { width: 30px; height: 30px; color: var(--accent); flex-shrink: 0; }
.brand-name {
    font-size: 1.25rem; font-weight: 700; letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--accent), #a78bfa);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}

.sidebar-section { display: flex; flex-direction: column; gap: 0.5rem; }
.sidebar-label { font-size: 0.7rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-muted); }

.session-badge {
    display: flex; align-items: center; gap: 0.5rem;
    font-size: 0.82rem; color: var(--text-secondary);
    padding: 0.45rem 0.65rem; border-radius: var(--radius-sm);
    border: 1px solid var(--border); background: var(--bg-card);
}

.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.dot-inactive { background: var(--text-muted); }
.dot-active { background: var(--success); box-shadow: 0 0 6px var(--success-glow); animation: pulse 2s infinite; }
.dot-live { background: var(--accent); animation: pulse 1.5s infinite; width: 5px; height: 5px; }

@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

/* TTL bar */
.ttl-bar-wrap {
    height: 3px; border-radius: 2px; background: var(--bg-input); overflow: hidden;
}
.ttl-bar {
    height: 100%; background: var(--success); border-radius: 2px;
    transition: width 1s linear, background 0.3s ease;
    width: 100%;
}
.ttl-bar.warning { background: var(--warning); }
.ttl-bar.danger { background: var(--danger); }
.ttl-text { font-size: 0.68rem; color: var(--text-muted); }

.security-badge {
    display: flex; align-items: flex-start; gap: 0.5rem;
    font-size: 0.72rem; color: var(--text-muted); line-height: 1.5;
}
.security-badge svg { flex-shrink: 0; margin-top: 1px; color: var(--success); }

/* ---- Live badge ---- */
.live-badge {
    display: inline-flex; align-items: center; gap: 0.3rem;
    font-size: 0.68rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.06em; color: var(--accent); margin-left: auto;
}

/* ---- Entities ---- */
.entities-list { display: flex; flex-direction: column; gap: 0.3rem; max-height: 240px; overflow-y: auto; }

.entity-tag {
    display: flex; align-items: center; gap: 0.3rem;
    padding: 0.25rem 0.5rem; border-radius: var(--radius-xs);
    font-size: 0.72rem; font-weight: 500; font-family: var(--font-mono);
    border: 1px solid; line-height: 1.3; cursor: default;
}

.entity-tag .entity-check { width: 14px; height: 14px; accent-color: var(--accent); cursor: pointer; flex-shrink: 0; }
.entity-tag .entity-type { font-weight: 600; font-size: 0.62rem; letter-spacing: 0.02em; flex-shrink: 0; }
.entity-tag .entity-arrow { color: var(--text-muted); font-size: 0.7rem; flex-shrink: 0; }
.entity-tag .entity-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.entity-tag.disabled { opacity: 0.35; text-decoration: line-through; }

/* Entity colors */
.entity-PERSON          { color: #f472b6; border-color: #f472b633; background: #f472b60a; }
.entity-EMAIL_ADDRESS   { color: #60a5fa; border-color: #60a5fa33; background: #60a5fa0a; }
.entity-PHONE_NUMBER    { color: #34d399; border-color: #34d39933; background: #34d3990a; }
.entity-LOCATION        { color: #fbbf24; border-color: #fbbf2433; background: #fbbf240a; }
.entity-CREDIT_CARD     { color: #f87171; border-color: #f8717133; background: #f871710a; }
.entity-DATE_TIME       { color: #a78bfa; border-color: #a78bfa33; background: #a78bfa0a; }
.entity-IBAN_CODE       { color: #fb923c; border-color: #fb923c33; background: #fb923c0a; }
.entity-IP_ADDRESS      { color: #2dd4bf; border-color: #2dd4bf33; background: #2dd4bf0a; }
.entity-URL             { color: #818cf8; border-color: #818cf833; background: #818cf80a; }
.entity-FR_SSN          { color: #f87171; border-color: #f8717133; background: #f871710a; }
.entity-NRP             { color: #2dd4bf; border-color: #2dd4bf33; background: #2dd4bf0a; }
.entity-default         { color: #94a3b8; border-color: #94a3b833; background: #94a3b80a; }

/* Highlight colors for preview */
.hl-PERSON          { background: #f472b625; border-bottom: 2px solid #f472b6; }
.hl-EMAIL_ADDRESS   { background: #60a5fa25; border-bottom: 2px solid #60a5fa; }
.hl-PHONE_NUMBER    { background: #34d39925; border-bottom: 2px solid #34d399; }
.hl-LOCATION        { background: #fbbf2425; border-bottom: 2px solid #fbbf24; }
.hl-CREDIT_CARD     { background: #f8717125; border-bottom: 2px solid #f87171; }
.hl-DATE_TIME       { background: #a78bfa25; border-bottom: 2px solid #a78bfa; }
.hl-IBAN_CODE       { background: #fb923c25; border-bottom: 2px solid #fb923c; }
.hl-IP_ADDRESS      { background: #2dd4bf25; border-bottom: 2px solid #2dd4bf; }
.hl-URL             { background: #818cf825; border-bottom: 2px solid #818cf8; }
.hl-FR_SSN          { background: #f8717125; border-bottom: 2px solid #f87171; }
.hl-NRP             { background: #2dd4bf25; border-bottom: 2px solid #2dd4bf; }
.hl-default         { background: #94a3b825; border-bottom: 2px solid #94a3b8; }

mark.hl { padding: 0.05rem 0.15rem; border-radius: 2px; color: inherit; }

/* Manual add form */
.manual-add {
    display: flex; gap: 0.35rem; align-items: center; margin-top: 0.25rem;
}
.manual-add .input-sm {
    flex: 1; min-width: 0;
    background: var(--bg-input); border: 1px solid var(--border); border-radius: var(--radius-xs);
    color: var(--text-primary); font-family: var(--font-sans); font-size: 0.78rem;
    padding: 0.3rem 0.5rem;
}
.manual-add .input-sm:focus { outline: none; border-color: var(--border-focus); }
.manual-add .select-sm { font-size: 0.72rem; padding: 0.3rem 0.4rem; max-width: 90px; }
.btn-icon { padding: 0.3rem; min-width: 28px; justify-content: center; }

/* ============================================================
   LAYOUT MAIN
   ============================================================ */
.layout-main {
    flex: 1; margin-left: var(--sidebar-width);
    display: flex; flex-direction: column; height: 100vh; overflow: hidden;
    transition: margin-left var(--transition);
}

.topbar {
    height: var(--topbar-height);
    display: flex; align-items: center; gap: 1rem; padding: 0 1.5rem;
    background: var(--bg-secondary); border-bottom: 1px solid var(--border); flex-shrink: 0;
    transition: background var(--transition), border-color var(--transition);
}
.topbar-title { font-size: 0.95rem; font-weight: 600; }
.topbar-hint {
    margin-left: auto; font-size: 0.72rem; color: var(--text-muted);
    padding: 0.2rem 0.6rem; border-radius: var(--radius-xs);
    border: 1px solid var(--border); background: var(--bg-card);
    display: flex; align-items: center; gap: 0.3rem;
}
.topbar-hint kbd { font-family: var(--font-mono); font-size: 0.68rem; font-weight: 600; }
.sidebar-toggle { display: none; }

/* ============================================================
   CONTENT
   ============================================================ */
.content {
    flex: 1; padding: 1.25rem; overflow-y: auto;
    display: flex; flex-direction: column; gap: 1.25rem;
}

.grid-row {
    display: grid; grid-template-columns: 1fr auto 1fr;
    align-items: stretch; min-height: 0; flex: 1;
}

.grid-arrow {
    display: flex; align-items: center; justify-content: center;
    width: 48px; color: var(--text-muted); flex-shrink: 0;
}

/* ============================================================
   PANELS
   ============================================================ */
.panel {
    background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius);
    display: flex; flex-direction: column; overflow: hidden; min-height: 0;
    transition: background var(--transition), border-color var(--transition);
}
.panel-output { border-color: var(--border-light); }

.panel-header {
    display: flex; align-items: center; gap: 0.55rem;
    padding: 0.7rem 1rem; border-bottom: 1px solid var(--border);
    background: var(--bg-secondary); flex-shrink: 0;
    transition: background var(--transition), border-color var(--transition);
}
.panel-header h2 { font-size: 0.85rem; font-weight: 600; }

.panel-icon {
    width: 28px; height: 28px; border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.panel-icon-input    { background: var(--accent-soft); color: var(--accent); }
.panel-icon-output   { background: rgba(34,197,94,0.1); color: var(--success); }
.panel-icon-llm      { background: rgba(168,85,247,0.1); color: #a855f7; }
.panel-icon-restored { background: rgba(251,146,60,0.1); color: #fb923c; }

.panel-body { padding: 0.85rem; overflow-y: auto; }
.panel-body-grow { flex: 1; min-height: 0; display: flex; flex-direction: column; }

.panel-footer {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.55rem 1rem; border-top: 1px solid var(--border);
    background: var(--bg-secondary); flex-shrink: 0;
    transition: background var(--transition), border-color var(--transition);
}

/* ============================================================
   FORM ELEMENTS
   ============================================================ */
.textarea {
    width: 100%; background: var(--bg-input); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-primary);
    font-family: var(--font-mono); font-size: 0.85rem; padding: 0.75rem 0.85rem;
    resize: none; transition: border-color var(--transition), box-shadow var(--transition); line-height: 1.65;
}
.textarea-full { flex: 1; min-height: 0; border: none; border-radius: 0; background: transparent; padding: 0; }
.textarea:focus { outline: none; border-color: var(--border-focus); box-shadow: 0 0 0 2px var(--accent-glow); }
.textarea-full:focus { box-shadow: none; }
.textarea::placeholder { color: var(--text-muted); }

.select {
    width: 100%; background: var(--bg-input); border: 1px solid var(--border);
    border-radius: var(--radius-sm); color: var(--text-primary);
    font-family: var(--font-sans); font-size: 0.85rem; padding: 0.45rem 0.65rem; cursor: pointer;
}
.select:focus { outline: none; border-color: var(--border-focus); }

.char-count { font-size: 0.72rem; color: var(--text-muted); font-variant-numeric: tabular-nums; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
    display: inline-flex; align-items: center; gap: 0.35rem;
    padding: 0.5rem 1rem; border-radius: var(--radius-sm);
    font-family: var(--font-sans); font-size: 0.82rem; font-weight: 500;
    border: none; cursor: pointer; transition: all var(--transition); white-space: nowrap;
}
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); box-shadow: 0 0 20px var(--accent-glow); }
.btn-secondary { background: var(--bg-hover); color: var(--text-secondary); border: 1px solid var(--border); }
.btn-secondary:hover:not(:disabled) { background: var(--border); color: var(--text-primary); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid rgba(239,68,68,0.3); }
.btn-danger:hover:not(:disabled) { background: var(--danger); color: #fff; }
.btn-ghost { background: transparent; color: var(--text-secondary); }
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-hover); }
.btn-sm { padding: 0.35rem 0.65rem; font-size: 0.78rem; }
.btn-block { width: 100%; justify-content: center; }
.btn-group { display: flex; gap: 0.5rem; }

/* ============================================================
   STATES
   ============================================================ */
.empty-state {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    justify-content: center; gap: 0.75rem; color: var(--text-muted);
    text-align: center; padding: 2rem;
}
.empty-state svg { opacity: 0.3; }
.empty-state span { font-size: 0.82rem; }

.loader {
    display: none; flex-direction: column; align-items: center;
    justify-content: center; gap: 0.75rem; padding: 2rem;
    color: var(--text-secondary); font-size: 0.85rem; flex: 1;
}
.loader.visible { display: flex; }

.spinner {
    width: 28px; height: 28px; border: 2.5px solid var(--border);
    border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Result text */
.result-text {
    font-family: var(--font-mono); font-size: 0.85rem; line-height: 1.7;
    white-space: pre-wrap; word-break: break-word; flex: 1;
}
.result-text .placeholder {
    color: var(--accent); font-weight: 600;
    background: var(--accent-glow); padding: 0.05rem 0.3rem; border-radius: 3px;
}

/* ============================================================
   SECTION DIVIDER
   ============================================================ */
.section-divider { display: flex; align-items: center; gap: 1rem; padding: 0.25rem 0; flex-shrink: 0; }
.divider-line { flex: 1; height: 1px; background: var(--border); }
.divider-label {
    font-size: 0.72rem; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.08em; color: var(--text-muted); white-space: nowrap;
}

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
    display: none; position: fixed; inset: 0; z-index: 500;
    background: var(--modal-bg); align-items: center; justify-content: center;
    backdrop-filter: blur(4px); animation: fadeIn 0.15s ease;
}
.modal-overlay.open { display: flex; }

.modal {
    background: var(--bg-card); border: 1px solid var(--border);
    border-radius: var(--radius); box-shadow: var(--shadow-lg);
    width: 420px; max-width: 90vw; animation: scaleIn 0.2s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }

.modal-header {
    display: flex; align-items: center; justify-content: space-between;
    padding: 1rem 1.25rem; border-bottom: 1px solid var(--border);
}
.modal-header h3 { font-size: 0.95rem; font-weight: 600; }

.modal-body { padding: 1rem 1.25rem; display: flex; flex-direction: column; gap: 0.5rem; }

.shortcut-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 0.4rem 0; font-size: 0.85rem;
}

.kbd-group { display: flex; gap: 0.25rem; }

kbd {
    display: inline-block; padding: 0.15rem 0.45rem; border-radius: var(--radius-xs);
    border: 1px solid var(--border); background: var(--bg-input);
    font-family: var(--font-mono); font-size: 0.72rem; font-weight: 500;
    color: var(--text-secondary); line-height: 1.5;
}

/* ============================================================
   UTILITIES
   ============================================================ */
.text-muted { color: var(--text-muted); }
.text-xs { font-size: 0.72rem; }

/* ============================================================
   TOAST
   ============================================================ */
.toast {
    position: fixed; bottom: 1.25rem; right: 1.25rem;
    padding: 0.6rem 1.1rem; border-radius: var(--radius-sm);
    font-size: 0.82rem; font-weight: 500; color: #fff;
    box-shadow: var(--shadow-lg); z-index: 9999;
    animation: toastIn 0.25s ease, toastOut 0.25s ease 2.5s forwards;
}
.toast-success { background: var(--success); }
.toast-error   { background: var(--danger); }

@keyframes toastIn { from { opacity: 0; transform: translateY(10px) scale(0.97); } to { opacity: 1; transform: translateY(0) scale(1); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(6px); } }

.fade-in { animation: fadeIn 0.3s ease; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 1024px) {
    .sidebar { transform: translateX(-100%); transition: transform 0.25s ease; }
    .sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
    .sidebar-toggle { display: flex !important; }
    .layout-main { margin-left: 0; }
    .grid-row { grid-template-columns: 1fr; gap: 1rem; }
    .grid-arrow { display: none; }
}

@media (max-width: 640px) {
    .content { padding: 0.75rem; }
    .topbar { padding: 0 0.75rem; }
    .topbar-hint { display: none; }
}

.sidebar-overlay {
    display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 199;
}
.sidebar-overlay.active { display: block; }
