/* Nexus Gateway — Unified Styles */
:root {
    --bg: #f5f5f5;
    --card: #fff;
    --border: #e5e5e5;
    --border-light: #f0f0f0;
    --text: #333;
    --text-sec: #888;
    --text-muted: #aaa;
    --accent: #0066ff;
    --accent-bg: #f0f7ff;
    --accent-border: #b3d4ff;
    --green: #22863a;
    --green-bg: #e6ffed;
    --red: #cc3333;
    --red-bg: #fff0f0;
    --red-border: #ffcccc;
    --radius: 10px;
    --radius-sm: 6px;
}

*{margin:0;padding:0;box-sizing:border-box}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

/* Persistent desktop shell */
.with-app-sidebar {
    min-height: 100vh;
    display: grid;
    grid-template-columns: 240px minmax(0, 1fr);
    grid-template-rows: auto 1fr;
    padding-left: 0;
    transition: grid-template-columns .2s ease;
}
.app-sidebar {
    position: sticky;
    top: 0;
    grid-column: 1;
    grid-row: 1 / span 100;
    width: 100%;
    height: 100vh;
    z-index: 120;
    background: var(--card);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width .2s ease;
}
.app-sidebar-head {
    height: 52px;
    padding: 0 10px 0 18px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    font-size: 16px;
    font-weight: 700;
    color: var(--accent);
    text-decoration: none;
}
.app-sidebar-brand {
    color: inherit;
    text-decoration: none;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.app-sidebar-toggle {
    width: 30px;
    height: 30px;
    flex: 0 0 auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--card);
    color: var(--text-sec);
    cursor: pointer;
    font-size: 15px;
    line-height: 1;
}
.app-sidebar-toggle:hover {
    background: var(--accent-bg);
    color: var(--accent);
    border-color: var(--accent-border);
}
.app-sidebar-links {
    flex: 1;
    padding: 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.app-sidebar-links a {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 12px;
    border-radius: 8px;
    color: #555;
    text-decoration: none;
    font-size: 13px;
    transition: background .15s, color .15s;
}
.app-sidebar-icon {
    width: 18px;
    flex: 0 0 18px;
    text-align: center;
    color: var(--text-sec);
}
.app-sidebar-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.app-sidebar-links a:hover,
.app-sidebar-links a.active {
    background: var(--accent-bg);
    color: var(--accent);
}
.app-sidebar-divider {
    height: 1px;
    background: var(--border-light);
    margin: 4px 0;
}
.with-app-sidebar .nav {
    grid-column: 2;
    grid-row: 1;
    left: auto;
    width: auto;
    transition: none;
}
.with-app-sidebar > .page,
.with-app-sidebar > main,
.with-app-sidebar > .diagnostic-head {
    grid-column: 2;
}
.with-app-sidebar.app-sidebar-collapsed {
    grid-template-columns: 68px minmax(0, 1fr);
    padding-left: 0;
}
.with-app-sidebar.app-sidebar-collapsed .app-sidebar {
    width: 100%;
}
.with-app-sidebar.app-sidebar-collapsed .app-sidebar-head {
    padding: 0;
    justify-content: center;
}
.with-app-sidebar.app-sidebar-collapsed .app-sidebar-brand,
.with-app-sidebar.app-sidebar-collapsed .app-sidebar-text {
    display: none;
}
.with-app-sidebar.app-sidebar-collapsed .app-sidebar-links {
    padding: 10px 8px;
}
.with-app-sidebar.app-sidebar-collapsed .app-sidebar-links a {
    justify-content: center;
    padding: 10px 0;
}
.with-app-sidebar.app-sidebar-collapsed .app-sidebar-divider {
    margin: 6px 8px;
}
.with-app-sidebar.app-sidebar-collapsed .nav {
    left: auto;
    width: auto;
}

/* ── Nav ──────────────────────────────────────── */
.nav {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    height: 52px;
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-brand {
    font-size: 16px; font-weight: 700;
    color: var(--accent); text-decoration: none;
    margin-right: 32px;
}
.nav-links { display: flex; gap: 2px; }
.nav-links a {
    padding: 6px 14px; border-radius: 6px;
    font-size: 13px; color: var(--text-sec);
    text-decoration: none; transition: all .15s;
}
.nav-links a:hover { background: var(--accent-bg); color: var(--accent); }
.nav-links a.active { background: var(--accent-bg); color: var(--accent); font-weight: 500; }

/* ── Page ─────────────────────────────────────── */
.page { max-width: 720px; margin: 0 auto; padding: 24px 16px; }
.page-wide { max-width: 860px; }

/* ── Card ─────────────────────────────────────── */
.card {
    background: var(--card); border-radius: var(--radius);
    padding: 20px; margin-bottom: 16px;
    border: 1px solid var(--border);
}
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; }
.card-subtitle { font-size: 12px; color: var(--text-muted); font-weight: 400; margin-left: 8px; }

/* ── Section divider ──────────────────────────── */
.section-label {
    font-size: 12px; color: var(--text-sec); font-weight: 600;
    letter-spacing: .3px; margin: 20px 0 10px;
    padding-bottom: 6px; border-bottom: 1px solid var(--border-light);
}
.section-label:first-child { margin-top: 0; }

/* ── Form ─────────────────────────────────────── */
label { display: block; font-size: 13px; color: var(--text-sec); margin-bottom: 4px; margin-top: 12px; }
label:first-of-type { margin-top: 0; }
input, select, textarea {
    width: 100%; padding: 8px 12px;
    border: 1px solid #ddd; border-radius: var(--radius-sm);
    font-size: 14px; font-family: inherit;
    outline: none; transition: border-color .2s;
    background: var(--card);
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
textarea { resize: vertical; min-height: 80px; }
.input-row { display: flex; gap: 8px; align-items: flex-end; }

/* ── Buttons ──────────────────────────────────── */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 8px 16px; border: none; border-radius: var(--radius-sm);
    font-size: 14px; cursor: pointer; transition: opacity .15s;
    font-family: inherit; white-space: nowrap;
}
.btn:hover { opacity: .85; }
.btn:disabled { opacity: .4; cursor: default; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-outline { background: var(--card); color: var(--text); border: 1px solid #ddd; }
.btn-danger  { background: var(--card); color: var(--red); border: 1px solid var(--red-border); }
.btn-success { background: var(--green-bg); color: var(--green); border: 1px solid #34d058; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-row { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* ── Toggle ───────────────────────────────────── */
.toggle { position: relative; display: inline-block; width: 38px; height: 22px; flex-shrink: 0; }
.toggle input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-slider {
    position: absolute; inset: 0;
    background: #ccc; border-radius: 22px;
    cursor: pointer; transition: .2s;
}
.toggle-slider::before {
    content: ""; position: absolute;
    width: 16px; height: 16px; left: 3px; bottom: 3px;
    background: #fff; border-radius: 50%; transition: .2s;
}
.toggle input:checked + .toggle-slider { background: var(--accent); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ── Tabs ─────────────────────────────────────── */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 16px; }
.tab {
    padding: 10px 20px; font-size: 14px;
    color: var(--text-sec); cursor: pointer;
    border: none; border-bottom: 2px solid transparent;
    margin-bottom: -2px; background: none;
    font-family: inherit; transition: all .15s;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }

/* ── Toast ────────────────────────────────────── */
.toast {
    position: fixed; bottom: 24px; left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: #333; color: #fff;
    padding: 10px 20px; border-radius: 8px;
    font-size: 13px; opacity: 0;
    transition: all .3s ease; z-index: 999;
    pointer-events: none;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Memory item ──────────────────────────────── */
.mem-item {
    padding: 12px 0;
    border-bottom: 1px solid var(--border-light);
    display: flex; gap: 12px; align-items: flex-start;
}
.mem-item:last-child { border-bottom: none; }
.mem-content { flex: 1; min-width: 0; }
.mem-text { font-size: 14px; line-height: 1.55; word-break: break-word; }
.mem-meta {
    font-size: 12px; color: var(--text-muted);
    margin-top: 4px; display: flex;
    gap: 8px; flex-wrap: wrap; align-items: center;
}
.mem-actions { display: flex; gap: 4px; flex-shrink: 0; }

/* ── Stats ────────────────────────────────────── */
.stats-row { display: flex; gap: 12px; margin-bottom: 16px; }
.stat-box {
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); padding: 12px 16px; flex: 1;
}
.stat-value { font-size: 24px; font-weight: 700; color: var(--accent); }
.stat-label { font-size: 12px; color: var(--text-sec); }

/* ── Search ───────────────────────────────────── */
.search-bar { display: flex; gap: 8px; margin-bottom: 16px; }
.search-bar input { flex: 1; }

/* ── Model picker ─────────────────────────────── */
.model-picker {
    display: none; margin-top: 6px;
    max-height: 200px; overflow-y: auto;
    border: 1px solid #ddd; border-radius: var(--radius-sm);
    background: var(--card);
}
.model-item {
    padding: 8px 12px; cursor: pointer;
    font-size: 13px; border-bottom: 1px solid var(--border-light);
}
.model-item:hover { background: var(--accent-bg); }
.model-item:last-child { border-bottom: none; }

/* ── Profile row ──────────────────────────────── */
.profile-row {
    display: flex; align-items: center; justify-content: space-between;
    padding: 10px 0; border-bottom: 1px solid var(--border-light);
}
.profile-row:last-child { border-bottom: none; }
.tag-active { color: var(--green); font-size: 12px; margin-left: 6px; }

/* ── Misc ─────────────────────────────────────── */
.empty { text-align: center; padding: 32px; color: var(--text-muted); font-size: 14px; }

.ops-banner {
    align-self: flex-start; background: var(--accent-bg);
    border: 1px solid var(--accent-border); color: #0055cc;
    padding: 6px 14px; border-radius: 8px;
    font-size: 12px; max-width: 82%;
}

/* ── Scrollbar ────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #d1d1d1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #aaa; }

/* ── Responsive ───────────────────────────────── */
@media (max-width: 640px) {
    .with-app-sidebar { padding-left: 0; }
    .app-sidebar { display: none; }
    .with-app-sidebar,
    .with-app-sidebar.app-sidebar-collapsed {
        display: block;
        padding-left: 0;
    }
    .with-app-sidebar .nav { left: 0; width: 100%; }
    .nav { padding: 0 12px; }
    .nav-brand { margin-right: 16px; }
    .nav-links a { padding: 6px 8px; font-size: 12px; }
    .page { padding: 16px 12px; }
    .stats-row { flex-direction: column; }
    .input-row { flex-direction: column; }
}
