/* ============================================
   The Journey Books — Dashboard Styles
   Premium dark theme with glassmorphism
   ============================================ */

:root {
    --bg-primary: #0a0e17;
    --bg-secondary: #111827;
    --bg-card: rgba(17, 24, 39, 0.8);
    --bg-glass: rgba(255, 255, 255, 0.05);
    --border: rgba(255, 255, 255, 0.08);
    --text-primary: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --success: #22c55e;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    --radius: 12px;
    --radius-sm: 8px;
}

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

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100vh;
    line-height: 1.6;
}

/* ── Header ── */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 2rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-brand {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.header-brand .logo {
    font-size: 1.5rem;
}

.header-brand h1 {
    font-size: 1.1rem;
    font-weight: 600;
    letter-spacing: -0.02em;
}

.badge {
    background: var(--accent);
    color: white;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.7rem;
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.header-indicators {
    display: flex;
    gap: 1.5rem;
}

.header-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--warning);
    animation: pulse 2s infinite;
    flex-shrink: 0;
}

.status-dot.connected {
    background: var(--success);
}

.status-dot.error {
    background: var(--danger);
}

@keyframes pulse {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.4;
    }
}

/* ── Navigation ── */
.nav {
    display: flex;
    gap: 0.5rem;
    padding: 1rem 2rem;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.nav-btn {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid transparent;
    padding: 0.5rem 1.2rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.85rem;
    font-family: inherit;
    transition: all 0.2s ease;
}

.nav-btn:hover {
    background: var(--bg-glass);
    color: var(--text-primary);
}

.nav-btn.active {
    background: var(--accent);
    color: white;
    border-color: transparent;
}

/* ── Main Content ── */
.main {
    padding: 1.5rem 2rem;
    max-width: 1400px;
    margin: 0 auto;
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
}

.section-header h2 {
    font-size: 1.3rem;
    font-weight: 600;
}

.filters {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.search-input {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.82rem;
    width: 200px;
    transition: border-color 0.2s;
}

.search-input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

/* ── Stats Row ── */
.stats-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    transition: all 0.2s ease;
}

.stat-card:hover {
    border-color: rgba(99, 102, 241, 0.2);
    transform: translateY(-1px);
}

.stat-icon {
    font-size: 1.5rem;
}

.stat-info {
    display: flex;
    flex-direction: column;
}

.stat-number {
    font-size: 1.6rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-label {
    font-size: 0.72rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.stat-breakdown {
    grid-column: span 1;
}

.stat-breakdown-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.stat-breakdown-grid .breakdown-item {
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    background: var(--bg-glass);
    color: var(--text-secondary);
    white-space: nowrap;
}

/* ── Table ── */
.table-wrap {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th {
    background: rgba(255, 255, 255, 0.03);
    text-align: left;
    padding: 0.75rem 1rem;
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

td {
    padding: 0.65rem 1rem;
    font-size: 0.82rem;
    border-bottom: 1px solid var(--border);
    color: var(--text-secondary);
}

tr:last-child td {
    border-bottom: none;
}

tr:hover td {
    background: rgba(255, 255, 255, 0.02);
}

tr.clickable {
    cursor: pointer;
}

tr.clickable:hover td {
    background: rgba(99, 102, 241, 0.05);
}

/* ── Status Badges ── */
.status-pill {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    border-radius: 20px;
    font-size: 0.72rem;
    font-weight: 500;
}

.status-pill.new {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
}

.status-pill.info-sent {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
}

.status-pill.active {
    background: rgba(249, 115, 22, 0.15);
    color: #f97316;
}

.status-pill.handed-off {
    background: rgba(59, 130, 246, 0.15);
    color: var(--info);
}

.status-pill.booking {
    background: rgba(168, 85, 247, 0.15);
    color: #a855f7;
}

.status-pill.booked {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
}

.status-pill.dead {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

/* ── Buttons ── */
.btn {
    background: var(--bg-glass);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 0.5rem 1rem;
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 0.82rem;
    font-family: inherit;
    transition: all 0.2s ease;
}

.btn:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.15);
}

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

.btn-sm {
    padding: 0.35rem 0.7rem;
    font-size: 0.75rem;
}

.btn-primary {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

.btn-primary:hover {
    background: #5558e6;
    box-shadow: 0 0 20px var(--accent-glow);
}

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

.btn-danger:hover {
    background: rgba(239, 68, 68, 0.25);
}

.btn-warning {
    background: rgba(245, 158, 11, 0.15);
    color: var(--warning);
    border-color: rgba(245, 158, 11, 0.3);
}

.btn-warning:hover {
    background: rgba(245, 158, 11, 0.25);
}

.action-btns {
    display: flex;
    gap: 0.3rem;
}

/* ── Trips Grid ── */
.trips-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}

.trip-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    transition: all 0.2s ease;
    position: relative;
}

.trip-card:hover {
    border-color: rgba(99, 102, 241, 0.3);
    transform: translateY(-2px);
}

.trip-card.inactive {
    opacity: 0.5;
}

.trip-card h3 {
    font-size: 1rem;
    margin-bottom: 0.5rem;
}

.trip-card .trip-meta {
    display: flex;
    gap: 1rem;
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-bottom: 0.75rem;
}

.trip-card .trip-price {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--success);
    margin-bottom: 0.75rem;
}

.trip-card .trip-actions {
    display: flex;
    gap: 0.4rem;
}

.trip-badge {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    font-size: 0.65rem;
    padding: 0.15rem 0.5rem;
    border-radius: 10px;
    font-weight: 500;
}

.trip-badge.active-badge {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
}

.trip-badge.inactive-badge {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
}

/* ── Settings Form ── */
.settings-form,
.bot-panel {
    max-width: 600px;
}

.settings-group {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.settings-group h3 {
    font-size: 0.9rem;
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.form-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0;
}

.form-row.full-width {
    flex-direction: column;
    align-items: stretch;
    gap: 0.3rem;
}

.form-row label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.form-row input,
.form-row select,
.form-row textarea {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.85rem;
    width: 180px;
}

.form-row.full-width input,
.form-row.full-width textarea {
    width: 100%;
}

.form-row textarea {
    resize: vertical;
}

.form-row input:focus,
.form-row select:focus,
.form-row textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

select {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 0.4rem 0.75rem;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 0.82rem;
}

/* ── Bot Panel ── */
.bot-status-card {
    padding: 1rem;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
}

.bot-status-indicator {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.bot-status-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: var(--warning);
    animation: pulse 2s infinite;
}

.bot-status-dot.connected {
    background: var(--success);
}

.bot-status-dot.error {
    background: var(--danger);
}

.bot-status-label {
    font-size: 1rem;
    font-weight: 600;
}

.bot-detail-row {
    display: flex;
    justify-content: space-between;
    padding: 0.3rem 0;
    font-size: 0.85rem;
}

.bot-detail-key {
    color: var(--text-muted);
}

.bot-detail-val {
    color: var(--text-primary);
    font-weight: 500;
}

.bot-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
}

.diag-result {
    margin-top: 1rem;
    padding: 0.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    display: none;
}

.diag-result.passed {
    background: rgba(34, 197, 94, 0.1);
    color: var(--success);
    border: 1px solid rgba(34, 197, 94, 0.2);
    display: block;
}

.diag-result.failed {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
    display: block;
}

/* ── Lead Detail Panel ── */
.panel-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 200;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.panel-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.lead-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 480px;
    max-width: 90vw;
    height: 100vh;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border);
    z-index: 201;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.lead-panel.open {
    transform: translateX(0);
}

.panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.panel-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.panel-close {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: all 0.2s;
}

.panel-close:hover {
    background: var(--bg-glass);
    color: var(--text-primary);
}

.panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 1.25rem 1.5rem;
}

.panel-section {
    margin-bottom: 1.5rem;
}

.panel-section h4 {
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid var(--border);
}

.panel-field {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.4rem 0;
    font-size: 0.85rem;
}

.panel-field label {
    color: var(--text-muted);
    font-size: 0.78rem;
    min-width: 100px;
}

.panel-field span {
    color: var(--text-primary);
    font-weight: 500;
    text-align: right;
}

.panel-field.editable input,
.panel-field.editable select {
    background: var(--bg-primary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 0.3rem 0.6rem;
    border-radius: 6px;
    font-size: 0.82rem;
    font-family: inherit;
    width: 180px;
    text-align: right;
}

.panel-field.editable input:focus,
.panel-field.editable select:focus {
    outline: none;
    border-color: var(--accent);
}

.panel-actions {
    display: flex;
    gap: 0.4rem;
    margin-top: 1rem;
    flex-wrap: wrap;
}

/* ── Chat Container ── */
.chat-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    max-height: 400px;
    overflow-y: auto;
    padding: 0.5rem;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
}

.chat-loading {
    text-align: center;
    color: var(--text-muted);
    padding: 2rem;
    font-size: 0.85rem;
}

.chat-bubble {
    max-width: 80%;
    padding: 0.6rem 0.9rem;
    border-radius: 12px;
    font-size: 0.82rem;
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-bubble.inbound {
    background: var(--bg-glass);
    border: 1px solid var(--border);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.chat-bubble.outbound {
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.2);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.chat-time {
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

.chat-bubble.inbound .chat-time {
    text-align: left;
}

.chat-bubble.outbound .chat-time {
    text-align: right;
}

/* ── Modal ── */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    z-index: 300;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s ease;
}

.modal-backdrop.open {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) scale(0.95);
    width: 520px;
    max-width: 90vw;
    max-height: 85vh;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    z-index: 301;
    opacity: 0;
    pointer-events: none;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
}

.modal.open {
    opacity: 1;
    pointer-events: auto;
    transform: translate(-50%, -50%) scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    border-bottom: 1px solid var(--border);
}

.modal-body {
    padding: 1.25rem 1.5rem;
    overflow-y: auto;
    flex: 1;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding-top: 1rem;
    margin-top: 0.5rem;
    border-top: 1px solid var(--border);
}

/* ── Toast ── */
.toast {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    z-index: 999;
    animation: slideUp 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
    max-width: 350px;
}

.toast.success {
    background: rgba(34, 197, 94, 0.15);
    color: var(--success);
    border: 1px solid rgba(34, 197, 94, 0.3);
}

.toast.error {
    background: rgba(239, 68, 68, 0.15);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.3);
}

@keyframes slideUp {
    from {
        transform: translateY(20px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

@keyframes fadeOut {
    to {
        opacity: 0;
        transform: translateY(-10px);
    }
}

/* ── Responsive ── */
@media (max-width: 768px) {
    .header {
        padding: 0.75rem 1rem;
        flex-direction: column;
        gap: 0.5rem;
    }

    .header-indicators {
        gap: 1rem;
    }

    .nav {
        padding: 0.75rem 1rem;
        overflow-x: auto;
    }

    .main {
        padding: 1rem;
    }

    .section-header {
        flex-direction: column;
        gap: 0.75rem;
        align-items: flex-start;
    }

    .filters {
        flex-wrap: wrap;
    }

    .search-input {
        width: 100%;
    }

    .stats-row {
        grid-template-columns: repeat(2, 1fr);
    }

    .table-wrap {
        overflow-x: auto;
    }

    .form-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.3rem;
    }

    .form-row input,
    .form-row select {
        width: 100%;
    }

    .lead-panel {
        width: 100vw;
    }
}