/* ==========================================================================
   HarmonyAgentic Admin Panel — Stylesheet
   Brand: Harmony = gold #D4A843, Agentic = cyan #2eaadc
   Dark theme: navy #0f172a, cards #162032
   ========================================================================== */

:root {
    --gold: #D4A843;
    --cyan: #2eaadc;
    --navy: #0f172a;
    --card-bg: #162032;
    --card-border: #1e2d42;
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --bg-hover: #1a2738;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --sidebar-width: 240px;
    --radius: 10px;
    --radius-sm: 6px;
    --transition: 0.2s ease;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--navy);
    color: var(--text-primary);
    min-height: 100vh;
    font-size: 14px;
}

.hidden { display: none !important; }

/* ===== Logo ===== */
.logo {
    font-size: 22px;
    font-weight: 800;
    letter-spacing: -0.5px;
}
.logo-harmony { color: var(--gold); }
.logo-agentic { color: var(--cyan); }

/* ===== Login Screen ===== */
.login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--navy) 0%, #0c1424 100%);
}
.login-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: 16px;
    padding: 40px;
    width: 400px;
    max-width: 90vw;
    text-align: center;
}
.login-card .logo { font-size: 28px; margin-bottom: 8px; }
.login-subtitle { color: var(--text-secondary); font-size: 13px; margin-bottom: 28px; }
.login-error { color: var(--danger); font-size: 13px; margin-top: 12px; min-height: 18px; }

.form-group { text-align: left; margin-bottom: 18px; }
.form-group label {
    display: block; font-size: 13px; font-weight: 500; color: var(--text-secondary);
    margin-bottom: 6px;
}
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 10px 14px;
    background: var(--navy);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 14px;
    font-family: inherit;
    transition: border-color var(--transition);
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--cyan);
}
.form-group textarea { resize: vertical; min-height: 60px; }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    transition: all var(--transition);
    text-decoration: none;
    white-space: nowrap;
}
.btn-primary { background: var(--cyan); color: #fff; }
.btn-primary:hover { background: #2590c4; }
.btn-gold { background: var(--gold); color: #1a1206; }
.btn-gold:hover { background: #c19836; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #16a34a; }
.btn-outline {
    background: transparent; border: 1px solid var(--card-border); color: var(--text-secondary);
}
.btn-outline:hover { border-color: var(--cyan); color: var(--cyan); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; }

/* ===== App Layout ===== */
.app { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: #0b1424;
    border-right: 1px solid var(--card-border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    z-index: 100;
    transition: transform var(--transition);
}
.sidebar-header {
    padding: 20px 20px;
    border-bottom: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.badge {
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 1px;
    background: var(--gold);
    color: #1a1206;
    padding: 2px 6px;
    border-radius: 4px;
}
.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    color: var(--text-secondary);
    text-decoration: none;
    border-radius: var(--radius-sm);
    font-size: 14px;
    font-weight: 500;
    margin-bottom: 4px;
    transition: all var(--transition);
}
.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active {
    background: rgba(46, 170, 220, 0.12);
    color: var(--cyan);
}
.nav-item svg { flex-shrink: 0; }

.sidebar-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--card-border);
}
.btn-logout {
    width: 100%;
    padding: 8px;
    background: transparent;
    border: 1px solid var(--danger);
    color: var(--danger);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    margin-bottom: 8px;
    transition: all var(--transition);
}
.btn-logout:hover { background: var(--danger); color: #fff; }
.copyright { font-size: 11px; color: var(--text-muted); text-align: center; }

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    background: var(--card-bg);
    border-bottom: 1px solid var(--card-border);
    padding: 14px 24px;
    display: flex;
    align-items: center;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar h1 { font-size: 20px; font-weight: 700; flex: 1; }
.menu-toggle {
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 20px;
    cursor: pointer;
    display: none;
}
.admin-badge {
    background: rgba(212, 168, 67, 0.15);
    color: var(--gold);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

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

/* ===== Stats Cards (Dashboard) ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 28px;
}
.stat-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 20px;
    transition: border-color var(--transition);
}
.stat-card:hover { border-color: var(--cyan); }
.stat-card .stat-icon {
    width: 44px; height: 44px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 12px;
    font-size: 22px;
}
.stat-icon.gold { background: rgba(212, 168, 67, 0.15); color: var(--gold); }
.stat-icon.cyan { background: rgba(46, 170, 220, 0.15); color: var(--cyan); }
.stat-icon.green { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.stat-icon.red { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.stat-card .stat-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 4px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; }

/* ===== Table ===== */
.table-wrapper {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    overflow: hidden;
}
.table-header {
    padding: 16px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    border-bottom: 1px solid var(--card-border);
}
.table-header h2 { font-size: 16px; }
.table-controls { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.search-input {
    padding: 7px 12px;
    background: var(--navy);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    width: 220px;
}
.search-input:focus { outline: none; border-color: var(--cyan); }
.filter-select {
    padding: 7px 12px;
    background: var(--navy);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
}
.filter-select:focus { outline: none; border-color: var(--cyan); }

table {
    width: 100%;
    border-collapse: collapse;
}
th {
    text-align: left;
    padding: 12px 16px;
    font-size: 11px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--card-border);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
}
th:hover { color: var(--text-secondary); }
td {
    padding: 12px 16px;
    border-bottom: 1px solid rgba(30, 45, 66, 0.5);
    font-size: 13px;
    color: var(--text-primary);
}
tr:hover td { background: var(--bg-hover); }

/* ===== Status Badges ===== */
.badge-status {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.badge-active { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.badge-suspended { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.badge-cancelled { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.badge-running { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.badge-stopped { background: rgba(100, 116, 139, 0.15); color: var(--text-muted); }
.badge-error { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.badge-draft { background: rgba(100, 116, 139, 0.15); color: var(--text-muted); }
.badge-sent { background: rgba(59, 130, 246, 0.15); color: var(--info); }
.badge-paid { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.badge-overdue { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.badge-pending { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.badge-confirmed { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.badge-failed { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.badge-past_due { background: rgba(245, 158, 11, 0.15); color: var(--warning); }

/* ===== Pagination ===== */
.pagination {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-top: 1px solid var(--card-border);
}
.pagination-info { font-size: 12px; color: var(--text-secondary); }
.pagination-buttons { display: flex; gap: 4px; }
.page-btn {
    padding: 6px 12px;
    background: var(--navy);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 12px;
    cursor: pointer;
    transition: all var(--transition);
}
.page-btn:hover:not(:disabled) { border-color: var(--cyan); color: var(--cyan); }
.page-btn.active { background: var(--cyan); color: #fff; border-color: var(--cyan); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== Modal ===== */
#modal-container {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
}
#modal-container.show {
    display: flex;
}
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 20px;
}
.modal {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    width: 500px;
    max-width: 95vw;
    max-height: 85vh;
    overflow-y: auto;
}
.modal-header {
    padding: 18px 24px;
    border-bottom: 1px solid var(--card-border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-header h3 { font-size: 17px; }
.modal-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 22px;
    cursor: pointer;
    line-height: 1;
    padding: 0 4px;
}
.modal-close:hover { color: var(--text-primary); }
.modal-body { padding: 24px; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--card-border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 300;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.toast {
    padding: 12px 18px;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    min-width: 280px;
    animation: slideIn 0.3s ease;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
}
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
.toast-success { background: rgba(34, 197, 94, 0.15); border: 1px solid var(--success); color: var(--success); }
.toast-error { background: rgba(239, 68, 68, 0.15); border: 1px solid var(--danger); color: var(--danger); }
.toast-info { background: rgba(59, 130, 246, 0.15); border: 1px solid var(--info); color: var(--info); }

/* ===== Detail View ===== */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.detail-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 20px;
}
.detail-card h3 {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.detail-row {
    display: flex;
    justify-content: space-between;
    padding: 6px 0;
    font-size: 13px;
}
.detail-row .label { color: var(--text-secondary); }
.detail-row .value { font-weight: 500; }

/* ===== Action Icons ===== */
.action-icons { display: flex; gap: 6px; flex-wrap: wrap; }
.action-icon {
    width: 28px; height: 28px;
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: all var(--transition);
    border: none;
    flex-shrink: 0;
}
.action-icon:hover { transform: scale(1.1); }
.action-icon.view { background: rgba(59, 130, 246, 0.15); color: var(--info); }
.action-icon.edit { background: rgba(212, 168, 67, 0.15); color: var(--gold); }
.action-icon.delete { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.action-icon.start { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.action-icon.stop { background: rgba(245, 158, 11, 0.15); color: var(--warning); }
.action-icon.logs { background: rgba(46, 170, 220, 0.15); color: var(--cyan); }

/* Action buttons in tables (text buttons, not icons) */
.action-icons .btn { min-height: 30px; }
td .action-icons .btn-sm { font-size: 11px; padding: 4px 8px; }

/* Cyan button (used in portal info cards) */
.btn-cyan { background: var(--cyan); color: #fff; }
.btn-cyan:hover { background: #2590c4; }

/* ===== Log Viewer ===== */
.log-viewer {
    background: #0a0f1a;
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    padding: 14px;
    font-family: 'Courier New', monospace;
    font-size: 12px;
    color: #a8b3c8;
    max-height: 400px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ===== Empty State ===== */
.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}
.empty-state p { font-size: 14px; }

/* ===== Login Switch Link ===== */
.login-switch {
    margin-top: 16px;
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.8;
}
.login-switch a {
    color: var(--cyan);
    text-decoration: none;
}
.login-switch a:hover { text-decoration: underline; }

/* ===== Portal Info Banner ===== */
.info-banner {
    background: rgba(46, 170, 220, 0.1);
    border: 1px solid rgba(46, 170, 220, 0.3);
    border-radius: var(--radius);
    padding: 14px 18px;
    margin-bottom: 20px;
    font-size: 13px;
    color: var(--cyan);
}
.info-banner.warning {
    background: rgba(245, 158, 11, 0.1);
    border-color: rgba(245, 158, 11, 0.3);
    color: var(--warning);
}
.info-banner.danger {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.3);
    color: var(--danger);
}

/* ===== User Dashboard Quick Cards ===== */
.quick-info-card {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 20px;
    margin-bottom: 16px;
}
.quick-info-card h3 {
    font-size: 14px;
    color: var(--text-secondary);
    margin-bottom: 14px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}
.quick-info-card .next-billing {
    font-size: 20px;
    font-weight: 700;
    color: var(--gold);
}

/* ===== Responsive ===== */

/* Tablet & below */
@media (max-width: 1024px) {
    :root { --sidebar-width: 220px; }
    .page-body { padding: 20px; }
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
}

/* Mobile */
@media (max-width: 768px) {
    :root { --sidebar-width: 260px; }

    /* Sidebar slide-in dengan overlay */
    .sidebar {
        transform: translateX(-100%);
        box-shadow: 4px 0 24px rgba(0,0,0,0.4);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-overlay {
        display: none;
        position: fixed;
        top: 0; left: 0; right: 0; bottom: 0;
        background: rgba(0,0,0,0.5);
        z-index: 99;
        backdrop-filter: blur(2px);
    }
    .sidebar-overlay.show { display: block; }

    .main-content { margin-left: 0; }
    .menu-toggle { display: block; }

    /* Topbar compact */
    .topbar { padding: 10px 16px; }
    .topbar h1 { font-size: 17px; }
    .admin-badge { font-size: 11px; padding: 3px 10px; }

    /* Page body */
    .page-body { padding: 16px; }

    /* Stats: 2 kolom di mobile */
    .stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
    .stat-card { padding: 14px; }
    .stat-card .stat-value { font-size: 22px; }
    .stat-card .stat-icon { width: 36px; height: 36px; font-size: 18px; }

    /* Table: horizontal scroll + compact */
    .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
    .table-header { padding: 12px 14px; flex-direction: column; align-items: flex-start; gap: 8px; }
    .table-header h2 { font-size: 15px; }
    .table-controls { width: 100%; flex-wrap: wrap; }
    .search-input { width: 100%; }
    th, td { padding: 10px 12px; font-size: 12px; }
    th { font-size: 10px; }

    /* Form row stack */
    .form-row { flex-direction: column; gap: 0; }

    /* Modal full-width */
    .modal { width: 100%; max-width: 100vw; border-radius: 0; min-height: 100vh; }
    .modal-overlay { padding: 0; }
    .modal-header { padding: 14px 16px; }
    .modal-body { padding: 16px; }
    .modal-footer { padding: 12px 16px; flex-direction: column-reverse; gap: 8px; }
    .modal-footer .btn { width: 100%; }

    /* Login card */
    .login-card { padding: 28px 20px; width: 100%; max-width: 380px; border-radius: 12px; }
    .login-card .logo { font-size: 24px; }

    /* Toast: bottom on mobile */
    .toast-container { top: auto; bottom: 16px; right: 16px; left: 16px; }
    .toast { min-width: auto; }

    /* Pagination */
    .pagination { flex-direction: column; gap: 8px; align-items: flex-start; }
    .pagination-info { font-size: 11px; }

    /* Detail grid 1 kolom */
    .detail-grid { grid-template-columns: 1fr; }

    /* Quick info card */
    .quick-info-card { padding: 16px; }

    /* Buttons: bigger touch target */
    .btn { padding: 10px 16px; font-size: 13px; min-height: 40px; }
    .btn-sm { padding: 8px 12px; min-height: 34px; }

    /* Action icons bigger */
    .action-icon { width: 34px; height: 34px; }

    /* Log viewer smaller font */
    .log-viewer { font-size: 11px; padding: 10px; max-height: 300px; }

    /* Nav items */
    .nav-item { padding: 12px 14px; font-size: 14px; }
    .sidebar-header { padding: 16px; }
    .sidebar-footer { padding: 14px 16px; }

    /* Table controls: full width */
    .filter-select { width: 100%; }
    .table-controls .btn { width: 100%; }
    .table-controls { width: 100%; }
    .table-controls > * { width: 100%; }

    /* Detail grid 1 kolom */
    .detail-grid { grid-template-columns: 1fr; }

    /* Settings page */
    .settings-page { padding: 0; }
    .settings-section { padding: 16px; }
    .plans-grid { grid-template-columns: 1fr; }
    .settings-info-grid { grid-template-columns: 1fr; }
    .settings-form-row { grid-template-columns: 1fr; }
}

/* Small mobile */
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; }
    .topbar h1 { font-size: 15px; }
    .page-body { padding: 12px; }
    .login-card { padding: 24px 16px; }

    /* Table: card-like layout untuk small screens */
    .table-wrapper table { min-width: 600px; }

    /* Badge status smaller */
    .badge-status { font-size: 10px; padding: 2px 8px; }

    /* Form inputs bigger touch target */
    .form-group input, .form-group select, .form-group textarea {
        padding: 12px 14px;
        font-size: 15px; /* prevents iOS zoom */
    }

    /* Toast full width bottom */
    .toast-container { right: 8px; left: 8px; bottom: 8px; }
    .toast { min-width: auto; font-size: 12px; }

    /* Buttons full width in modals */
    .modal-footer .btn { width: 100%; }

    /* Instance info card compact */
    .inst-info-label { font-size: 11px; }
    .quick-info-card { padding: 14px; }
    .inst-info-actions .btn { width: 100%; }
}

/* Landscape mobile: use more space */
@media (max-width: 900px) and (orientation: landscape) {
    .stats-grid { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
}

/* Safe area untuk notch phones */
@supports (padding: env(safe-area-inset-bottom)) {
    .toast-container {
        padding-bottom: env(safe-area-inset-bottom);
    }
    .sidebar-footer {
        padding-bottom: calc(14px + env(safe-area-inset-bottom));
    }
}

/* ===== Settings Page ===== */
.settings-page { max-width: 900px; margin: 0 auto; }
.settings-section {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
}
.settings-section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 20px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--card-border);
}
.settings-section-icon {
    width: 36px; height: 36px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.settings-section-icon.gold { background: rgba(212, 168, 67, 0.15); color: var(--gold); }
.settings-section-icon.cyan { background: rgba(46, 170, 220, 0.15); color: var(--cyan); }
.settings-section-icon.green { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.settings-section-icon.blue { background: rgba(59, 130, 246, 0.15); color: var(--info); }
.settings-section-icon.red { background: rgba(239, 68, 68, 0.15); color: var(--danger); }
.settings-section-title { font-size: 15px; font-weight: 600; color: var(--text-primary); }
.settings-section-desc { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.settings-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 600px) { .settings-form-row { grid-template-columns: 1fr; } }
.settings-info-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 12px;
    margin-bottom: 16px;
}
.settings-info-item {
    background: rgba(255,255,255,0.02);
    border: 1px solid var(--card-border);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
}
.settings-info-item .label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 4px; }
.settings-info-item .value { font-size: 14px; font-weight: 500; color: var(--text-primary); }

/* Pricing plan cards */
.plans-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; }
.plan-card {
    background: rgba(255,255,255,0.02);
    border: 1px solid var(--card-border);
    border-radius: var(--radius);
    padding: 18px;
    transition: all var(--transition);
    position: relative;
    overflow: hidden;
}
.plan-card:hover { border-color: var(--cyan); transform: translateY(-2px); }
.plan-card.popular { border-color: var(--gold); }
.plan-card.popular::before {
    content: 'Popular';
    position: absolute;
    top: 8px; right: 8px;
    background: var(--gold);
    color: var(--navy);
    font-size: 10px;
    font-weight: 700;
    padding: 2px 8px;
    border-radius: 4px;
    text-transform: uppercase;
}
.plan-card-name { font-size: 14px; font-weight: 600; color: var(--text-primary); margin-bottom: 4px; text-transform: capitalize; }
.plan-card-price { font-size: 22px; font-weight: 700; color: var(--cyan); margin-bottom: 2px; }
.plan-card-price span { font-size: 12px; font-weight: 400; color: var(--text-secondary); }
.plan-card-features { list-style: none; padding: 0; margin: 12px 0 0 0; }
.plan-card-features li {
    font-size: 12px;
    color: var(--text-secondary);
    padding: 4px 0;
    display: flex;
    align-items: center;
    gap: 6px;
}
.plan-card-features li::before { content: '✓'; color: var(--success); font-weight: 700; flex-shrink: 0; }

/* ===== Instance Info Card (Portal) ===== */
.inst-info-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 4px 0;
}
.inst-info-label {
    color: var(--text-muted);
    min-width: 120px;
    flex-shrink: 0;
}
.inst-info-value {
    color: var(--text-primary);
    word-break: break-all;
    flex: 1;
    min-width: 0;
}
.inst-info-value code {
    background: var(--navy);
    padding: 2px 8px;
    border-radius: 4px;
    color: var(--gold);
    user-select: all;
    word-break: break-all;
}
.inst-info-actions {
    margin-top: 12px;
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.inst-guide-list {
    margin: 0;
    padding-left: 18px;
    color: var(--text-muted);
    line-height: 1.7;
}
.inst-guide-list code {
    background: var(--navy);
    padding: 1px 4px;
    border-radius: 3px;
    word-break: break-all;
}

@media (max-width: 600px) {
    .inst-info-row { flex-direction: column; align-items: flex-start; gap: 2px; }
    .inst-info-label { min-width: 0; font-size: 11px; }
    .inst-info-value { width: 100%; }
    .inst-info-value code { display: inline-block; word-break: break-all; }
}

/* ---------------------------------------------------------------------------
   Chat Preview Modal
   --------------------------------------------------------------------------- */
.chat-preview-modal {
    width: 520px;
    max-width: 95vw;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chat-preview-body {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    min-height: 300px;
    max-height: calc(80vh - 120px);
    background: var(--navy);
}
.chat-messages { display: flex; flex-direction: column; gap: 10px; }
.chat-welcome {
    text-align: center;
    color: var(--text-muted);
    padding: 30px 16px;
    font-size: 13px;
}
.chat-welcome p { margin: 0 0 8px; }
.chat-msg {
    display: flex;
    max-width: 85%;
}
.chat-msg-user {
    align-self: flex-end;
    justify-content: flex-end;
}
.chat-msg-agent {
    align-self: flex-start;
    flex-direction: column;
    align-items: flex-start;
}
.chat-msg-bubble {
    padding: 10px 14px;
    border-radius: 14px;
    font-size: 14px;
    line-height: 1.5;
    word-wrap: break-word;
    position: relative;
}
.chat-msg-time {
    display: block;
    font-size: 10px;
    color: rgba(255,255,255,0.6);
    margin-top: 4px;
    text-align: right;
}
.chat-msg-agent .chat-msg-time {
    color: var(--text-muted);
}
.chat-msg-user .chat-msg-bubble {
    background: var(--cyan);
    color: #fff;
    border-bottom-right-radius: 4px;
}
.chat-msg-agent .chat-msg-bubble {
    background: var(--card-bg);
    border: 1px solid var(--card-border);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
}
.chat-msg-error {
    border-color: #ef5350 !important;
    color: #ef5350 !important;
    background: rgba(239, 83, 80, 0.1) !important;
}
.chat-typing-bubble {
    display: flex;
    gap: 4px;
    align-items: center;
    padding: 12px 16px;
}
.chat-typing-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: chatTypingBounce 1.4s infinite ease-in-out;
}
.chat-typing-dot:nth-child(2) { animation-delay: 0.2s; }
.chat-typing-dot:nth-child(3) { animation-delay: 0.4s; }

/* Tool call badges in chat — subtle inline labels above response */
.chat-tool-calls {
    margin-bottom: 4px;
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}
.chat-tool-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    background: rgba(34, 211, 238, 0.08);
    color: var(--cyan, #22d3ee);
    border: 1px solid rgba(34, 211, 238, 0.2);
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 10px;
    font-weight: 500;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    opacity: 0.85;
}

/* Chat modal with sessions sidebar */
.chat-modal-with-sessions {
    max-width: 900px;
    width: 90vw;
    height: 80vh;
    padding: 0;
    display: flex;
    flex-direction: column;
}
.chat-layout {
    display: flex;
    flex: 1;
    overflow: hidden;
}
.chat-sidebar {
    width: 220px;
    border-right: 1px solid var(--card-border);
    overflow-y: auto;
    flex-shrink: 0;
}
.chat-session-item {
    padding: 10px 12px;
    border-bottom: 1px solid var(--card-border);
    cursor: pointer;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 4px;
    transition: background 0.15s;
    position: relative;
}
.chat-session-item:hover {
    background: rgba(255,255,255,0.04);
}
.chat-session-item.active {
    background: rgba(34,211,238,0.1);
    border-left: 3px solid var(--cyan, #22d3ee);
}
.chat-session-title {
    font-size: 13px;
    color: var(--text);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 130px;
}
.chat-session-date {
    font-size: 10px;
    color: var(--text-muted);
    width: 100%;
}
.chat-session-delete {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    font-size: 12px;
    padding: 2px 4px;
    opacity: 0;
    transition: opacity 0.15s;
}
.chat-session-item:hover .chat-session-delete {
    opacity: 1;
}
.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}
.chat-modal-with-sessions .chat-preview-body {
    flex: 1;
}
@media (max-width: 640px) {
    .chat-sidebar { display: none; }
}

@keyframes chatTypingBounce {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}
.chat-input-bar {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--card-border);
    background: var(--card-bg);
}
.chat-input-bar input {
    flex: 1;
    padding: 10px 14px;
    background: var(--navy);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
}
.chat-input-bar input:focus { border-color: var(--cyan); }
.chat-input-bar button { flex-shrink: 0; }
.chat-code-block {
    background: var(--navy);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    padding: 10px 12px;
    overflow-x: auto;
    margin: 8px 0;
    font-size: 12px;
}
.chat-code-block code { color: var(--gold); font-family: monospace; }
.chat-inline-code {
    background: var(--navy);
    padding: 1px 5px;
    border-radius: 3px;
    font-size: 13px;
    color: var(--gold);
}

@media (max-width: 600px) {
    .chat-preview-modal { width: 100vw; max-width: 100vw; max-height: 100vh; border-radius: 0; }
    .chat-preview-body { min-height: 50vh; }
    .chat-msg { max-width: 95%; }
}
}
/* ============================================================
   Role Editor (white-label persona)
   ============================================================ */

.role-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 8px;
    margin-top: 6px;
    max-height: 380px;
    overflow-y: auto;
    padding-right: 4px;
}

.role-filter-tab {
    padding: 5px 12px;
    border-radius: 100px;
    font-size: 11px;
    font-weight: 600;
    background: var(--navy);
    border: 1px solid var(--card-border);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.role-filter-tab:hover {
    border-color: var(--gold);
    color: var(--text);
}

.role-filter-tab.active {
    background: rgba(212, 168, 67, 0.15);
    border-color: var(--gold);
    color: var(--gold);
}

.role-card {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: var(--navy);
    border: 1px solid var(--card-border);
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.18s ease;
    position: relative;
}

.role-card:hover {
    border-color: rgba(212, 168, 67, 0.5);
    background: rgba(212, 168, 67, 0.06);
    transform: translateY(-1px);
}

.role-card-active {
    border-color: var(--gold);
    background: rgba(212, 168, 67, 0.12);
    box-shadow: 0 0 0 1px var(--gold);
}

.role-card-icon {
    font-size: 22px;
    flex-shrink: 0;
    width: 32px;
    text-align: center;
}

.role-card-content {
    flex: 1;
    min-width: 0;
}

.role-card-name {
    color: var(--text);
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 2px;
}

.role-card-desc {
    color: var(--text-muted);
    font-size: 11px;
    line-height: 1.3;
}

.role-card-check {
    color: var(--gold);
    font-weight: bold;
    font-size: 16px;
    flex-shrink: 0;
}

.role-input,
.role-textarea {
    width: 100%;
    background: var(--navy);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--text);
    font-size: 13px;
    font-family: inherit;
    margin-top: 4px;
    transition: border-color 0.15s;
    box-sizing: border-box;
}

.role-input:focus,
.role-textarea:focus {
    outline: none;
    border-color: var(--gold);
}

.role-textarea {
    resize: vertical;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
    font-size: 12px;
    line-height: 1.5;
    min-height: 180px;
}

.role-preview {
    background: var(--navy);
    border: 1px solid var(--card-border);
    border-radius: 6px;
    padding: 12px;
    color: var(--text);
    font-size: 12px;
    line-height: 1.55;
    max-height: 220px;
    overflow-y: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
    margin-top: 6px;
    font-family: 'SF Mono', 'Monaco', 'Menlo', 'Consolas', monospace;
}

.role-preview::-webkit-scrollbar {
    width: 6px;
}

.role-preview::-webkit-scrollbar-track {
    background: transparent;
}

.role-preview::-webkit-scrollbar-thumb {
    background: var(--card-border);
    border-radius: 3px;
}

.role-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

@media (max-width: 600px) {
    .role-grid {
        grid-template-columns: 1fr;
    }
}

/* ── Web Search Toggle Switch ────────────────────────────────── */
.ws-toggle {
    position: relative;
    display: inline-flex;
    align-items: center;
    cursor: pointer;
    margin-right: 4px;
    vertical-align: middle;
}
.ws-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
    position: absolute;
}
.ws-toggle-slider {
    width: 32px;
    height: 18px;
    background: var(--card-border);
    border-radius: 9px;
    transition: background 0.2s;
    position: relative;
    flex-shrink: 0;
}
.ws-toggle-slider::after {
    content: "";
    position: absolute;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    top: 2px;
    left: 2px;
    transition: transform 0.2s;
}
.ws-toggle input:checked + .ws-toggle-slider {
    background: var(--cyan, #22d3ee);
}
.ws-toggle input:checked + .ws-toggle-slider::after {
    transform: translateX(14px);
}

/* Larger variant for portal cards */
.ws-toggle-lg .ws-toggle-slider {
    width: 38px;
    height: 22px;
    border-radius: 11px;
}
.ws-toggle-lg .ws-toggle-slider::after {
    width: 18px;
    height: 18px;
    top: 2px;
    left: 2px;
}
.ws-toggle-lg input:checked + .ws-toggle-slider::after {
    transform: translateX(16px);
}

/* ── Tech Level Badge ────────────────────────────────────────── */
.tech-level-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
    user-select: none;
}
.tech-level-badge:hover {
    opacity: 0.8;
}
.tech-level-badge.basic {
    background: rgba(107, 114, 128, 0.15);
    color: var(--text-muted, #9ca3af);
    border: 1px solid rgba(107, 114, 128, 0.3);
}
.tech-level-badge.advanced {
    background: rgba(168, 85, 247, 0.15);
    color: #a855f7;
    border: 1px solid rgba(168, 85, 247, 0.4);
}

/* ── Notification Badge & Items ─────────────────────────────── */
.notif-badge {
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 18px;
    height: 18px;
    border-radius: 9px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 5px;
    margin-left: auto;
}
.notif-badge.hidden { display: none !important; }
.notif-list { display: flex; flex-direction: column; gap: 8px; }
.notif-item {
    display: flex;
    gap: 12px;
    padding: 14px 16px;
    background: var(--card-bg, var(--navy));
    border: 1px solid var(--card-border);
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s;
    position: relative;
}
.notif-item:hover { background: rgba(255,255,255,0.06); }
.notif-item.unread { border-left: 3px solid var(--cyan, #22d3ee); }
.notif-icon { font-size: 22px; flex-shrink: 0; }
.notif-content { flex: 1; min-width: 0; }
.notif-title { font-weight: 600; font-size: 14px; color: var(--text); margin-bottom: 2px; }
.notif-message { font-size: 13px; color: var(--text-muted); line-height: 1.4; word-break: break-word; }
.notif-time { font-size: 11px; color: var(--text-dim, #6b7280); margin-top: 6px; }
.notif-dot {
    width: 8px; height: 8px; border-radius: 50%;
    background: var(--cyan, #22d3ee);
    flex-shrink: 0;
    margin-top: 4px;
}


/* ==========================================================================
   Messaging Integration Styles
   ========================================================================== */

.msg-badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 600;
    white-space: nowrap;
}
.msg-connected {
    background: rgba(37,211,102,0.15);
    color: #25d366;
    border: 1px solid rgba(37,211,102,0.4);
}
.msg-paired {
    background: rgba(255,193,7,0.15);
    color: #ffc107;
    border: 1px solid rgba(255,193,7,0.4);
}
.msg-offline {
    background: rgba(107,114,128,0.15);
    color: var(--text-muted);
    border: 1px solid rgba(107,114,128,0.3);
}
.msg-platform-card {
    transition: border-color 0.2s;
}
.msg-platform-card:hover {
    border-color: rgba(34,211,238,0.3);
}
.spinner {
    border: 3px solid rgba(34,211,238,0.2);
    border-top: 3px solid var(--cyan);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

