/* =====================================================
   GLOBAL STYLES & VARIABLES
   ===================================================== */

:root {
    --bg-primary: #1a1a2e;
    --bg-secondary: #16213e;
    --bg-tertiary: #0f3460;
    --bg-card: #1f2937;
    --text-primary: #e5e7eb;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --accent-cyan: #00d4ff;
    --accent-green: #10b981;
    --accent-red: #ef4444;
    --border-color: #374151;
    --hover-bg: #374151;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: linear-gradient(135deg, var(--bg-primary) 0%, var(--bg-secondary) 100%);
    color: var(--text-primary);
    min-height: 100vh;
}

/* =====================================================
   APP CONTAINER & TABS
   ===================================================== */

.app-container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
}

.tab-nav {
    display: flex;
    gap: 8px;
    margin-bottom: 20px;
    background: var(--bg-card);
    padding: 10px;
    border-radius: 12px;
}

.tab-btn {
    padding: 12px 24px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 15px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    transition: all 0.2s ease;
}

.tab-btn:hover {
    background: var(--hover-bg);
    color: var(--text-primary);
}

.tab-btn.active {
    background: var(--bg-tertiary);
    color: var(--accent-cyan);
}

.tab-panel {
    display: none;
}

.tab-panel.active {
    display: block;
}

/* =====================================================
   PANEL LAYOUT (Sidebar + Main)
   ===================================================== */

.panel-layout {
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 20px;
    height: calc(100vh - 140px);
}

.sidebar {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.sidebar h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 15px;
    color: var(--text-primary);
}

.main-content {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.content-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
}

.content-header h2 {
    font-size: 20px;
    font-weight: 600;
}

/* =====================================================
   INPUTS & BUTTONS
   ===================================================== */

.search-input,
.text-input,
.select-input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}

.search-input:focus,
.text-input:focus,
.select-input:focus {
    border-color: var(--accent-cyan);
}

.search-input {
    margin-bottom: 15px;
}

.select-input {
    appearance: none;
    cursor: pointer;
}

.select-small {
    width: auto;
    min-width: 130px;
}

.text-wide {
    flex: 1;
}

.btn {
    padding: 10px 18px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.btn:hover:not(:disabled) {
    opacity: 0.9;
    transform: translateY(-1px);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-success {
    background: var(--accent-green);
    color: white;
}

.btn-danger {
    background: var(--accent-red);
    color: white;
}

.btn-small {
    padding: 8px 12px;
    font-size: 13px;
}

.btn-full {
    width: 100%;
    margin-bottom: 15px;
}

.btn-row {
    display: flex;
    gap: 8px;
    margin-bottom: 15px;
}

/* =====================================================
   ITEM LISTS
   ===================================================== */

.item-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.item-btn {
    width: 100%;
    padding: 10px 14px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-primary);
    font-size: 14px;
    text-align: left;
    cursor: pointer;
    transition: background 0.2s;
}

.item-btn:hover {
    background: var(--hover-bg);
}

.item-btn.active {
    background: var(--bg-tertiary);
    color: var(--accent-cyan);
}

/* =====================================================
   FACTS CONTAINER (Memory Bank)
   ===================================================== */

.facts-container {
    flex: 1;
    overflow-y: auto;
    padding-right: 10px;
}

.fact-group {
    margin-bottom: 20px;
}

.fact-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.fact-key {
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-cyan);
    text-transform: capitalize;
}

.fact-values {
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 10px;
}

.fact-row {
    display: flex;
    align-items: center;
    padding: 8px 10px;
    border-radius: 6px;
    transition: background 0.2s;
}

.fact-row:hover {
    background: var(--bg-tertiary);
}

.fact-value {
    flex: 1;
    font-size: 14px;
}

.fact-actions {
    display: flex;
    gap: 5px;
    opacity: 0;
    transition: opacity 0.2s;
}

.fact-row:hover .fact-actions {
    opacity: 1;
}

.action-btn {
    padding: 5px 8px;
    background: var(--bg-card);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
    transition: background 0.2s;
}

.action-btn:hover {
    background: var(--hover-bg);
}

.action-btn.edit {
    color: var(--text-secondary);
}

.action-btn.delete {
    color: var(--accent-red);
}

/* =====================================================
   INPUT FOOTER
   ===================================================== */

.input-footer {
    display: flex;
    align-items: center;
    gap: 10px;
    padding-top: 15px;
    border-top: 1px solid var(--border-color);
    margin-top: auto;
}

.input-footer label {
    font-weight: 500;
    color: var(--text-secondary);
}

.status-text {
    padding: 10px 0;
    font-size: 13px;
    color: var(--text-muted);
}

/* =====================================================
   CHAT LOGS
   ===================================================== */

.log-viewer {
    flex: 1;
    overflow-y: auto;
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 15px;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 13px;
    line-height: 1.6;
}

.log-entry {
    margin-bottom: 15px;
    padding-bottom: 15px;
    border-bottom: 1px dashed var(--border-color);
}

.log-entry:last-child {
    border-bottom: none;
}

.log-header {
    color: var(--text-muted);
    margin-bottom: 5px;
}

.log-content {
    white-space: pre-wrap;
    color: var(--text-primary);
}

.log-bot {
    color: var(--accent-cyan);
}

.log-user {
    color: var(--accent-green);
}

/* =====================================================
   TRACKS CONTAINER (Playlists)
   ===================================================== */

.tracks-container {
    flex: 1;
    overflow-y: auto;
    padding-right: 10px;
}

.track-row {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin-bottom: 8px;
    transition: background 0.2s;
}

.track-row:hover {
    background: var(--bg-tertiary);
}

.track-index {
    width: 30px;
    font-size: 13px;
    color: var(--text-muted);
    text-align: right;
    margin-right: 10px;
}

.track-type {
    width: 25px;
    font-size: 16px;
    margin-right: 10px;
}

.track-info {
    flex: 1;
    overflow: hidden;
}

.track-title {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.track-author {
    font-size: 12px;
    color: var(--text-muted);
}

.track-actions {
    display: flex;
    gap: 5px;
}

/* =====================================================
   API DEBUGGER
   ===================================================== */

#api.tab-panel {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 20px;
    height: calc(100vh - 140px);
    display: none;
    flex-direction: column;
}

#api.tab-panel.active {
    display: flex;
}

.api-split {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    flex: 1;
    overflow: hidden;
}

.api-column {
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.api-column h3 {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 10px;
    color: var(--text-secondary);
}

.code-block {
    flex: 1;
    background: var(--bg-secondary);
    border-radius: 8px;
    padding: 15px;
    overflow: auto;
    font-family: 'Consolas', 'Monaco', monospace;
    font-size: 12px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-break: break-word;
}

/* =====================================================
   MODALS
   ===================================================== */

.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 25px;
    min-width: 500px;
    max-width: 700px;
    max-height: 80vh;
    display: flex;
    flex-direction: column;
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

.modal-header h3 {
    font-size: 18px;
    margin: 0;
}

.modal-subtitle {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 15px;
}

.search-results-list {
    max-height: 300px;
    overflow-y: auto;
    margin-bottom: 15px;
}

.search-result-item {
    display: flex;
    align-items: center;
    padding: 12px 15px;
    background: var(--bg-secondary);
    border-radius: 8px;
    margin-bottom: 8px;
    cursor: pointer;
    transition: background 0.2s;
}

.search-result-item:hover {
    background: var(--bg-tertiary);
}

.search-result-item input[type="checkbox"] {
    width: 18px;
    height: 18px;
    margin-right: 12px;
    cursor: pointer;
}

.search-result-info {
    flex: 1;
}

.search-result-title {
    font-size: 14px;
    font-weight: 500;
}

.search-result-meta {
    font-size: 12px;
    color: var(--text-muted);
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    padding-top: 10px;
    border-top: 1px solid var(--border-color);
}

/* =====================================================
   PLAYLIST FOOTER
   ===================================================== */

.playlist-footer {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
}

.import-row,
.browse-row {
    display: flex;
    align-items: center;
    gap: 10px;
}

.import-row label,
.browse-row label {
    min-width: 60px;
}

.browse-row .status-text {
    flex: 1;
    padding: 0;
}

/* =====================================================
   SCROLLBARS
   ===================================================== */

::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-secondary);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* =====================================================
   EMPTY STATES
   ===================================================== */

.empty-state {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

.empty-state p {
    font-size: 15px;
}
