/* ============================================================
   前台样式（assets/css/front.css）
   纯手写 CSS，不引用任何外部资源；移动端优先。
   ============================================================ */

:root {
    --bg: #f1f5f9;
    --bg-soft: #f8fafc;
    --card: #ffffff;
    --text: #0f172a;
    --text-soft: #475569;
    --muted: #64748b;
    --line: #e2e8f0;
    --line-strong: #cbd5e1;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-soft: #eff6ff;
    --ok: #059669;
    --ok-soft: #ecfdf5;
    --warn: #b45309;
    --warn-soft: #fffbeb;
    --danger: #dc2626;
    --danger-soft: #fef2f2;
    --header-bg: #0f172a;
    --radius: 14px;
    --radius-sm: 9px;
    --shadow: 0 8px 24px rgba(15, 23, 42, .07);
    --shadow-sm: 0 2px 8px rgba(15, 23, 42, .05);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.65;
}

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

code, .mono {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
    font-size: .92em;
}

code {
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: 5px;
    padding: 1px 5px;
}

.muted { color: var(--muted); }
.strong { font-weight: 700; color: var(--text); }

.wrap {
    width: 100%;
    max-width: 980px;
    margin: 0 auto;
    padding: 0 16px;
}

.skip-link {
    position: absolute;
    left: -9999px;
    top: 0;
    background: #fff;
    color: var(--primary);
    padding: 8px 14px;
    z-index: 99;
}
.skip-link:focus { left: 8px; top: 8px; }

/* ---------------- 头部 ---------------- */

.site-header {
    background: var(--header-bg);
    color: #e2e8f0;
    padding: 12px 0;
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: 0 2px 12px rgba(15, 23, 42, .18);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }

.brand-mark {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 11px;
    background: linear-gradient(135deg, #3b82f6, #22d3ee);
    color: #fff;
    flex: 0 0 auto;
}

.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-text strong {
    font-size: 16px;
    line-height: 1.25;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 60vw;
}
.brand-text small { color: #94a3b8; font-size: 12px; }

.header-nav { display: flex; gap: 4px; flex-wrap: wrap; }
.nav-link {
    color: #cbd5e1;
    font-size: 13px;
    padding: 6px 10px;
    border-radius: 999px;
    white-space: nowrap;
}
.nav-link:hover { background: rgba(148, 163, 184, .18); color: #fff; text-decoration: none; }

/* ---------------- 主体 ---------------- */

.main { padding-top: 18px; padding-bottom: 28px; }

.panel {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    padding: 18px;
    margin-bottom: 16px;
}

.panel-primary { border-color: #bfdbfe; box-shadow: var(--shadow); }

.panel-head { margin-bottom: 14px; }
.panel-head h2 {
    margin: 0 0 4px;
    font-size: 18px;
    line-height: 1.3;
}
.panel-sub { margin: 0; color: var(--muted); font-size: 13px; }

.panel-summary {
    cursor: pointer;
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 2px;
    margin: -4px 0;
    padding: 4px 0;
}
.panel-summary::-webkit-details-marker { display: none; }
.panel-summary .summary-title { font-size: 18px; font-weight: 700; }
.panel-summary .summary-sub { color: var(--muted); font-size: 13px; }
.panel-summary::after {
    content: "展开";
    position: absolute;
    right: 18px;
    color: var(--primary);
    font-size: 13px;
}
details#channels { position: relative; }
details[open].panel-summary-open .summary-title { color: var(--primary); }
.details-body { margin-top: 14px; }

/* ---------------- 概览统计 ---------------- */

.stats {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}
.stat {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 12px 14px;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.stat-num { font-size: 22px; font-weight: 700; line-height: 1.2; }
.stat-num-text { font-size: 15px; font-weight: 600; }
.stat-label { color: var(--muted); font-size: 12px; }

/* ---------------- 提示 ---------------- */

.flash, .notice, .alert, .closed-tip {
    border-radius: var(--radius-sm);
    padding: 11px 14px;
    font-size: 14px;
    margin-bottom: 14px;
    border: 1px solid transparent;
}
.flash { margin-top: 14px; margin-bottom: 0; }
.flash-success, .alert-ok { background: var(--ok-soft); border-color: #a7f3d0; color: #065f46; }
.flash-error, .alert-error { background: var(--danger-soft); border-color: #fecaca; color: #991b1b; }
.flash-warning, .alert-warning { background: var(--warn-soft); border-color: #fde68a; color: #92400e; }
.flash-info, .alert-info { background: var(--primary-soft); border-color: #bfdbfe; color: #1e40af; }
.alert-loading { background: var(--primary-soft); border-color: #bfdbfe; color: #1e40af; }

.notice {
    display: flex;
    gap: 9px;
    align-items: flex-start;
    background: var(--warn-soft);
    border-color: #fde68a;
    color: #92400e;
}
.notice-icon {
    flex: 0 0 auto;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #f59e0b;
    color: #fff;
    font-size: 12px;
    font-weight: 700;
    text-align: center;
    line-height: 18px;
    margin-top: 2px;
}
.closed-tip {
    background: var(--warn-soft);
    border-color: #fde68a;
    color: #92400e;
}
.alert { margin-bottom: 12px; }
.alert:last-child { margin-bottom: 0; }

/* ---------------- 表单 ---------------- */

.inline-form {
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field-grow { flex: 1 1 auto; }
.field-label { font-size: 13px; color: var(--text-soft); font-weight: 600; }

.input {
    width: 100%;
    padding: 11px 13px;
    font-size: 15px;
    color: var(--text);
    background: var(--bg-soft);
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    outline: none;
    -webkit-appearance: none;
    appearance: none;
}
.input:focus {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, .14);
}
.input-lg { font-size: 16px; padding: 13px 14px; letter-spacing: .4px; }
.input::placeholder { color: #94a3b8; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 10px 16px;
    font-size: 14px;
    font-family: inherit;
    font-weight: 600;
    line-height: 1.2;
    color: var(--text);
    background: #fff;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    cursor: pointer;
    white-space: nowrap;
    transition: background .15s, border-color .15s, opacity .15s;
}
.btn:hover { background: var(--bg-soft); }
.btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 1px; }
.btn[disabled] { opacity: .6; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-ghost { background: transparent; border-color: var(--line-strong); color: var(--text-soft); }
.btn-sm { padding: 7px 11px; font-size: 13px; }
.btn-lg { padding: 13px 20px; font-size: 15px; }
.btn-copied { background: var(--ok); border-color: var(--ok); color: #fff; }

.form-hint { margin: 8px 0 0; color: var(--muted); font-size: 12.5px; }
.alert-inline-error { color: var(--danger); }

/* ---------------- 结果卡片 ---------------- */

.result { margin-top: 14px; }

.line-card {
    border: 1px solid #bfdbfe;
    background: linear-gradient(180deg, #f8fbff, #fff 55%);
    border-radius: var(--radius);
    padding: 14px;
    animation: fade-in .22s ease-out;
}
@keyframes fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: none; }
}

.line-card-head {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
    margin-bottom: 8px;
}
.line-kind { font-size: 15px; }
.line-token { margin-left: auto; color: var(--muted); font-size: 12px; }

.line-msg {
    margin: 0 0 10px;
    padding: 9px 12px;
    background: var(--ok-soft);
    border: 1px solid #a7f3d0;
    border-radius: var(--radius-sm);
    color: #065f46;
    font-size: 14px;
}

.line-meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px 12px;
    margin: 0 0 12px;
}
.line-meta > div {
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    min-width: 0;
}
.line-meta dt { color: var(--muted); font-size: 12px; margin: 0 0 2px; }
.line-meta dd { margin: 0; font-size: 14px; word-break: break-all; }

.sub-list { display: flex; flex-direction: column; gap: 8px; }
.sub-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
}
.sub-tag {
    flex: 0 0 auto;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: .5px;
    color: #1e40af;
    background: var(--primary-soft);
    border-radius: 5px;
    padding: 2px 6px;
}
.sub-url {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 12.5px;
    color: var(--text-soft);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.sub-url:hover { color: var(--primary); }

.line-actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin-top: 12px;
}

.extend-form {
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px dashed var(--line-strong);
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.extend-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------- 已记住的线路 ---------------- */

.saved-tip {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
    padding: 10px 12px;
    background: var(--primary-soft);
    border: 1px solid #bfdbfe;
    border-radius: var(--radius-sm);
    font-size: 13px;
}
.saved-actions { display: flex; gap: 8px; margin-left: auto; }
.saved-tip code { background: #fff; }

/* ---------------- 表格 ---------------- */

.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td {
    text-align: left;
    padding: 10px 12px;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}
.table th {
    color: var(--muted);
    font-size: 12.5px;
    font-weight: 600;
    background: var(--bg-soft);
    white-space: nowrap;
}
.table tr:last-child td { border-bottom: 0; }

.badge {
    display: inline-block;
    padding: 2px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    line-height: 1.6;
    border: 1px solid transparent;
}
.badge-soft { background: var(--primary-soft); color: #1e40af; border-color: #bfdbfe; }
.badge-ok { background: var(--ok-soft); color: #065f46; border-color: #a7f3d0; }
.badge-warn { background: var(--warn-soft); color: #92400e; border-color: #fde68a; }
.badge-danger { background: var(--danger-soft); color: #991b1b; border-color: #fecaca; }

/* ---------------- 使用说明 ---------------- */

.steps { margin: 0; padding-left: 20px; }
.steps li { margin-bottom: 8px; }
.steps li:last-child { margin-bottom: 0; }

/* ---------------- 频道速查 ---------------- */

.channel-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
    margin-top: 12px;
}
.channel-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 9px 11px;
    background: var(--bg-soft);
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    font-size: 13.5px;
    font-family: inherit;
    color: var(--text);
    cursor: pointer;
    text-align: left;
}
.channel-item:hover { border-color: var(--primary); background: var(--primary-soft); }
.channel-item.active { border-color: var(--primary); background: var(--primary-soft); }
.channel-count { color: var(--muted); font-size: 12px; flex: 0 0 auto; }

.channel-detail {
    margin-top: 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 12px;
    background: var(--bg-soft);
}
.channel-detail h3 { margin: 0 0 10px; font-size: 15px; }
.url-row {
    display: flex;
    align-items: center;
    gap: 8px;
    background: #fff;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px 9px;
    margin-bottom: 7px;
}
.url-row:last-child { margin-bottom: 0; }
.url-index {
    flex: 0 0 auto;
    width: 20px;
    color: var(--muted);
    font-size: 12px;
    text-align: right;
}
.url-text {
    flex: 1 1 auto;
    min-width: 0;
    font-size: 12.5px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.url-type {
    flex: 0 0 auto;
    font-size: 11px;
    color: var(--muted);
    border: 1px solid var(--line);
    border-radius: 4px;
    padding: 1px 5px;
}

.pager {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-top: 12px;
    font-size: 13px;
}

/* ---------------- 底部 & 提示条 ---------------- */

.site-footer {
    border-top: 1px solid var(--line);
    background: #fff;
    padding: 16px 0 calc(16px + env(safe-area-inset-bottom));
    color: var(--muted);
    font-size: 12.5px;
}
.site-footer p { margin: 0 0 4px; }
.site-footer p:last-child { margin-bottom: 0; }

.toast {
    position: fixed;
    left: 50%;
    bottom: calc(24px + env(safe-area-inset-bottom));
    transform: translateX(-50%);
    max-width: 88vw;
    background: #0f172a;
    color: #f8fafc;
    padding: 10px 16px;
    border-radius: 999px;
    font-size: 13.5px;
    box-shadow: 0 10px 26px rgba(15, 23, 42, .28);
    z-index: 60;
    animation: fade-in .18s ease-out;
}
.toast-error { background: #b91c1c; }

/* ---------------- 宽屏 ---------------- */

@media (min-width: 720px) {
    body { font-size: 15.5px; }
    .wrap { padding: 0 22px; }
    .main { padding-top: 24px; padding-bottom: 36px; }
    .panel { padding: 22px; margin-bottom: 20px; }
    .panel-head h2 { font-size: 19px; }
    .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .inline-form { flex-direction: row; align-items: flex-end; }
    .inline-form .btn { flex: 0 0 auto; }
    .line-meta { grid-template-columns: repeat(4, minmax(0, 1fr)); }
    .line-card { padding: 18px; }
    .brand-text strong { max-width: none; }
    .col-hide-sm { display: table-cell; }
}

@media (max-width: 719px) {
    .col-hide-sm { display: none; }
    .header-nav { width: 100%; }
    .panel-summary::after { display: none; }
    .line-token { margin-left: 0; width: 100%; }
    .saved-actions { margin-left: 0; width: 100%; }
    .sub-row { flex-wrap: wrap; }
    .sub-url { flex-basis: 100%; order: 3; }
    .url-row { flex-wrap: wrap; }
    .url-text { flex-basis: 100%; order: 3; white-space: normal; word-break: break-all; }
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}
