/* CogniKin Console - Styles adapted from admin dashboard */
* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

/* --- Navigation --- */
.nav {
    background: #1a1a2e;
    color: #fff;
    padding: 0.75rem 1.5rem;
    display: flex;
    gap: 0.25rem;
    align-items: center;
    flex-wrap: wrap;
}
.nav a {
    color: #ccc;
    text-decoration: none;
    padding: 0.5rem 0.85rem;
    border-radius: 4px;
    font-size: 0.9rem;
    transition: background 0.15s;
}
.nav a:hover, .nav a.active {
    color: #fff;
    background: rgba(255,255,255,0.1);
}
.nav .brand {
    font-weight: bold;
    font-size: 1.2rem;
    color: #fff;
    margin-right: 1rem;
}
.nav-spacer { flex: 1; }
.nav-user {
    font-size: 0.85rem;
    color: #aaa;
    margin-right: 0.5rem;
}
.nav-logout {
    color: #f87171 !important;
    font-size: 0.85rem;
}

/* --- Layout --- */
.container {
    max-width: 1200px;
    margin: 1.5rem auto;
    padding: 0 1rem;
}

/* --- Cards --- */
.card {
    background: #fff;
    border-radius: 8px;
    padding: 1.5rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}
.cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}
.card h3 {
    font-size: 0.85rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}
.card .value {
    font-size: 2rem;
    font-weight: bold;
    margin-top: 0.5rem;
}

/* --- Tables --- */
table { width: 100%; border-collapse: collapse; }
th, td {
    padding: 0.75rem;
    text-align: left;
    border-bottom: 1px solid #eee;
    font-size: 0.9rem;
}
th {
    background: #f8f8f8;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
}

/* --- Badges --- */
.badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    font-size: 0.8rem;
    font-weight: 500;
}
.badge-green { background: #e6f9e6; color: #1a7a1a; }
.badge-red { background: #fde8e8; color: #9b1c1c; }
.badge-blue { background: #e8f0fe; color: #1a56db; }
.badge-yellow { background: #fef3c7; color: #92400e; }
.badge-gray { background: #f0f0f0; color: #666; }

/* --- Buttons --- */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    display: inline-block;
    transition: background 0.15s;
}
.btn-primary { background: #1a56db; color: #fff; }
.btn-primary:hover { background: #1544b0; }
.btn-danger { background: #9b1c1c; color: #fff; }
.btn-danger:hover { background: #7a1515; }
.btn-success { background: #059669; color: #fff; }
.btn-success:hover { background: #047857; }
.btn-secondary { background: #e5e7eb; color: #333; }
.btn-secondary:hover { background: #d1d5db; }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

/* --- Forms --- */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    margin-bottom: 0.3rem;
    font-weight: 500;
    font-size: 0.85rem;
}
.form-control {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.9rem;
    font-family: inherit;
    transition: border-color 0.15s;
}
.form-control:focus {
    outline: none;
    border-color: #1a56db;
    box-shadow: 0 0 0 2px rgba(26,86,219,0.15);
}
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { appearance: auto; }

/* --- Filter bar --- */
.filter-bar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
    align-items: center;
}

/* --- Alerts --- */
.alert {
    padding: 0.75rem 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.alert-error { background: #fde8e8; color: #9b1c1c; border: 1px solid #f5c6cb; }
.alert-success { background: #e6f9e6; color: #1a7a1a; border: 1px solid #c3e6cb; }
.alert-info { background: #e8f0fe; color: #1a56db; border: 1px solid #bee3f8; }
.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }

/* --- Auth pages --- */
.auth-container {
    max-width: 420px;
    margin: 4rem auto;
}
.auth-card {
    background: #fff;
    border-radius: 8px;
    padding: 2rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
}
.auth-header {
    text-align: center;
    margin-bottom: 1.5rem;
}
.auth-header h1 {
    font-size: 1.5rem;
    color: #1a1a2e;
}
.auth-header p {
    color: #666;
    font-size: 0.9rem;
    margin-top: 0.3rem;
}
.auth-footer {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.85rem;
    color: #666;
}
.auth-footer a { color: #1a56db; text-decoration: none; }

/* --- Modals --- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 100;
    align-items: center;
    justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
    background: #fff;
    border-radius: 8px;
    padding: 2rem;
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}
.modal h3 { margin-bottom: 1rem; }
.modal .actions { display: flex; gap: 0.5rem; justify-content: flex-end; }

/* --- Tabs (HTMX) --- */
.tabs {
    display: flex;
    gap: 0;
    border-bottom: 2px solid #e5e7eb;
    margin-bottom: 1rem;
}
.tab {
    padding: 0.6rem 1.2rem;
    font-size: 0.9rem;
    font-weight: 500;
    color: #666;
    text-decoration: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    cursor: pointer;
    transition: all 0.15s;
}
.tab:hover { color: #333; }
.tab.active {
    color: #1a56db;
    border-bottom-color: #1a56db;
}

/* --- Connection cards --- */
.conn-cards {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}
.conn-card {
    background: #fff;
    border-radius: 8px;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
    border-left: 4px solid #1a56db;
    transition: box-shadow 0.15s;
}
.conn-card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.15); }
.conn-card.blocked { border-left-color: #9b1c1c; opacity: 0.7; }
.conn-card .conn-brain { font-weight: 600; font-size: 1.1rem; }
.conn-card .conn-meta { font-size: 0.85rem; color: #666; margin-top: 0.3rem; }

/* --- Expandable rows --- */
.expand-row { cursor: pointer; }
.expand-row:hover { background: #f8f9fa; }
.expand-content {
    display: none;
    padding: 1rem;
    background: #f8f9fa;
    border-bottom: 1px solid #eee;
}
.expand-content.open { display: table-row; }

/* --- Slider --- */
input[type="range"] {
    width: 100%;
    accent-color: #1a56db;
}

/* --- Loading --- */
.loading { color: #999; font-style: italic; }
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline; }
.htmx-request.htmx-indicator { display: inline; }

/* --- Pagination --- */
.pagination {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    align-items: center;
}
.pagination .page-info { font-size: 0.85rem; color: #666; flex: 1; }

/* --- Empty state --- */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: #999;
}
.empty-state h3 { font-size: 1.1rem; margin-bottom: 0.5rem; color: #666; }

/* --- Brain selector dropdown --- */
.brain-selector { position: relative; }
.brain-selector-btn {
    background: rgba(255,255,255,0.1);
    color: #fff;
    border: 1px solid rgba(255,255,255,0.2);
    padding: 0.35rem 0.75rem;
    border-radius: 4px;
    font-size: 0.85rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    font-family: inherit;
}
.brain-selector-btn:hover { background: rgba(255,255,255,0.15); }
.brain-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 4px);
    background: #fff;
    border-radius: 6px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.2);
    min-width: 200px;
    z-index: 50;
    overflow: hidden;
}
.brain-option {
    display: flex;
    align-items: center;
    width: 100%;
    padding: 0.6rem 1rem;
    border: none;
    background: none;
    font-size: 0.85rem;
    color: #333;
    cursor: pointer;
    text-align: left;
    font-family: inherit;
}
.brain-option:hover { background: #f0f0f0; }
.brain-option.active { font-weight: 600; color: #1a56db; }
.brain-check { margin-left: auto; font-size: 0.75rem; }
.brain-divider { border-top: 1px solid #eee; margin: 0.25rem 0; }
.brain-option.brain-create { color: #1a56db; font-weight: 500; }
.brain-create-form {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem;
    align-items: center;
}
.brain-create-form input { flex: 1; font-size: 0.85rem; padding: 0.35rem 0.5rem; }
[x-cloak] { display: none !important; }

/* --- Action buttons (inline in table rows) --- */
.action-btns { white-space: nowrap; }
.action-btns .btn { margin-right: 0.25rem; }
.gate-reason-row td { border-bottom: 2px solid #eee; }

/* --- Nav badge (inbox count) --- */
.nav-badge {
    background: #ef4444;
    color: #fff;
    font-size: 0.7rem;
    font-weight: 600;
    padding: 0.1rem 0.4rem;
    border-radius: 10px;
    margin-left: 0.3rem;
    vertical-align: super;
}

/* --- Toast notifications (SSE real-time) --- */
#toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 200;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}
.toast {
    background: #1a1a2e;
    color: #fff;
    padding: 0.75rem 1.25rem;
    border-radius: 6px;
    font-size: 0.85rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.25);
    opacity: 0;
    transform: translateX(100%);
    transition: opacity 0.3s, transform 0.3s;
    pointer-events: auto;
    max-width: 380px;
}
.toast-show {
    opacity: 1;
    transform: translateX(0);
}
.toast-info { border-left: 4px solid #1a56db; }
.toast-success { border-left: 4px solid #059669; }
.toast-warning { border-left: 4px solid #d97706; }
.toast-error { border-left: 4px solid #ef4444; }

/* --- Responsive --- */
@media (max-width: 768px) {
    .nav { padding: 0.5rem; gap: 0.1rem; }
    .nav a { padding: 0.4rem 0.6rem; font-size: 0.8rem; }
    .nav .brand { font-size: 1rem; margin-right: 0.5rem; }
    .container { padding: 0 0.5rem; margin: 1rem auto; }
    .cards { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); }
    .conn-cards { grid-template-columns: 1fr; }
    table { font-size: 0.8rem; }
    th, td { padding: 0.5rem; }
    #toast-container { left: 0.5rem; right: 0.5rem; }
    .toast { max-width: 100%; }
}
