:root {
  --bg: #f5f7fb;
  --surface: #ffffff;
  --surface-2: #eef3f8;
  --ink: #171a21;
  --muted: #647080;
  --line: #d8e0ea;
  --blue: #1f66d1;
  --blue-dark: #194f9d;
  --green: #138a62;
  --red: #be3b35;
  --gold: #b98113;
  --purple: #6a54f5;
  --shadow: 0 18px 48px rgba(22, 30, 45, 0.08);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  line-height: 1.45;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--blue);
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto 1fr;
}

.topbar {
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px clamp(16px, 4vw, 46px);
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
}

.brand,
.top-actions {
  display: inline-flex;
  align-items: center;
}

.brand {
  gap: 11px;
  color: var(--ink);
  text-decoration: none;
  font-weight: 800;
}

.brand-mark {
  min-width: 44px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  color: #fff;
  background: var(--blue);
  font-size: 0.82rem;
  letter-spacing: 0;
  padding: 0 8px;
}

.top-actions {
  gap: 10px;
}

.nav-link {
  min-height: 36px;
  display: inline-grid;
  place-items: center;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  text-decoration: none;
  font-weight: 700;
}

.main {
  width: min(1320px, calc(100% - 28px));
  margin: 0 auto;
  padding: clamp(22px, 4vw, 42px) 0 54px;
}

.auth-layout,
.app-layout,
.admin-layout {
  display: grid;
  gap: 18px;
}

.auth-layout {
  width: min(100%, 480px);
  margin: 8vh auto 0;
}

.panel,
.toolbar,
.notice,
.chart-card {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel,
.chart-card {
  padding: clamp(18px, 3vw, 28px);
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
}

.toolbar-group,
.button-row,
.row-actions,
.stats-grid,
.field-grid,
.summary-grid,
.worker-grid,
.meter-row,
.meta-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.summary-grid,
.worker-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.field-grid {
  align-items: end;
}

.field {
  display: grid;
  gap: 7px;
  margin: 0 0 14px;
}

.field-grid .field {
  min-width: min(100%, 220px);
  flex: 1;
}

label {
  color: #303846;
  font-size: 0.88rem;
  font-weight: 780;
}

input,
select,
textarea {
  width: 100%;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--ink);
  background: #fff;
}

textarea {
  min-height: 110px;
  resize: vertical;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible,
a:focus-visible {
  outline: 3px solid rgba(31, 102, 209, 0.22);
  outline-offset: 2px;
}

.button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: #fff;
  font-weight: 760;
}

.button.primary {
  border-color: var(--blue);
  color: #fff;
  background: var(--blue);
}

.button.primary:hover {
  background: var(--blue-dark);
}

.button.danger {
  border-color: rgba(190, 59, 53, 0.32);
  color: var(--red);
}

.button.small {
  min-height: 32px;
  padding: 0 9px;
  font-size: 0.88rem;
}

.language-switch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f9fbfd;
}

.language-switch .button {
  min-height: 32px;
  border-color: transparent;
  background: transparent;
}

.language-switch .button.active {
  color: #fff;
  background: var(--ink);
}

.hidden {
  display: none !important;
}

h1,
h2,
h3,
p {
  overflow-wrap: anywhere;
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.12;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(1.8rem, 5vw, 3.2rem);
}

h2 {
  margin-bottom: 14px;
  font-size: clamp(1.25rem, 3vw, 1.8rem);
}

h3 {
  margin-bottom: 10px;
  font-size: 1.02rem;
}

p {
  margin: 0 0 12px;
  color: var(--muted);
}

.muted {
  color: var(--muted);
}

.notice {
  padding: 12px 14px;
  color: #243242;
  background: #f9fbff;
}

.notice.good {
  border-color: rgba(19, 138, 98, 0.25);
  color: #0d6548;
  background: #effaf5;
}

.notice.warn {
  border-color: rgba(185, 129, 19, 0.3);
  color: #744f08;
  background: #fff8e8;
}

.notice.bad {
  border-color: rgba(190, 59, 53, 0.28);
  color: var(--red);
  background: #fff2f1;
}

.drop-panel {
  position: relative;
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 2px dashed rgba(31, 102, 209, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.65);
}

.drop-panel.is-dragging {
  border-color: rgba(31, 102, 209, 0.7);
  background: rgba(242, 247, 255, 0.96);
}

.drop-panel input[type="file"] {
  display: none;
}

.drop-copy {
  display: grid;
  gap: 8px;
}

.drop-copy strong {
  font-size: 1.05rem;
}

.file-pill {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 0.93rem;
}

.model-card {
  display: grid;
  gap: 6px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.model-card strong {
  display: block;
}

.stat {
  display: grid;
  gap: 6px;
  padding: 14px 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.stat strong {
  font-size: 1.3rem;
}

.file-table {
  width: 100%;
  border-collapse: collapse;
}

.file-table th,
.file-table td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

.file-table th {
  color: var(--muted);
  background: #f9fbfd;
  font-size: 0.82rem;
}

.table-wrap {
  overflow-x: auto;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 780;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge.uploading {
  color: var(--blue-dark);
  background: rgba(31, 102, 209, 0.12);
  border-color: rgba(31, 102, 209, 0.18);
}

.badge.queued {
  color: #6b4a00;
  background: rgba(185, 129, 19, 0.14);
  border-color: rgba(185, 129, 19, 0.22);
}

.badge.running,
.badge.cancelling {
  color: #5940d8;
  background: rgba(106, 84, 245, 0.12);
  border-color: rgba(106, 84, 245, 0.18);
}

.badge.completed {
  color: #0d6548;
  background: rgba(19, 138, 98, 0.12);
  border-color: rgba(19, 138, 98, 0.18);
}

.badge.failed,
.badge.cancelled {
  color: var(--red);
  background: rgba(190, 59, 53, 0.12);
  border-color: rgba(190, 59, 53, 0.18);
}

.progress-stack {
  display: grid;
  gap: 6px;
  min-width: 220px;
}

.progress-bar {
  height: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7eef7;
}

.progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--blue), var(--purple));
}

.output-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.log-list {
  display: grid;
  gap: 8px;
  max-height: 540px;
  overflow: auto;
}

.log-entry {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.code {
  display: inline-block;
  max-width: 100%;
  overflow-wrap: anywhere;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 0.86rem;
}

.worker-card {
  display: grid;
  gap: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.worker-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.meter {
  display: grid;
  gap: 4px;
}

.meter-row {
  align-items: center;
  justify-content: space-between;
}

.meter-row span:last-child {
  min-width: 58px;
  text-align: right;
}

.mini-bar {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #e7eef7;
}

.mini-bar > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--blue), var(--purple));
}

.chart-card {
  display: grid;
  gap: 10px;
}

.chart-svg {
  width: 100%;
  height: 180px;
  display: block;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  color: var(--muted);
  font-size: 0.9rem;
}

.legend-dot {
  width: 10px;
  height: 10px;
  display: inline-block;
  border-radius: 999px;
  margin-right: 6px;
}

.legend-dot.cpu {
  background: var(--blue);
}

.legend-dot.ram {
  background: var(--green);
}

.legend-dot.gpu {
  background: var(--purple);
}

.legend-dot.vram {
  background: var(--gold);
}

.split-grid {
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 420px) minmax(0, 1fr);
}

@media (max-width: 980px) {
  .split-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  .main {
    width: min(100%, calc(100% - 20px));
  }

  .topbar,
  .toolbar,
  .worker-head {
    align-items: stretch;
    flex-direction: column;
  }

  .file-table th,
  .file-table td {
    padding: 10px 8px;
  }
}
