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

/* Dark scrollbars globally */
* { scrollbar-color: #333 #000; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: #000; }
::-webkit-scrollbar-thumb { background: #333; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #555; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f1624;
    color: #e0e0e0;
    min-height: 100vh;
}

/* Header */
.header {
    background: #1a1a2e;
    padding: 0 20px;
    display: flex;
    align-items: center;
    height: 52px;
    border-bottom: 1px solid #2a2a4a;
    position: relative;
    z-index: 50;
}
.header-brand { display: flex; align-items: baseline; gap: 10px; flex-shrink: 0; }
.header-title { font-size: 17px; font-weight: 700; color: #fff; line-height: 1; }
.header-subtitle { font-size: 11px; color: #555; white-space: nowrap; }
.header-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-left: auto;
    font-size: 12px;
    color: #a0a0c0;
}
.header-actions .separator {
    width: 1px;
    height: 20px;
    background: #2a2a4a;
    flex-shrink: 0;
}
.stat { display: flex; align-items: center; gap: 4px; font-size: 11px; white-space: nowrap; }
.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-idle { background: #22c55e; }
.dot-active { background: #f59e0b; }

/* User Dropdown */
.user-dropdown { position: relative; }
.user-dropdown-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 12px;
    background: #0f1624;
    border: 1px solid #2a2a4a;
    border-radius: 6px;
    color: #60a5fa;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
    white-space: nowrap;
}
.user-dropdown-btn:hover { background: #1a1a2e; border-color: #3a3a5a; }
.user-dropdown-btn .chevron {
    width: 10px;
    height: 10px;
    transition: transform 0.2s;
}
.user-dropdown.open .user-dropdown-btn { border-color: #60a5fa; }
.user-dropdown.open .chevron { transform: rotate(180deg); }
.user-dropdown-menu {
    display: none;
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    min-width: 180px;
    background: #1a1a2e;
    border: 1px solid #2a2a4a;
    border-radius: 8px;
    padding: 4px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
    z-index: 200;
}
.user-dropdown.open .user-dropdown-menu { display: block; }
.user-dropdown-menu a {
    display: block;
    padding: 8px 12px;
    color: #c0c0d0;
    text-decoration: none;
    font-size: 12px;
    font-weight: 500;
    border-radius: 5px;
    transition: background 0.12s, color 0.12s;
}
.user-dropdown-menu a:hover { background: #2a2a4a; color: #fff; }
.user-dropdown-menu a.active { color: #60a5fa; }
.user-dropdown-menu .dropdown-divider {
    height: 1px;
    background: #2a2a4a;
    margin: 4px 8px;
}
.user-dropdown-menu .dropdown-logout { color: #ef4444; }
.user-dropdown-menu .dropdown-logout:hover { background: rgba(239, 68, 68, 0.12); color: #ef4444; }
.btn-wake-all {
    padding: 5px 14px;
    border-radius: 5px;
    font-size: 11px;
    font-weight: 600;
    border: none;
    background: #f59e0b;
    color: #000;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-wake-all:hover { background: #d97706; }
.btn-wake-all:disabled { background: #555; color: #999; cursor: default; }
/* Mailroom Header Button */
.btn-mailroom {
    padding: 5px 14px;
    border-radius: 5px;
    font-size: 11px;
    font-weight: 600;
    border: none;
    background: #60a5fa;
    color: #000;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-mailroom:hover { background: #3b82f6; }

.refresh-indicator { color: #444; font-size: 10px; white-space: nowrap; }
.refresh-indicator.pulse { color: #60a5fa; }

/* Agent Grid */
.agent-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 12px;
    padding: 16px;
    max-width: 1600px;
    margin: 0 auto;
}
@media (min-width: 800px) {
    .agent-grid { grid-template-columns: 1fr 1fr 1fr; }
}
@media (min-width: 1400px) {
    .agent-grid { grid-template-columns: 1fr 1fr 1fr 1fr; }
}

/* Agent Card */
.agent-card {
    background: #1a1a2e;
    border-radius: 8px;
    padding: 16px;
    border-left: 4px solid #22c55e;
    transition: border-color 0.3s;
    display: flex;
    flex-direction: column;
}
.agent-card[data-status="busy"] { border-left-color: #f59e0b; }
.agent-card[data-status="waiting"] { border-left-color: #a855f7; }
.agent-card[data-status="recent"] { border-left-color: #38bdf8; }
.agent-card[data-status="idle"] { border-left-color: #22c55e; }

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}
.card-identity { display: flex; align-items: baseline; gap: 8px; }
.card-name { font-size: 15px; font-weight: 700; color: #fff; }
.card-role { font-size: 11px; color: #888; }

.status-badge {
    padding: 2px 10px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
}
.status-badge.busy { background: #f59e0b; color: #000; }
.status-badge.waiting { background: #a855f7; color: #fff; }
.status-badge.recent { background: #38bdf8; color: #000; }
.status-badge.idle { background: #22c55e; color: #000; }

/* Current Task Block */
.task-block {
    background: #0f1624;
    padding: 8px 12px;
    border-radius: 6px;
    margin-bottom: 10px;
    border-left: 2px solid #22c55e;
    height: 90px;
    overflow-y: hidden;
}
.agent-card[data-status="busy"] .task-block { border-left-color: #f59e0b; }
.agent-card[data-status="waiting"] .task-block { border-left-color: #a855f7; }
.agent-card[data-status="recent"] .task-block { border-left-color: #38bdf8; }

.task-label {
    font-size: 9px;
    text-transform: uppercase;
    font-weight: 600;
    margin-bottom: 3px;
    letter-spacing: 0.5px;
}
.agent-card[data-status="busy"] .task-label { color: #f59e0b; }
.agent-card[data-status="waiting"] .task-label { color: #a855f7; }
.agent-card[data-status="recent"] .task-label { color: #38bdf8; }
.agent-card[data-status="idle"] .task-label { color: #22c55e; }

.task-description { font-size: 12px; color: #e0e0e0; line-height: 1.4; }
.task-meta { font-size: 10px; color: #666; margin-top: 4px; }

/* Recent Jobs */
.recent-jobs { margin-bottom: 12px; height: 200px; overflow-y: auto; }
.recent-header { font-size: 11px; color: #aaa; font-weight: 600; margin-bottom: 4px; }
.recent-list { font-size: 11px; color: #888; line-height: 1.6; }
.recent-date { color: #555; margin-right: 4px; }
.recent-empty { color: #555; font-style: italic; font-size: 11px; }

/* Card Button Group */
.card-actions {
    display: flex;
    gap: 0;
    margin-top: auto;
}
.card-actions button {
    flex: 1;
    padding: 6px 12px;
    color: #fff;
    border: none;
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}
.btn-task {
    background: #2563eb;
    border-radius: 5px 0 0 5px;
}
.btn-task:hover { background: #1d4ed8; }
.btn-console {
    background: #4b5563;
    border-radius: 0 5px 5px 0;
    border-left: 1px solid #374151;
}
.btn-console:hover { background: #6b7280; }
.btn-console.running { background: #22c55e; color: #000; }
.btn-console.running:hover { background: #16a34a; }

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 100;
    align-items: center;
    justify-content: center;
}
.modal-overlay.active { display: flex; }

.modal {
    background: #1a1a2e;
    border-radius: 10px;
    width: 440px;
    max-width: 90vw;
    border: 1px solid #2a2a4a;
}
.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid #2a2a4a;
}
.modal-header h2 { font-size: 14px; color: #fff; }
.modal-close {
    background: none;
    border: none;
    color: #888;
    font-size: 20px;
    cursor: pointer;
}
.modal-close:hover { color: #fff; }

.modal-body { padding: 16px 18px; }

.form-label {
    display: block;
    font-size: 11px;
    color: #888;
    margin-bottom: 4px;
    margin-top: 12px;
}
.form-label:first-child { margin-top: 0; }

.form-textarea {
    width: 100%;
    background: #0f1624;
    border: 1px solid #333;
    border-radius: 6px;
    padding: 10px;
    color: #e0e0e0;
    font-size: 12px;
    font-family: inherit;
    resize: vertical;
}
.form-textarea:focus { outline: none; border-color: #2563eb; }

.route-toggle { display: flex; gap: 6px; margin-top: 4px; }
.route-btn {
    padding: 5px 14px;
    border-radius: 4px;
    font-size: 11px;
    border: 1px solid #333;
    background: #0f1624;
    color: #e0e0e0;
    cursor: pointer;
    transition: all 0.2s;
}
.route-btn.active { background: #2563eb; border-color: #2563eb; color: #fff; }

.modal-status {
    font-size: 10px;
    color: #666;
    text-align: center;
    margin-top: 12px;
    min-height: 16px;
}

.modal-footer {
    display: flex;
    gap: 8px;
    padding: 12px 18px;
    border-top: 1px solid #2a2a4a;
}
.btn {
    flex: 1;
    padding: 8px 16px;
    border: none;
    border-radius: 5px;
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
}
.btn-send { background: #22c55e; color: #000; }
.btn-send:hover { background: #16a34a; }
.btn-cancel { background: #374151; color: #e0e0e0; }
.btn-cancel:hover { background: #4b5563; }

/* Recent Job Clickable */
.recent-job {
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 3px;
    transition: background 0.15s;
}
.recent-job:hover {
    background: #2a2a4a;
    color: #e0e0e0;
}

/* Job Detail Dialog */
.job-dialog {
    background: #1a1a2e;
    color: #e0e0e0;
    border: 1px solid #2a2a4a;
    border-radius: 10px;
    padding: 0;
    width: 700px;
    max-width: 90vw;
    max-height: 80vh;
}
.job-dialog[open] {
    display: flex;
    flex-direction: column;
}
.job-dialog::backdrop {
    background: rgba(0, 0, 0, 0.6);
}
.job-dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid #2a2a4a;
    flex-shrink: 0;
}
.job-dialog-header h2 {
    font-size: 14px;
    color: #fff;
    margin: 0;
}
.job-dialog-close {
    background: none;
    border: none;
    color: #888;
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
}
.job-dialog-close:hover { color: #fff; }
.job-dialog-body {
    padding: 16px 18px;
    overflow-y: auto;
    flex: 1;
}
.job-dialog-content {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 12px;
    line-height: 1.6;
    white-space: pre-wrap;
    word-wrap: break-word;
    color: #d0d0d0;
    margin: 0;
}

/* Mailroom Dialog */
.mailroom-dialog {
    background: #1a1a2e;
    color: #e0e0e0;
    border: 1px solid #2a2a4a;
    border-radius: 10px;
    padding: 0;
    width: 700px;
    max-width: 90vw;
    max-height: 80vh;
}
.mailroom-dialog[open] {
    display: flex;
    flex-direction: column;
}
.mailroom-dialog::backdrop {
    background: rgba(0, 0, 0, 0.6);
}
.mailroom-dialog-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px 18px;
    border-bottom: 1px solid #2a2a4a;
    flex-shrink: 0;
}
.mailroom-dialog-header h2 {
    font-size: 14px;
    color: #fff;
    margin: 0;
}
.mailroom-dialog-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}
.mailroom-dialog-close {
    background: none;
    border: none;
    color: #888;
    font-size: 20px;
    cursor: pointer;
    padding: 0 4px;
}
.mailroom-dialog-close:hover { color: #fff; }
.mailroom-dialog-body {
    padding: 16px 18px;
    overflow-y: auto;
    flex: 1;
}
.mailroom-dialog-log {
    font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
    font-size: 11px;
    line-height: 1.5;
    color: #a0a0c0;
    white-space: pre-wrap;
    word-wrap: break-word;
    margin: 0;
}

/* Nav page link buttons */
.btn-nav-page {
    padding: 5px 12px;
    border-radius: 6px;
    font-size: 11px;
    font-weight: 600;
    background: transparent;
    color: #8888aa;
    text-decoration: none;
    border: 1px solid transparent;
    transition: all 0.15s;
    white-space: nowrap;
}
.btn-nav-page:hover { background: #2a2a4a; color: #e0e0e0; }
.btn-nav-page.active-page { color: #60a5fa; border-color: rgba(96, 165, 250, 0.25); background: rgba(96, 165, 250, 0.08); }

/* Header title as a link */
.header-title-link {
    text-decoration: none;
    color: inherit;
}
.header-title-link:hover { color: #60a5fa; }

/* All Agents Table Page */
.all-agents-main {
    padding: 20px clamp(16px, 4vw, 48px);
    overflow-x: auto;
}

.agents-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
    min-width: 640px;
}

.agents-table thead {
    position: sticky;
    top: 0;
    z-index: 10;
}

.agents-table thead th {
    text-align: left;
    padding: 10px 16px;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: #555;
    background: #0f1624;
    border-bottom: 2px solid #22224a;
    white-space: nowrap;
}

.agents-table thead th.th-actions {
    text-align: right;
}

.agents-table tbody tr {
    border-bottom: 1px solid #14142a;
    transition: background 0.15s;
}

.agents-table tbody tr:hover {
    background: #141428;
}

.agents-table tbody tr[data-status="busy"] { border-left: 3px solid #f59e0b; }
.agents-table tbody tr[data-status="waiting"] { border-left: 3px solid #a855f7; }
.agents-table tbody tr[data-status="recent"] { border-left: 3px solid #38bdf8; }
.agents-table tbody tr[data-status="idle"] { border-left: 3px solid #22c55e; }

.agents-table td {
    padding: 12px 16px;
    vertical-align: middle;
    border-bottom: 1px solid #252545;
}

.td-name {
    white-space: nowrap;
    min-width: 130px;
}
.td-name .card-name { display: block; font-size: 14px; font-weight: 700; color: #fff; }
.td-name .card-role { display: block; font-size: 11px; color: #777; margin-top: 2px; }

.td-status { white-space: nowrap; }

.td-recent-job {
    color: #888;
    font-size: 12px;
}

.table-no-job { color: #3a3a55; font-style: italic; }

.table-recent-job {
    cursor: pointer;
    display: inline-block;
    padding: 3px 8px;
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
}
.table-recent-job:hover { background: #1e1e38; color: #c0c0e0; }
.table-recent-job .recent-date { color: #555; margin-right: 6px; font-size: 11px; }

.td-actions {
    white-space: nowrap;
    text-align: right;
    min-width: 180px;
}

/* Table action buttons — polished pill group */
.td-actions .btn-task {
    padding: 7px 18px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: #fff;
    border: none;
    border-radius: 6px 0 0 6px;
    cursor: pointer;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.12), 0 1px 3px rgba(0,0,0,0.4);
    transition: filter 0.15s, transform 0.1s;
}
.td-actions .btn-task:hover { filter: brightness(1.2); }
.td-actions .btn-task:active { transform: scale(0.97); filter: brightness(0.92); }

.td-actions .btn-console {
    padding: 7px 18px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
    background: #1c1c36;
    color: #8888aa;
    border: none;
    border-radius: 0 6px 6px 0;
    border-left: 1px solid #2a2a4a;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.4);
    transition: background 0.15s, color 0.15s;
}
.td-actions .btn-console:hover { background: #26263e; color: #c8c8e8; }
.td-actions .btn-console.running {
    background: linear-gradient(135deg, #16a34a 0%, #15803d 100%);
    color: #fff;
    border-left-color: #166534;
    box-shadow: inset 0 1px 0 rgba(255,255,255,0.12), 0 1px 3px rgba(0,0,0,0.4);
}
.td-actions .btn-console.running:hover { filter: brightness(1.1); }

/* Legacy header-user (kept for compat, hidden) */
.header-user { display: none; }

/* Login Page */
/* Login Page */
.login-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    min-height: 100dvh;
    padding: 20px;
    background: radial-gradient(ellipse at 50% 40%, #1a1a3a 0%, #0f1624 70%);
}
.login-card {
    background: #1a1a2e;
    border: 1px solid #2a2a4a;
    border-radius: 14px;
    padding: 40px 32px 36px;
    width: 380px;
    max-width: 100%;
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45), 0 0 0 1px rgba(96, 165, 250, 0.06);
}
.login-title {
    font-size: 22px;
    font-weight: 700;
    color: #fff;
    text-align: center;
    margin-bottom: 6px;
}
.login-subtitle {
    font-size: 12px;
    color: #555;
    text-align: center;
    margin-bottom: 28px;
}
.login-error {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.4);
    color: #ef4444;
    font-size: 12px;
    padding: 10px 14px;
    border-radius: 8px;
    margin-bottom: 18px;
    text-align: center;
}
.login-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    color: #777;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.login-label:not(:first-of-type) { margin-top: 16px; }
.login-input {
    width: 100%;
    background: #0b0f1a;
    border: 1px solid #2a2a4a;
    border-radius: 8px;
    padding: 11px 14px;
    color: #e0e0e0;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
}
.login-input:focus {
    outline: none;
    border-color: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
.login-input::placeholder { color: #3a3a55; }
.login-btn {
    width: 100%;
    margin-top: 24px;
    padding: 12px;
    font-size: 14px;
    font-weight: 600;
    border-radius: 8px;
    background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%);
    color: #fff;
    border: none;
    cursor: pointer;
    transition: filter 0.15s, transform 0.1s;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.3);
}
.login-btn:hover { filter: brightness(1.15); }
.login-btn:active { transform: scale(0.98); filter: brightness(0.95); }

/* Mobile menu button — far right, always in DOM but hidden on desktop */
.mobile-menu-btn {
    display: none;
    background: none;
    border: 1px solid #2a2a4a;
    border-radius: 6px;
    color: #a0a0c0;
    font-size: 18px;
    padding: 5px 9px;
    cursor: pointer;
    line-height: 1;
    flex-shrink: 0;
    margin-left: 10px;
    transition: background 0.15s, color 0.15s;
}
.mobile-menu-btn:hover { background: #2a2a4a; color: #fff; }

/* Mobile slide-down panel */
.mobile-menu {
    display: none;
    position: absolute;
    top: 52px;
    left: 0;
    right: 0;
    background: #1a1a2e;
    border-bottom: 1px solid #2a2a4a;
    flex-direction: column;
    padding: 8px;
    gap: 2px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 100;
}
.mobile-menu.open { display: flex; }

.mobile-menu-user {
    color: #60a5fa;
    font-size: 13px;
    font-weight: 600;
    padding: 8px 12px 6px;
}
.mobile-menu-stats {
    display: flex;
    gap: 14px;
    padding: 6px 12px 10px;
    font-size: 11px;
    color: #a0a0c0;
    border-bottom: 1px solid #1a1a3a;
    margin-bottom: 4px;
}
.mobile-menu-item {
    display: block;
    padding: 10px 12px;
    color: #c0c0d0;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    border-radius: 6px;
    transition: background 0.15s;
}
.mobile-menu-item:hover,
.mobile-menu-item.active { background: #2a2a4a; color: #fff; }
.mobile-menu-logout { color: #ef4444; }
.mobile-menu-logout:hover { background: rgba(239, 68, 68, 0.12); color: #ef4444; }
.mobile-menu-divider { height: 1px; background: #2a2a4a; margin: 4px 8px; }

/* Responsive — tablet */
@media (max-width: 860px) {
    .refresh-indicator { display: none; }
    .stat-jobs { display: none; }
}

/* Responsive — mobile */
@media (max-width: 639px) {
    .header { padding: 0 14px; }
    .header-actions { display: none; }
    .mobile-menu-btn { display: block; }
}
