:root {
    --bg-color: #f1f5f9;
    --sidebar-bg: #0f172a;
    --sidebar-hover: #1e293b;
    --sidebar-text: #94a3b8;
    --sidebar-text-active: #ffffff;
    --card-bg: #ffffff;
    --text-main: #0f172a;
    --text-muted: #64748b;
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --secondary: #e2e8f0;
    --secondary-hover: #cbd5e1;
    --danger: #ef4444;
    --danger-hover: #dc2626;
    --success: #10b981;
    --warning: #f59e0b;
    --border: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-md: 0.5rem;
    --radius-lg: 0.75rem;
    --radius-xl: 1rem;
    --sidebar-width: 260px;
}

[data-theme="dark"] {
    --bg-color: #0f172a;
    --card-bg: #1e293b;
    --text-main: #f8fafc;
    --text-muted: #94a3b8;
    --border: #334155;
    --sidebar-bg: #020617;
    --secondary: #334155;
    --secondary-hover: #475569;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    font-family: 'Inter', sans-serif;
}

body {
    background-color: var(--bg-color);
    color: var(--text-main);
    transition: background-color .3s, color .3s;
    overflow-x: hidden;
}

/* ===================== LOGIN ===================== */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #4f46e5 0%, #3b82f6 100%);
    position: relative;
    overflow: hidden;
}

.login-container::before {
    content: '';
    position: absolute;
    width: 200%;
    height: 200%;
    background: radial-gradient(circle, rgba(255, 255, 255, 0.1) 0%, transparent 60%);
    top: -50%;
    left: -50%;
    animation: pulseBg 10s infinite alternate;
}

@keyframes pulseBg {
    0% {
        transform: scale(1);
    }

    100% {
        transform: scale(1.1);
    }
}

.login-card {
    background: var(--card-bg);
    padding: 2.5rem;
    border-radius: var(--radius-xl);
    width: 100%;
    max-width: 400px;
    box-shadow: var(--shadow-lg);
    text-align: center;
    z-index: 1;
    animation: slideUp .5s ease-out;
}

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

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

.login-logo {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .75rem;
    margin-bottom: 0.5rem;
}

.login-logo .logo-icon {
    background: linear-gradient(135deg, #4f46e5, #3b82f6);
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
}

.login-logo h1 {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text-main);
}

.login-card>p {
    color: var(--text-muted);
    margin-bottom: 1.5rem;
    font-size: .85rem;
}

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

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    padding: 1.25rem 0.875rem;
    position: fixed;
    height: 100vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-md);
    z-index: 200;
    transition: transform .3s ease;
}

.logo {
    font-size: 1.1rem;
    font-weight: 800;
    color: white;
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: 0.5rem .75rem;
    margin-bottom: 1.5rem;
}

.logo-icon {
    background: linear-gradient(135deg, #4f46e5, #3b82f6);
    width: 34px;
    height: 34px;
    border-radius: var(--radius-md);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .75rem 1rem;
    border-radius: var(--radius-md);
    margin-bottom: .2rem;
    cursor: pointer;
    color: var(--sidebar-text);
    font-weight: 500;
    font-size: .9rem;
    transition: all .2s ease;
}

.nav-item:hover {
    background: var(--sidebar-hover);
    color: var(--sidebar-text-active);
    transform: translateX(3px);
}

.nav-item.active {
    background: linear-gradient(90deg, rgba(79, 70, 229, .25) 0%, transparent 100%);
    color: var(--primary);
    border-left: 3px solid var(--primary);
}

.nav-icon {
    font-size: 1rem;
    opacity: .8;
}

.nav-item.active .nav-icon {
    opacity: 1;
}

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, .5);
    z-index: 190;
}

/* hamburger */
.hamburger {
    display: none;
    position: fixed;
    top: 1rem;
    left: 1rem;
    z-index: 300;
    background: var(--sidebar-bg);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: var(--radius-md);
    font-size: 1.2rem;
    cursor: pointer;
    align-items: center;
    justify-content: center;
}

/* ===================== MAIN ===================== */
.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    padding: 2rem 2.5rem;
    max-width: none;
    width: auto;
}

.tab-content {
    display: none;
    animation: fadeIn .3s ease-out forwards;
}

.tab-content.active {
    display: block;
}

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

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

/* ===================== CARDS ===================== */
.card {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 2rem;
    margin-bottom: 1.5rem;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border);
    transition: box-shadow .3s;
}

.card:hover {
    box-shadow: var(--shadow-md);
}

.card-header {
    margin-bottom: 1.5rem;
}

.card-header h2 {
    font-size: 1.4rem;
    color: var(--text-main);
    margin-bottom: .4rem;
}

.card-header p {
    color: var(--text-muted);
    font-size: .9rem;
}

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1.5rem;
}

/* ===================== AGENT CARD ===================== */
.assistant-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    transition: all .2s ease;
    position: relative;
    overflow: hidden;
    cursor: pointer;
}

.assistant-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, #4f46e5, #3b82f6);
    opacity: 0;
    transition: opacity .2s;
}

.assistant-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-md);
}

.assistant-card:hover::before {
    opacity: 1;
}

.assistant-card h3 {
    font-size: 1.1rem;
    color: var(--text-main);
    display: flex;
    align-items: center;
    gap: .5rem;
}

.assistant-meta {
    font-size: .8rem;
    color: var(--text-muted);
    background: var(--bg-color);
    padding: .35rem .6rem;
    border-radius: 999px;
    display: inline-block;
}

.card-meta-row {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}

.card-prompt-preview {
    font-size: .8rem;
    color: var(--text-muted);
    background: var(--bg-color);
    padding: .75rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    line-height: 1.5;
    max-height: 70px;
    overflow: hidden;
    position: relative;
}

.card-prompt-preview::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    height: 24px;
    background: linear-gradient(transparent, var(--bg-color));
}

.flex-actions {
    display: flex;
    gap: .4rem;
    flex-wrap: wrap;
    margin-top: auto;
}

/* ===================== FORMS ===================== */
.form-group {
    margin-bottom: 1.1rem;
    text-align: left;
}

label {
    display: block;
    font-size: .85rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: .4rem;
}

input,
select,
textarea {
    width: 100%;
    padding: .7rem 1rem;
    background: var(--bg-color);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    font-size: .9rem;
    color: var(--text-main);
    transition: all .2s ease;
    appearance: none;
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79, 70, 229, .1);
    background: var(--card-bg);
}

textarea {
    resize: vertical;
    min-height: 120px;
    line-height: 1.5;
}

/* ===================== BUTTONS ===================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: .5rem;
    padding: .7rem 1.25rem;
    border-radius: var(--radius-md);
    border: none;
    font-weight: 600;
    font-size: .875rem;
    cursor: pointer;
    transition: all .2s ease;
}

.btn:active {
    transform: scale(.98);
}

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

.btn-primary:hover {
    background: var(--primary-hover);
    box-shadow: 0 4px 12px rgba(79, 70, 229, .25);
}

.btn-secondary {
    background: var(--secondary);
    color: var(--text-main);
}

.btn-secondary:hover {
    background: var(--secondary-hover);
}

.btn-danger {
    background: var(--danger);
    color: white;
}

.btn-danger:hover {
    background: var(--danger-hover);
    box-shadow: 0 4px 12px rgba(239, 68, 68, .2);
}

.btn-success {
    background: var(--success);
    color: white;
}

.btn-small {
    padding: .4rem .7rem;
    font-size: .8rem;
}

/* ===================== TABLES ===================== */
.table-container {
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    background: var(--card-bg);
}

table {
    width: 100%;
    border-collapse: collapse;
    text-align: left;
    min-width: 600px;
}

th {
    background: var(--bg-color);
    padding: .875rem 1rem;
    font-size: .8rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: .05em;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

td {
    padding: .875rem 1rem;
    font-size: .875rem;
    color: var(--text-main);
    border-bottom: 1px solid var(--border);
}

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

tr:hover td {
    background: var(--bg-color);
}

.status-badge {
    display: inline-block;
    padding: .25rem .75rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 600;
}

.play-link {
    display: inline-flex;
    align-items: center;
    gap: .25rem;
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.play-link:hover {
    text-decoration: underline;
}

/* ===================== CHAT ===================== */
.chat-messages {
    height: 380px;
    overflow-y: auto;
    background: var(--bg-color);
    padding: 1.25rem;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: .75rem;
}

.msg-bubble {
    max-width: 85%;
    padding: .8rem 1.1rem;
    border-radius: 1.25rem;
    font-size: .925rem;
    line-height: 1.6;
    word-break: break-word;
    overflow-wrap: break-word;
    position: relative;
}

.msg-user {
    align-self: flex-end;
    background: var(--primary);
    color: white;
    border-bottom-right-radius: .25rem;
}

.msg-agent {
    align-self: flex-start;
    background: var(--card-bg);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-bottom-left-radius: .25rem;
}

/* Markdown Styles in Chat */
.msg-bubble p {
    margin-bottom: 0.75rem;
}

.msg-bubble p:last-child {
    margin-bottom: 0;
}

.msg-bubble ul,
.msg-bubble ol {
    margin-bottom: 0.75rem;
    padding-left: 1.5rem;
}

.msg-bubble ul ul,
.msg-bubble ol ol,
.msg-bubble ul ol,
.msg-bubble ol ul {
    margin-bottom: 0;
    margin-top: 0.25rem;
}

.msg-bubble li {
    margin-bottom: 0.35rem;
}

.msg-bubble h1,
.msg-bubble h2,
.msg-bubble h3 {
    margin: 0.75rem 0 0.5rem 0;
    font-size: 1.1rem;
}

.chat-input-area {
    display: flex;
    gap: .5rem;
    flex-wrap: wrap;
}

.chat-input-area input {
    flex: 1;
    min-width: 120px;
}

/* ===================== MODAL ===================== */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, .55);
    backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    transition: opacity .2s;
}

.modal.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: var(--card-bg);
    border-radius: var(--radius-xl);
    padding: 2rem;
    width: 90%;
    max-width: 600px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
    transform: scale(.95);
    transition: transform .2s;
}

.modal.active .modal-content {
    transform: scale(1);
}

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

.modal-header h3 {
    font-size: 1.2rem;
    color: var(--text-main);
    font-weight: 700;
}

.close-btn {
    background: none;
    border: none;
    font-size: 1.4rem;
    color: var(--text-muted);
    cursor: pointer;
    line-height: 1;
    padding: .25rem;
}

.close-btn:hover {
    color: var(--text-main);
}

.kb-list {
    list-style: none;
    margin-bottom: 1.25rem;
}

.kb-list li {
    padding: .65rem .875rem;
    background: var(--bg-color);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    margin-bottom: .4rem;
    display: flex;
    align-items: center;
    gap: .5rem;
    color: var(--text-main);
    font-size: .875rem;
}

/* ===================== SETTINGS CARDS ===================== */
.settings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1.25rem;
}

.settings-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.5rem;
}

.settings-card-title {
    font-weight: 700;
    font-size: .95rem;
    color: var(--text-main);
    margin-bottom: .25rem;
}

.settings-card-desc {
    font-size: .8rem;
    color: var(--text-muted);
    margin-bottom: 1rem;
}

.balance-display {
    font-size: 2rem;
    font-weight: 800;
    color: var(--primary);
    margin: .5rem 0;
}

/* ===================== THEME TOGGLE ===================== */
.theme-toggle {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    background: var(--card-bg);
    color: var(--text-main);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-md);
    border-radius: 50%;
    width: 46px;
    height: 46px;
    font-size: 1.1rem;
    cursor: pointer;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all .2s;
}

.theme-toggle:hover {
    transform: scale(1.1);
}

hr {
    margin: 1.25rem 0;
    border: none;
    border-top: 1px solid var(--border);
}

/* ===================== RESPONSIVE ===================== */
@media (max-width: 900px) {
    :root {
        --sidebar-width: 240px;
    }

    .main-content {
        padding: 1.5rem;
    }
}

@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: none;
    }

    .sidebar.open {
        transform: translateX(0);
        box-shadow: var(--shadow-lg);
    }

    .sidebar-overlay.active {
        display: block;
    }

    .hamburger {
        display: flex;
    }

    .main-content {
        margin-left: 0;
        padding: 1rem;
        padding-top: 4rem;
    }

    .grid {
        grid-template-columns: 1fr;
    }

    .settings-grid {
        grid-template-columns: 1fr;
    }

    table {
        min-width: 480px;
    }

    .chat-input-area .btn {
        flex: none;
    }

    .modal-content {
        padding: 1.25rem;
        width: 95%;
    }

    .card {
        padding: 1.25rem;
    }
}

@media (max-width: 480px) {
    .login-card {
        padding: 1.75rem 1.25rem;
        margin: 1rem;
    }

    .flex-actions {
        gap: .3rem;
    }

    .btn-small {
        padding: .35rem .6rem;
        font-size: .75rem;
    }

    th,
    td {
        padding: .65rem .75rem;
    }
}/* ===================== TRANSCRIPT ===================== */
.transcript-btn {
    padding: .35rem .6rem;
    font-size: .75rem;
    background: rgba(79, 70, 229, 0.1);
    color: var(--primary);
    border: 1px solid rgba(79, 70, 229, 0.2);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-weight: 600;
    transition: all .2s;
}

.transcript-btn:hover {
    background: var(--primary);
    color: white;
}

.transcript-box {
    max-height: 500px;
    overflow-y: auto;
    padding: 1.5rem;
    background: var(--bg-color);
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.trn-row {
    display: flex;
    width: 100%;
}

.trn-row-user { justify-content: flex-end; }
.trn-row-ai { justify-content: flex-start; }

.trn-msg {
    max-width: 80%;
    padding: .8rem 1.1rem;
    border-radius: 1.25rem;
    font-size: .9rem;
    line-height: 1.5;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.trn-ai {
    background: var(--card-bg);
    color: var(--text-main);
    border: 1px solid var(--border);
    border-bottom-left-radius: .25rem;
}

.trn-user {
    background: var(--primary);
    color: white;
    border-bottom-right-radius: .25rem;
}

.trn-label {
    font-size: .7rem;
    font-weight: 700;
    margin-bottom: .25rem;
    display: block;
    opacity: .7;
    text-transform: uppercase;
}

/* Audio container improvements */
.audio-card {
    background: var(--bg-color);
    padding: .75rem;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    gap: .5rem;
    box-shadow: inset 0 2px 4px rgba(0,0,0,0.02);
}
