/* ═══════════════════════════════════════════════════════════════════════════
   Manwha Library — Web UI Styles
   ═══════════════════════════════════════════════════════════════════════════ */

:root {
    --bg: #0f0f1a;
    --surface: #1a1a2e;
    --surface2: #16213e;
    --accent: #e94560;
    --accent2: #0f3460;
    --text: #eaeaea;
    --text-dim: #888;
    --border: #2a2a4a;
    --radius: 8px;
}

*, *::before, *::after { 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);
    line-height: 1.6;
    min-height: 100vh;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Layout ────────────────────────────────────────────────────────────── */

nav {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    flex-wrap: wrap;
}
nav .brand {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--accent);
}
nav a {
    color: var(--text-dim);
    font-size: 0.9rem;
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius);
    transition: background 0.2s, color 0.2s;
}
nav a:hover, nav a.active {
    background: var(--surface2);
    color: var(--text);
    text-decoration: none;
}

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

/* ── Cards / Grid ──────────────────────────────────────────────────────── */

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: transform 0.2s, box-shadow 0.2s;
    cursor: pointer;
}
.card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(233, 69, 96, 0.15);
}
.card-img-wrapper {
    position: relative;
}
.card-img-wrapper img {
    width: 100%;
    aspect-ratio: 3/4;
    object-fit: cover;
    display: block;
}
.card-edit-overlay {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: rgba(233, 69, 96, 0.85);
    color: #fff !important;
    padding: 0.3rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none !important;
    opacity: 0;
    transition: opacity 0.2s;
}
.card-img-wrapper:hover .card-edit-overlay {
    opacity: 1;
}
.card-edit-overlay:hover {
    background: var(--accent) !important;
}
.card .body {
    padding: 0.75rem;
}
.card .body h3 {
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.card .body .meta {
    font-size: 0.75rem;
    color: var(--text-dim);
}

/* ── Alphabet Jump ─────────────────────────────────────────────────────── */

.alphabet {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
    margin-bottom: 1rem;
    justify-content: center;
}
.alphabet a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 1.8rem;
    height: 1.8rem;
    font-size: 0.8rem;
    border-radius: 4px;
    background: var(--surface);
    color: var(--text-dim);
    transition: background 0.2s, color 0.2s;
}
.alphabet a:hover, .alphabet a.active {
    background: var(--accent);
    color: #fff;
    text-decoration: none;
}

/* ── Forms ─────────────────────────────────────────────────────────────── */

input, select, button, textarea {
    font: inherit;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface2);
    color: var(--text);
    outline: none;
    transition: border-color 0.2s;
}
input:focus, select:focus { border-color: var(--accent); }
button, .btn {
    background: var(--accent);
    color: #fff;
    border: none;
    cursor: pointer;
    font-weight: 600;
    padding: 0.5rem 1.25rem;
    transition: opacity 0.2s;
}
button:hover, .btn:hover { opacity: 0.85; text-decoration: none; }
.btn-outline {
    background: transparent;
    border: 1px solid var(--accent);
    color: var(--accent);
}

/* ── Search Bar ────────────────────────────────────────────────────────── */

.search-bar {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.search-bar input { flex: 1; }
.search-bar .filters {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.search-bar .filters label {
    font-size: 0.8rem;
    color: var(--text-dim);
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

/* ── Reader ────────────────────────────────────────────────────────────── */

.reader {
    max-width: 800px;
    margin: 0 auto;
}
.reader img {
    width: 100%;
    display: block;
    margin-bottom: 0;
}
.reader-nav {
    display: flex;
    justify-content: space-between;
    padding: 1rem 0;
    gap: 1rem;
}

/* ── Import Results ────────────────────────────────────────────────────── */

.site-result {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.site-result .info { display: flex; align-items: center; gap: 1rem; }
.site-result .status-badge {
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
}
.status-found { background: #1b5e20; color: #a5d6a7; }
.status-not-found { background: #b71c1c; color: #ef9a9a; }

/* ── Progress Bar ──────────────────────────────────────────────────────── */

.progress-bar {
    width: 100%;
    height: 0.5rem;
    background: var(--surface2);
    border-radius: 4px;
    overflow: hidden;
    margin: 0.5rem 0;
}
.progress-bar .fill {
    height: 100%;
    background: var(--accent);
    transition: width 0.3s;
}

/* ── Misc ──────────────────────────────────────────────────────────────── */

.hidden { display: none !important; }
.text-center { text-align: center; }
.text-dim { color: var(--text-dim); }
.mt-1 { margin-top: 1rem; }
.mb-1 { margin-bottom: 1rem; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 1rem; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }

/* ── Responsive ────────────────────────────────────────────────────────── */

/* ── Entry Overview (Read Page) ─────────────────────────────────────────── */

.entry-header {
    display: flex;
    gap: 2rem;
    margin-bottom: 2rem;
}
.entry-cover {
    flex-shrink: 0;
    width: 240px;
}
.entry-cover .cover-img {
    width: 100%;
    border-radius: var(--radius);
    aspect-ratio: 3/4;
    object-fit: cover;
}
.entry-cover .cover-placeholder {
    width: 100%;
    aspect-ratio: 3/4;
    background: var(--surface2);
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 4rem;
    color: var(--text-dim);
}
.entry-info {
    flex: 1;
}
.entry-info h1 {
    font-size: 1.8rem;
    margin-bottom: 0.25rem;
}
.entry-type {
    color: var(--accent);
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}
.entry-chapter-count {
    font-size: 1.1rem;
    margin-bottom: 1rem;
}
.badge-edited {
    display: inline-block;
    font-size: 0.75rem;
    padding: 0.15rem 0.5rem;
    background: var(--accent2);
    color: var(--accent);
    border-radius: 4px;
    margin-left: 0.5rem;
}
.entry-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-top: 1rem;
}
.btn-continue {
    background: #1b5e20 !important;
    border-color: #2e7d32 !important;
}
.entry-description {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    margin-bottom: 2rem;
}
.entry-description h2 {
    font-size: 1.1rem;
    margin-bottom: 0.75rem;
}
.entry-description p {
    line-height: 1.7;
    color: var(--text-dim);
}

/* ── Entry Nav Actions ─────────────────────────────────────────────────── */

.entry-nav-actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
    justify-content: center;
    margin: 1.5rem 0 2rem;
}
.entry-nav-actions .btn {
    font-size: 0.95rem;
    padding: 0.7rem 1.5rem;
}

/* ── Chapter List ──────────────────────────────────────────────────────── */

.chapter-grid {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 0.75rem;
}
.chapter-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.4rem 0.75rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.8rem;
    color: var(--text) !important;
    transition: background 0.2s, border-color 0.2s;
    text-decoration: none !important;
}
.chapter-chip:hover {
    background: var(--surface2);
    border-color: var(--accent);
}

/* ── Card Actions ──────────────────────────────────────────────────────── */

.card-actions {
    display: flex;
    gap: 0.25rem;
    padding: 0.5rem 0.75rem;
    border-top: 1px solid var(--border);
}
.card-action-link {
    font-size: 0.75rem;
    color: var(--text-dim) !important;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: background 0.2s, color 0.2s;
    text-decoration: none !important;
}
.card-action-link:hover {
    background: var(--surface2);
    color: var(--accent) !important;
}

/* ── Reader Header ──────────────────────────────────────────────────────── */

.reader-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid var(--border);
}
.reader-nav-top {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 0.5rem;
}

/* ── Discover Section ───────────────────────────────────────────────────── */

.section-divider {
    border: none;
    border-top: 2px solid var(--accent);
    margin: 2rem 0;
}
.discover-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
}
.discover-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(233, 69, 96, 0.15);
}
.discover-card-img {
    width: 100%;
    aspect-ratio: 3/4;
    object-fit: cover;
    display: block;
}
.discover-card-placeholder {
    width: 100%;
    aspect-ratio: 3/4;
    background: var(--surface2);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 3rem;
    color: var(--text-dim);
}
.discover-card-body {
    padding: 0.75rem;
}
.discover-card-body h4 {
    font-size: 0.95rem;
    margin-bottom: 0.25rem;
}
.discover-card-body .meta {
    font-size: 0.8rem;
}
.discover-card-desc {
    font-size: 0.8rem;
    color: var(--text-dim);
    line-height: 1.4;
    margin-top: 0.4rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}
.discover-card-sites {
    font-size: 0.7rem;
    color: var(--accent2);
    margin-top: 0.3rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Discover Modal ────────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.7);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-content {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 2rem;
    max-width: 700px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
}
.modal-close {
    position: absolute;
    top: 0.75rem;
    right: 0.75rem;
    background: transparent;
    border: none;
    color: var(--text-dim);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}
.modal-close:hover { background: var(--surface2); }
.discover-detail {
    display: flex;
    gap: 1.5rem;
}
.discover-detail-cover {
    flex-shrink: 0;
}
.discover-detail-info h2 {
    margin-bottom: 0.5rem;
}
.discover-detail-info p {
    color: var(--text-dim);
    margin-bottom: 1rem;
    line-height: 1.6;
}
.discover-detail-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
}

/* ── Edit Page ──────────────────────────────────────────────────────────── */

.edit-page {
    max-width: 1000px;
    margin: 0 auto;
}
.image-strip {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    min-height: 150px;
    overflow-x: auto;
}
.image-strip-inner {
    display: flex;
    gap: 0.5rem;
    padding: 1rem;
    overflow-x: auto;
}
.strip-image-wrapper {
    position: relative;
    flex-shrink: 0;
    width: 120px;
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    transition: border-color 0.2s;
}
.strip-image-wrapper:hover {
    border-color: var(--accent2);
}
.strip-image-wrapper.selected {
    border-color: var(--accent);
}
.strip-image-wrapper img {
    width: 100%;
    height: 160px;
    object-fit: cover;
    display: block;
}
.strip-image-overlay {
    position: absolute;
    top: 0; left: 0; right: 0;
    display: flex;
    justify-content: space-between;
    padding: 0.25rem;
    background: rgba(0,0,0,0.6);
    font-size: 0.7rem;
}
.strip-image-num {
    color: #fff;
    font-weight: 600;
}
.strip-image-delete {
    color: var(--accent);
    cursor: pointer;
    font-weight: 700;
    padding: 0 0.25rem;
}
.strip-image-delete:hover {
    color: #fff;
}

/* ── Category Badges ────────────────────────────────────────────────────── */

.category-badge {
    display: inline-block;
    padding: 0.15rem 0.45rem;
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    vertical-align: middle;
    margin-left: 0.35rem;
}
.category-original {
    background: #e94560;
    color: #fff;
}
.category-translated {
    background: #0f3460;
    color: #eaeaea;
}
.category-ai_translated {
    background: #7b2d8e;
    color: #eaeaea;
}

/* ── Responsive ────────────────────────────────────────────────────────── */

@media (max-width: 768px) {
    .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
    nav { gap: 0.75rem; }
    .search-bar { flex-direction: column; }
    .entry-header { flex-direction: column; }
    .entry-cover { width: 100%; max-width: 200px; }
    .discover-detail { flex-direction: column; }
    .discover-detail-cover { text-align: center; }
}

/* ── Import from Files ──────────────────────────────────────────────────── */

.import-form {
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 720px;
}
.form-row {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}
.form-row .form-field { flex: 1 1 200px; }
.form-field {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}
.form-field label {
    font-size: 0.8rem;
    color: var(--text-dim);
}
.form-field input[type="text"],
.form-field select,
.form-field textarea {
    width: 100%;
}
.form-field textarea { resize: vertical; }

.title-upload-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.title-preview {
    width: 48px;
    height: 64px;
    flex-shrink: 0;
    border-radius: 4px;
    background: var(--surface2);
    border: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.65rem;
    color: var(--text-dim);
    text-align: center;
    overflow: hidden;
}
.title-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.chapter-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}
.chapter-block-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
}
.chapter-num-label {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: var(--text-dim);
}
.chapter-num-label input { width: 5.5rem; }
.remove-chapter-btn {
    font-size: 0.8rem;
    padding: 0.3rem 0.6rem;
}

.drop-zone-wrap {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}
.drop-zone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
    color: var(--text-dim);
    font-size: 0.85rem;
    cursor: pointer;
    transition: border-color 0.2s, background 0.2s, color 0.2s;
}
.drop-zone:hover {
    border-color: var(--accent2);
    color: var(--text);
}
.drop-zone.dragover {
    border-color: var(--accent);
    background: rgba(233, 69, 96, 0.08);
    color: var(--text);
}
.file-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}
.file-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 0.4rem 0.6rem;
    cursor: grab;
    user-select: none;
}
.file-row.dragging {
    opacity: 0.45;
    border-color: var(--accent);
}
.file-index {
    color: var(--text-dim);
    font-size: 0.8rem;
    min-width: 1.5rem;
    text-align: right;
}
.file-name {
    flex: 1;
    font-size: 0.85rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.file-remove {
    background: transparent;
    border: none;
    color: var(--accent);
    font-size: 1.1rem;
    line-height: 1;
    padding: 0.1rem 0.35rem;
    border-radius: 4px;
    cursor: pointer;
}
.file-remove:hover {
    background: rgba(233, 69, 96, 0.15);
    color: #fff;
}

.status { font-size: 0.85rem; min-height: 1.2em; }
.status.ok { color: #a5d6a7; }
.status.err { color: #ef9a9a; }
button:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Add Chapter to existing Series ─────────────────────────────────────── */

.accordion {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
}
.accordion summary {
    list-style: none;
    cursor: pointer;
    padding: 1rem 3rem 1rem 1.25rem;
    font-size: 1.35rem;
    font-weight: 700;
    position: relative;
    user-select: none;
    transition: background 0.2s;
}
.accordion summary::-webkit-details-marker { display: none; }
.accordion summary:hover { background: var(--surface2); }
.accordion summary::after {
    content: '▸';
    position: absolute;
    right: 1.25rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--accent);
    transition: transform 0.2s;
}
.accordion[open] summary { border-bottom: 1px solid var(--border); }
.accordion[open] summary::after { transform: translateY(-50%) rotate(90deg); }
.accordion-body {
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    max-width: 720px;
}

.series-picker { position: relative; }
.series-picker-btn {
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    background: var(--surface2);
    border: 1px solid var(--border);
    text-align: left;
    cursor: pointer;
}
.series-picker-btn:hover {
    border-color: var(--accent);
    opacity: 1;
}
.series-picker-value {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.6rem;
    min-width: 0;
    overflow: hidden;
}
.series-picker-value > span:last-child {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.series-picker-caret { color: var(--text-dim); flex-shrink: 0; }
.series-picker-panel {
    position: absolute;
    top: calc(100% + 0.25rem);
    left: 0;
    right: 0;
    z-index: 50;
    max-height: 320px;
    overflow-y: auto;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.series-picker-row {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.75rem;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
}
.series-picker-row:last-child { border-bottom: none; }
.series-picker-row:hover { background: var(--surface2); }
.series-picker-thumb {
    width: 28px;
    height: 40px;
    object-fit: cover;
    border-radius: 4px;
    flex-shrink: 0;
    background: var(--surface2);
}
.series-picker-row .series-picker-thumb {
    width: 40px;
    height: 56px;
}
.series-picker-emoji {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--surface2);
    border-radius: 4px;
    color: var(--text-dim);
    flex-shrink: 0;
}
.series-picker-value .series-picker-emoji { width: 28px; height: 40px; font-size: 1rem; }
.series-picker-row .series-picker-emoji { width: 40px; height: 56px; font-size: 1.4rem; }
.series-picker-info {
    display: flex;
    flex-direction: column;
    min-width: 0;
}
.series-picker-title {
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.series-picker-meta {
    font-size: 0.72rem;
    color: var(--text-dim);
}
.series-picker-loading,
.series-picker-empty {
    padding: 1rem;
    text-align: center;
    color: var(--text-dim);
    font-size: 0.85rem;
}

@media (max-width: 768px) {
    .form-row { flex-direction: column; }
    .chapter-block-header { flex-direction: column; align-items: flex-start; }
    .series-picker-panel { max-height: 240px; }
}
