:root {
  color-scheme: light;
  font-family: Inter, "Segoe UI", "Microsoft YaHei", sans-serif;
  font-synthesis: none;
  --ink: #17202a;
  --muted: #68727d;
  --line: #d9dee4;
  --line-strong: #bcc4cd;
  --surface: #ffffff;
  --surface-soft: #f5f7f9;
  --canvas: #eef1f4;
  --orange: #d95d0b;
  --orange-dark: #a84208;
  --orange-soft: #fff1e7;
  --green: #177245;
  --green-soft: #e8f6ee;
  --blue: #1769aa;
  --blue-soft: #e8f2fb;
  --red: #b42318;
  --red-soft: #fff0ef;
  --shadow: 0 12px 32px rgba(23, 32, 42, 0.12);
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; background: var(--canvas); color: var(--ink); font-size: 14px; letter-spacing: 0; }
button, input, select { font: inherit; letter-spacing: 0; }
button { cursor: pointer; }
svg { width: 18px; height: 18px; stroke-width: 2; }

.topbar {
  position: sticky; top: 0; z-index: 20; height: 60px; display: flex; align-items: center;
  justify-content: space-between; padding: 0 22px; background: #20262c; color: #fff;
  border-bottom: 3px solid var(--orange);
}
.brand { display: inline-flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; font-weight: 700; font-size: 17px; }
.brand-mark { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 6px; background: var(--orange); }
.brand-mark svg { width: 20px; height: 20px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.connection { display: flex; align-items: center; gap: 7px; margin-right: 8px; color: #c7cdd3; font-size: 12px; }
.connection-dot { width: 8px; height: 8px; border-radius: 50%; background: #808890; }
.connection.is-online .connection-dot { background: #4bd48a; box-shadow: 0 0 0 3px rgba(75, 212, 138, 0.16); }
.connection.is-online { color: #e5f9ee; }

.app-shell { min-height: calc(100vh - 60px); display: grid; grid-template-columns: 208px minmax(0, 1fr); }
.sidebar { padding: 18px 12px; background: #fff; border-right: 1px solid var(--line); }
.nav-item {
  width: 100%; min-height: 42px; display: flex; align-items: center; gap: 11px; padding: 0 12px;
  border: 0; border-left: 3px solid transparent; border-radius: 4px; background: transparent;
  color: #4f5a65; text-align: left; font-weight: 600;
}
.nav-item + .nav-item { margin-top: 4px; }
.nav-item:hover { background: var(--surface-soft); color: var(--ink); }
.nav-item.is-active { background: var(--orange-soft); border-left-color: var(--orange); color: var(--orange-dark); }

.main-content { min-width: 0; padding: 28px; }
.view { max-width: 1440px; margin: 0 auto; }
.view[hidden] { display: none; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 20px; }
h1, h2, p { margin: 0; }
h1 { font-size: 24px; line-height: 1.25; font-weight: 720; }
.page-heading p, .dialog-heading p { margin-top: 5px; color: var(--muted); font-size: 12px; }

.toolbar { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.search-field { position: relative; width: min(420px, 100%); }
.search-field svg { position: absolute; top: 50%; left: 11px; width: 16px; height: 16px; color: var(--muted); transform: translateY(-50%); pointer-events: none; }
.search-field input { width: 100%; padding-left: 36px; }

input, select {
  width: 100%; min-height: 38px; padding: 8px 10px; border: 1px solid var(--line-strong);
  border-radius: 5px; background: #fff; color: var(--ink); outline: none;
}
input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(23, 105, 170, 0.12); }
input::placeholder { color: #939ba3; }

.button, .icon-button {
  display: inline-flex; align-items: center; justify-content: center; border: 1px solid transparent;
  border-radius: 5px; font-weight: 650; transition: background 120ms, border-color 120ms, color 120ms;
}
.button { min-height: 38px; gap: 8px; padding: 7px 13px; white-space: nowrap; }
.button svg { width: 16px; height: 16px; }
.button.primary { background: var(--orange); border-color: var(--orange); color: #fff; }
.button.primary:hover { background: var(--orange-dark); border-color: var(--orange-dark); }
.button.secondary { background: #fff; border-color: var(--line-strong); color: #36414b; }
.button.secondary:hover { background: var(--surface-soft); border-color: #9ca6af; }
.button.danger { background: #fff; border-color: #efb6b1; color: var(--red); }
.button:disabled { opacity: 0.55; cursor: not-allowed; }
.icon-button { width: 36px; height: 36px; padding: 0; background: transparent; color: inherit; }
.topbar .icon-button:hover { background: rgba(255, 255, 255, 0.1); }

.table-frame { position: relative; overflow-x: auto; background: var(--surface); border: 1px solid var(--line); border-radius: 7px; }
table { width: 100%; border-collapse: collapse; text-align: left; }
th, td { padding: 11px 13px; border-bottom: 1px solid #e6e9ed; vertical-align: middle; }
th { color: #5f6973; background: #f8f9fa; font-size: 11px; font-weight: 700; text-transform: uppercase; white-space: nowrap; }
td { min-width: 100px; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fbfcfd; }
.actions-column { width: 158px; text-align: right; }
.row-actions { display: flex; justify-content: flex-end; gap: 3px; }
.row-actions .icon-button { width: 31px; height: 31px; color: #59646f; }
.row-actions .icon-button:hover { background: var(--surface-soft); color: var(--ink); }
.row-actions .danger-action:hover { background: var(--red-soft); color: var(--red); }
.icon-button.is-spinning svg { animation: spin 800ms linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.primary-cell { min-width: 190px; font-weight: 650; }
.file-link { color: var(--blue); text-decoration: none; }
.file-link:hover { text-decoration: underline; }
.secondary-line { display: block; max-width: 300px; margin-top: 3px; color: var(--muted); font: 11px/1.4 ui-monospace, SFMono-Regular, Consolas, monospace; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mono { font: 12px/1.45 ui-monospace, SFMono-Regular, Consolas, monospace; }
.truncate { display: block; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 5px; font-size: 11px; font-weight: 700; }
.badge.enabled, .badge.configured { color: var(--green); background: var(--green-soft); }
.badge.legacy { color: var(--blue); background: var(--blue-soft); }
.badge.disabled, .badge.missing { color: var(--red); background: var(--red-soft); }
.empty-state { min-height: 260px; display: grid; place-content: center; justify-items: center; gap: 10px; color: var(--muted); }
.empty-state[hidden] { display: none; }
.empty-state svg { width: 32px; height: 32px; }

dialog { width: min(680px, calc(100vw - 28px)); max-height: calc(100vh - 40px); padding: 0; border: 1px solid var(--line); border-radius: 8px; background: #fff; box-shadow: var(--shadow); color: var(--ink); }
dialog::backdrop { background: rgba(20, 26, 32, 0.55); }
.dialog-form { padding: 20px; overflow-y: auto; }
.dialog-heading { display: flex; align-items: flex-start; gap: 12px; margin-bottom: 20px; }
.dialog-heading h2 { font-size: 18px; }
.dialog-heading .close-dialog { margin-left: auto; color: var(--muted); }
.dialog-icon { display: grid; place-items: center; width: 36px; height: 36px; border-radius: 6px; background: var(--orange-soft); color: var(--orange-dark); }
.auth-form { max-width: 440px; margin: 0 auto; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.form-grid label, .dialog-form > label { display: grid; gap: 6px; min-width: 0; }
label > span { color: #4d5862; font-size: 12px; font-weight: 650; }
.span-two { grid-column: 1 / -1; }
.toggle-row { align-content: end; }
.toggle-row input { width: 18px; min-height: 18px; accent-color: var(--orange); }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 20px; }

.upload-workspace { background: #fff; border: 1px solid var(--line); border-radius: 7px; padding: 22px; }
.drop-zone { min-height: 230px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 9px; border: 1px dashed #aeb8c2; border-radius: 6px; background: #fafbfc; cursor: pointer; }
.drop-zone:hover, .drop-zone.is-dragging { border-color: var(--orange); background: var(--orange-soft); }
.drop-zone input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.drop-icon { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 7px; color: var(--blue); background: var(--blue-soft); }
.drop-icon svg { width: 25px; height: 25px; }
.drop-zone > span:last-child { color: var(--muted); font-size: 12px; }
.upload-fields { margin-top: 20px; grid-template-columns: 2fr 1fr; }
.upload-progress { margin-top: 20px; }
.upload-progress > div { display: flex; justify-content: space-between; margin-bottom: 7px; font-size: 12px; }
progress { width: 100%; height: 9px; accent-color: var(--orange); }

.toast-region { position: fixed; z-index: 50; right: 18px; bottom: 18px; display: grid; gap: 8px; width: min(380px, calc(100vw - 36px)); }
.toast { display: flex; align-items: flex-start; gap: 9px; padding: 12px 14px; border: 1px solid var(--line); border-left: 4px solid var(--green); border-radius: 6px; background: #fff; box-shadow: var(--shadow); }
.toast.error { border-left-color: var(--red); }
.toast svg { flex: 0 0 auto; width: 17px; height: 17px; color: var(--green); }
.toast.error svg { color: var(--red); }
.toast span { min-width: 0; line-height: 1.45; overflow-wrap: anywhere; }

@media (max-width: 900px) {
  .app-shell { display: block; min-height: calc(100vh - 60px); }
  .sidebar { position: sticky; top: 60px; z-index: 15; display: grid; grid-template-columns: repeat(3, 1fr); align-items: start; align-content: start; padding: 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav-item + .nav-item { margin-top: 0; }
  .nav-item { justify-content: center; min-height: 40px; padding: 0 8px; border-left: 0; border-bottom: 3px solid transparent; }
  .nav-item.is-active { border-bottom-color: var(--orange); }
  .main-content { padding: 20px 16px; }
  .upload-fields { grid-template-columns: 1fr; }
}

@media (max-width: 560px) {
  .topbar { height: 56px; padding: 0 12px; }
  .app-shell { min-height: calc(100vh - 56px); }
  .brand { font-size: 15px; }
  .brand-mark { width: 31px; height: 31px; }
  .connection span:last-child { display: none; }
  .sidebar { top: 56px; }
  .nav-item { flex-direction: column; gap: 3px; min-height: 50px; font-size: 11px; }
  .nav-item svg { width: 16px; height: 16px; }
  .main-content { padding: 17px 12px; }
  .page-heading { align-items: center; }
  h1 { font-size: 20px; }
  .page-heading .button span { display: none; }
  .page-heading .button { width: 38px; padding: 0; }
  .toolbar { align-items: stretch; }
  .toolbar .button span { display: none; }
  .toolbar .button { width: 38px; padding: 0; }
  .form-grid { grid-template-columns: 1fr; }
  .span-two { grid-column: auto; }
  .drop-zone { min-height: 190px; }
  dialog { max-height: calc(100vh - 20px); }
}
