:root {
  --bg: #f3f6f9;
  --panel: #ffffff;
  --ink: #1c2733;
  --muted: #5c6b7a;
  --line: #d9e2ea;
  --accent: #1657ff;
  --accent-ink: #ffffff;
  --ok: #0e7a3d;
  --warn: #9a6700;
  --bad: #b3261e;
  --info: #0b5394;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  --radius: 10px;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font: 14px/1.6 -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  background: var(--bg); color: var(--ink);
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--mono); font-size: 92%; }

/* layout */
.topbar { background: #10202f; color: #fff; display: flex; align-items: center; gap: 12px; padding: 0 16px; height: 52px; }
.topbar .brand { font-weight: 700; font-size: 15px; letter-spacing: .5px; color: #fff; white-space: nowrap; }
.topbar nav { display: flex; gap: 2px; flex: 1; min-width: 0; overflow-x: auto; scrollbar-width: none; }
.topbar nav::-webkit-scrollbar { display: none; }
.topbar nav a { color: #b9c8d6; padding: 6px 7px; border-radius: 6px; font-size: 13.5px; white-space: nowrap; flex-shrink: 0; }
.topbar nav a:hover { background: #1d3346; color: #fff; text-decoration: none; }
.topbar nav a.active { background: var(--accent); color: #fff; }
.topbar .me { color: #b9c8d6; font-size: 13px; white-space: nowrap; }
.topbar .me b { color: #fff; }
.wrap { max-width: 1280px; margin: 0 auto; padding: 22px 20px 60px; }
.page-title { display: flex; align-items: baseline; justify-content: space-between; margin: 4px 0 18px; }
.page-title h1 { font-size: 20px; margin: 0; }
.page-title .sub { color: var(--muted); font-size: 13px; }

/* panels & grids */
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; margin-bottom: 18px; }
.panel h2 { font-size: 15px; margin: 0 0 12px; color: #10202f; }
.grid { display: grid; gap: 16px; }
/* prevent long unbreakable content from blowing out 1fr columns */
.grid > * { min-width: 0; }
.grid.cols-2 { grid-template-columns: 1fr 1fr; }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1000px) { .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; } }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .num { font-size: 26px; font-weight: 700; }
.kpi .label { color: var(--muted); font-size: 12.5px; }

/* tables */
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th, table.data td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.data th { color: var(--muted); font-weight: 600; font-size: 12.5px; white-space: nowrap; }
table.data tr:hover td { background: #f7fafc; }
table.data td.actions { white-space: nowrap; }
/* action cells: comfortable spacing between adjacent links/buttons */
table.data td.actions > * + * { margin-left: 12px; }
.badge + .badge { margin-left: 6px; }
/* layout helpers: keep short cells on one line, let long content cells wrap anywhere */
.nowrap { white-space: nowrap; }
table.data td.t-break { word-break: break-all; }
.scroll-x { overflow-x: auto; }
.attempts-table { table-layout: fixed; min-width: 680px; }
.attempts-table col.attempt-number { width: 7%; }
.attempts-table col.attempt-type-col { width: 29%; }
.attempts-table col.attempt-status { width: 12%; }
.attempts-table col.attempt-times { width: 22%; }
.attempts-table col.attempt-links { width: 30%; }
.attempts-table td { overflow-wrap: anywhere; }
.attempts-table .attempt-type-cell,
.attempts-table .attempt-links-cell { white-space: normal; word-break: break-word; }
.attempts-table .attempt-times-cell span { white-space: nowrap; }

/* badges */
.badge { display: inline-block; padding: 1px 9px; border-radius: 20px; font-size: 12px; border: 1px solid transparent; vertical-align: middle; white-space: nowrap; }
.badge.ok { color: var(--ok); background: #e7f5ec; border-color: #bfe3cc; }
.badge.warn { color: var(--warn); background: #fdf3dd; border-color: #ecd9a0; }
.badge.bad { color: var(--bad); background: #fbeae9; border-color: #efc5c2; }
.badge.info { color: var(--info); background: #e8f1fa; border-color: #c4dcf2; }
.badge.muted { color: var(--muted); background: #eef2f6; border-color: var(--line); }

/* forms */
button, .btn { background: var(--accent); color: var(--accent-ink); border: 0; border-radius: 7px; padding: 7px 14px; font-size: 13.5px; cursor: pointer; white-space: nowrap; }
button.ghost, .btn.ghost { background: transparent; color: var(--accent); border: 1px solid var(--accent); }
button.danger { background: var(--bad); }
button.small { padding: 3px 10px; font-size: 12.5px; border-radius: 6px; }
button:disabled { opacity: .5; cursor: not-allowed; }
label { display: block; font-size: 12.5px; color: var(--muted); margin: 10px 0 4px; }
/* custom file picker row (localized, replaces the browser-rendered file input) */
.file-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
/* custom datetime text control (replaces type=datetime-local, see app.js) */
.dt-input.invalid { border-color: var(--bad); }
/* custom datetime text control (replaces type=datetime-local, see app.js) */
.dt-input.invalid { border-color: var(--bad); }
input[type=text], input[type=password], input[type=number], input[type=datetime-local], select, textarea {
  width: 100%; padding: 7px 10px; border: 1px solid var(--line); border-radius: 7px; font: inherit; background: #fff;
}
textarea { min-height: 90px; resize: vertical; }
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; }
.check { display: flex; gap: 8px; align-items: center; font-size: 13.5px; color: var(--ink); margin: 8px 0; }
.check input { width: auto; }
fieldset { border: 1px solid var(--line); border-radius: 8px; margin: 0 0 12px; padding: 4px 14px 12px; }
legend { font-size: 12.5px; color: var(--muted); padding: 0 6px; }

/* misc */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-bottom: 14px; }
.filters > div { min-width: 130px; display: flex; flex-direction: column; justify-content: flex-end; }
.filters label { margin: 0 0 3px; }
.toast { position: fixed; right: 18px; bottom: 18px; max-width: 420px; padding: 12px 16px; border-radius: 8px;
  color: #fff; font-size: 13.5px; box-shadow: 0 6px 24px rgba(16,32,47,.25); display: none; z-index: 1000; }
.toast.show { display: block; }
.toast.ok { background: #10512c; }
.toast.err { background: #7c1d18; }
.timeline { list-style: none; margin: 0; padding: 0 0 0 18px; border-left: 2px solid var(--line); }
.timeline li { position: relative; padding: 4px 0 12px; }
.timeline li::before { content: ""; position: absolute; left: -24px; top: 10px; width: 10px; height: 10px;
  border-radius: 50%; background: var(--accent); border: 2px solid #fff; }
.timeline .t { color: var(--muted); font-size: 12px; font-family: var(--mono); }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
pre.code { background: #10202f; color: #d7e1ea; padding: 12px; border-radius: 8px; overflow-x: auto; font-size: 12.5px; }
/* login page: full-viewport background image, centered card */
.login-page { min-height: 100vh; background: #10202f url("/static/img/login-bg.svg") center / cover no-repeat;
  display: flex; align-items: center; justify-content: center; position: relative; padding: 24px; }
.login-page .login-box { margin: 0; width: 100%; max-width: 400px; box-shadow: 0 18px 48px rgba(4, 12, 20, .55); }
/* prominent language switch on the login page */
.lang-switch { position: absolute; top: 16px; right: 18px; display: flex;
  border: 1px solid rgba(185, 200, 214, .4); border-radius: 17px; overflow: hidden;
  background: rgba(16, 32, 47, .55); backdrop-filter: blur(4px); }
.lang-switch button { background: transparent; color: #b9c8d6; border: 0; border-radius: 0;
  padding: 5px 14px; font-size: 12.5px; cursor: pointer; }
.lang-switch button + button { border-left: 1px solid rgba(185, 200, 214, .25); }
.lang-switch button:hover { color: #fff; }
.lang-switch button.active { background: var(--accent); color: #fff; }
/* topbar language toggle: visible pill instead of a plain link */
.topbar .me .lang-link { border: 1px solid #3a556e; border-radius: 12px; padding: 1px 10px; color: #d7e2ec; }
.topbar .me .lang-link:hover { border-color: #7c99b5; color: #fff; text-decoration: none; }
.tabs { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs button { background: #e6edf3; color: var(--ink); }
.tabs button.active { background: var(--accent); color: #fff; }
.pager { display: flex; gap: 10px; align-items: center; justify-content: flex-end; margin-top: 12px; font-size: 13px; }
.btn-row { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.hint { background: #eef4fb; border: 1px solid #c9dcee; color: #23425e; padding: 9px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 14px; }
dialog { border: 1px solid var(--line); border-radius: 12px; padding: 20px; min-width: 460px; max-width: 90vw; }
dialog::backdrop { background: rgba(16,32,47,.45); }
/* Dialog footer button row: even spacing, right-aligned. */
.dialog-actions { display: flex; gap: 10px; justify-content: flex-end; align-items: center; margin-top: 16px; }

/* output settings */
.output-layout { display: grid; grid-template-columns: minmax(480px, 560px) minmax(460px, 1fr); gap: 18px; align-items: start; }
.output-settings-stack { min-width: 0; }
.output-config-card { margin-bottom: 18px; }
.output-section-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.output-section-head h2 { margin-bottom: 2px; }
.output-section-head p { margin: 0 0 12px; }
.output-formats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 12px; margin: 4px 0 12px; }
.watermark-fieldset { background: #f8fafc; padding: 8px 14px 14px; }
.watermark-switch { border-bottom: 1px solid var(--line); padding-bottom: 10px; margin-bottom: 4px; }
.watermark-switch .small { margin-left: auto; }
.watermark-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; align-items: end; }
.watermark-fields .wide { grid-column: 1 / -1; }
.watermark-fields textarea { min-height: 68px; }
.watermark-fields .repeat-check { min-height: 36px; margin: 10px 0 0; }
.mailbox-config-body { border-top: 1px solid var(--line); margin-top: 14px; padding-top: 8px; }
.mailbox-mode { background: #f5f8fb; border-radius: 7px; padding: 9px 10px; }
.mailbox-config-body fieldset { padding: 4px 12px 12px; margin-top: 10px; }
.mailbox-output-fieldset { padding-top: 8px !important; }
.mailbox-output-fieldset .output-formats { margin-bottom: 0; }
.mailbox-watermark-fieldset { margin-top: 12px !important; }
.mailbox-watermark-fields { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.watermark-options { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 12px; border-top: 1px solid var(--line); margin-top: 12px; padding-top: 8px; }
.watermark-options .check { margin: 0; white-space: nowrap; }
.form-disabled { opacity: .62; }
.empty-config { border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); text-align: center; padding: 24px 12px; margin-top: 14px; }
.output-preview-card { position: sticky; top: 68px; margin-bottom: 18px; }
.preview-source { color: var(--muted); font-size: 12.5px; margin: 0 0 8px; }
.preview-frame-wrap { position: relative; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; }
.preview-frame-wrap iframe { display: block; width: 100%; height: 620px; border: 0; background: #fff; }
.preview-watermark-off { position: absolute; right: 12px; bottom: 12px; background: rgba(16,32,47,.82); color: #fff; padding: 5px 9px; border-radius: 5px; font-size: 12px; pointer-events: none; }
.log-line { margin: 0; white-space: pre-wrap; word-break: break-all; max-width: 900px; font: 12px/1.45 var(--mono); }
@media (max-width: 1100px) { .output-layout { grid-template-columns: 1fr; } .output-preview-card { position: static; } .preview-frame-wrap iframe { height: 480px; } }
@media (max-width: 700px) { .output-formats, .watermark-fields, .watermark-options { grid-template-columns: 1fr; } .watermark-fields .wide { grid-column: auto; } }
