/* ===== Reset & Base ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #0d1117;
    --bg-secondary: #161b22;
    --bg-tertiary: #21262d;
    --bg-hover: #30363d;
    --border-color: #30363d;
    --text-primary: #e6edf3;
    --text-secondary: #8b949e;
    --text-muted: #6e7681;
    --accent: #58a6ff;
    --accent-hover: #79b8ff;
    --green: #3fb950;
    --yellow: #d29922;
    --red: #f85149;
    --orange: #f0883e;
    --purple: #bc8cff;
    --cyan: #39d2c0;
    --radius: 8px;
    --radius-sm: 4px;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    --transition: 0.2s ease;
}

body {
    font-family:
        -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
        sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    line-height: 1.5;
    overflow: hidden;
    height: 100vh;
}

/* ===== Layout ===== */
.app {
    display: flex;
    height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
    width: 240px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    padding: 16px 0;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 16px 20px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 16px;
}

.logo-icon {
    font-size: 28px;
}

.logo-text {
    font-size: 20px;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), var(--cyan));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.sidebar-nav {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 0 8px;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    background: transparent;
    border: none;
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    transition: var(--transition);
    text-align: left;
}

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

.nav-item.active {
    background: var(--bg-tertiary);
    color: var(--accent);
}

.nav-icon {
    font-size: 16px;
}

.sidebar-stats {
    padding: 16px;
    border-top: 1px solid var(--border-color);
}

.stat-row {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.stat-value {
    color: var(--text-primary);
    font-weight: 600;
    font-family: "SF Mono", "Fira Code", monospace;
}

/* ===== Main Content ===== */
.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* ===== Top Bar ===== */
.top-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
}

.magnet-input {
    flex: 1;
    display: flex;
    gap: 8px;
}

.magnet-input input {
    flex: 1;
    padding: 10px 14px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: var(--transition);
}

.magnet-input input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

.magnet-input input::placeholder {
    color: var(--text-muted);
}

.top-actions {
    display: flex;
    gap: 8px;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn-primary {
    background: var(--accent);
    color: #fff;
}

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

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

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

.btn-icon {
    background: var(--bg-tertiary);
    padding: 8px 10px;
    font-size: 16px;
}

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

/* ===== Torrent List ===== */
.torrent-list-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.torrent-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
}

.torrent-list-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.filter-controls select {
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    outline: none;
}

.torrent-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* ===== Torrent Item ===== */
.torrent-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 14px 16px;
    cursor: pointer;
    transition: var(--transition);
}

.torrent-item:hover {
    border-color: var(--accent);
    background: var(--bg-tertiary);
}

.torrent-item.selected {
    border-color: var(--accent);
    box-shadow: 0 0 0 2px rgba(88, 166, 255, 0.2);
}

.torrent-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 10px;
}

.torrent-name {
    font-weight: 500;
    font-size: 14px;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 70%;
}

.torrent-status {
    font-size: 12px;
    color: var(--text-secondary);
}

.torrent-status.downloading {
    color: var(--green);
}

.torrent-status.seeding {
    color: var(--cyan);
}

.torrent-status.paused {
    color: var(--yellow);
}

.torrent-status.error {
    color: var(--red);
}

.torrent-progress {
    margin-bottom: 10px;
}

.progress-bar {
    height: 6px;
    background: var(--bg-primary);
    border-radius: 3px;
    overflow: hidden;
    margin-bottom: 6px;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent), var(--cyan));
    border-radius: 3px;
    transition: width 0.3s ease;
}

.progress-fill.seeding {
    background: linear-gradient(90deg, var(--green), var(--cyan));
}

.progress-text {
    display: flex;
    justify-content: space-between;
    font-size: 11px;
    color: var(--text-muted);
}

.torrent-stats {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--text-secondary);
}

.torrent-stat {
    display: flex;
    align-items: center;
    gap: 4px;
}

.torrent-stat .icon {
    font-size: 10px;
}

.torrent-stat.download {
    color: var(--green);
}

.torrent-stat.upload {
    color: var(--cyan);
}

.torrent-stat.peers {
    color: var(--text-muted);
}

/* ===== Empty State ===== */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 60px 20px;
    text-align: center;
}

.empty-state.hidden {
    display: none;
}

.empty-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.6;
}

.empty-state h3 {
    font-size: 18px;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.empty-state p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ===== Details Panel ===== */
.details-panel {
    position: fixed;
    right: 0;
    top: 0;
    bottom: 0;
    width: 380px;
    background: var(--bg-secondary);
    border-left: 1px solid var(--border-color);
    box-shadow: var(--shadow);
    transform: translateX(100%);
    transition: transform 0.3s ease;
    z-index: 100;
    overflow-y: auto;
}

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

.details-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    z-index: 10;
}

.details-header h3 {
    font-size: 16px;
    font-weight: 600;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 90%;
}

.close-details {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
}

.close-details:hover {
    color: var(--text-primary);
}

.details-content {
    padding: 20px;
}

.detail-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
    margin-bottom: 24px;
}

.detail-stat {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detail-stat .label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-stat .value {
    font-size: 14px;
    font-weight: 500;
    font-family: "SF Mono", "Fira Code", monospace;
}

.detail-files,
.detail-peers-list {
    margin-bottom: 24px;
}

.detail-files h4,
.detail-peers-list h4 {
    font-size: 14px;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.detail-files ul,
.detail-peers-list ul {
    list-style: none;
}

.detail-files li,
.detail-peers-list li {
    padding: 8px 12px;
    background: var(--bg-primary);
    border-radius: var(--radius-sm);
    margin-bottom: 6px;
    font-size: 13px;
    font-family: "SF Mono", "Fira Code", monospace;
    display: flex;
    justify-content: space-between;
}

/* ===== Search View ===== */
.search-view {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    z-index: 200;
    padding: 40px;
    overflow-y: auto;
}

.search-view.hidden {
    display: none;
}

.search-container {
    max-width: 800px;
    margin: 0 auto;
}

.search-container h2 {
    margin-bottom: 24px;
}

.search-input-group {
    display: flex;
    gap: 12px;
    margin-bottom: 32px;
}

.search-input-group input {
    flex: 1;
    padding: 14px 18px;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    color: var(--text-primary);
    font-size: 16px;
    outline: none;
}

.search-input-group input:focus {
    border-color: var(--accent);
}

.search-results {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.search-result-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    padding: 16px;
    cursor: pointer;
    transition: var(--transition);
}

.search-result-item:hover {
    border-color: var(--accent);
}

.search-result-name {
    font-weight: 500;
    margin-bottom: 6px;
}

.search-result-meta {
    display: flex;
    gap: 16px;
    font-size: 12px;
    color: var(--text-secondary);
}

.search-result-meta .seeds {
    color: var(--green);
}

.search-result-meta .peers {
    color: var(--yellow);
}

/* ===== Modal ===== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    width: 90%;
    max-width: 500px;
    box-shadow: var(--shadow);
}

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

.modal-header h3 {
    font-size: 18px;
}

.modal-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
}

.modal-close:hover {
    color: var(--text-primary);
}

.modal-body {
    padding: 20px;
    max-height: 60vh;
    overflow-y: auto;
}

.setting-group {
    margin-bottom: 24px;
}

.setting-group h4 {
    font-size: 14px;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

.setting-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid var(--border-color);
}

.setting-row:last-child {
    border-bottom: none;
}

.setting-row label {
    font-size: 14px;
}

.setting-row input[type="number"],
.setting-row input[type="text"] {
    width: 180px;
    padding: 8px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 13px;
    outline: none;
}

.setting-row input[type="checkbox"] {
    width: 18px;
    height: 18px;
    accent-color: var(--accent);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    padding: 16px 20px;
    border-top: 1px solid var(--border-color);
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 8px;
}

::-webkit-scrollbar-track {
    background: var(--bg-primary);
}

::-webkit-scrollbar-thumb {
    background: var(--bg-hover);
    border-radius: 4px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== Animations ===== */
@keyframes pulse {
    0%,
    100% {
        opacity: 1;
    }
    50% {
        opacity: 0.5;
    }
}

.pulse {
    animation: pulse 2s ease-in-out infinite;
}

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

.torrent-item:first-child {
    animation: slideIn 0.3s ease;
}

/* ===== Responsive ===== */
@media (max-width: 768px) {
    .sidebar {
        width: 60px;
    }

    .logo-text,
    .nav-item span:not(.nav-icon),
    .sidebar-stats {
        display: none;
    }

    .nav-item {
        justify-content: center;
        padding: 12px;
    }

    .details-panel {
        width: 100%;
    }
}

/* ===== Logger View ===== */
.logger-view {
    position: fixed;
    inset: 0;
    background: var(--bg-primary);
    z-index: 200;
    padding: 20px;
    overflow-y: auto;
}

.logger-view.hidden {
    display: none;
}

.logger-container {
    max-width: 1000px;
    margin: 0 auto;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius);
    height: calc(100vh - 40px);
    display: flex;
    flex-direction: column;
}

.logger-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
}

.logger-header h2 {
    font-size: 18px;
}

.logger-controls {
    display: flex;
    gap: 10px;
    align-items: center;
}

.logger-controls select {
    padding: 6px 10px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    color: var(--text-primary);
    font-size: 12px;
    cursor: pointer;
    outline: none;
}

.logger-list {
    flex: 1;
    overflow-y: auto;
    list-style: none;
    padding: 10px;
    font-family: "SF Mono", "Fira Code", monospace;
    font-size: 12px;
}

.log-entry {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 4px 8px;
    border-radius: var(--radius-sm);
    margin-bottom: 2px;
    line-height: 1.4;
}

.log-entry:hover {
    background: var(--bg-tertiary);
}

.log-entry.info {
    color: var(--text-secondary);
}

.log-entry.success {
    color: var(--green);
}

.log-entry.warning {
    color: var(--yellow);
}

.log-entry.error {
    color: var(--red);
}

.log-entry.debug {
    color: var(--purple);
}

.log-time {
    color: var(--text-muted);
    white-space: nowrap;
}

.log-icon {
    font-size: 12px;
    flex-shrink: 0;
}

.log-message {
    word-break: break-all;
}

/* ===== Drag & Drop Overlay ===== */
.drop-overlay {
    position: fixed;
    inset: 0;
    background: rgba(13, 17, 23, 0.95);
    border: 3px dashed var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
}

.drop-overlay.visible {
    opacity: 1;
    pointer-events: auto;
}

.drop-message {
    font-size: 24px;
    color: var(--accent);
    font-weight: 600;
    padding: 40px;
    text-align: center;
    background: var(--bg-secondary);
    border-radius: var(--radius);
    border: 2px solid var(--accent);
}

/* ===== Detail Actions (Recheck) ===== */
.detail-actions {
    margin-bottom: 24px;
    padding: 12px;
    background: var(--bg-primary);
    border-radius: var(--radius);
}

.detail-actions .btn {
    width: 100%;
}

.recheck-progress {
    margin-top: 10px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.recheck-progress.hidden {
    display: none;
}

.recheck-progress .progress-bar {
    flex: 1;
}

.recheck-progress-text {
    font-size: 12px;
    color: var(--text-secondary);
    font-family: "SF Mono", "Fira Code", monospace;
    min-width: 40px;
}
