:root {
    --bg: #f4f1ea;
    --ink: #1c1917;
    --muted: #78716c;
    --card: #fffaf3;
    --line: #e7e0d6;
    --accent: #0f766e;
    --accent-ink: #fff;
    --danger: #b91c1c;
    --warn: #c2410c;
    --ok: #15803d;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
    font: 15px/1.45 "Segoe UI", system-ui, sans-serif;
    color: var(--ink);
    background: var(--bg);
}

a { color: var(--accent); }
code { font-size: 12px; background: #efe8dc; padding: 1px 5px; border-radius: 4px; }

.top {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 12px 20px;
    background: #1c1917;
    color: #fafaf9;
}
.brand { font-weight: 700; letter-spacing: .02em; }
.nav { display: flex; gap: 4px; }
.nav a {
    color: #d6d3d1;
    text-decoration: none;
    padding: 6px 10px;
    border-radius: 8px;
    font-size: 14px;
}
.nav a:hover { color: #fff; background: #292524; }
.nav a.active { color: #fff; background: #44403c; }
.status {
    font-size: 12px;
    padding: 4px 10px;
    border-radius: 999px;
    background: #292524;
}
.status.on { background: #14532d; }
.status.off { background: #7f1d1d; }
.spacer { flex: 1; }
.user { color: #a8a29e; font-size: 13px; }

.main { padding: 20px 16px; max-width: none; margin: 0; }
.main-login {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card { width: min(380px, 100%); }
.login-card h1 { margin: 0 0 6px; font-size: 22px; }
.muted { color: var(--muted); margin: 0 0 18px; }

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 22px;
}

label { display: grid; gap: 6px; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
input[type="text"], input[type="password"], input[type="search"] {
    width: 100%;
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 8px;
    padding: 9px 11px;
    font: inherit;
    color: inherit;
}

.btn, button.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--ink);
    border-radius: 8px;
    padding: 8px 12px;
    font: inherit;
    cursor: pointer;
    text-decoration: none;
}
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); width: 100%; }
.btn-ghost { background: transparent; border-color: #44403c; color: #fafaf9; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-warn { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn-ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 13px; }

.toolbar, .toolbar-actions, .search, .inline-form, .table-meta, .pager {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}
.toolbar { justify-content: space-between; margin-bottom: 16px; }
.search input { min-width: 260px; }

.alert { padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; }
.alert-ok, .alert-success { background: #dcfce7; color: #14532d; }
.alert-error { background: #fee2e2; color: #7f1d1d; }

.table-meta { justify-content: space-between; margin-bottom: 8px; color: var(--muted); font-size: 13px; }
.table-meta-actions, .latest-download { display: flex; gap: 8px; align-items: center; }
.latest-download-label { display: flex; align-items: center; gap: 6px; margin: 0; color: inherit; font-size: 13px; }
.latest-download-label input { width: 72px; padding: 6px 8px; }
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.captures {
    width: 100%;
    min-width: 1100px;
    border-collapse: collapse;
    table-layout: fixed;
}
.captures col.col-check { width: 40px; }
.captures col.col-id { width: 56px; }
.captures col.col-date { width: 158px; }
.captures col.col-login { width: 108px; }
.captures col.col-algo { width: 76px; }
.captures col.col-serp { width: 58px; }
.captures col.col-url { width: auto; }
.captures col.col-file { width: 128px; }
.captures col.col-size { width: 76px; }
.captures col.col-ip { width: 124px; }
.captures col.col-act { width: 76px; }
.captures th, .captures td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.captures th { font-size: 12px; color: var(--muted); font-weight: 600; background: #faf6ef; }
.captures .col-check { text-align: center; }
.captures .col-id,
.captures .col-serp,
.captures .col-size { text-align: right; }
.captures td.col-url { min-width: 0; }
.captures td.col-file { white-space: nowrap; }
.captures td.col-file a + a { margin-left: 8px; }
.nowrap { white-space: nowrap; }
.url-cell {
    display: flex;
    align-items: center;
    gap: 8px;
    min-width: 0;
    max-width: 100%;
}
.url-link {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
    text-decoration: none;
    color: inherit;
    line-height: 1.25;
}
.url-host,
.url-path {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.url-host { font-size: 13px; font-weight: 650; color: var(--ink); }
.url-path { font-size: 12px; color: var(--muted); }
.url-link:hover .url-host { color: var(--accent); }
.url-copy {
    flex: 0 0 auto;
    border: 1px solid var(--line);
    background: #fff;
    color: var(--muted);
    border-radius: 6px;
    padding: 3px 7px;
    font: 11px/1.2 inherit;
    cursor: pointer;
}
.url-copy:hover { color: var(--ink); border-color: #d6cfc3; }
.empty { text-align: center; color: var(--muted); padding: 28px; white-space: normal; }
.link-danger {
    border: 0; background: none; color: var(--danger); cursor: pointer; font: inherit; padding: 0;
}

.pager { margin-top: 14px; }
.pager a {
    min-width: 32px; text-align: center; padding: 6px 8px; border-radius: 6px;
    text-decoration: none; border: 1px solid var(--line); color: inherit; background: #fff;
}
.pager a.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.settings {
    display: grid;
    gap: 16px;
    max-width: 920px;
}
.settings-wide { max-width: 1100px; }
.stats-head {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}
.stats-head h1 { margin: 0; font-size: 22px; }
.stats-filter label { margin: 0; }
.stats-filter select {
    border: 1px solid var(--line);
    background: #fff;
    border-radius: 8px;
    padding: 8px 10px;
    font: inherit;
}
.stat-cards {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin: 16px 0;
}
.stat-card { padding: 16px 18px; }
.stat-label { font-size: 12px; color: var(--muted); }
.stat-value { font-size: 28px; font-weight: 700; letter-spacing: -.02em; margin: 4px 0; }
.stat-sub { font-size: 12px; color: var(--muted); }
.chart-legend {
    display: flex;
    gap: 16px;
    flex-wrap: wrap;
    font-size: 13px;
    color: var(--muted);
    margin-bottom: 12px;
}
.chart-legend .dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 999px;
    margin-right: 6px;
    vertical-align: middle;
}
.dot.saved, .seg.saved { background: var(--ok); }
.dot.skipped, .seg.skipped { background: var(--warn); }
.dot.rejected, .seg.rejected { background: var(--danger); }
.chart-card h2 { margin: 0 0 14px; font-size: 16px; }
.chart-card { margin-bottom: 14px; }
.chart {
    display: grid;
    grid-template-columns: repeat(var(--n), minmax(0, 1fr));
    gap: 4px;
    align-items: end;
    height: 180px;
}
.chart-col { display: flex; flex-direction: column; height: 100%; min-width: 0; }
.chart-track {
    flex: 1;
    display: flex;
    align-items: flex-end;
    background: #f3eee6;
    border-radius: 4px 4px 0 0;
    overflow: hidden;
}
.chart-bar {
    width: 100%;
    display: flex;
    flex-direction: column-reverse;
    min-height: 0;
}
.seg { display: block; width: 100%; }
.chart-label {
    font-size: 10px;
    color: var(--muted);
    text-align: center;
    margin-top: 6px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
@media (max-width: 900px) {
    .stat-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
.stream-tabs {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin: 0 0 10px;
}
.stream-tabs a {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    border-radius: 8px;
    background: #fff;
    border: 1px solid var(--line);
    color: var(--ink);
    text-decoration: none;
    font-size: 13px;
}
.stream-tabs a.active { background: var(--accent); border-color: var(--accent); color: #fff; }
.stream-tabs .tab-count {
    font-size: 11px;
    opacity: .75;
}
.stream-tabs .tab-add { color: var(--muted); }
.stream-desc { margin: 0 0 14px; color: var(--muted); font-size: 13px; }
.stream-create {
    display: grid;
    grid-template-columns: 180px 1fr auto;
    gap: 10px;
    align-items: end;
}
.stream-create label { margin: 0; }
.stream-create .btn { width: auto; height: 40px; }
.inline-delete { display: inline; }
.check-label {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--ink);
    margin-bottom: 12px;
}
.settings h2 { margin: 0 0 14px; font-size: 18px; }
.settings h3 { margin: 18px 0 10px; font-size: 14px; }
.password-form { max-width: 360px; }
.password-form .btn { width: auto; }
.help-lead { margin: 0 0 16px; }
.help-url {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}
.help-label { font-size: 12px; color: var(--muted); }
.help-endpoint {
    font-size: 13px;
    padding: 6px 8px;
    background: #efe8dc;
    border-radius: 6px;
}
.help-table-wrap { overflow: auto; }
.help-table { width: 100%; border-collapse: collapse; table-layout: auto; }
.help-table th, .help-table td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    white-space: normal;
    overflow: visible;
    vertical-align: top;
    line-height: 1.4;
}
.help-table th { font-size: 12px; color: var(--muted); font-weight: 600; background: #faf6ef; }
.help-table td:first-child { width: 180px; white-space: nowrap; }
.help-table td:nth-child(2) { width: 220px; color: var(--muted); font-size: 13px; }
.streams-table { width: 100%; border-collapse: collapse; table-layout: auto; }
.streams-table th, .streams-table td {
    text-align: left;
    padding: 8px 10px;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
    line-height: 1.4;
}
.streams-table th { font-size: 12px; color: var(--muted); font-weight: 600; background: #faf6ef; }
