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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #0f0f0f;
    color: #e0e0e0;
    min-height: 100vh;
}

nav {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 0.75rem 1.5rem;
    background: #1a1a1a;
    border-bottom: 1px solid #2a2a2a;
    position: sticky;
    top: 0;
    z-index: 100;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    text-decoration: none;
}

.nav-link {
    color: #aaa;
    text-decoration: none;
    font-size: 0.9rem;
}

.nav-link:hover {
    color: #fff;
}

main {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1.5rem;
}

.flash-container {
    max-width: 1400px;
    margin: 0.5rem auto;
    padding: 0 1.5rem;
}

.flash {
    padding: 0.6rem 1rem;
    border-radius: 6px;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.flash-success {
    background: #1a3a1a;
    color: #7d7;
    border: 1px solid #2a5a2a;
}

.flash-error {
    background: #3a1a1a;
    color: #d77;
    border: 1px solid #5a2a2a;
}

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

.grid-header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

/* Clip Grid */
.clip-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 1rem;
}

.clip-card {
    background: #1a1a1a;
    border-radius: 10px;
    overflow: hidden;
    transition: transform 0.15s;
}

.clip-card:hover {
    transform: translateY(-2px);
}

.clip-thumb-link {
    position: relative;
    display: block;
    aspect-ratio: 16 / 9;
    overflow: hidden;
    background: #000;
}

.clip-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.clip-thumb-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #555;
    font-size: 0.85rem;
}

.clip-badge {
    position: absolute;
    bottom: 6px;
    right: 6px;
    font-size: 0.7rem;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}

.clip-badge.downloaded {
    background: #1a6b1a;
    color: #7d7;
}

.clip-badge.remote {
    background: #444;
    color: #ccc;
}

.custom-thumb-badge {
    position: absolute;
    top: 6px;
    left: 6px;
    background: #3a5a8a;
    color: #adf;
    font-size: 0.65rem;
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
}

.clip-info {
    padding: 0.6rem 0.75rem;
}

.clip-name {
    margin-bottom: 0.15rem;
}

.clip-title {
    color: #eee;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.clip-title:hover {
    color: #4af;
}

.clip-title-static {
    color: #eee;
    text-decoration: none;
    font-size: 0.9rem;
    font-weight: 500;
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.clip-profile {
    font-size: 0.8rem;
    color: #888;
}

.empty-state {
    text-align: center;
    padding: 4rem 1rem;
    color: #666;
}

/* Buttons */
.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    background: #2a2a2a;
    color: #eee;
    border: 1px solid #444;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    text-decoration: none;
    transition: background 0.15s;
}

.btn:hover {
    background: #3a3a3a;
}

.btn-sm {
    padding: 0.3rem 0.6rem;
    font-size: 0.8rem;
}

.btn-danger {
    border-color: #5a2a2a;
    color: #d77;
}

.btn-danger:hover {
    background: #3a1a1a;
}

/* Settings */
.settings-section {
    margin-bottom: 2rem;
}

.settings-section h2 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 1px solid #2a2a2a;
}

.settings-form {
    max-width: 480px;
}

.form-group {
    margin-bottom: 0.75rem;
}

.form-group label {
    display: block;
    font-size: 0.85rem;
    color: #aaa;
    margin-bottom: 0.25rem;
}

.form-group input[type="text"],
.form-group input[type="number"] {
    width: 100%;
    padding: 0.5rem 0.65rem;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 6px;
    color: #eee;
    font-size: 0.9rem;
}

.form-group input:focus {
    outline: none;
    border-color: #4af;
}

.form-hint {
    display: block;
    font-size: 0.75rem;
    color: #666;
    margin-top: 0.2rem;
}

.checkbox-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
}

.form-row {
    display: flex;
    gap: 0.75rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.form-row .form-group {
    flex: 1;
    min-width: 120px;
}

.form-row .btn {
    margin-bottom: 0.75rem;
    white-space: nowrap;
}

.add-profile-form {
    margin-bottom: 1rem;
}

/* Table */
.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

th, td {
    padding: 0.5rem 0.75rem;
    text-align: left;
    border-bottom: 1px solid #2a2a2a;
}

th {
    color: #888;
    font-weight: 500;
}

td.actions {
    white-space: nowrap;
    display: flex;
    gap: 0.4rem;
}

.empty-note {
    color: #666;
    font-size: 0.9rem;
}

.inline-pattern-form {
    display: flex;
    gap: 0.3rem;
    align-items: center;
}

.pattern-input {
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 4px;
    color: #eee;
    font-size: 0.75rem;
    padding: 0.2rem 0.4rem;
    width: 160px;
    font-family: monospace;
}

.pattern-input:focus {
    outline: none;
    border-color: #4af;
}

.btn-pattern {
    padding: 0.15rem 0.4rem;
    font-size: 0.7rem;
}

/* Edit page */
.edit-container {
    max-width: 560px;
}

.back-link {
    display: inline-block;
    color: #888;
    text-decoration: none;
    font-size: 0.85rem;
    margin-bottom: 1rem;
}

.back-link:hover {
    color: #4af;
}

.edit-preview {
    background: #1a1a1a;
    border: 1px solid #2a2a2a;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.85rem;
}

.edit-preview p {
    margin-bottom: 0.25rem;
}

.edit-preview code {
    color: #7d7;
    font-size: 0.8rem;
}

/* Edit page thumbnail */
.edit-thumb-preview {
    width: 320px;
    aspect-ratio: 16 / 9;
    background: #111;
    border: 1px solid #2a2a2a;
    border-radius: 8px;
    overflow: hidden;
    margin-top: 1rem;
}

.edit-thumb-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.edit-thumb-options {
    margin-top: 0.75rem;
}

.upload-area {
    margin: 0.75rem 0;
    display: flex;
    align-items: center;
}

.upload-btn {
    cursor: pointer;
}

/* Responsive */
/* Context menu */
.context-menu {
    position: fixed;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 8px;
    padding: 0.3rem 0;
    min-width: 180px;
    z-index: 200;
    box-shadow: 0 4px 16px rgba(0,0,0,0.5);
}

.context-item {
    padding: 0.5rem 1rem;
    font-size: 0.85rem;
    color: #ddd;
    cursor: pointer;
}

.context-item:hover {
    background: #2a2a2a;
    color: #4af;
}

.context-sep {
    height: 1px;
    background: #2a2a2a;
    margin: 0.25rem 0;
}

/* Setup wizard */
.setup-wizard {
    max-width: 680px;
    margin: 3rem auto;
    text-align: center;
}

.setup-wizard h1 {
    font-size: 1.8rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
}

.setup-subtitle {
    color: #888;
    font-size: 0.95rem;
    margin-bottom: 2rem;
}

.setup-form {
    text-align: left;
    background: #1a1a1a;
    border: 1px solid #2a2a2a;
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.btn-setup {
    margin-top: 0.5rem;
    width: 100%;
    padding: 0.65rem;
    font-size: 0.95rem;
    font-weight: 600;
    background: #2a4a6a;
    border-color: #3a5a8a;
}

.btn-setup:hover {
    background: #3a5a8a;
}

.setup-profiles {
    text-align: left;
    background: #1a1a1a;
    border: 1px solid #2a2a2a;
    border-radius: 12px;
    padding: 1rem 1.5rem;
    margin-bottom: 1.5rem;
}

.setup-profiles h3 {
    font-size: 0.95rem;
    font-weight: 600;
    margin-bottom: 0.5rem;
}

/* Admin collapsible */
.admin-collapse {
    text-align: left;
    background: #1a1a1a;
    border: 1px solid #2a2a2a;
    border-radius: 12px;
    overflow: hidden;
}

.admin-collapse summary {
    padding: 0.75rem 1.5rem;
    cursor: pointer;
    font-size: 0.9rem;
    color: #aaa;
    font-weight: 500;
}

.admin-collapse summary:hover {
    color: #eee;
}

.admin-collapse-content {
    padding: 0 1.5rem 1.25rem;
}

.admin-collapse[open] summary {
    border-bottom: 1px solid #2a2a2a;
}

/* Search bar */
.search-bar {
    flex: 0 0 auto;
}

.search-input {
    padding: 0.45rem 0.75rem;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 6px;
    color: #eee;
    font-size: 0.85rem;
    width: 220px;
}

.search-input:focus {
    outline: none;
    border-color: #4af;
}

.search-input::placeholder {
    color: #555;
}

/* Watch Page */
.watch-layout {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.watch-primary {
    min-width: 0;
}

.video-container {
    position: relative;
    background: #000;
    border-radius: 10px;
    overflow: hidden;
    width: 100%;
}

.video-player {
    display: block;
    width: 100%;
    max-height: 75vh;
    background: #000;
}

.video-controls-overlay {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    display: flex;
    gap: 0.4rem;
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
    z-index: 10;
}

.video-container:hover .video-controls-overlay {
    opacity: 1;
    pointer-events: auto;
}

.ctrl-btn {
    background: rgba(0,0,0,0.7);
    border: none;
    color: #fff;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
}

.ctrl-btn:hover {
    background: rgba(0,0,0,0.9);
}

.ctrl-btn.active {
    background: #2a4a6a;
}

.video-info {
    padding: 0.75rem 0;
}

.video-title {
    font-size: 1.15rem;
    font-weight: 600;
    margin-bottom: 0.2rem;
}

.video-server {
    font-size: 0.85rem;
    color: #888;
}

.video-edit-btn {
    margin-top: 0.5rem;
}

/* Recommended section */
.rec-search {
    margin-bottom: 0.5rem;
}

.rec-search .search-input {
    width: 100%;
    max-width: 320px;
}

.recommended-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.rec-item {
    display: flex;
    gap: 0.75rem;
    border-radius: 8px;
    text-decoration: none;
    color: inherit;
    transition: background 0.15s;
    padding: 0.4rem;
}

.rec-item:hover {
    background: #1a1a1a;
}

.rec-thumb-wrap {
    width: 160px;
    flex-shrink: 0;
    aspect-ratio: 16 / 9;
    border-radius: 6px;
    overflow: hidden;
    background: #000;
}

.rec-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.rec-thumb-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    color: #555;
    font-size: 0.7rem;
}

.rec-info {
    display: flex;
    flex-direction: column;
    gap: 0.15rem;
    min-width: 0;
    justify-content: center;
}

.rec-title {
    font-size: 0.85rem;
    font-weight: 500;
    color: #eee;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.rec-profile {
    font-size: 0.75rem;
    color: #888;
}

/* Cinema mode */
.watch-layout.cinema-mode .video-container {
    max-width: 90vw;
    margin: 0 auto;
}

.watch-layout.cinema-mode .video-player {
    max-height: 85vh;
}

/* Responsive */
@media (max-width: 800px) {
    .search-input {
        width: 160px;
    }

    .rec-item {
        width: 160px;
    }
}

@media (max-width: 600px) {
    .clip-grid {
        grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
        gap: 0.6rem;
    }

    .form-row {
        flex-direction: column;
    }
}
