:root {
  --bg: #f3f6f8;
  --surface: #ffffff;
  --surface-soft: #f7fafb;
  --ink: #172432;
  --muted: #6b7b88;
  --line: #dce5e9;
  --teal: #129b8b;
  --teal-dark: #087a6f;
  --teal-soft: #e2f5f1;
  --amber: #d88a22;
  --amber-soft: #fff4df;
  --red: #c34d4d;
  --red-soft: #fdeaea;
  --blue: #386fa8;
  --shadow: 0 18px 50px rgba(24, 47, 61, .09);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; background: var(--bg); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }

.upload-panel {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.02);
}

.upload-controls {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto minmax(120px, 1fr) auto;
  align-items: center;
  gap: 12px;
}

.upload-progress {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--line);
}

.upload-progress i {
  display: block;
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--teal);
  transition: width 180ms ease;
}

#uploadProgressText { color: var(--muted); font-size: 12px; white-space: nowrap; }
.muted, .subtle { color: var(--muted); }
.subtle { font-size: 13px; }
.eyebrow { margin: 0 0 6px; color: var(--teal-dark); font-size: 11px; font-weight: 800; letter-spacing: .14em; }
h1, h2, h3, p { margin-top: 0; }
h1 { margin-bottom: 0; font-size: clamp(26px, 3vw, 38px); letter-spacing: -.04em; }
h2 { margin-bottom: 0; font-size: 22px; letter-spacing: -.025em; }

.login-view { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(circle at 15% 15%, #d7f2ed, transparent 35%), radial-gradient(circle at 85% 80%, #dce9f3, transparent 35%), #f4f7f8; }
.login-card { width: min(440px, 100%); padding: 42px; border: 1px solid rgba(255,255,255,.8); border-radius: 28px; background: rgba(255,255,255,.9); box-shadow: var(--shadow); backdrop-filter: blur(18px); }
.brand-mark { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 15px; color: white; background: linear-gradient(145deg, #17aa98, #087a6f); font-weight: 900; box-shadow: 0 10px 24px rgba(18,155,139,.26); }
.login-card .brand-mark { margin-bottom: 28px; }
.login-card h1 { margin-bottom: 12px; }
.login-card > .muted { margin-bottom: 28px; line-height: 1.7; }
label { display: grid; gap: 8px; color: #263746; font-size: 14px; font-weight: 700; }
input, select, textarea { width: 100%; border: 1px solid #cbd8de; border-radius: 14px; background: #fff; color: var(--ink); outline: none; transition: border-color .2s, box-shadow .2s; }
input, select { min-height: 48px; padding: 0 15px; }
textarea { padding: 13px 15px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--teal); box-shadow: 0 0 0 4px rgba(18,155,139,.12); }
.login-card label { margin-bottom: 17px; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 230px minmax(0, 1fr); }
.sidebar { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; padding: 25px 18px; border-right: 1px solid #dbe4e8; background: rgba(250,252,253,.92); backdrop-filter: blur(20px); }
.brand { display: flex; align-items: center; gap: 12px; padding: 0 8px 28px; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 16px; }
.brand span { margin-top: 3px; color: var(--muted); font-size: 10px; letter-spacing: .13em; }
.sidebar nav { display: grid; gap: 7px; }
.nav-item { display: flex; align-items: center; gap: 11px; padding: 11px 12px; border: 0; border-radius: 13px; color: #586b79; background: transparent; text-align: left; font-weight: 700; }
.nav-item span { width: 27px; height: 27px; display: grid; place-items: center; border-radius: 9px; background: #eef3f5; font-size: 12px; }
.nav-item:hover, .nav-item.active { color: var(--teal-dark); background: var(--teal-soft); }
.nav-item.active span { color: white; background: var(--teal); }
.sidebar-foot { margin-top: auto; display: grid; gap: 18px; }
.secure-note { display: flex; gap: 10px; padding: 13px; border: 1px solid #d9ebe8; border-radius: 14px; color: #31564f; background: #f0faf7; font-size: 12px; line-height: 1.5; }
.secure-note i { flex: 0 0 auto; width: 9px; height: 9px; margin-top: 4px; border-radius: 50%; background: var(--teal); box-shadow: 0 0 0 4px rgba(18,155,139,.13); }
.secure-note small { color: #728a84; }
.link-button { border: 0; color: var(--muted); background: none; text-align: left; }

main { min-width: 0; padding: 0 34px 70px; }
.topbar { min-height: 112px; display: flex; align-items: center; justify-content: space-between; gap: 24px; border-bottom: 1px solid var(--line); }
.top-actions, .dialog-actions, .filters { display: flex; align-items: center; gap: 10px; }
.button { min-height: 42px; padding: 0 16px; border: 1px solid transparent; border-radius: 12px; font-weight: 800; transition: transform .15s, background .2s, border-color .2s; }
.button:hover { transform: translateY(-1px); }
.button.primary { color: white; background: var(--teal); box-shadow: 0 8px 18px rgba(18,155,139,.2); }
.button.primary:hover { background: var(--teal-dark); }
.button.ghost { border-color: #ccd9de; color: #3a4c59; background: white; }
.button.danger { border-color: #f0caca; color: var(--red); background: #fff; }
.button.full { width: 100%; margin-top: 7px; }
.button:disabled { cursor: wait; opacity: .58; transform: none; }
.section { padding-top: 28px; scroll-margin-top: 16px; }
.page-view { display: none; }
.page-view.active { display: block; }

.metric-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; }
.metric-card { min-height: 142px; padding: 22px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); box-shadow: 0 8px 28px rgba(28,55,69,.045); }
.metric-card span, .metric-card small { display: block; color: var(--muted); }
.metric-card span { font-size: 13px; font-weight: 800; }
.metric-card strong { display: block; margin: 12px 0 5px; font-size: 38px; line-height: 1; letter-spacing: -.05em; }
.metric-card small { font-size: 12px; }
.metric-card.accent { color: white; border-color: transparent; background: linear-gradient(140deg, #109789, #086f68); }
.metric-card.accent span, .metric-card.accent small { color: rgba(255,255,255,.72); }
.system-grid { display: grid; grid-template-columns: 1.25fr .75fr; gap: 16px; margin-top: 16px; }
.panel { padding: 23px; border: 1px solid var(--line); border-radius: 20px; background: var(--surface); }
.panel-head, .section-head, .task-head, .task-actions, .resource-item > div:first-child { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.route-list { display: grid; gap: 11px; margin-top: 21px; }
.route-row { display: grid; grid-template-columns: 44px 1fr auto; align-items: center; gap: 13px; padding: 13px; border: 1px solid #e3eaed; border-radius: 15px; background: var(--surface-soft); }
.route-row strong, .route-row span { display: block; }
.route-row span { margin-top: 3px; color: var(--muted); font-size: 12px; }
.route-icon { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 13px; color: white; font-size: 12px; font-weight: 900; }
.route-icon.us { background: #3971a7; }
.route-icon.jp { background: #bd5262; }
.route-icon.pool { background: #7658a8; }
.route-status { padding: 6px 9px; border-radius: 999px; font-size: 11px; font-weight: 900; }
.route-status.ok { color: var(--teal-dark); background: var(--teal-soft); }
.route-status.fail { color: var(--red); background: var(--red-soft); }
.route-status.pending { color: var(--muted); background: #edf2f4; }
.chip { padding: 7px 10px; border-radius: 999px; color: #45616f; background: #eef4f6; font-size: 12px; font-weight: 800; }
.resource-item { margin-top: 20px; }
.resource-item strong { font-size: 13px; }
.progress { height: 8px; margin-top: 8px; overflow: hidden; border-radius: 999px; background: #edf1f3; }
.progress i { display: block; width: 0; height: 100%; border-radius: inherit; background: var(--teal); transition: width .5s; }
.resource-warning { margin: 22px 0 0; padding: 12px 13px; border-radius: 12px; color: #826126; background: var(--amber-soft); font-size: 12px; line-height: 1.55; }

.tasks-section { padding-top: 42px; }
.section-head { align-items: end; }
.section-head .muted { max-width: 680px; margin: 9px 0 0; font-size: 13px; line-height: 1.65; }
.filters input { width: min(290px, 28vw); }
.filters select { width: 142px; }
.task-list { display: grid; gap: 13px; margin-top: 20px; }
.task-card { padding: 20px; border: 1px solid var(--line); border-radius: 19px; background: var(--surface); box-shadow: 0 7px 25px rgba(28,55,69,.04); }
.task-head { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; }
.task-title { display: flex; align-items: center; gap: 10px; }
.task-title h3 { margin: 0; font-size: 18px; }
.task-account { max-width: 260px; overflow: hidden; padding: 5px 8px; border-radius: 999px; color: #47606e; background: #eef4f6; font-size: 11px; font-weight: 850; text-overflow: ellipsis; white-space: nowrap; }
.state-badge { padding: 6px 9px; border-radius: 999px; font-size: 11px; font-weight: 900; }
.state-badge.streaming { color: #fff; background: var(--teal); }
.state-badge.resolving, .state-badge.starting, .state-badge.fallback_starting { color: #355f92; background: #e5eff9; }
.state-badge.fallback { color: #8b5e16; background: var(--amber-soft); }
.state-badge.waiting { color: #7a657d; background: #f2eaf4; }
.state-badge.error { color: var(--red); background: var(--red-soft); }
.state-badge.stopped, .state-badge.stopping { color: #6c7b86; background: #edf1f3; }
.task-meta { display: grid; grid-template-columns: 1.35fr .85fr .8fr 1fr; gap: 15px; margin-top: 18px; padding-top: 16px; border-top: 1px solid #e8edef; }
.task-meta div { min-width: 0; }
.task-meta span, .task-meta strong { display: block; }
.task-meta span { margin-bottom: 5px; color: var(--muted); font-size: 11px; font-weight: 800; letter-spacing: .04em; }
.task-meta strong { overflow: hidden; color: #354854; font-size: 13px; text-overflow: ellipsis; white-space: nowrap; }
.task-actions { margin-top: 0; justify-content: flex-end; }
.task-actions .button { min-height: 36px; padding: 0 12px; font-size: 12px; }
.meta-link { display: block; overflow: hidden; color: var(--blue); font-size: 13px; font-weight: 800; text-decoration: none; text-overflow: ellipsis; white-space: nowrap; }
.meta-link:hover { text-decoration: underline; }
.text-warning { color: #9b6817 !important; }
.text-danger { color: var(--red) !important; }
.task-alert { display: flex; gap: 10px; margin-top: 14px; padding: 10px 12px; border-radius: 11px; color: var(--red); background: var(--red-soft); font-size: 12px; line-height: 1.45; }
.task-alert strong { flex: 0 0 auto; }
.task-alert span { overflow-wrap: anywhere; }
.task-note { margin: 10px 0 0; color: var(--muted); font-size: 12px; }
.empty-state { display: grid; place-items: center; padding: 70px 20px; margin-top: 20px; border: 1px dashed #cddade; border-radius: 22px; background: rgba(255,255,255,.55); text-align: center; }
.empty-state > div { width: 54px; height: 54px; display: grid; place-items: center; border-radius: 17px; color: var(--teal-dark); background: var(--teal-soft); font-size: 28px; }
.empty-state h3 { margin: 17px 0 7px; }
.empty-state p { color: var(--muted); }
.empty-state.compact { padding: 38px 20px; }
.empty-state.compact > div { width: 44px; height: 44px; font-size: 17px; }
.empty-state.compact h3 { margin-top: 12px; }
.empty-state.compact p { margin-bottom: 0; }
.files-section { padding-top: 48px; }
.file-actions { display: flex; align-items: center; gap: 10px; }
.file-actions select { width: 165px; }
.file-actions #fileNodeFilter { width: 230px; }
.file-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-top: 20px; }
.file-summary > div { padding: 16px; border: 1px solid var(--line); border-radius: 16px; background: white; }
.file-summary span, .file-summary strong { display: block; }
.file-summary span { color: var(--muted); font-size: 11px; font-weight: 800; }
.file-summary strong { margin-top: 7px; font-size: 19px; }
.file-table-wrap { margin-top: 14px; overflow: auto; border: 1px solid var(--line); border-radius: 18px; background: white; }
.file-table { width: 100%; border-collapse: collapse; min-width: 760px; }
.file-table th, .file-table td { padding: 13px 14px; border-bottom: 1px solid #e7edef; text-align: left; font-size: 12px; }
.file-table th { color: var(--muted); background: #f7fafb; font-size: 11px; letter-spacing: .04em; }
.file-table tr:last-child td { border-bottom: 0; }
.file-name { max-width: 460px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 750; }
.file-state { display: inline-flex; padding: 5px 8px; border-radius: 999px; color: var(--teal-dark); background: var(--teal-soft); font-weight: 800; }
.file-state.busy { color: #8b5e16; background: var(--amber-soft); }

.dialog { width: min(920px, calc(100vw - 32px)); max-height: calc(100vh - 40px); padding: 0; overflow: auto; border: 0; border-radius: 24px; color: var(--ink); background: white; box-shadow: 0 32px 100px rgba(17,36,48,.28); }
.dialog::backdrop { background: rgba(13,28,38,.48); backdrop-filter: blur(5px); }
.dialog form, .log-dialog { padding: 25px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 20px; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.icon-button { width: 38px; height: 38px; border: 0; border-radius: 11px; color: #607380; background: #eef3f5; font-size: 24px; line-height: 1; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 17px; padding: 22px 0; }
.span-2 { grid-column: span 2; }
.check-card { grid-template-columns: auto 1fr; align-items: flex-start; padding: 15px; border: 1px solid #d6e6e3; border-radius: 15px; background: #eff9f6; }
.check-card input { width: 20px; min-height: 20px; margin-top: 1px; accent-color: var(--teal); }
.check-card strong, .check-card small { display: block; }
.check-card small { margin-top: 4px; color: #6a827c; font-weight: 500; line-height: 1.45; }
.dialog-actions { padding-top: 18px; border-top: 1px solid var(--line); }
.spacer { flex: 1; }
.form-error { min-height: 20px; color: var(--red); font-size: 13px; }
.source-test-result { display: flex; gap: 8px; align-items: flex-start; margin-top: 14px; padding: 12px 14px; border-radius: 10px; border: 1px solid; }
.source-test-result strong { flex: 0 0 auto; }
.source-test-result span { line-height: 1.45; overflow-wrap: anywhere; }
.source-test-result.pending { color: var(--amber); background: rgba(245, 158, 11, .08); border-color: rgba(245, 158, 11, .35); }
.source-test-result.ok { color: var(--teal); background: rgba(20, 184, 166, .08); border-color: rgba(20, 184, 166, .35); }
.source-test-result.fail { color: var(--red); background: rgba(239, 68, 68, .08); border-color: rgba(239, 68, 68, .35); }
.log-dialog { width: min(1050px, calc(100vw - 32px)); }
.log-dialog pre { min-height: 440px; max-height: 62vh; margin: 18px 0; padding: 18px; overflow: auto; border-radius: 16px; color: #cce8df; background: #102029; font: 12px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; word-break: break-word; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 50; max-width: 360px; padding: 13px 16px; border-radius: 13px; color: white; background: #203743; box-shadow: var(--shadow); opacity: 0; transform: translateY(14px); pointer-events: none; transition: .25s; }
.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { background: #a54040; }

@media (max-width: 1080px) {
  .metric-grid { grid-template-columns: repeat(2, 1fr); }
  .system-grid { grid-template-columns: 1fr; }
  .task-meta { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 760px) {
  .app-shell { display: block; }
  .sidebar { position: sticky; z-index: 20; width: 100%; height: auto; padding: 12px 16px; flex-direction: row; flex-wrap: wrap; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar .brand { padding: 0; }
  .sidebar nav { order: 3; width: 100%; display: flex; gap: 7px; padding-top: 10px; overflow-x: auto; }
  .nav-item { flex: 0 0 auto; padding: 9px 11px; }
  .nav-item span { display: none; }
  .sidebar nav .nav-item[data-action="new"] { display: none; }
  .sidebar-foot { margin: 0 0 0 auto; }
  .secure-note { display: none; }
  main { padding: 0 16px 50px; }
  .topbar { min-height: 96px; }
  .topbar .button.ghost { display: none; }
  .metric-grid, .form-grid { grid-template-columns: 1fr; }
  .file-summary { grid-template-columns: repeat(2, 1fr); }
  .file-actions { width: 100%; flex-wrap: wrap; }
  .span-2 { grid-column: auto; }
  .section-head { align-items: stretch; flex-direction: column; }
  .filters { width: 100%; }
  .filters input { width: 100%; }
  .filters select { width: 132px; }
  .task-head { display: flex; align-items: flex-start; gap: 12px; flex-direction: column; }
  .task-title { flex-wrap: wrap; }
  .task-meta { grid-template-columns: 1fr; }
  .task-actions { justify-content: flex-start; flex-wrap: wrap; }
  .dialog-actions { flex-wrap: wrap; }
  .login-card { padding: 30px 24px; }
}
