/* Audible Plex Downloader - UI Styles */

:root {
    --bg: #1a1a2e;
    --surface: #16213e;
    --surface-2: #0f3460;
    --accent: #e94560;
    --accent-hover: #d63851;
    --text: #eee;
    --text-muted: #aaa;
    --success: #4caf50;
    --warning: #ff9800;
    --error: #f44336;
    --info: #2196f3;
    --neutral: #607d8b;
    --border: #2a3a5c;
    --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    display: flex;
    min-height: 100vh;
}

/* Sidebar */
.sidebar {
    width: 220px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0;
    bottom: 0;
}

.sidebar-header {
    position: relative;
    padding: 0.9rem 0.85rem;
    border-bottom: 1px solid var(--border);
    display: grid;
    grid-template-columns: 40px minmax(0, 1fr);
    align-items: center;
    gap: 0.7rem;
    overflow: hidden;
    background: linear-gradient(160deg, rgba(15, 52, 96, 0.55), rgba(22, 33, 62, 0.9));
}

.sidebar-header::before {
    content: "";
    position: absolute;
    width: 110px;
    height: 110px;
    right: -42px;
    top: -46px;
    border-radius: 999px;
    background: radial-gradient(circle, rgba(31, 200, 245, 0.28), rgba(31, 200, 245, 0));
    pointer-events: none;
}

.sidebar-header img.sidebar-logo {
    width: 40px;
    height: 40px;
    object-fit: contain;
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    box-shadow: 0 8px 18px rgba(0, 0, 0, 0.35);
    position: relative;
    z-index: 1;
}

.sidebar-brand {
    min-width: 0;
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.brand-title {
    font-size: 1rem;
    letter-spacing: 0.01em;
    line-height: 1.05;
    color: #f5f8ff;
    font-weight: 800;
    margin: 0;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
    white-space: nowrap;
}

.brand-subtitle {
    margin-top: 0.2rem;
    color: #7cc9ff;
    font-size: 0.56rem;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    opacity: 0.9;
    white-space: nowrap;
}

.nav-links {
    list-style: none;
    padding: 0.5rem 0;
}

.nav-links li a {
    display: block;
    padding: 0.75rem 1.25rem;
    color: var(--text-muted);
    text-decoration: none;
    transition: background 0.2s, color 0.2s;
}

.nav-links li a:hover,
.nav-links li a.active {
    background: var(--surface-2);
    color: var(--text);
}

/* Main content */
.content {
    margin-left: 220px;
    padding: 2rem;
    flex: 1;
    max-width: 1200px;
}

h1 { margin-bottom: 1.5rem; font-size: 1.5rem; }
h2 { margin: 1.5rem 0 0.75rem; font-size: 1.2rem; color: var(--text-muted); }

/* Stats grid */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    text-align: center;
}

.stat-value {
    font-size: 2rem;
    font-weight: 700;
    color: var(--accent);
}

.stat-label {
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-top: 0.25rem;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.9rem;
    color: var(--text);
    transition: background 0.2s;
}

.btn-primary { background: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-2); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }
.btn-danger { background: var(--error); }
.btn-danger:hover { background: #c62828; }
.btn-small { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

.actions-bar {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 0.5rem;
}

.sync-status-row {
    margin-bottom: 1.25rem;
}

.queue-paused-banner {
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    border: 1px solid #7f1d1d;
    border-radius: var(--radius);
    background: rgba(244, 67, 54, 0.12);
    color: #ffb3aa;
}

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: var(--radius);
    overflow: hidden;
}

.data-table th,
.data-table td {
    padding: 0.75rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

.data-table th {
    background: var(--surface-2);
    color: var(--text-muted);
    font-size: 0.85rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.data-table tr:hover { background: rgba(255,255,255,0.03); }

.cover-cell { width: 50px; }
.cover-thumb { width: 40px; height: 60px; object-fit: cover; border-radius: 4px; }

.empty { text-align: center; color: var(--text-muted); padding: 2rem; }
.result-count { color: var(--text-muted); margin-bottom: 0.75rem; font-size: 0.9rem; }

/* Badges */
.badge {
    display: inline-block;
    padding: 0.2rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
}

.badge-success { background: var(--success); color: #fff; }
.badge-warning { background: var(--warning); color: #000; }
.badge-error { background: var(--error); color: #fff; }
.badge-info { background: var(--info); color: #fff; }
.badge-neutral { background: var(--neutral); color: #fff; }

/* Search bar */
.search-bar {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.search-bar input,
.search-bar select {
    padding: 0.5rem 0.75rem;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
}
    .search-bar select,
    .form-group select {
        color-scheme: dark;
    }
    .search-bar select option,
    .form-group select option {
        background: var(--surface);
        color: var(--text);
    }
.data-table td a {
    color: #78b7ff;
    text-decoration: none;
    font-weight: 500;
}
.data-table td a:hover,
.data-table td a:focus-visible {
    color: #9cc9ff;
    text-decoration: underline;
}

.search-bar input { flex: 1; }

/* Book detail */
.book-detail {
    display: flex;
    gap: 2rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
}

.book-cover img { max-width: 250px; border-radius: var(--radius); }
.book-info h2 { margin: 0 0 0.5rem; }
.book-info p { margin: 0.35rem 0; color: var(--text-muted); }
.book-info strong { color: var(--text); }
.book-actions { margin: 1rem 0; }
.description { margin-top: 1.5rem; }
.description p { line-height: 1.6; }
.series { color: var(--accent); font-style: italic; }

.book-description-html p {
    margin: 0.6rem 0;
    line-height: 1.6;
}

.book-description-html ul,
.book-description-html ol {
    margin: 0.7rem 0 0.7rem 1.2rem;
}

.book-description-html li {
    margin: 0.25rem 0;
}

/* Progress bar */
.progress-bar {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.progress-fill {
    height: 100%;
    background: var(--accent);
    transition: width 0.3s;
}

/* Download cards */
.download-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
}

.dl-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.dl-details {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.pool-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.pool-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 0.75rem;
}

.pool-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.35rem;
}

.pool-workers {
    color: var(--text-muted);
    font-size: 0.8rem;
}

.pool-stats {
    display: flex;
    gap: 0.5rem;
    color: var(--text-muted);
    font-size: 0.85rem;
    margin-bottom: 0.45rem;
}

.pool-waiting-list {
    list-style: none;
}

.pool-waiting-list li {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    padding: 0.2rem 0;
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    font-size: 0.82rem;
}

.pool-item-title {
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pool-item-asin,
.pool-more,
.pool-empty {
    color: var(--text-muted);
    font-size: 0.78rem;
}

.error-text { color: var(--error); font-size: 0.85rem; }

/* Info box */
.info-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    color: var(--text-muted);
}

.info-box-compact {
    margin-bottom: 1rem;
}

/* Forms */
.settings-form { max-width: 500px; }

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.35rem;
    font-weight: 600;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9rem;
}

.form-group small { color: var(--text-muted); }

.status-msg { margin-left: 0.75rem; font-size: 0.9rem; }
.status-msg.success { color: var(--success); }
.status-msg.error { color: var(--error); }
.status-msg.warning { color: var(--warning, #e6a817); }
.status-msg.sync-running { font-weight: 600; }
.muted { color: var(--text-muted); }
.sync-progress {
    margin-top: 0.35rem;
    max-width: 360px;
}

/* Button group */
.btn-group {
    display: inline-flex;
    gap: 0.35rem;
}

/* Sync status container */
.sync-status-container {
    display: block;
    margin-left: 0;
    font-size: 0.9rem;
}
.sync-header {
    margin-bottom: 0.25rem;
}
.sync-detail {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-top: 0.15rem;
}

/* Sync phase indicators */
.sync-phases {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 0.4rem;
    margin: 0.35rem 0;
}
.sync-phase {
    display: flex;
    flex-direction: column;
    height: 56px;
    padding: 0.2rem 0.35rem;
    border-radius: var(--radius);
    font-size: 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    overflow: hidden;
}
.phase-main {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    flex-wrap: nowrap;
    min-width: 0;
}
.sync-phase.complete { border-color: var(--success); }
.sync-phase.complete .phase-icon { color: var(--success); }
.sync-phase.failed { border-color: var(--error); }
.sync-phase.failed .phase-icon { color: var(--error); }
.sync-phase.running { border-color: var(--accent); }
.sync-phase.running .phase-icon { color: var(--accent); animation: pulse 1s ease-in-out infinite; }
.sync-phase.skipped { opacity: 0.5; }
.phase-icon {
    font-size: 0.8rem;
    flex-shrink: 0;
}
.phase-label {
    font-weight: 500;
    font-size: 0.75rem;
    white-space: nowrap;
    flex-shrink: 0;
}
.phase-detail {
    color: var(--text-muted);
    font-size: 0.7rem;
    flex: 1;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.phase-detail.error { color: var(--error); }
.phase-count {
    margin-left: auto;
    color: var(--text-muted);
    font-size: 0.65rem;
    white-space: nowrap;
    flex-shrink: 0;
}
.phase-run-btn {
    margin-left: auto;
    background: none;
    border: 1px solid var(--border);
    border-radius: 3px;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0 0.3rem;
    font-size: 0.6rem;
    line-height: 1.4;
    flex-shrink: 0;
    transition: color 0.15s, border-color 0.15s;
}
.phase-run-btn:hover {
    color: var(--accent);
    border-color: var(--accent);
}
.phase-count + .phase-run-btn {
    margin-left: 0.25rem;
}

.phase-progress-track {
    margin-top: auto;
    height: 3px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
}

.phase-progress-fill {
    height: 100%;
    background: var(--accent);
    transition: width 0.25s ease;
}

.phase-progress-track.indeterminate .phase-progress-fill {
    width: 35%;
    animation: phase-indeterminate 1.1s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

@keyframes phase-indeterminate {
    0% { transform: translateX(-130%); }
    100% { transform: translateX(320%); }
}

/* Small buttons for inline actions */
.btn-sm {
    padding: 0.2rem 0.5rem;
    font-size: 0.8rem;
}
.btn-warning {
    background: var(--warning, #e6a817);
    color: #000;
    border: none;
    padding: 0.4rem 1rem;
    border-radius: var(--radius);
    cursor: pointer;
}
.btn-warning:hover { opacity: 0.9; }

/* Responsive */
@media (max-width: 768px) {
    .sync-phases { gap: 0.25rem; }
    .sync-phases { grid-template-columns: 1fr; }
    .sidebar {
        width: 100%;
        position: relative;
        flex-direction: row;
        border-right: none;
        border-bottom: 1px solid var(--border);
    }
    .sidebar-header { display: none; }
    .nav-links { display: flex; }
    .nav-links li a { padding: 0.75rem; }
    .content { margin-left: 0; padding: 1rem; }
    body { flex-direction: column; }
    .book-detail { flex-direction: column; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
