:root {
  --bg: #f4f6fa;
  --panel: #ffffff;
  --line: #e3e8ef;
  --text: #1d2733;
  --muted: #7b8798;
  --brand: #245bd6;
  --brand-soft: #eaf1ff;
  --ok: #16845b;
  --warn: #b7791f;
  --err: #c53030;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(20, 34, 56, .07);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.55 -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #f0f3f8; border-radius: 4px; padding: 1px 5px; font-size: 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 12.5px; }
.req { color: var(--err); }

.app { display: flex; min-height: 100vh; }
.sidebar { width: 214px; flex: 0 0 214px; background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: 10px; padding: 20px 18px; border-bottom: 1px solid var(--line); font-weight: 700; }
.brand-mark { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 8px; background: var(--brand); color: #fff; font-size: 15px; }
.brand-text { font-size: 14px; }
.nav { padding: 12px 10px; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 9px 12px; border-radius: 7px; color: #465569; margin-bottom: 3px; }
.nav-item:hover { background: #f6f8fc; text-decoration: none; }
.nav-item.active { background: var(--brand-soft); color: var(--brand); font-weight: 600; }
.nav-dot { width: 6px; height: 6px; border-radius: 50%; background: #c3ccda; }
.nav-item.active .nav-dot { background: var(--brand); }
.sidebar-foot { padding: 14px 18px; border-top: 1px solid var(--line); color: var(--muted); font-size: 11px; }

.main { flex: 1; min-width: 0; }
.topbar { height: 60px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; }
.topbar-title { font-weight: 700; font-size: 16px; }
.topbar-user { display: flex; align-items: center; gap: 10px; color: #465569; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-admin { background: var(--brand-soft); color: var(--brand); }
.badge-agent { background: #fff4e2; color: var(--warn); }
.inline-form { display: inline; margin: 0; }
.link-btn { border: 0; background: none; color: var(--brand); cursor: pointer; padding: 0; font: inherit; }
.link-btn:hover { text-decoration: underline; }
.content { padding: 22px 24px 40px; max-width: 1480px; }

.flash { padding: 10px 14px; border-radius: 8px; margin-bottom: 14px; border: 1px solid; }
.flash.ok { background: #eefbf5; border-color: #b8e6d2; color: var(--ok); }
.flash.err { background: #fff2f2; border-color: #f4c7c7; color: var(--err); }

.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px 20px; margin-bottom: 18px; }
.card.narrow { max-width: 680px; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.card h2 { font-size: 16px; margin: 0 0 14px; }
.card-head h2 { margin: 0; }
.actions { display: flex; gap: 8px; }

.btn { display: inline-block; border: 1px solid #d3dbe7; background: #fff; color: #35435a; padding: 7px 13px; border-radius: 7px; cursor: pointer; font: inherit; font-size: 13px; }
.btn:hover { background: #f7f9fc; text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: #1c4fbd; }
.btn.danger { background: #fff; border-color: #f4c7c7; color: var(--err); }
.btn.danger:hover { background: #fff2f2; }
.btn.ghost { background: #fff; }
.btn.small { padding: 4px 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.filters, .filter-row { display: flex; flex-wrap: wrap; gap: 9px; margin-bottom: 14px; }
.filters input, .filters select, .filter-row input, input, select, textarea {
  border: 1px solid #d5dde8; border-radius: 7px; padding: 7px 10px; background: #fff; color: var(--text); font: inherit; font-size: 13px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid #cfe0ff; border-color: var(--brand); }
.filters input[type=text] { min-width: 190px; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: middle; white-space: nowrap; }
th { background: #f8fafd; color: #5b687a; font-weight: 600; font-size: 12px; }
tbody tr:hover { background: #fafcff; }
td .sub { color: var(--muted); font-size: 11px; }
td.check, th.check { width: 34px; }
.ops { display: flex; align-items: center; gap: 10px; }
.link { border: 0; background: none; padding: 0; color: var(--brand); cursor: pointer; font: inherit; }
.link:hover { text-decoration: underline; }
.link.danger { color: var(--err); }
.pill { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 11px; background: #eef1f6; color: #5b687a; }
.pill.active, .pill.ok { background: #e8f8f0; color: var(--ok); }
.pill.idle { background: #eef1f6; color: #5b687a; }
.pill.disabled, .pill.err { background: #fdeeee; color: var(--err); }
.pager { display: flex; align-items: center; gap: 8px; margin-top: 14px; color: var(--muted); font-size: 12px; }
.pager-last { white-space: nowrap; }
.pager-jump { display: inline-flex; align-items: center; gap: 5px; margin: 0; }
.pager-jump-input { width: 58px; text-align: center; padding: 7px 8px; border: 1px solid #d3dbe7; border-radius: 7px; background: #fff; color: var(--text); font: inherit; font-size: 13px; }
.pager-jump-input:focus { outline: 2px solid #cfe0ff; border-color: var(--brand); }
@media (max-width: 860px) { .pager-cards { flex-wrap: wrap; } }

.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 14px; margin-bottom: 18px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
.stat.warn { border-left: 3px solid var(--warn); }
.stat-label { color: var(--muted); font-size: 12px; }
.stat-value { font-size: 26px; font-weight: 700; margin-top: 6px; }

.form { display: flex; flex-direction: column; gap: 14px; margin-top: 8px; }
.form label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: #465569; }
.form.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form.two-col .full, .form .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 10px; margin-top: 6px; }
.form-actions.full { grid-column: 1 / -1; }
.hint { color: var(--muted); font-size: 12px; margin: 0; }
.detail { display: grid; grid-template-columns: 100px 1fr; gap: 8px 14px; margin: 10px 0 18px; font-size: 13px; }
.detail dt { color: var(--muted); }
.detail dd { margin: 0; }
.notes { margin: 0; padding-left: 20px; color: #465569; line-height: 1.9; }
.result { background: #f7f9fc; border: 1px solid var(--line); border-radius: 8px; padding: 12px; min-height: 70px; max-height: 260px; overflow: auto; font-size: 12px; white-space: pre-wrap; word-break: break-all; }
.break-all { word-break: break-all; }
.group-title { grid-column: 1 / -1; margin-top: 6px; padding-bottom: 6px; border-bottom: 1px solid var(--line); font-weight: 700; color: #24344a; }
fieldset.group-title { border: 0; border-top: 1px solid var(--line); padding: 10px 0 4px; margin-top: 4px; }
fieldset.group-title legend { padding: 0 8px 0 0; font-weight: 700; color: #24344a; font-size: 13px; }
.form label.check-line { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; padding: 4px 0; cursor: pointer; }
.form label.check-line input { width: 15px; height: 15px; }

.standalone { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 24px; }
.login-box { width: 100%; max-width: 400px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 28px; box-shadow: var(--shadow); }
.login-box h1 { font-size: 20px; margin: 14px 0 4px; }
.login-brand { display: flex; align-items: center; gap: 9px; font-weight: 700; }

.menu-btn { display: none; border: 1px solid var(--line); background: #fff; border-radius: 7px; width: 34px; height: 34px; font-size: 17px; line-height: 1; cursor: pointer; color: #24344a; flex: 0 0 auto; }
.nav-mask { display: none; position: fixed; inset: 0; background: rgba(15, 30, 50, .45); z-index: 40; opacity: 0; transition: opacity .18s ease; }
.nav-mask.show { opacity: 1; }

@media (max-width: 860px) {
  .topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
  .menu-btn { display: inline-flex; align-items: center; justify-content: center; }
  .sidebar {
    position: fixed; left: 0; top: 0; bottom: 0;
    width: 218px; flex: 0 0 218px; max-width: 78vw;
    transform: translateX(-105%); transition: transform .2s ease;
    z-index: 50; overflow-y: auto; box-shadow: none;
  }
  .sidebar.open { transform: none; box-shadow: 6px 0 24px rgba(15, 30, 50, .18); }
  .nav-item { font-size: 13.5px; }
  .sidebar.open ~ .main .content { overflow: hidden; }
  .content { padding: 16px; }
  .form.two-col { grid-template-columns: 1fr; }
  .table-scroll, table { max-width: 100%; }
}
