/* ============================
   Voice Bot Admin — Dark Theme
   ============================ */

:root {
    --bg:          #0f1117;
    --bg-surface:  #181a20;
    --bg-elevated: #1e2028;
    --bg-hover:    #252730;
    --border:      #2a2d37;
    --text:        #e4e5e9;
    --text-muted:  #8b8d97;
    --text-dim:    #6c6e78;
    --accent:      #6c8aff;
    --accent-hover:#8ba3ff;
    --danger:      #ff6b6b;
    --success:     #51cf66;
    --badge-user:       #3b82f6;
    --badge-assistant:  #8b5cf6;
    --badge-system:     #6b7280;
    --badge-tool:       #f59e0b;
    --radius:      8px;
    --radius-sm:   4px;
    --font:        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    --font-mono:   "SF Mono", "Cascadia Code", "Fira Code", Consolas, monospace;
}

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

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* ---- Navbar ---- */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    height: 56px;
    background: var(--bg-surface);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-brand {
    font-weight: 700;
    font-size: 1.05rem;
    letter-spacing: -0.5px;
}

.nav-links {
    display: flex;
    gap: 8px;
}

.nav-link {
    color: var(--text-muted);
    text-decoration: none;
    padding: 6px 14px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    transition: background 0.15s, color 0.15s;
}
.nav-link:hover {
    background: var(--bg-hover);
    color: var(--text);
}
.nav-link-logout {
    color: var(--danger);
}
.nav-link-logout:hover {
    background: rgba(255, 107, 107, 0.1);
}

/* ---- Container ---- */
.container {
    max-width: 1100px;
    margin: 0 auto;
    padding: 32px 24px;
}

/* ---- Page header ---- */
.page-header {
    display: flex;
    align-items: baseline;
    gap: 16px;
    margin-bottom: 24px;
    flex-wrap: wrap;
}
.page-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    letter-spacing: -0.5px;
}
.page-header-meta {
    color: var(--text-muted);
    font-size: 0.9rem;
}

.back-link {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 0.85rem;
    display: inline-block;
    margin-bottom: 6px;
    transition: color 0.15s;
}
.back-link:hover { color: var(--accent); }

/* ---- Tables ---- */
.table-wrap {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--bg-surface);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
thead {
    background: var(--bg-elevated);
}
th {
    text-align: left;
    padding: 12px 16px;
    color: var(--text-muted);
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    white-space: nowrap;
}
td {
    padding: 10px 16px;
    border-top: 1px solid var(--border);
    white-space: nowrap;
}
tr:hover td {
    background: var(--bg-hover);
}

.session-id {
    font-family: var(--font-mono);
    font-size: 0.85rem;
    color: var(--accent);
    background: rgba(108, 138, 255, 0.1);
    padding: 2px 6px;
    border-radius: var(--radius-sm);
}

.snippet-cell {
    white-space: normal;
    max-width: 260px;
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 8px 18px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-elevated);
    color: var(--text);
    font-size: 0.9rem;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}
.btn:hover {
    background: var(--bg-hover);
    border-color: var(--text-dim);
}
.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}
.btn-primary:hover {
    background: var(--accent-hover);
    border-color: var(--accent-hover);
}
.btn-small {
    padding: 4px 12px;
    font-size: 0.8rem;
}
.btn-block {
    width: 100%;
}

/* ---- Pagination ---- */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    margin-top: 20px;
    padding-top: 16px;
}
.page-info {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* ---- Filter bar ---- */
.filter-bar {
    margin-bottom: 24px;
}
.filter-row {
    display: flex;
    gap: 20px;
    align-items: flex-end;
    flex-wrap: wrap;
}
.filter-left {
    flex: 1;
    min-width: 260px;
}
.filter-right {
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
}
.filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.filter-label {
    font-size: 0.75rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}
.filter-summary {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 14px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}
.result-count {
    color: var(--text-muted);
    font-size: 0.85rem;
}

/* Search input */
.search-group {
    display: flex;
    gap: 8px;
}
.search-input {
    flex: 1;
    padding: 8px 14px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.15s;
}
.search-input:focus {
    border-color: var(--accent);
}
.search-input::placeholder {
    color: var(--text-dim);
}

/* Period buttons (segmented control) */
.period-buttons {
    display: flex;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.period-btn {
    padding: 7px 14px;
    font-size: 0.82rem;
    font-weight: 500;
    background: var(--bg-surface);
    color: var(--text-muted);
    border: none;
    border-right: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
    font-family: var(--font);
}
.period-btn:last-child {
    border-right: none;
}
.period-btn:hover {
    background: var(--bg-hover);
    color: var(--text);
}
.period-btn.active {
    background: var(--accent);
    color: #fff;
}

/* Tag multiselect dropdown */
.tag-select {
    position: relative;
    min-width: 180px;
}
.tag-select-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 7px 12px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text-muted);
    transition: border-color 0.15s;
    gap: 8px;
}
.tag-select-trigger:hover {
    border-color: var(--text-dim);
}
.tag-select.open .tag-select-trigger {
    border-color: var(--accent);
}
.tag-select-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 160px;
}
.tag-select-arrow {
    font-size: 0.7rem;
    color: var(--text-dim);
    transition: transform 0.15s;
}
.tag-select.open .tag-select-arrow {
    transform: rotate(180deg);
}
.tag-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 50;
    max-height: 240px;
    overflow-y: auto;
    padding: 4px 0;
}
.tag-select.open .tag-dropdown {
    display: block;
}
.tag-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--text);
    transition: background 0.1s;
}
.tag-option:hover {
    background: var(--bg-hover);
}
.tag-option input[type="checkbox"] {
    display: none;
}
.tag-option-check {
    width: 16px;
    height: 16px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: var(--bg-surface);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.1s, border-color 0.1s;
}
.tag-option input[type="checkbox"]:checked + .tag-option-check {
    background: var(--accent);
    border-color: var(--accent);
}
.tag-option input[type="checkbox"]:checked + .tag-option-check::after {
    content: "✓";
    color: #fff;
    font-size: 0.7rem;
    font-weight: 700;
}

/* ---- Login ---- */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: var(--bg);
}
.login-card {
    width: 100%;
    max-width: 380px;
    padding: 40px 32px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: 12px;
}
.login-header {
    text-align: center;
    margin-bottom: 28px;
}
.login-icon {
    font-size: 2.2rem;
    display: block;
    margin-bottom: 8px;
}
.login-header h1 {
    font-size: 1.3rem;
    font-weight: 700;
}

.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.85rem;
    color: var(--text-muted);
    font-weight: 500;
}
.form-group input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.15s;
}
.form-group input:focus {
    border-color: var(--accent);
}

.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 18px;
    font-size: 0.9rem;
}
.alert-error {
    background: rgba(255, 107, 107, 0.1);
    border: 1px solid rgba(255, 107, 107, 0.25);
    color: var(--danger);
}

/* ---- Transcript ---- */
.session-meta {
    display: flex;
    gap: 20px;
    flex-wrap: wrap;
    color: var(--text-muted);
    font-size: 0.85rem;
}

.transcript {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.turn {
    padding: 14px 18px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    transition: border-color 0.15s;
}
.turn:hover {
    border-color: var(--text-dim);
}
.turn-user    { border-left: 3px solid var(--badge-user); }
.turn-assistant { border-left: 3px solid var(--badge-assistant); }
.turn-system  { border-left: 3px solid var(--badge-system); }
.turn-tool    { border-left: 3px solid var(--badge-tool); }

.turn-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}
.turn-time {
    color: var(--text-dim);
    font-size: 0.8rem;
}
.turn-body {
    font-size: 0.92rem;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ---- Badges ---- */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
}
.badge-user       { background: rgba(59, 130, 246, 0.15); color: var(--badge-user); }
.badge-assistant  { background: rgba(139, 92, 246, 0.15); color: var(--badge-assistant); }
.badge-system     { background: rgba(107, 114, 128, 0.15); color: var(--badge-system); }
.badge-tool       { background: rgba(245, 158, 11, 0.15); color: var(--badge-tool); }
.badge-default    { background: rgba(107, 114, 128, 0.15); color: var(--badge-system); }

/* ---- Tags ---- */
.tags-cell {
    white-space: normal;
    max-width: 300px;
}
.tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 0.72rem;
    font-weight: 500;
    background: rgba(107, 114, 128, 0.15);
    color: var(--text-muted);
    text-decoration: none;
    margin: 1px 2px;
    transition: background 0.15s;
}
a.tag:hover {
    background: rgba(107, 114, 128, 0.3);
    color: var(--text);
}
.tag-frustration-low {
    background: rgba(251, 191, 36, 0.15);
    color: #fbbf24;
}
.tag-frustration-medium {
    background: rgba(251, 146, 60, 0.2);
    color: #fb923c;
}
.tag-frustration-high {
    background: rgba(255, 107, 107, 0.2);
    color: var(--danger);
    font-weight: 700;
}
.session-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 8px;
}

/* ---- Empty state ---- */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state p:first-child {
    font-size: 1.1rem;
    margin-bottom: 8px;
}
.text-muted {
    color: var(--text-dim);
}

/* ---- Test Call ---- */
.test-call-card {
    max-width: 520px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 28px;
}
.test-call-actions {
    display: flex;
    gap: 12px;
    margin: 20px 0;
}
.test-call-status {
    padding: 14px 16px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-muted);
    font-size: 0.9rem;
    min-height: 48px;
}
.btn-danger {
    background: transparent;
    border-color: rgba(255, 107, 107, 0.35);
    color: var(--danger);
}
.btn-danger:hover {
    background: rgba(255, 107, 107, 0.1);
    border-color: var(--danger);
}
.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

/* ---- Tabs ---- */
.test-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 24px;
    border-bottom: 1px solid var(--border);
}
.tab-btn {
    padding: 10px 24px;
    font-size: 0.9rem;
    font-weight: 500;
    font-family: var(--font);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    color: var(--text-muted);
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
}
.tab-btn:hover {
    color: var(--text);
}
.tab-btn.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}
.tab-panel {
    display: none;
}
.tab-panel.active {
    display: block;
}

/* ---- Chat ---- */
.chat-card {
    max-width: 640px;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    display: flex;
    flex-direction: column;
}
.chat-messages {
    min-height: 320px;
    max-height: 480px;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.chat-empty {
    color: var(--text-dim);
    text-align: center;
    margin: auto;
    font-size: 0.9rem;
}
.chat-msg {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-width: 85%;
}
.chat-msg-user {
    align-self: flex-end;
}
.chat-msg-assistant {
    align-self: flex-start;
}
.chat-msg-role {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-dim);
}
.chat-msg-user .chat-msg-role {
    text-align: right;
}
.chat-msg-text {
    display: block;
    padding: 10px 14px;
    border-radius: var(--radius);
    font-size: 0.9rem;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}
.chat-msg-user .chat-msg-text {
    background: var(--accent);
    color: #fff;
    border-bottom-right-radius: var(--radius-sm);
}
.chat-msg-assistant .chat-msg-text {
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    color: var(--text);
    border-bottom-left-radius: var(--radius-sm);
}
.chat-input-form {
    display: flex;
    gap: 8px;
    padding: 12px 20px;
    border-top: 1px solid var(--border);
}
.chat-input {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-elevated);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 0.9rem;
    font-family: var(--font);
    outline: none;
    transition: border-color 0.15s;
}
.chat-input:focus {
    border-color: var(--accent);
}
.chat-input::placeholder {
    color: var(--text-dim);
}
.chat-input:disabled {
    opacity: 0.5;
}
.chat-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 20px 12px;
    font-size: 0.8rem;
}

/* Typing dots animation */
.typing-dots span {
    animation: blink 1.4s infinite both;
    font-weight: 700;
    font-size: 1.2rem;
    line-height: 1;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes blink {
    0%, 80%, 100% { opacity: 0.2; }
    40% { opacity: 1; }
}

/* ---- Responsive ---- */
@media (max-width: 640px) {
    .container { padding: 16px 12px; }
    .navbar { padding: 0 12px; }
    .page-header { flex-direction: column; gap: 4px; }
    .session-meta { flex-direction: column; gap: 4px; }
    .filter-row { flex-direction: column; }
    .filter-left { min-width: unset; }
    .filter-right { flex-direction: column; width: 100%; }
    .tag-select { width: 100%; }
}
