:root {
    --ink: #0f172a;
    --ink-2: #334155;
    --muted: #64748b;
    --line: #e2e8f0;
    --line-2: #cbd5e1;
    --bg: #f5f7f7;
    --card: #ffffff;
    --primary: #0f766e;
    --primary-d: #0b5c56;
    --primary-l: #e6f4f1;
    --amber: #b45309;
    --amber-l: #fef3e2;
    --danger: #b91c1c;
    --radius: 14px;
    --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -12px rgba(15, 23, 42, .12);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", sans-serif;
    font-size: 15px;
    line-height: 1.6;
}

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

.wrap { max-width: 1240px; margin: 0 auto; padding: 0 24px; }

/* 顶栏 */
.topbar {
    background: rgba(255, 255, 255, .92);
    backdrop-filter: blur(8px);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar-inner { display: flex; align-items: center; justify-content: space-between; height: 64px; }
.brand { display: flex; align-items: center; gap: 12px; color: var(--ink); }
.brand-mark {
    width: 36px; height: 36px; border-radius: 10px;
    background: linear-gradient(135deg, var(--primary), #159a8d);
    color: #fff; display: grid; place-items: center;
    font-weight: 700; font-size: 17px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; letter-spacing: .3px; }
.brand-text small { color: var(--muted); font-size: 12px; }
.nav { display: flex; gap: 6px; }
.nav a {
    padding: 7px 14px; border-radius: 9px; color: var(--ink-2);
    font-size: 14px; transition: .15s;
}
.nav a:hover { background: #eef2f2; }
.nav a.on { background: var(--primary-l); color: var(--primary-d); font-weight: 600; }

main.wrap { padding-top: 26px; padding-bottom: 60px; }

/* 提示条 */
.flashes { display: flex; flex-direction: column; gap: 10px; margin-bottom: 18px; }
.flash {
    padding: 11px 16px; border-radius: 10px; font-size: 14px;
    border: 1px solid transparent; white-space: pre-wrap;
}
.flash-ok { background: #ecfdf5; border-color: #a7f3d0; color: #065f46; }
.flash-warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.flash-error { background: #fef2f2; border-color: #fecaca; color: var(--danger); }

/* 卡片 */
.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 22px 24px;
    margin-bottom: 20px;
}
.card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.card-head.compact { margin-bottom: 10px; align-items: center; }
.card-head h2 { margin: 0 0 2px; font-size: 16px; letter-spacing: .2px; }
.muted { color: var(--muted); font-size: 13px; }

/* Hero */
.hero {
    display: flex; gap: 28px; align-items: center; justify-content: space-between;
    background: linear-gradient(135deg, #0f766e 0%, #127f74 45%, #17a394 100%);
    color: #fff; border-radius: var(--radius); padding: 26px 28px; margin-bottom: 20px;
    box-shadow: 0 16px 36px -22px rgba(15, 118, 110, .8);
    flex-wrap: wrap;
}
.hero h1 { margin: 0 0 6px; font-size: 22px; letter-spacing: .5px; }
.hero p { margin: 0; font-size: 13.5px; color: rgba(255, 255, 255, .82); max-width: 640px; }
.hero-stats { display: flex; gap: 10px; flex-wrap: wrap; }
.stat {
    background: rgba(255, 255, 255, .13);
    border: 1px solid rgba(255, 255, 255, .18);
    border-radius: 11px; padding: 9px 16px; min-width: 76px; text-align: center;
}
.stat b { display: block; font-size: 20px; line-height: 1.2; }
.stat span { font-size: 12px; color: rgba(255, 255, 255, .78); }

/* 数据提示 */
.notice {
    background: #fffbeb; border: 1px solid #fcd34d; border-left: 4px solid #d97706;
    border-radius: 10px; padding: 14px 18px; margin-bottom: 20px;
}
.notice strong { display: block; font-size: 14px; color: #92400e; margin-bottom: 6px; }
.notice p { margin: 4px 0; font-size: 13px; color: #78350f; line-height: 1.7; }

/* 上传 */
.upload-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.upload-grid-single { grid-template-columns: minmax(0, 1fr); max-width: 560px; }
.hero-small h1 { font-size: 19px; }
.check {
    display: inline-flex; align-items: center; gap: 8px; margin-top: 16px;
    font-size: 13.5px; color: var(--ink-2); cursor: pointer;
}
.check input { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }
.muted.small { font-size: 12.5px; line-height: 1.8; margin-top: 8px; max-width: 720px; }

/* 状态标签 */
.tag {
    display: inline-block; padding: 2px 9px; border-radius: 999px;
    font-size: 12px; font-weight: 600; line-height: 1.7;
}
.tag-ok { background: #ecfdf5; color: #047857; }
.tag-warn { background: #fef2f2; color: #b91c1c; }
.tag-info { background: #eff6ff; color: #1d4ed8; }

.drop {
    position: relative; display: flex; flex-direction: column; gap: 4px;
    border: 1.5px dashed var(--line-2); border-radius: 12px;
    padding: 18px 18px 16px; cursor: pointer; transition: .16s; background: #fcfdfd;
}
.drop:hover { border-color: var(--primary); background: var(--primary-l); }
.drop input[type=file] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop-title { font-weight: 650; font-size: 14.5px; }
.drop-hint { color: var(--muted); font-size: 12.5px; }
.file-name {
    margin-top: 8px; font-size: 12.5px; color: var(--muted);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.file-name.has-file { color: var(--primary-d); font-weight: 600; }

.actions { display: flex; align-items: center; gap: 12px; margin-top: 18px; flex-wrap: wrap; }
.actions form.inline { display: inline; }

/* 按钮 */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    border-radius: 9px; padding: 9px 18px; font-size: 14px; font-weight: 600;
    border: 1px solid transparent; cursor: pointer; transition: .15s;
    font-family: inherit; line-height: 1.4;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-d); color: #fff; }
.btn-ghost { background: #fff; border-color: var(--line-2); color: var(--ink-2); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary-d); }
.btn-danger-ghost { background: #fff; border-color: #f3c8c8; color: var(--danger); }
.btn-danger-ghost:hover { background: #fef2f2; }
.btn-small { padding: 6px 12px; font-size: 13px; background: var(--primary-l); color: var(--primary-d); }
.btn-small:hover { background: #d6ebe6; }

/* 批次表 */
.batch-table table { width: 100%; border-collapse: collapse; font-size: 14px; }
.batch-table th, .batch-table td {
    text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line);
}
.batch-table th { color: var(--muted); font-weight: 600; font-size: 13px; background: #fafbfb; }
.batch-table tr:last-child td { border-bottom: none; }

/* 规则说明 */
.rule-note {
    margin-top: 16px; padding: 14px 18px; background: #fafbfb;
    border: 1px solid var(--line); border-radius: 11px;
}
.rule-note h3 { margin: 0 0 8px; font-size: 13.5px; color: var(--ink-2); }
.rule-note ul { margin: 0; padding-left: 20px; }
.rule-note li { font-size: 13px; color: var(--ink-2); margin-bottom: 3px; }

/* 空状态 */
.empty-state { text-align: center; padding: 46px 24px; }
.empty-state h2 { margin: 0 0 8px; font-size: 17px; }
.code {
    display: inline-block; background: #0f172a; color: #d1fae5; padding: 12px 18px;
    border-radius: 9px; font-size: 13px; font-family: ui-monospace, Menlo, Consolas, monospace;
    margin: 10px 0;
}

/* 结果布局 */
.result-layout { display: grid; grid-template-columns: 268px 1fr; gap: 20px; align-items: start; }
.session-list { padding: 16px 14px; position: sticky; top: 84px; max-height: calc(100vh - 110px); overflow: auto; }
.session-items { display: flex; flex-direction: column; gap: 6px; }
.session-item {
    display: flex; flex-direction: column; gap: 1px; padding: 10px 12px;
    border-radius: 9px; border: 1px solid transparent; color: var(--ink);
}
.session-item:hover { background: #f6f8f8; }
.session-item.on { background: var(--primary-l); border-color: #b9ded8; }
.si-sub { font-weight: 650; font-size: 14px; }
.si-meta { font-size: 12px; color: var(--muted); }
.si-count { font-size: 11.5px; color: var(--primary-d); }

.head-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.session-edit {
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    padding: 10px 14px; background: #fafbfb; border: 1px solid var(--line);
    border-radius: 10px; font-size: 13px;
}
.session-edit label { display: inline-flex; align-items: center; gap: 6px; color: var(--ink-2); }
.session-edit input {
    border: 1px solid var(--line-2); border-radius: 7px; padding: 5px 9px;
    font-size: 13px; font-family: inherit; color: var(--ink); background: #fff; width: 120px;
}
.session-edit input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15,118,110,.12); }

.room-grid {
    display: grid; grid-template-columns: repeat(auto-fill, minmax(330px, 1fr)); gap: 16px;
}
.room-card {
    background: #fff; border: 1px solid var(--line); border-radius: 12px;
    box-shadow: var(--shadow); overflow: hidden;
}
.room-head {
    display: flex; align-items: center; gap: 8px; padding: 11px 14px;
    background: #fafbfb; border-bottom: 1px solid var(--line); font-size: 14px;
}
.pill {
    font-size: 11.5px; padding: 1px 8px; border-radius: 20px;
    background: var(--primary-l); color: var(--primary-d); font-weight: 600;
}
.pill-merge { background: var(--amber-l); color: var(--amber); }
.seat-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.seat-table th {
    text-align: left; padding: 6px 10px; color: var(--muted); font-weight: 600;
    background: #fff; border-bottom: 1px solid var(--line);
}
.seat-table td { padding: 5px 10px; border-bottom: 1px solid #f1f5f5; }
.seat-table tr:last-child td { border-bottom: none; }
.seat-table td.num { color: var(--muted); width: 44px; }
.seat-table td.major { color: var(--ink-2); max-width: 130px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.footer {
    display: flex; justify-content: space-between; gap: 16px; padding: 24px;
    color: var(--muted); font-size: 12.5px; flex-wrap: wrap;
}

/* 打印 */
.print-mode { background: #fff; }
.print-main { padding: 0; }
.print-bar {
    position: sticky; top: 0; z-index: 10; display: flex; align-items: center; gap: 12px;
    padding: 12px 24px; background: #fff; border-bottom: 1px solid var(--line); margin-bottom: 20px;
}
.print-page {
    padding: 0 24px 28px; page-break-after: always; break-after: page;
    max-width: 900px; margin: 0 auto;
}
.print-page:last-child { page-break-after: auto; break-after: auto; }
.pp-head { text-align: center; padding: 6px 0 12px; border-bottom: 2px solid var(--ink); margin-bottom: 4px; }
.pp-head h1 { margin: 0 0 6px; font-size: 19px; letter-spacing: 2px; }
.pp-meta { display: flex; justify-content: center; gap: 16px; font-size: 12.5px; color: var(--ink-2); flex-wrap: wrap; }
.pp-room { font-weight: 700; }
.pp-table { width: 100%; border-collapse: collapse; font-size: 12.5px; margin-top: 8px; }
.pp-table th {
    border: 1px solid var(--line-2); background: #f7f9f9; padding: 6px 8px;
    font-weight: 600; font-size: 12px;
}
.pp-table td { border: 1px solid var(--line-2); padding: 5px 8px; height: 24px; }
.pp-table td.c { text-align: center; }
.pp-table td.small { font-size: 11px; color: var(--ink-2); }
.pp-table td.strong { font-weight: 700; font-size: 13px; }
.pp-foot {
    display: flex; justify-content: space-between; margin-top: 10px;
    font-size: 12px; color: var(--ink-2);
}

@page { size: A4; margin: 13mm 12mm; }

@media print {
    html, body { background: #fff; font-size: 12px; }
    .print-bar { display: none !important; }
    .print-page { padding: 0; max-width: none; margin: 0; }
    .pp-table th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .pp-foot { margin-bottom: 0; }
}

@media (max-width: 1000px) {
    .result-layout { grid-template-columns: 1fr; }
    .session-list { position: static; max-height: none; }
    .session-items { flex-direction: row; overflow-x: auto; }
    .session-item { min-width: 190px; }
}
@media (max-width: 760px) {
    .upload-grid { grid-template-columns: 1fr; }
    .hero { padding: 20px; }
    .wrap { padding: 0 16px; }
}

/* 考场一览表 */
.overview-form .field { margin-bottom: 14px; max-width: 780px; }
.overview-form .field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink-2); }
.overview-form input[type=text],
.overview-form textarea {
    width: 100%; padding: 9px 12px; border: 1px solid var(--line-2); border-radius: 9px;
    font-family: inherit; font-size: 14px; color: var(--ink); background: #fff; line-height: 1.6;
}
.overview-form textarea { resize: vertical; }
.overview-form input[type=text]:focus,
.overview-form textarea:focus { outline: none; border-color: var(--primary); }
.overview-form .field-inline { margin-top: 4px; }
.overview-form .check { margin-top: 0; }

.table-scroll { overflow-x: auto; margin-top: 4px; padding-bottom: 4px; }
.sheet-table { border-collapse: collapse; font-size: 12.5px; margin: 0 auto; }
.sheet-table th,
.sheet-table td {
    border: 1px solid var(--line-2); padding: 5px 8px;
    text-align: center; vertical-align: middle; white-space: nowrap;
}
.sheet-table thead th { background: #f4f6f7; font-weight: 600; color: var(--ink-2); }
.sheet-table th.sheet-title { font-size: 15px; padding: 10px 8px; color: var(--ink); }
.sheet-subject { text-align: center; min-width: 140px; white-space: normal; }
.sheet-subject span { display: block; line-height: 1.55; }
.sheet-empty { color: #c9ced1; }
.sheet-note { text-align: left; font-size: 12px; color: var(--muted); white-space: normal; }
.sheet-table tfoot th,
.sheet-table tfoot td { background: #fafbfb; }

/* 编排规则卡片 */
.rule-head-actions { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.rule-list {
    margin: 4px 0 0; padding: 14px 18px 14px 34px;
    background: #fafbfb; border: 1px solid var(--line); border-radius: 11px;
}
.rule-list li { font-size: 13.5px; color: var(--ink-2); margin-bottom: 5px; line-height: 1.65; }
.rule-list li:last-child { margin-bottom: 0; }
#rules-stale { margin: 10px 0 0; color: var(--amber); }
.hidden { display: none !important; }

/* 对话框 */
.modal {
    width: min(620px, calc(100vw - 32px));
    max-height: calc(100vh - 64px);
    padding: 0; border: none; border-radius: 16px;
    background: #fff; color: var(--ink);
    box-shadow: 0 24px 60px -20px rgba(15, 23, 42, .45);
    overflow: hidden;
}
.modal::backdrop { background: rgba(15, 23, 42, .42); backdrop-filter: blur(2px); }
.modal[open] { display: flex; flex-direction: column; animation: modal-in .16s ease-out; }
@keyframes modal-in {
    from { opacity: 0; transform: translateY(-6px) scale(.99); }
    to { opacity: 1; transform: none; }
}
.modal form { display: flex; flex-direction: column; min-height: 0; max-height: inherit; }
.modal-head {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    padding: 16px 22px; border-bottom: 1px solid var(--line); background: #fafbfb;
}
.modal-head h2 { margin: 0; font-size: 16px; }
.modal-x {
    border: none; background: transparent; font-size: 22px; line-height: 1;
    color: var(--muted); cursor: pointer; padding: 2px 6px; border-radius: 8px;
}
.modal-x:hover { background: #eef2f2; color: var(--ink); }
.modal-body { padding: 18px 22px 4px; overflow: auto; }
.modal-tip { margin: 0 0 14px; font-size: 12.5px; color: var(--muted); }
.modal-tip em { color: var(--danger); font-style: normal; }
.modal-foot {
    display: flex; justify-content: flex-end; gap: 10px;
    padding: 14px 22px; border-top: 1px solid var(--line); background: #fafbfb;
}

.modal .field { margin-bottom: 16px; }
.modal .field > label { display: block; font-size: 13.5px; font-weight: 650; color: var(--ink-2); margin-bottom: 6px; }
.modal .field > label em { color: var(--danger); font-style: normal; font-weight: 400; }
.modal select,
.modal input[type=number],
.modal textarea {
    width: 100%; padding: 9px 12px; border: 1px solid var(--line-2); border-radius: 9px;
    font-family: inherit; font-size: 14px; color: var(--ink); background: #fff; line-height: 1.6;
}
.modal input[type=number] { max-width: 140px; }
.modal select:focus,
.modal input[type=number]:focus,
.modal textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(15, 118, 110, .12); }
.modal textarea { resize: vertical; }
.field-hint { margin: 5px 0 0; font-size: 12px; color: var(--muted); line-height: 1.6; }
.field-err { margin: 4px 0 0; font-size: 12px; color: var(--danger); }
.field-err:empty { display: none; }
.field.has-err select,
.field.has-err input[type=number],
.field.has-err textarea { border-color: var(--danger); background: #fffafa; }
.form-alert {
    margin: 0 0 14px; padding: 10px 14px; border-radius: 9px; font-size: 13px;
    background: #fef2f2; border: 1px solid #fecaca; color: var(--danger); white-space: pre-wrap;
}
.btn[disabled] { opacity: .65; cursor: default; }

/* 轻提示 */
.toast-host {
    position: fixed; left: 50%; top: 20px; transform: translateX(-50%);
    z-index: 60; display: flex; flex-direction: column; gap: 8px;
    width: min(560px, calc(100vw - 32px)); pointer-events: none;
}
.toast-host .flash { box-shadow: 0 10px 30px -12px rgba(15, 23, 42, .3); transition: opacity .3s, transform .3s; }
.toast-host .flash.toast-out { opacity: 0; transform: translateY(-6px); }

@media (max-width: 560px) {
    .modal { width: 100vw; max-height: 100vh; border-radius: 0; }
    .modal-foot { flex-direction: column-reverse; }
    .modal-foot .btn { width: 100%; }
}
