/**
 * Meta Monitor — monitor.css
 * Styles for the Meta Monitor MVP
 */

/* ================================================================
   RESET & BASE
   ================================================================ */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --bg: #0f1117;
    --surface: #1a1d27;
    --surface-2: #22262f;
    --border: #2a2e3a;
    --text: #e4e6eb;
    --text-muted: #8a8d97;
    --primary: #1877f2;
    --primary-hover: #166fe0;
    --success: #22c55e;
    --danger: #ef4444;
    --warning: #f59e0b;
    --msg-in-bg: #2a2e3a;
    --msg-out-bg: #1a3a5c;
    --radius: 8px;
    --radius-lg: 12px;
    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html, body {
    height: 100%;
    font-family: var(--font);
    font-size: 14px;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    overflow: hidden;
}

/* ================================================================
   TOP BAR
   ================================================================ */
#topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 48px;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-logo {
    font-weight: 700;
    font-size: 16px;
    color: var(--primary);
}

.topbar-account {
    font-size: 13px;
    color: var(--text-muted);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.topbar-user {
    font-size: 13px;
    font-weight: 500;
}

.topbar-page {
    font-size: 12px;
    color: var(--text-muted);
    background: var(--surface-2);
    padding: 2px 8px;
    border-radius: 4px;
}

/* ================================================================
   BUTTONS
   ================================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background .15s, opacity .15s;
    text-decoration: none;
    color: #fff;
}

.btn:disabled {
    opacity: .5;
    cursor: not-allowed;
}

.btn-primary { background: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-fb {
    background: #1877f2;
    padding: 12px 24px;
    font-size: 15px;
    border-radius: 8px;
    width: 100%;
}
.btn-fb:hover { background: #166fe0; }

.btn-page {
    background: var(--surface-2);
    border: 1px solid var(--border);
    padding: 12px 16px;
    width: 100%;
    text-align: left;
    color: var(--text);
    border-radius: 8px;
}
.btn-page:hover { background: var(--border); }

.btn-sm {
    padding: 4px 10px;
    font-size: 12px;
    border-radius: 4px;
    border: 1px solid var(--border);
    background: var(--surface-2);
    color: var(--text);
    cursor: pointer;
}
.btn-sm:hover { background: var(--border); }

.btn-outline {
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
}
.btn-outline:hover { border-color: var(--text-muted); }

.btn-danger {
    border-color: var(--danger);
    color: var(--danger);
}
.btn-danger:hover { background: rgba(239, 68, 68, .1); }

.btn-load-more {
    display: block;
    width: 100%;
    padding: 8px;
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--text-muted);
    cursor: pointer;
    border-radius: 4px;
    font-size: 12px;
    margin: 4px 0;
}
.btn-load-more:hover { background: var(--surface-2); }

/* ================================================================
   LOGIN / PAGE SELECTOR SCREENS
   ================================================================ */
.screen-center {
    display: flex;
    align-items: center;
    justify-content: center;
    height: calc(100vh - 48px);
}

.login-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 40px 32px;
    max-width: 400px;
    width: 100%;
    text-align: center;
}

.login-card h1 {
    font-size: 24px;
    margin-bottom: 8px;
    color: var(--primary);
}

.login-card h2 {
    font-size: 20px;
    margin-bottom: 8px;
}

.login-subtitle {
    color: var(--text-muted);
    margin-bottom: 24px;
    font-size: 13px;
}

.pages-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.alert {
    padding: 10px 14px;
    border-radius: 6px;
    font-size: 13px;
    margin-bottom: 16px;
}
.alert-error {
    background: rgba(239, 68, 68, .1);
    border: 1px solid rgba(239, 68, 68, .3);
    color: #fca5a5;
}

/* ================================================================
   MAIN LAYOUT — 3-column
   ================================================================ */
#app-container {
    height: calc(100vh - 48px);
    overflow: hidden;
}

#monitor-app {
    display: flex;
    flex-direction: column;
    height: 100%;
}

/* Channel tabs */
#channel-tabs {
    display: flex;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.tab {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 20px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    transition: color .15s, border-color .15s;
}
.tab:hover { color: var(--text); }
.tab.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}
.tab svg { opacity: .7; }
.tab.active svg { opacity: 1; }

/* 3-column layout */
#monitor-layout {
    display: grid;
    grid-template-columns: 300px 1fr 260px;
    height: calc(100% - 42px);
    overflow: hidden;
}

/* ================================================================
   CONVERSATIONS SIDEBAR
   ================================================================ */
#conv-sidebar {
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--surface);
    overflow: hidden;
}

#conv-search {
    padding: 8px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

#search-input {
    width: 100%;
    padding: 8px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 13px;
    outline: none;
}
#search-input:focus { border-color: var(--primary); }
#search-input::placeholder { color: var(--text-muted); }

#conv-list {
    flex: 1;
    overflow-y: auto;
}

.conv-item {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background .1s;
}
.conv-item:hover { background: var(--surface-2); }
.conv-item.active { background: rgba(24, 119, 242, .1); border-left: 3px solid var(--primary); }

.conv-name {
    font-weight: 500;
    font-size: 13px;
    margin-bottom: 2px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.conv-phone {
    font-size: 11px;
    color: var(--text-muted);
}

.conv-snippet {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.conv-time {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* AI status dot */
.ai-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.ai-on { background: var(--success); }
.ai-off { background: var(--text-muted); }

/* ================================================================
   CHAT AREA
   ================================================================ */
#chat-area {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

#chat-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.chat-header-info {
    display: flex;
    flex-direction: column;
}

#chat-user-name {
    font-weight: 600;
    font-size: 14px;
}

#chat-user-detail {
    font-size: 12px;
    color: var(--text-muted);
}

.chat-header-actions {
    display: flex;
    gap: 6px;
}

#chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.empty-state {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 13px;
}

.error-msg {
    color: var(--danger);
    padding: 12px;
    text-align: center;
    font-size: 13px;
}

/* Messages */
.msg {
    max-width: 70%;
    padding: 8px 12px;
    border-radius: var(--radius);
    font-size: 13px;
    line-height: 1.4;
    word-break: break-word;
}

.msg-in {
    background: var(--msg-in-bg);
    align-self: flex-start;
    border-bottom-left-radius: 2px;
}

.msg-out {
    background: var(--msg-out-bg);
    align-self: flex-end;
    border-bottom-right-radius: 2px;
}

.msg-sender {
    font-size: 11px;
    font-weight: 600;
    color: var(--primary);
    margin-bottom: 2px;
}

.msg-out .msg-sender { color: var(--success); }

.msg-text {
    white-space: pre-wrap;
}

.msg-time {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: 4px;
    text-align: right;
}

.msg-media img {
    max-width: 200px;
    max-height: 200px;
    border-radius: 6px;
    margin-bottom: 4px;
}

.msg-media audio {
    max-width: 250px;
}

/* Chat input */
#chat-input-area {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    background: var(--surface);
    border-top: 1px solid var(--border);
    flex-shrink: 0;
}

#msg-input {
    flex: 1;
    padding: 8px 12px;
    background: var(--surface-2);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 13px;
    font-family: var(--font);
    resize: none;
    outline: none;
}
#msg-input:focus { border-color: var(--primary); }
#msg-input::placeholder { color: var(--text-muted); }

#btn-send {
    padding: 8px 16px;
    align-self: flex-end;
}

/* ================================================================
   SIGNAL PANEL (right sidebar)
   ================================================================ */
#signal-panel {
    display: flex;
    flex-direction: column;
    background: var(--surface);
    border-left: 1px solid var(--border);
    overflow-y: auto;
    padding: 12px;
}

#signal-panel h3 {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    margin-bottom: 12px;
}

#signal-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.signal-item {
    padding: 8px 10px;
    background: var(--surface-2);
    border-radius: 6px;
    border-left: 3px solid var(--text-muted);
    font-size: 12px;
}
.signal-high { border-left-color: var(--danger); }
.signal-mid { border-left-color: var(--warning); }
.signal-low { border-left-color: var(--success); }

.signal-user {
    font-weight: 500;
    margin-bottom: 2px;
}

.signal-meta {
    display: flex;
    gap: 8px;
    color: var(--text-muted);
    font-size: 11px;
}

.signal-level { font-weight: 600; }
.signal-ai { opacity: .8; }

.signal-reason {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
    font-style: italic;
}

/* Heartbeat status */
#heartbeat-status {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 10px 0;
    border-top: 1px solid var(--border);
    margin-top: 12px;
    font-size: 12px;
    color: var(--text-muted);
}

.dot-online {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
}
.dot-offline {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
}

/* ================================================================
   LOADING
   ================================================================ */
.loading-indicator {
    padding: 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ================================================================
   SCROLLBAR
   ================================================================ */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ================================================================
   RESPONSIVE
   ================================================================ */
@media (max-width: 900px) {
    #monitor-layout {
        grid-template-columns: 260px 1fr;
    }
    #signal-panel { display: none; }
}

@media (max-width: 640px) {
    #monitor-layout {
        grid-template-columns: 1fr;
    }
    #conv-sidebar {
        display: none;
    }
    #signal-panel { display: none; }
}
