@import "variables.css";

/* ── Reset / Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
    height: 100%;
    background-color: var(--bg-body);
    color: var(--text-primary);
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-bright); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--text-primary); }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.bh-layout {
    display: flex;
    height: 100vh;
    overflow: hidden;
}

/* ── Sidebar ──────────────────────────────────────────────────────────────── */
.bh-sidebar {
    width: var(--sidebar-width);
    min-width: var(--sidebar-width);
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.bh-sidebar-header {
    padding: 20px 16px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.bh-sidebar-logo {
    width: 32px; height: 32px;
    background: var(--gradient-silver);
    border-radius: var(--radius-sm);
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; font-size: 13px; color: var(--text-inverse);
    flex-shrink: 0;
}

.bh-sidebar-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.bh-sidebar-section {
    padding: 20px 16px 4px;
}

.bh-sidebar-section-label {
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0 4px;
}

.bh-sidebar-nav {
    list-style: none;
    padding: 6px 8px;
}

.bh-sidebar-nav li { margin-bottom: 1px; }

.bh-sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 13.5px;
    font-weight: 500;
    transition: background var(--transition), color var(--transition);
    border-left: 3px solid transparent;
}

.bh-sidebar-nav a:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.bh-sidebar-nav a.active {
    background: var(--bg-active);
    color: var(--text-primary);
    border-left-color: var(--accent-bright);
}

.bh-sidebar-nav a svg {
    width: 16px; height: 16px;
    flex-shrink: 0;
    opacity: 0.6;
    transition: opacity var(--transition);
}
.bh-sidebar-nav a:hover svg,
.bh-sidebar-nav a.active svg { opacity: 1; }

.bh-sidebar-footer {
    margin-top: auto;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 10px;
}

.bh-sidebar-footer-avatar {
    width: 28px; height: 28px;
    border-radius: 50%;
    background: var(--bg-active);
    display: flex; align-items: center; justify-content: center;
    font-size: 11px;
    font-weight: 600;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.bh-sidebar-footer-name {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

/* ── Main content ─────────────────────────────────────────────────────────── */
.bh-main {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

.bh-topbar {
    height: 52px;
    min-height: 52px;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 12px;
}

.bh-topbar-title {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
}

.bh-topbar-actions {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: 8px;
}

.bh-page {
    padding: 24px;
    flex: 1;
}

/* ── Cards ────────────────────────────────────────────────────────────────── */
.bh-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 20px;
}

.bh-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.bh-card-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

/* ── Buttons ──────────────────────────────────────────────────────────────── */
.bh-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background var(--transition), color var(--transition), border-color var(--transition);
    user-select: none;
    text-decoration: none;
}

.bh-btn-primary {
    background: var(--color-primary, #a78bfa);
    color: var(--bg-body, #0f0f0f);
}
.bh-btn-primary:hover {
    background: var(--color-primary-bright, #c4b5fd);
    color: var(--bg-body, #0f0f0f);
}

.bh-btn-ghost {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border);
}
.bh-btn-ghost:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
    border-color: var(--border-bright);
}

.bh-btn-danger {
    background: transparent;
    color: var(--color-error);
    border-color: var(--color-error);
}
.bh-btn-danger:hover {
    background: rgba(248,113,113,0.1);
}

/* ── Form elements ────────────────────────────────────────────────────────── */
.bh-input {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    padding: 8px 12px;
    transition: border-color var(--transition);
    outline: none;
}
.bh-input:focus { border-color: var(--accent); }
.bh-input::placeholder { color: var(--text-muted); }

.bh-label {
    display: block;
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 5px;
}

.bh-form-group { margin-bottom: 16px; }

/* ── Toggle switch ────────────────────────────────────────────────────────── */
.bh-toggle {
    position: relative;
    width: 36px;
    height: 20px;
    flex-shrink: 0;
}
.bh-toggle input { opacity: 0; width: 0; height: 0; }
.bh-toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--bg-hover);
    border: 1px solid var(--border-bright);
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: background var(--transition);
}
.bh-toggle-slider::before {
    content: '';
    position: absolute;
    width: 14px; height: 14px;
    left: 2px; top: 50%;
    transform: translateY(-50%);
    background: var(--text-muted);
    border-radius: 50%;
    transition: transform var(--transition), background var(--transition);
}
.bh-toggle input:checked + .bh-toggle-slider {
    background: var(--toggle-color, var(--accent-dim));
    border-color: var(--toggle-color, var(--accent));
}
.bh-toggle input:checked + .bh-toggle-slider::before {
    transform: translate(16px, -50%);
    background: white;
}

/* Toggle Track variant (used in some components) */
.bh-toggle-track {
    display: flex;
    align-items: center;
    width: 100%;
    height: 100%;
    background: var(--bg-hover);
    border-radius: var(--radius-pill);
    transition: background var(--transition);
    padding: 2px;
}
.bh-toggle-thumb {
    width: 16px;
    height: 16px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: transform var(--transition), background var(--transition);
}
.bh-toggle input:checked ~ .bh-toggle-track {
    background: var(--toggle-color, var(--accent-dim));
}
.bh-toggle input:checked ~ .bh-toggle-track .bh-toggle-thumb {
    transform: translateX(16px);
    background: white;
}

/* ── Status badge ─────────────────────────────────────────────────────────── */
.bh-badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 2px 8px;
    border-radius: var(--radius-pill);
    font-size: 11px;
    font-weight: 600;
}
.bh-badge-dot {
    width: 6px; height: 6px;
    border-radius: 50%;
    flex-shrink: 0;
}
.bh-badge-ok    { color: var(--color-ok);    background: rgba(74,222,128,0.1); }
.bh-badge-ok    .bh-badge-dot { background: var(--color-ok); }
.bh-badge-warn  { color: var(--color-warn);  background: rgba(250,204,21,0.1); }
.bh-badge-warn  .bh-badge-dot { background: var(--color-warn); }
.bh-badge-error { color: var(--color-error); background: rgba(248,113,113,0.1); }
.bh-badge-error .bh-badge-dot { background: var(--color-error); }

/* ── Table ────────────────────────────────────────────────────────────────── */
.bh-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.bh-table th {
    text-align: left;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}
.bh-table td {
    padding: 11px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}
.bh-table tr:hover td { background: var(--bg-hover); color: var(--text-primary); }
.bh-table tr:last-child td { border-bottom: none; }

/* ── Terminal / Log viewer ────────────────────────────────────────────────── */
.bh-terminal {
    background: #0a0a0a;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 14px;
    font-family: 'JetBrains Mono', 'Fira Code', 'Courier New', monospace;
    font-size: 12px;
    line-height: 1.6;
    color: #c8c8c8;
    overflow-y: auto;
    max-height: 500px;
}
.bh-terminal .log-info   { color: #60a5fa; }
.bh-terminal .log-warn   { color: #facc15; }
.bh-terminal .log-error  { color: #f87171; }
.bh-terminal .log-ok     { color: #4ade80; }
.bh-terminal .log-muted  { color: #555; }

/* ── Scrollbar ────────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-bright); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

/* ── Utility ──────────────────────────────────────────────────────────────── */
.bh-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.bh-grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.bh-grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.bh-flex   { display: flex; align-items: center; }
.bh-flex-between { display: flex; align-items: center; justify-content: space-between; }
.bh-gap-sm { gap: 8px; }
.bh-gap-md { gap: 16px; }
.bh-mt-sm { margin-top: 8px; }
.bh-mt-md { margin-top: 16px; }
.bh-text-muted { color: var(--text-muted); }
.bh-text-sm { font-size: 12px; }
.bh-badge-muted { color: var(--text-muted); background: var(--bg-hover); }
.bh-badge-muted .bh-badge-dot { background: var(--text-muted); }

/* ── Bot Cards (sidebar) ──────────────────────────────────────────────────── */
.bh-bot-switcher {
    padding: 10px 10px 8px;
    border-bottom: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.bh-bot-chip {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-md);
    cursor: pointer;
    text-decoration: none;
    background: var(--bg-card);
    border: 1px solid var(--border);
    transition: border-color var(--transition), background var(--transition), box-shadow var(--transition);
}

.bh-bot-chip:hover {
    background: var(--bg-hover);
    border-color: var(--border-bright);
    color: var(--text-primary);
}

.bh-bot-chip.active {
    background: var(--bg-active);
    border-color: var(--accent-dim);
    box-shadow: 0 0 0 1px var(--accent-dim);
}

.bh-bot-chip-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--gradient-silver);
    display: flex; align-items: center; justify-content: center;
    font-size: 13px; font-weight: 700;
    color: var(--text-inverse);
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.bh-bot-chip.active .bh-bot-chip-avatar {
    box-shadow: 0 0 0 2px var(--accent);
}

.bh-bot-chip-info {
    flex: 1;
    overflow: hidden;
}

.bh-bot-chip-name {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    line-height: 1.3;
}

.bh-bot-chip.active .bh-bot-chip-name { color: var(--text-primary); }

.bh-bot-chip-sub {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 1px;
}

.bh-bot-chip-status {
    width: 7px; height: 7px;
    border-radius: 50%;
    flex-shrink: 0;
    background: var(--text-muted);
}
.bh-bot-chip-status.running { background: var(--color-ok); box-shadow: 0 0 4px var(--color-ok); }
.bh-bot-chip-status.error   { background: var(--color-error); }

/* ── Modal ────────────────────────────────────────────────────────────────── */
.bh-modal-overlay {
    display: none;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.6);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    backdrop-filter: blur(2px);
}
.bh-modal-overlay.open { display: flex; }

.bh-modal-box {
    background: var(--bg-card);
    border: 1px solid var(--border-bright);
    border-radius: var(--radius-lg);
    padding: 28px 28px 24px;
    width: 100%;
    max-width: 420px;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.bh-modal-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 20px;
}

.bh-modal-close {
    float: right;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    line-height: 1;
    margin-top: -4px;
}
.bh-modal-close:hover { color: var(--text-primary); }

/* ── Alert ────────────────────────────────────────────────────────────────── */
.bh-alert {
    position: relative;
    padding: 10px 14px 15px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    margin-bottom: 12px;
    overflow: hidden;
}
.bh-alert-ok    { background: rgba(74,222,128,.08); border: 1px solid var(--color-ok);    color: var(--color-ok); }
.bh-alert-error { background: rgba(248,113,113,.08); border: 1px solid var(--color-error); color: var(--color-error); }
.bh-alert-warn  { background: rgba(251,191,36,.08);  border: 1px solid var(--color-warn);  color: var(--color-warn); }

/* progress bar */
.bh-alert-bar {
    position: absolute;
    bottom: 0; left: 0;
    height: 3px;
    width: 100%;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
}
.bh-alert-ok    .bh-alert-bar { background: var(--color-ok); }
.bh-alert-error .bh-alert-bar { background: var(--color-error); }
.bh-alert-warn  .bh-alert-bar { background: var(--color-warn); }

@keyframes bh-bar-shrink {
    from { width: 100%; }
    to   { width: 0%; }
}

/* ── Form row ─────────────────────────────────────────────────────────────── */
.bh-form-row {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}
.bh-form-row .bh-form-group { flex: 1; min-width: 160px; }

/* ── Mobile / Hamburger ───────────────────────────────────────────────────── */
.bh-hamburger {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 36px; height: 36px;
    padding: 6px;
    background: none;
    border: none;
    cursor: pointer;
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}
.bh-hamburger span {
    display: block;
    height: 2px;
    background: var(--text-secondary);
    border-radius: 2px;
    transition: transform .2s, opacity .2s;
}
.bh-hamburger:hover span { background: var(--text-primary); }

/* Overlay behind open sidebar */
.bh-sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.55);
    z-index: 99;
}

/* ── Sidebar Search ───────────────────────────────────────────────────────── */
.bh-sidebar-search {
    position: relative;
    padding: 8px 10px 4px;
}

.bh-sidebar-search-input {
    width: 100%;
    box-sizing: border-box;
    background: #1a1a1a;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    padding: 6px 10px;
    outline: none;
    transition: border-color var(--transition);
}

.bh-sidebar-search-input:focus {
    border-color: var(--accent-dim);
}

.bh-sidebar-search-input::placeholder {
    color: var(--text-muted);
}

.bh-sidebar-search-results {
    display: none;
    position: absolute;
    left: 10px;
    right: 10px;
    top: 100%;
    background: #1c1c1c;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-md);
    z-index: 200;
    max-height: 260px;
    overflow-y: auto;
    margin-top: 4px;
}

.bh-sidebar-search-results.open {
    display: block;
}

.bh-search-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    cursor: pointer;
    font-size: 13px;
    border-bottom: 1px solid var(--border-dim);
    transition: background var(--transition);
}

.bh-search-item:last-child {
    border-bottom: none;
}

.bh-search-item:hover,
.bh-search-item.focused {
    background: var(--bg-active);
}

.bh-search-badge {
    font-size: 10px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: var(--radius-pill);
    flex-shrink: 0;
    background: #2a2a2a;
    color: var(--text-muted);
}

.bh-search-badge.page {
    background: #1e2a3a;
    color: #6ab0f5;
}

.bh-search-badge.module {
    background: #2a1e3a;
    color: #a78bfa;
}

.bh-search-badge.command {
    background: #1e3a2a;
    color: #6af5ab;
}

.bh-search-empty {
    padding: 10px;
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
}

/* ── Tablet (≤ 900px) ─────────────────────────────────────────────────────── */
@media (max-width: 900px) {
    .bh-page { padding: 16px; }
    .bh-topbar { padding: 0 16px; }
}

/* ── Mobile (≤ 680px) ─────────────────────────────────────────────────────── */
@media (max-width: 680px) {

    /* Hamburger visible */
    .bh-hamburger { display: flex; }

    /* Sidebar becomes a fixed drawer */
    .bh-sidebar {
        position: fixed;
        top: 0; left: 0;
        height: 100%;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform .25s ease;
        box-shadow: 4px 0 24px rgba(0,0,0,.4);
    }
    .bh-sidebar.open { transform: translateX(0); }
    .bh-sidebar-overlay.open { display: block; }

    /* Main fills full width */
    .bh-main { width: 100%; }

    .bh-topbar { padding: 0 12px; gap: 8px; }
    .bh-topbar-title { font-size: 14px; }
    .bh-page { padding: 12px; }

    /* Grids → 1 column */
    .bh-grid-3,
    [style*="grid-template-columns:repeat(3"] {
        grid-template-columns: 1fr !important;
    }

    /* Module grid → 2 columns */
    [style*="grid-template-columns:repeat(5,1fr)"] {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* Bot grid → 1 column */
    [style*="minmax(280px"] {
        grid-template-columns: 1fr !important;
    }

    /* Server grid → 1 column */
    [style*="minmax(260px"] {
        grid-template-columns: 1fr !important;
    }

    /* Tables scroll */
    .bh-table { font-size: 12px; }
    .bh-card { overflow-x: auto; }

    /* Forms stack */
    .bh-form-row { flex-direction: column; }
    .bh-form-row .bh-form-group { min-width: 0; }

    /* Hide topbar search on very small screens, show below */
    .bh-topbar-actions input[type="search"] { width: 140px !important; }

    /* Bot chips horizontal scroll */
    .bh-bot-switcher { flex-direction: column; }
}
