:root {
    --bg: #fafaf8;
    --fg: #1a1a1a;
    --muted: #888;
    --border: #ddd;
    --accent: #2c5f2d;
    --done: #2c5f2d;
    --partial: #c89f3c;
    --error: #b33;
    --pending: #aaa;
    --card-bg: #fff;
    --radius: 4px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--fg);
    line-height: 1.5;
}

header {
    background: var(--accent);
    color: #fff;
    padding: 0.5rem 1rem;
}

.breadcrumb { font-size: 0.9rem; }
.breadcrumb a { color: #fff; text-decoration: none; }
.breadcrumb a:hover { text-decoration: underline; }
.breadcrumb .sep { margin: 0 0.3rem; opacity: 0.6; }

main { max-width: 1200px; margin: 0 auto; padding: 1rem; }

footer {
    text-align: center;
    padding: 1.5rem;
    color: var(--muted);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
    margin-top: 2rem;
}
footer a { color: var(--muted); text-decoration: none; }
footer a:hover { text-decoration: underline; color: var(--accent); }
.footer-about {
    max-width: 900px;
    margin: 0 auto 0.75rem;
    line-height: 1.5;
    font-size: 0.8rem;
}
.footer-about p { margin-bottom: 0.4rem; }
.footer-about p[lang="en"] { font-style: italic; }
.footer-links { margin-bottom: 0.3rem; }
.footer-links .sep { margin: 0 0.4rem; opacity: 0.5; }
.visitor-count { margin-top: 0.25rem; font-size: 0.8rem; }

h1 { margin-bottom: 0.25rem; }
.subtitle { color: var(--muted); margin-bottom: 1rem; }

/* Book header */
.book-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 1rem;
}
.book-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Stats bar */
.stats-bar {
    display: flex;
    gap: 1.5rem;
    flex-wrap: wrap;
    padding: 0.75rem 1rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}
.error-badge { color: var(--error); font-weight: 600; }
.pipeline-bar a { color: var(--accent); text-decoration: none; font-weight: 500; }
.pipeline-bar a:hover { text-decoration: underline; }

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}
.data-table th, .data-table td {
    padding: 0.5rem 0.75rem;
    text-align: right;
    border-bottom: 1px solid var(--border);
    font-variant-numeric: tabular-nums;
}
.data-table th:first-child, .data-table td:first-child {
    text-align: left;
}
.data-table th {
    background: #f0f0ee;
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}
.data-table tbody tr:hover { background: #f5f5f0; }
.data-table a { color: var(--accent); text-decoration: none; font-weight: 500; }
.data-table a:hover { text-decoration: underline; }

/* Progress bar */
.progress-bar {
    display: inline-block;
    width: 60px;
    height: 8px;
    background: #e8e8e8;
    border-radius: 4px;
    overflow: hidden;
    vertical-align: middle;
}
.progress-fill {
    height: 100%;
    border-radius: 4px;
    transition: width 0.3s;
}
.progress-fill.complete { background: var(--done); }
.progress-fill.partial { background: var(--partial); }
.pct {
    font-size: 0.8rem;
    margin-left: 0.3rem;
    font-variant-numeric: tabular-nums;
}
.pct.muted { color: var(--muted); }

/* External link */
.ext-link {
    font-size: 0.8rem;
    color: var(--muted);
    text-decoration: none;
    border: 1px solid var(--border);
    padding: 0.15rem 0.4rem;
    border-radius: var(--radius);
}
.ext-link:hover { border-color: var(--accent); color: var(--accent); }

/* Page grid */
.page-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
    gap: 0.5rem;
}
.page-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 0.75rem 0.5rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--fg);
    transition: border-color 0.15s;
}
.page-card:hover { border-color: var(--accent); }
.page-card.pending { opacity: 0.5; cursor: default; }
.page-card.error { border-color: var(--error); }
.page-num { font-weight: 600; font-size: 1.1rem; }
.badge {
    font-size: 0.65rem;
    padding: 0.1rem 0.3rem;
    border-radius: 3px;
    margin-top: 0.25rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.badge.done { background: #e0f0e0; color: var(--done); }
.badge.error { background: #fde0e0; color: var(--error); }
.badge.pending { background: #eee; color: var(--muted); }
.badge.processing { background: #e8e0f0; color: #6a4c93; }
.badge.completed { background: #e0f0e0; color: var(--done); }

/* Request inline — matches .stats-bar sizing */
.request-inline {
    margin-bottom: 1rem;
}
.request-input-wrap {
    display: flex;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    transition: border-color 0.15s;
}
.request-input-wrap:focus-within { border-color: var(--accent); }
.request-input-wrap input[type="url"] {
    flex: 1;
    padding: 0.75rem 1rem;
    border: none;
    outline: none;
    font-size: 0.9rem;
    font-family: inherit;
    background: transparent;
    color: var(--fg);
    min-width: 0;
}
.request-input-wrap input::placeholder { color: var(--muted); }
.request-submit {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 1rem;
    background: none;
    border: none;
    border-left: 1px solid var(--border);
    color: var(--muted);
    cursor: pointer;
    transition: color 0.15s, background 0.15s;
}
.request-submit:hover { color: var(--accent); background: #f5f5f0; }
.request-result {
    margin-top: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius);
    font-size: 0.9rem;
}
.request-result.success { background: #e0f0e0; color: var(--done); }
.request-result.error { background: #fde0e0; color: var(--error); }

/* Viewer */
.viewer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
}
.viewer-nav {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}
.viewer-title { font-weight: 600; }
.viewer-title small { font-weight: 400; color: var(--muted); }
.viewer-links {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn {
    display: inline-block;
    padding: 0.35rem 0.75rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--fg);
    text-decoration: none;
    font-size: 0.85rem;
    cursor: pointer;
}
.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn.disabled { opacity: 0.4; cursor: default; pointer-events: none; }

#osd-viewer {
    width: 100%;
    height: calc(100vh - 160px);
    min-height: 400px;
    background: #222;
    border-radius: var(--radius);
}

.viewer-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 300px;
    background: #f0f0ee;
    border-radius: var(--radius);
    color: var(--muted);
}

/* Table scroll wrapper for mobile */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Responsive */
@media (max-width: 768px) {
    main { padding: 0.5rem; }
    .data-table { font-size: 0.8rem; }
    .data-table th, .data-table td { padding: 0.35rem 0.5rem; white-space: nowrap; }
    .stats-bar { gap: 0.75rem; font-size: 0.8rem; padding: 0.5rem 0.75rem; }
    .page-grid { grid-template-columns: repeat(auto-fill, minmax(65px, 1fr)); }
    .viewer-header { flex-direction: column; align-items: flex-start; }
    .viewer-nav { flex-wrap: wrap; gap: 0.4rem; }
    .viewer-links { flex-wrap: wrap; gap: 0.4rem; }
    .viewer-title { font-size: 0.9rem; }
    #osd-viewer { height: calc(100vh - 180px); min-height: 300px; }
    .btn { padding: 0.3rem 0.5rem; font-size: 0.8rem; }
    .request-input-wrap input[type="url"] { padding: 0.6rem 0.75rem; font-size: 0.85rem; }
    .footer-about { font-size: 0.75rem; }
    h1 { font-size: 1.3rem; }
    h2 { font-size: 1.1rem; }
}
