:root {
  --bg: #f5f7fb;
  --panel: #ffffff;
  --panel-2: #f8fafc;
  --text: #172033;
  --muted: #687386;
  --line: #e4e8ef;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --danger: #dc2626;
  --shadow: 0 8px 24px rgba(15, 23, 42, .055);
  --radius: 12px;
}

* { box-sizing: border-box; }
html, body { min-width: 320px; }
body {
  margin: 0;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
}
button, input, textarea { font: inherit; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .55; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 220px 1fr; }
.sidebar {
  background: #111827;
  color: #fff;
  padding: 20px 16px;
}
.brand { display: flex; gap: 10px; align-items: center; margin-bottom: 26px; }
.brand-mark {
  width: 36px; height: 36px; border-radius: 9px; display: grid; place-items: center;
  background: #fff; color: #111827; font-weight: 800;
}
.brand strong { display: block; font-size: 15px; }
.brand span { display: block; color: #9ca3af; font-size: 11px; margin-top: 1px; }
.nav-group-title { color: #6b7280; font-size: 11px; padding: 0 9px 6px; }
.nav { display: grid; gap: 5px; }
.nav-item {
  border: 0; background: transparent; color: #cbd5e1; text-align: left;
  padding: 9px 10px; border-radius: 8px; font-size: 13px;
}
.nav-item.active { background: #1f2937; color: #fff; font-weight: 600; }
.nav-item.disabled { color: #6b7280; }

.main {
  width: min(1220px, 100%);
  height: 100vh;
  min-height: 650px;
  padding: 20px 26px 14px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.page-header {
  display: flex; align-items: center; justify-content: space-between; gap: 14px;
  margin-bottom: 12px; flex: 0 0 auto;
}
h1 { margin: 0 0 2px; font-size: 24px; line-height: 1.2; }
.page-header p { margin: 0; color: var(--muted); font-size: 12px; }
.privacy-badge {
  background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0;
  padding: 6px 9px; border-radius: 999px; font-size: 11px; white-space: nowrap;
}
.panel {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.url-panel {
  padding: 12px 14px 10px;
  margin-bottom: 10px;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.compact-head { min-height: 30px; }
.title-line { display: flex; align-items: baseline; gap: 12px; min-width: 0; }
h2 { margin: 0; font-size: 15px; white-space: nowrap; }
.helper-text { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
textarea {
  width: 100%;
  flex: 1 1 auto;
  min-height: 260px;
  resize: none;
  margin-top: 8px;
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel-2); color: var(--text);
  padding: 11px 13px; line-height: 1.55; outline: none; transition: .18s border-color, .18s box-shadow;
}
textarea:focus, input:focus { border-color: #93b4ff; box-shadow: 0 0 0 3px rgba(37, 99, 235, .1); outline: none; }
.stats { display: flex; flex-wrap: wrap; gap: 14px; color: var(--muted); font-size: 12px; margin-top: 7px; min-height: 18px; }
.stats b { color: var(--text); }

.control-panel { padding: 10px 14px; flex: 0 0 auto; }
.controls-row {
  display: flex; align-items: center; gap: 18px; min-height: 42px;
}
.compact-field { display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.compact-field > span { font-size: 13px; font-weight: 700; }
.input-unit { display: flex; align-items: center; gap: 7px; }
.input-unit input {
  width: 94px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel-2); color: var(--text); padding: 7px 9px;
}
.input-unit > span { color: var(--muted); font-size: 12px; }
.check-field { display: flex; align-items: center; gap: 7px; white-space: nowrap; font-size: 13px; }
.check-field input { width: 16px; height: 16px; margin: 0; }
.compact-actions { margin-left: auto; display: flex; gap: 8px; }

.compact-progress {
  display: grid;
  grid-template-columns: minmax(220px, auto) 1fr auto;
  align-items: center;
  gap: 12px;
  border-top: 1px solid var(--line);
  margin-top: 9px;
  padding-top: 9px;
}
.status-wrap { min-width: 0; display: flex; align-items: center; gap: 9px; }
.status-wrap > strong { font-size: 12px; white-space: nowrap; }
.task-hint { color: var(--muted); font-size: 12px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.progress-track { height: 7px; background: #eaf0f8; border-radius: 999px; overflow: hidden; }
.progress-track div { height: 100%; width: 0; background: var(--accent); transition: width .2s ease; }
.progress-numbers { text-align: right; white-space: nowrap; }
.progress-numbers strong { font-size: 15px; }
.progress-numbers small { color: var(--muted); font-size: 10px; margin-left: 5px; }

.btn { border: 1px solid transparent; border-radius: 8px; padding: 8px 13px; font-weight: 700; font-size: 13px; }
.btn-sm { padding: 6px 10px; font-size: 12px; }
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: #eef2f7; color: #334155; border-color: #dbe2ea; }
.btn-ghost { background: transparent; border-color: var(--line); color: var(--text); }
.btn-danger { background: var(--danger); color: #fff; }
.notice { color: #6b7280; font-size: 11px; line-height: 1.35; padding: 7px 2px 0; flex: 0 0 auto; }

#clearDialog { border: 0; padding: 0; border-radius: 14px; width: min(420px, calc(100% - 32px)); }
#clearDialog::backdrop { background: rgba(15, 23, 42, .45); }
.dialog-card { padding: 22px; background: var(--panel); color: var(--text); }
.dialog-card h3 { margin: 0 0 8px; }
.dialog-card p { color: var(--muted); line-height: 1.55; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

@media (max-width: 980px) {
  .controls-row { gap: 12px; flex-wrap: wrap; }
  .compact-actions { margin-left: 0; }
  .compact-progress { grid-template-columns: 1fr auto; }
  .compact-progress .progress-track { grid-column: 1 / -1; grid-row: 2; }
}

@media (max-width: 820px) {
  body { overflow: auto; }
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { padding: 12px 16px; }
  .brand { margin-bottom: 10px; }
  .nav { grid-template-columns: 1fr 1fr; }
  .nav-group-title { grid-column: 1 / -1; }
  .main { height: auto; min-height: calc(100vh - 130px); padding: 14px; overflow: visible; }
  .page-header { align-items: flex-start; }
  .page-header p { display: none; }
  .title-line { display: block; }
  .helper-text { display: block; margin-top: 2px; }
  .url-panel { min-height: 430px; }
  textarea { min-height: 330px; resize: vertical; }
  .controls-row { align-items: flex-start; }
  .compact-field { flex: 1 1 260px; }
  .compact-check { flex: 1 1 120px; }
  .compact-actions { flex: 1 1 100%; }
}

@media (max-width: 540px) {
  .privacy-badge { display: none; }
  h1 { font-size: 21px; }
  .compact-field { flex-direction: column; align-items: flex-start; gap: 5px; }
  .compact-field .input-unit { width: 100%; }
  .compact-field input { flex: 1; width: 100%; }
  .compact-progress { grid-template-columns: 1fr; }
  .progress-numbers { text-align: left; }
  .compact-progress .progress-track { grid-column: auto; grid-row: auto; }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1020; --panel: #111827; --panel-2: #0f172a; --text: #e5e7eb;
    --muted: #94a3b8; --line: #243042; --shadow: none;
  }
  .sidebar { background: #070b14; }
  .privacy-badge { background: #052e24; border-color: #14532d; color: #86efac; }
  .btn-secondary { background: #182234; color: #dbeafe; border-color: #2b3a50; }
  .progress-track { background: #1d293b; }
}
