:root {
  color-scheme: light;
  --bg: #f4f6f9;
  --panel: #ffffff;
  --text: #16202f;
  --muted: #687586;
  --line: #dfe5ec;
  --brand: #1663c7;
  --brand-dark: #0f4d9e;
  --brand-soft: #eaf2ff;
  --ok: #16803c;
  --ok-soft: #e8f7ee;
  --warn: #a15c00;
  --warn-soft: #fff4e2;
  --danger: #bf2233;
  --danger-soft: #fdeef0;
  --shadow: 0 10px 30px rgba(24, 40, 70, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: var(--text);
  background: var(--bg);
  letter-spacing: .01em;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 13px; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    radial-gradient(circle at 20% 20%, rgba(22, 99, 199, .16), transparent 34%),
    radial-gradient(circle at 80% 0, rgba(22, 130, 199, .12), transparent 28%), var(--bg);
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 32px;
  display: grid;
  gap: 18px;
}

.brand { display: flex; gap: 14px; align-items: center; }
.brand h1 { margin: 0 0 4px; font-size: 22px; }
.brand p, .brand small { margin: 0; color: var(--muted); }
.brand-mark {
  width: 44px; height: 44px; flex: 0 0 44px;
  display: grid; place-items: center;
  border-radius: 12px; color: white; font-weight: 800; font-size: 20px;
  background: linear-gradient(135deg, #2b7fff, #0d4c9c);
}
.brand.compact strong { display: block; font-size: 15px; }

label { display: grid; gap: 7px; font-size: 13px; font-weight: 650; color: #384657; }
input, select {
  width: 100%; height: 40px;
  border: 1px solid var(--line); border-radius: 9px;
  padding: 0 11px; background: white; color: var(--text);
}
input:focus, select:focus { outline: 2px solid rgba(22, 99, 199, .18); border-color: #79a8e6; }
.checkbox { display: flex; align-items: center; gap: 8px; }
.checkbox input { width: 16px; height: 16px; }

.btn {
  border: 1px solid transparent; border-radius: 9px;
  min-height: 36px; padding: 0 14px; background: white; color: var(--text);
}
.btn.primary { background: var(--brand); color: white; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.secondary { background: var(--brand-soft); color: var(--brand-dark); border-color: #c6dcf8; }
.btn.danger { background: var(--danger-soft); color: var(--danger); border-color: #f0c4ca; }
.btn.subtle { color: var(--muted); border-color: var(--line); }
.btn.small { min-height: 30px; padding: 0 9px; font-size: 13px; }
.btn:disabled { opacity: .45; cursor: not-allowed; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 260px 1fr; }
.sidebar {
  background: #0d1727; color: white;
  display: flex; flex-direction: column; gap: 24px;
  padding: 24px 16px; position: sticky; top: 0; height: 100vh;
}
.sidebar nav { display: grid; gap: 7px; align-content: start; }
.nav-btn {
  text-align: left; border: 0; background: transparent; color: #a9b7c8;
  padding: 11px 13px; border-radius: 9px; font-weight: 650;
}
.nav-btn:hover { background: rgba(255,255,255,.08); color: white; }
.nav-btn.active { background: rgba(43, 127, 255, .25); color: white; }
.sidebar-footer { display: grid; gap: 10px; font-size: 13px; color: #a9b7c8; margin-top: auto; }

main { padding: 28px; }
.page { display: grid; gap: 20px; }
.page-header { display: flex; justify-content: space-between; align-items: end; gap: 20px; }
.page-header h2 { margin: 0 0 6px; font-size: 24px; }
.page-header p { margin: 0; color: var(--muted); }

.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: 15px; padding: 22px; box-shadow: var(--shadow);
}
.panel h3 { margin: 0 0 18px; font-size: 16px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(180px, 1fr)); gap: 16px; }
.form-grid.narrow { max-width: 620px; }
.span-2 { grid-column: 1 / -1; }
.actions { display: flex; justify-content: flex-end; }

.table-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.toolbar { display: flex; align-items: center; gap: 10px; }
.toolbar select { width: auto; height: 34px; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 12px 11px; border-bottom: 1px solid var(--line); text-align: left; font-size: 14px; vertical-align: middle; }
th { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
.empty { padding: 28px; text-align: center; color: var(--muted); }

.status {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 25px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700;
}
.status.queued, .status.downloading { background: var(--warn-soft); color: var(--warn); }
.status.running { background: var(--brand-soft); color: var(--brand-dark); }
.status.completed, .status.ready { background: var(--ok-soft); color: var(--ok); }
.status.failed { background: var(--danger-soft); color: var(--danger); }
.status.canceled, .status.not_installed { background: #edf1f5; color: var(--muted); }

.progress { margin-top: 8px; width: 170px; height: 7px; border-radius: 99px; background: #e6ebf1; overflow: hidden; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, #2b7fff, #1663c7); transition: width .3s; }

.upload-panel { display: grid; gap: 14px; }
#fileInput, .file-input { height: auto; padding: 12px; background: #fafbfc; }

.pagination {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; padding-top: 14px;
}
.pagination:empty { display: none; }
.row-actions { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

.modal-card.modal-form {
  width: min(760px, 100%); height: auto; max-height: 90vh;
  grid-template-rows: auto 1fr;
}
.modal-body { padding: 20px; overflow: auto; display: grid; gap: 16px; align-content: start; }
.upload-status { min-height: 20px; margin: 0; font-size: 13px; color: var(--brand-dark); }

.model-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 14px; }
.model-card {
  border: 1px solid var(--line); border-radius: 12px; padding: 15px;
  display: grid; gap: 10px; background: #fbfcfe;
}
.model-card strong { font-size: 15px; }
.model-card p { margin: 0; min-height: 36px; color: var(--muted); font-size: 13px; }
.model-card .row { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.progress.wide { width: 100%; margin-top: 0; }

.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(13, 23, 39, .55); display: grid; place-items: center; padding: 24px;
}
.modal-card {
  width: min(1100px, 100%); height: min(760px, 90vh);
  background: white; border-radius: 15px; display: grid;
  grid-template-rows: auto auto 1fr; overflow: hidden; box-shadow: var(--shadow);
}
.modal-card header {
  display: flex; justify-content: space-between; align-items: center;
  gap: 16px; padding: 18px 20px; border-bottom: 1px solid var(--line);
}
.modal-card h3 { margin: 0 0 4px; }
.preview-tabs { display: flex; gap: 8px; padding: 12px 20px 0; }
.preview-tabs button {
  border: 1px solid var(--line); background: white; border-radius: 7px;
  min-height: 30px; padding: 0 10px; color: var(--muted);
}
.preview-tabs button.active { border-color: #9dbfe8; background: var(--brand-soft); color: var(--brand-dark); font-weight: 700; }
#previewContent {
  margin: 0; padding: 18px 20px; overflow: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px;
  line-height: 1.7; white-space: pre-wrap; word-break: break-word; background: #f8fafc;
}

.toast {
  position: fixed; right: 24px; bottom: 24px; z-index: 80;
  background: #0d1727; color: white; border-radius: 10px;
  padding: 12px 16px; max-width: 440px; box-shadow: var(--shadow);
}
.toast.error { background: #8d1626; }
.form-error { color: var(--danger); min-height: 20px; margin: 0; font-size: 13px; }

@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; }
  .sidebar nav { grid-template-columns: repeat(2, 1fr); }
  main { padding: 16px; }
  .form-grid { grid-template-columns: 1fr; }
  .page-header { align-items: start; flex-direction: column; }
}
