/* Chatsabemio admin – server-rendered Twig UI with shadcn/Tailwind-inspired tokens. */

:root {
    --bg: #fafafa;
    --surface: #ffffff;
    --surface-subtle: #f5f5f5;
    --border: #e5e5e5;
    --border-strong: #d4d4d4;
    --text: #0a0a0a;
    --text-muted: #737373;
    --primary: #0a0a0a;
    --primary-hover: #262626;
    --danger: #dc2626;
    --success: #16a34a;
    --warning: #d97706;
    --sidebar-bg: #f7f7f7;
    --sidebar-text: #262626;
    --sidebar-muted: #737373;
    --sidebar-active: #0a0a0a;
    --radius: 8px;
    --shadow: 0 1px 2px rgb(0 0 0 / 0.04), 0 8px 24px rgb(0 0 0 / 0.04);
    --focus-ring: rgb(24 24 27 / 0.22);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 14px;
    line-height: 1.5;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Layout ------------------------------------------------------------------ */

.app {
    display: flex;
    min-height: 100vh;
    background: var(--bg);
}

.sidebar {
    width: 260px;
    flex-shrink: 0;
    background: var(--sidebar-bg);
    color: var(--sidebar-text);
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    border-right: 1px solid var(--border);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 22px 22px 16px;
    font-weight: 700;
    font-size: 16px;
    color: var(--sidebar-active);
}

.brand-dot {
    width: 22px; height: 22px;
    border-radius: 50%;
    background: #fff;
    border: 2px solid var(--primary);
    display: inline-block;
    box-shadow: inset 0 0 0 4px #fff, inset 0 0 0 7px var(--primary);
}

.sidebar-nav { display: flex; flex-direction: column; gap: 4px; padding: 8px 14px; flex: 1; }

.sidebar-nav a {
    color: var(--sidebar-text);
    padding: 9px 12px;
    border-radius: 8px;
    font-weight: 500;
}

.sidebar-nav a:hover { color: var(--sidebar-active); text-decoration: none; background: #fff; }
.sidebar-nav a.active { color: #fff; background: var(--primary); }

.sidebar-footer { padding: 14px 18px; border-top: 1px solid var(--border); }
.user-info { display: flex; flex-direction: column; margin-bottom: 8px; }
.user-info strong { color: var(--sidebar-active); font-size: 13px; }
.user-info span { font-size: 12px; overflow: hidden; text-overflow: ellipsis; }

.main {
    flex: 1;
    padding: 28px 32px 40px;
    max-width: none;
    min-width: 0;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.page-header h1 { margin: 0; font-size: 22px; letter-spacing: 0; }
.page-header .subtitle { color: var(--text-muted); margin: 4px 0 0; }
.header-actions { display: flex; gap: 8px; align-items: center; }
.filter-form { flex-wrap: wrap; }
.filter-form select,
.filter-form input[type="date"] {
    min-height: 34px;
    padding: 6px 10px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    background: #fff;
    color: var(--text);
    font: inherit;
    font-size: 13px;
}
.filter-form select:focus,
.filter-form input[type="date"]:focus {
    outline: 2px solid var(--focus-ring);
    border-color: var(--primary);
}

/* Cards ------------------------------------------------------------------- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 22px;
    overflow: hidden;
}

.card-header { padding: 18px 20px 0; }
.card-header h2 { margin: 0; font-size: 16px; }
.card-header .card-description { color: var(--text-muted); margin: 4px 0 0; font-size: 13px; }
.card-body { padding: 20px; }

.kpi-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.kpi {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px 20px;
}

.kpi .kpi-label { color: var(--text-muted); font-size: 13px; }
.kpi .kpi-value { font-size: 30px; font-weight: 700; margin-top: 8px; letter-spacing: 0; }

/* Tables ------------------------------------------------------------------ */

.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: 12px 20px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table th { color: var(--text-muted); font-size: 12px; font-weight: 600; background: #fafafa; }
.table tr:last-child td { border-bottom: none; }
.table .actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.table-empty { padding: 32px 20px; text-align: center; color: var(--text-muted); }
.compact-table { margin-top: 10px; }
.compact-table th { width: 180px; }
.chunk-preview {
    min-width: 260px;
    max-width: 620px;
    white-space: pre-wrap;
    overflow-wrap: anywhere;
}

/* Badges ------------------------------------------------------------------ */

.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    border: 1px solid var(--border);
}

.badge-active, .badge-indexed, .badge-open { background: #dcfce7; color: #166534; }
.badge-draft, .badge-pending { background: #fef9c3; color: #854d0e; }
.badge-archived, .badge-closed { background: #f3f4f6; color: #4b5563; }
.badge-processing { background: #dbeafe; color: #1e40af; }
.badge-failed { background: #fee2e2; color: #991b1b; }

/* Buttons & forms --------------------------------------------------------- */

.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border-radius: 8px;
    border: 1px solid var(--border-strong);
    background: var(--surface);
    color: var(--text);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
}

.btn:hover { background: #f3f4f6; text-decoration: none; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); }
.btn-danger { background: #fff; border-color: #fecaca; color: var(--danger); }
.btn-danger:hover { background: #fef2f2; }
.btn-ghost { background: transparent; border-color: transparent; color: inherit; }
.btn-ghost:hover { background: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; }

.field { margin-bottom: 14px; }
.field label { display: block; font-weight: 600; margin-bottom: 5px; font-size: 13px; }
.field .help { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

.field input[type="text"],
.field input[type="email"],
.field input[type="password"],
.field input[type="number"],
.field input[type="url"],
.field input[type="file"],
.field select,
.field textarea {
    width: 100%;
    padding: 8px 11px;
    border: 1px solid var(--border-strong);
    border-radius: 8px;
    font: inherit;
    background: #fff;
    color: var(--text);
}

.field input:focus, .field select:focus, .field textarea:focus {
    outline: 2px solid var(--focus-ring);
    border-color: var(--primary);
}

.field input[type="color"] { padding: 2px; height: 38px; width: 70px; border: 1px solid var(--border); border-radius: 8px; background: #fff; }
.field-checkbox { display: flex; align-items: center; gap: 8px; }
.field-checkbox input { width: auto; }
.field-checkbox label { margin: 0; }

.field-errors { color: var(--danger); font-size: 12px; margin-top: 4px; list-style: none; padding: 0; }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.form-actions { display: flex; gap: 10px; margin-top: 18px; }

.inline-form { display: inline; }

/* Flash messages ---------------------------------------------------------- */

.flash { padding: 11px 16px; border-radius: 8px; margin-bottom: 16px; font-weight: 500; }
.flash-success { background: #dcfce7; color: #166534; }
.flash-error, .flash-danger { background: #fee2e2; color: #991b1b; }
.flash-warning { background: #fef9c3; color: #854d0e; }

/* Auth page --------------------------------------------------------------- */

.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: var(--bg);
}

.auth-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 32px 34px;
    width: 100%;
    max-width: 400px;
}

.auth-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; margin-bottom: 18px; }
.auth-card h1 { font-size: 19px; margin: 0 0 18px; }

/* Charts (pure CSS bar chart) --------------------------------------------- */

.chart { display: flex; align-items: flex-end; gap: 3px; height: 180px; padding-top: 10px; }
.chart .bar-group { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; height: 100%; position: relative; }
.chart .bar { background: var(--primary); border-radius: 3px 3px 0 0; min-height: 2px; opacity: 0.85; }
.chart .bar-group:hover .bar { opacity: 1; }
.chart .bar-group .tooltip {
    display: none;
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--primary);
    color: #fff;
    font-size: 11px;
    padding: 5px 8px;
    border-radius: 6px;
    white-space: nowrap;
    z-index: 10;
}
.chart .bar-group:hover .tooltip { display: block; }
.chart-legend { display: flex; gap: 16px; color: var(--text-muted); font-size: 12px; margin-top: 10px; }

/* Conversation detail ------------------------------------------------------ */

.messages { display: flex; flex-direction: column; gap: 12px; }
.message {
    max-width: min(820px, 78%);
    padding: 10px 14px;
    border-radius: 8px;
    white-space: normal;
    overflow-wrap: anywhere;
}
.message-user {
    align-self: flex-end;
    max-width: min(680px, 72%);
    background: var(--primary);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.message-assistant {
    align-self: flex-start;
    background: #f3f4f6;
    border-bottom-left-radius: 4px;
}
.message-content { white-space: pre-wrap; }
.message a { color: inherit; font-weight: 700; text-decoration: underline; text-underline-offset: 2px; }
.message .message-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    font-size: 11px;
    line-height: 1.4;
    opacity: 0.7;
    margin-top: 4px;
    white-space: normal;
}
.message-sources-toggle {
    margin-top: 8px;
    padding-inline: 0;
    color: var(--text-muted);
}
.message-sources-toggle:hover {
    background: transparent;
    color: var(--text);
}
.message-sources {
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid rgb(0 0 0 / 0.08);
    font-size: 12px;
    line-height: 1.45;
    white-space: normal;
}
.message-sources[hidden] { display: none; }
.message-sources strong { display: block; margin-bottom: 6px; }
.message-sources ul {
    display: grid;
    gap: 8px;
    margin: 0;
    padding-left: 18px;
}
.message-sources li { margin: 0; padding-left: 2px; }
.source-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    color: var(--text-muted);
    margin-top: 2px;
    white-space: normal;
}

/* Misc --------------------------------------------------------------------- */

.snippet {
    background: #14161f;
    color: #e5e7eb;
    border-radius: 8px;
    padding: 14px 16px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12.5px;
    overflow-x: auto;
    white-space: pre;
}

.usage-bar { background: #e5e7eb; border-radius: 999px; height: 8px; overflow: hidden; margin-top: 8px; }
.usage-bar .usage-fill { background: var(--primary); height: 100%; border-radius: 999px; }
.usage-bar .usage-fill.usage-warn { background: var(--warning); }
.usage-bar .usage-fill.usage-over { background: var(--danger); }

.pagination { display: flex; gap: 6px; align-items: center; justify-content: center; margin-top: 16px; }
.pagination .current { font-weight: 700; padding: 5px 10px; }

.muted { color: var(--text-muted); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12.5px; }
