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

:root {
    --sidebar-width: 232px;
    --paper:    #f7f6f3;
    --surface:  #ffffff;
    --border:   #e5e3df;
    --border-2: #d4d2ce;
    --text:     #1a1a1a;
    --text-2:   #6b7280;
    --text-3:   #a3a3a3;
    --accent:   #4f6ef7;
    --accent-h: #3b5bdb;
    --form-color-scheme: light;
    color-scheme: light;
}

[data-theme="dark"] {
    --paper:    #111111;
    --surface:  #1c1c1c;
    --border:   #2a2a2a;
    --border-2: #383838;
    --text:     #e4e4e4;
    --text-2:   #9ca3af;
    --text-3:   #6b7280;
    --form-color-scheme: dark;
    color-scheme: dark;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--paper);
    color: var(--text);
    line-height: 1.6;
}

a { color: inherit; }

h1 { font-size: 1.6rem; font-weight: 600; margin-bottom: 1.5rem; color: var(--text); }
h2 { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.4rem; color: var(--text); }

code { font-family: "SF Mono", Consolas, monospace; font-size: 0.8rem; color: var(--accent); }

table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th { text-align: left; padding: 0.5rem 0.75rem; color: var(--text-2); border-bottom: 1px solid var(--border); font-weight: 500; }
td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--border); color: var(--text); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--paper); }

.status-active   { color: #16a34a; font-weight: 500; }
.status-inactive,
.status-failed   { color: #dc2626; font-weight: 500; }
.status-unknown  { color: var(--text-2); }

/* ── Sidebar ──────────────────────────────────────────────────────── */
.sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: var(--sidebar-width);
    background: #161616;
    border-right: 1px solid #222222;
    display: flex;
    flex-direction: column;
    z-index: 10;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    padding: 18px 20px 14px;
    text-decoration: none;
    border-bottom: 1px solid #222222;
    line-height: 0;
}

.sidebar-nav {
    flex: 1;
    padding: 12px 8px;
    overflow-y: auto;
}

.sidebar-section-label {
    font-size: 0.68rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: #4a4a5a;
    padding: 16px 12px 6px;
    margin: 0;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 12px;
    border-radius: 6px;
    color: #9ca3af;
    text-decoration: none;
    font-size: 0.875rem;
    font-weight: 500;
    transition: background 0.15s, color 0.15s;
}
.sidebar-link svg { width: 16px; height: 16px; flex-shrink: 0; }
.sidebar-link:hover { background: #1e1e1e; color: #e0e0e0; }
.sidebar-link.is-active { background: rgba(79, 110, 247, 0.14); color: #a5b4fc; }
.sidebar-link.is-active svg { color: #4f6ef7; }

.sidebar-footer {
    padding: 10px;
    border-top: 1px solid #222222;
    display: flex;
    align-items: center;
    gap: 6px;
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    padding: 6px 8px;
    border-radius: 6px;
    text-decoration: none;
    color: inherit;
    transition: background 0.15s;
}
.sidebar-user:hover { background: #1e1e1e; }

.sidebar-user-avatar {
    width: 30px; height: 30px;
    flex-shrink: 0;
    border-radius: 50%;
    background: #1e1e2e;
    color: #a5b4fc;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
}

.sidebar-user-meta { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.sidebar-user-name {
    font-size: 0.82rem; color: #e0e0e0; font-weight: 500;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-user-email {
    font-size: 0.7rem; color: #6b7280;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

.sidebar-signout {
    width: 32px; height: 32px;
    border-radius: 6px;
    color: #6b7280;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.sidebar-signout svg { width: 15px; height: 15px; }
.sidebar-signout:hover { background: #1e1e1e; color: #f87171; }

/* ── Main content area ──────────────────────────────────────────── */
.main-content {
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    background: var(--paper);
}

/* ── Login page ─────────────────────────────────────────────────── */
body.login-page {
    background: #111111;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
}
.login-box {
    background: #1c1c1c;
    border: 1px solid #2a2a2a;
    border-radius: 10px;
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 360px;
}
.login-box .brand {
    font-size: 1.4rem; font-weight: 700; color: #fff;
    letter-spacing: 0.05em; margin-bottom: 1.75rem; text-align: center;
}
.login-box label { display: block; font-size: 0.8rem; color: #9ca3af; margin-bottom: 0.3rem; margin-top: 1rem; }
.login-box input {
    width: 100%; background: #111111; border: 1px solid #2a2a2a;
    border-radius: 6px; color: #e0e0e0; font-size: 0.9rem;
    padding: 0.55rem 0.75rem; outline: none; color-scheme: dark;
}
.login-box input:focus { border-color: #4f6ef7; }
.login-box button {
    margin-top: 1.5rem; width: 100%; background: #4f6ef7; color: #fff;
    border: none; border-radius: 6px; padding: 0.65rem; font-size: 0.9rem;
    font-weight: 500; cursor: pointer; transition: background 0.15s;
}
.login-box button:hover { background: #3b5bdb; }
.flash-error {
    background: #3b1111; border: 1px solid #7f1d1d; border-radius: 6px;
    color: #fca5a5; font-size: 0.85rem; padding: 0.6rem 0.75rem; margin-bottom: 0.5rem;
}

/* ── Sara floating chat widget ──────────────────────────────────── */
#sara-widget {
    position: fixed;
    bottom: 24px; right: 24px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 12px;
}

.sara-fab {
    width: 52px; height: 52px;
    border-radius: 50%;
    background: var(--accent);
    border: none;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    box-shadow: 0 4px 16px rgba(79, 110, 247, 0.3);
    transition: background 0.15s, transform 0.15s;
    flex-shrink: 0;
}
.sara-fab:hover { background: var(--accent-h); transform: scale(1.05); }
.sara-fab svg { width: 22px; height: 22px; }

.sara-panel {
    width: 340px;
    max-height: 500px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 40px rgba(0,0,0,0.12);
    overflow: hidden;
}
.sara-panel[hidden] { display: none; }

.sara-header {
    display: flex; align-items: center;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
    background: var(--surface);
    gap: 6px;
}
.sara-name { flex: 1; font-weight: 600; color: var(--text); font-size: 0.9rem; }
.sara-clear, .sara-close {
    width: 28px; height: 28px;
    border: none; background: transparent;
    color: var(--text-3);
    cursor: pointer; border-radius: 5px;
    display: flex; align-items: center; justify-content: center;
    transition: background 0.15s, color 0.15s;
}
.sara-clear:hover, .sara-close:hover { background: var(--paper); color: var(--text); }
.sara-clear svg, .sara-close svg { width: 14px; height: 14px; }

.sara-context {
    padding: 4px 12px;
    font-size: 0.72rem;
    color: var(--accent);
    background: var(--paper);
    border-bottom: 1px solid var(--border);
    letter-spacing: 0.01em;
}

.sara-messages {
    flex: 1; overflow-y: auto;
    padding: 14px;
    display: flex; flex-direction: column; gap: 10px;
    min-height: 200px;
    background: var(--paper);
}

.sara-msg { display: flex; max-width: 85%; }
.sara-msg--user      { align-self: flex-end; }
.sara-msg--assistant { align-self: flex-start; }

.sara-msg span {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 12px;
    font-size: 0.83rem;
    line-height: 1.5;
    color: var(--text);
    white-space: pre-wrap;
    word-break: break-word;
}
.sara-msg--user span {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    border-bottom-right-radius: 3px;
}
.sara-msg--assistant span { border-bottom-left-radius: 3px; }
.sara-msg--loading span { color: var(--text-3); font-style: italic; border-color: transparent; background: transparent; }

.sara-form {
    display: flex; gap: 6px;
    padding: 10px 12px;
    border-top: 1px solid var(--border);
    background: var(--surface);
}
.sara-form input {
    flex: 1;
    background: var(--paper);
    border: 1px solid var(--border-2);
    border-radius: 6px;
    color: var(--text);
    font-size: 0.85rem;
    padding: 7px 10px;
    outline: none;
    color-scheme: var(--form-color-scheme);
}
.sara-form input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,110,247,0.1); }
.sara-form button {
    width: 34px; height: 34px;
    border: none; background: var(--accent);
    border-radius: 6px; color: #fff;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}
.sara-form button:hover { background: var(--accent-h); }
.sara-form button svg { width: 15px; height: 15px; }

@media (max-width: 768px) {
    :root { --sidebar-width: 0px; }
    .sidebar { transform: translateX(-100%); }
    #sara-widget { bottom: 16px; right: 16px; }
    .sara-panel  { width: calc(100vw - 32px); }
}

/* ── Theme toggle (sidebar footer) ──────────────────────────────── */
.theme-toggle {
    width: 32px; height: 32px;
    border-radius: 6px;
    background: transparent;
    border: none;
    color: #6b7280;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s, color 0.15s;
    flex-shrink: 0;
}
.theme-toggle svg { width: 15px; height: 15px; }
.theme-toggle:hover { background: #1e1e1e; color: #fbbf24; }
.theme-toggle .theme-icon-dark { display: inline-flex; }
.theme-toggle .theme-icon-light { display: none; }
[data-theme="dark"] .theme-toggle .theme-icon-dark { display: none; }
[data-theme="dark"] .theme-toggle .theme-icon-light { display: inline-flex; }

/* ── Dark-mode element tweaks ───────────────────────────────────── */
[data-theme="dark"] .status-active   { color: #4ade80; }
[data-theme="dark"] .status-inactive,
[data-theme="dark"] .status-failed   { color: #f87171; }

/* Sara panel keeps its surface background; ensure user msg text stays
   readable in both themes (already uses --accent which is fixed). */
[data-theme="dark"] .sara-panel { box-shadow: 0 8px 40px rgba(0,0,0,0.4); }

/* Login page is dark in both themes — no overrides needed. */
