:root {
  color: #17211b;
  background: #f4f6f4;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  --surface: #ffffff;
  --surface-muted: #f8faf8;
  --line: #dce3de;
  --text: #17211b;
  --muted: #68736c;
  --primary: #18794e;
  --primary-dark: #11623e;
  --primary-soft: #e6f3eb;
  --danger: #b42318;
  --danger-soft: #fcebea;
  --warning: #9a6700;
}

* { box-sizing: border-box; }
body { margin: 0; min-width: 320px; min-height: 100vh; background: #f4f6f4; color: var(--text); }
button, input { font: inherit; }
button { cursor: pointer; }
a { color: var(--primary-dark); }
.hidden { display: none !important; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .96);
}
.brand { display: flex; align-items: center; gap: 11px; color: inherit; text-decoration: none; }
.brand-mark { width: 36px; height: 36px; display: grid; place-items: center; border-radius: 7px; background: #15251d; color: white; font-size: 12px; font-weight: 800; }
.brand strong, .brand small { display: block; letter-spacing: 0; }
.brand strong { font-size: 15px; line-height: 1.15; }
.brand small { margin-top: 2px; color: var(--muted); font-size: 11px; }
.topbar-status { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 13px; }
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: #9aa39d; }
.status-dot.online { background: #20a567; }
.status-dot.offline { background: var(--danger); }
.status-dot.locked { background: var(--warning); }
.status-dot.loading { background: #4d7ea8; }

.shell { min-height: calc(100vh - 64px); display: grid; grid-template-columns: 208px minmax(0, 1fr); }
.sidebar { padding: 24px 14px; border-right: 1px solid var(--line); background: #eef2ef; }
.nav-item { width: 100%; min-height: 40px; padding: 0 12px; border: 0; border-radius: 6px; background: transparent; color: #4d5951; text-align: left; font-weight: 650; }
.nav-item:hover { background: #e4eae6; }
.nav-item.active { background: var(--surface); color: var(--primary-dark); box-shadow: inset 3px 0 var(--primary); }
.content { width: 100%; max-width: 1180px; padding: 36px 44px 80px; }
.page-head, .section-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.page-head { margin-bottom: 28px; }
.page-head h1, .auth-panel h1 { margin: 4px 0 0; font-size: 28px; line-height: 1.2; letter-spacing: 0; }
.section-label { margin: 0; color: var(--primary-dark); font-size: 12px; font-weight: 750; text-transform: uppercase; letter-spacing: 0; }
.version { padding: 5px 8px; border: 1px solid var(--line); border-radius: 5px; background: var(--surface); color: var(--muted); font-size: 12px; }

.metrics { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 8px; background: var(--surface); overflow: hidden; }
.metric { min-height: 116px; padding: 22px; border-right: 1px solid var(--line); }
.metric:last-child { border-right: 0; }
.metric span { display: block; color: var(--muted); font-size: 13px; }
.metric strong { display: block; margin-top: 18px; font-size: 26px; letter-spacing: 0; }
.detail-section, .form-section { margin-top: 32px; }
.section-head { min-height: 40px; margin-bottom: 12px; }
.section-head h2 { margin: 0; font-size: 16px; letter-spacing: 0; }
.info-list { margin: 0; border-top: 1px solid var(--line); background: var(--surface); }
.info-list div { min-height: 52px; display: grid; grid-template-columns: 190px minmax(0, 1fr); align-items: center; gap: 20px; padding: 10px 16px; border-bottom: 1px solid var(--line); }
.info-list dt { color: var(--muted); font-size: 13px; }
.info-list dd { margin: 0; overflow-wrap: anywhere; font-size: 13px; font-weight: 600; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; padding: 22px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.field span, .auth-form label span { display: block; margin-bottom: 7px; color: var(--muted); font-size: 12px; font-weight: 650; }
.field input, .auth-form input, .mapping-row input { width: 100%; height: 42px; padding: 0 11px; border: 1px solid #cbd4ce; border-radius: 6px; background: white; color: var(--text); outline: none; }
.field input:focus, .auth-form input:focus, .mapping-row input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(24, 121, 78, .12); }
.span-two { grid-column: span 2; }
.mapping-table { border: 1px solid var(--line); border-radius: 8px; background: var(--surface); overflow: hidden; }
.mapping-header, .mapping-row { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) 40px; align-items: center; gap: 12px; }
.mapping-header { min-height: 42px; padding: 0 16px; border-bottom: 1px solid var(--line); background: var(--surface-muted); color: var(--muted); font-size: 12px; font-weight: 700; }
.mapping-row { padding: 12px 16px; border-bottom: 1px solid var(--line); }
.mapping-row:last-child { border-bottom: 0; }
.primary-button, .secondary-button { min-height: 38px; padding: 0 15px; border-radius: 6px; font-weight: 700; }
.primary-button { border: 1px solid var(--primary); background: var(--primary); color: white; }
.primary-button:hover { background: var(--primary-dark); }
.primary-button:disabled { cursor: wait; opacity: .65; }
.secondary-button { border: 1px solid #bdc8c0; background: var(--surface); color: var(--text); }
.icon-button { width: 34px; height: 34px; display: grid; place-items: center; padding: 0; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--text); font-size: 18px; }
.icon-button:hover { background: var(--surface-muted); }
.icon-button.danger { color: var(--danger); }
.save-state { min-height: 22px; color: var(--muted); font-size: 13px; }

.task-table-wrap { position: relative; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); overflow-x: auto; }
.task-table { width: 100%; min-width: 800px; border-collapse: collapse; }
.task-table th, .task-table td { height: 50px; padding: 0 14px; border-bottom: 1px solid var(--line); text-align: left; font-size: 12px; }
.task-table th { background: var(--surface-muted); color: var(--muted); font-weight: 700; }
.task-table tr:last-child td { border-bottom: 0; }
.status-badge { display: inline-flex; align-items: center; min-height: 25px; padding: 0 8px; border-radius: 4px; background: #edf0ee; color: #4d5951; font-weight: 700; }
.status-processing, .status-queued { background: #fff4d6; color: #7a5200; }
.status-completed { background: var(--primary-soft); color: var(--primary-dark); }
.status-failed { background: var(--danger-soft); color: var(--danger); }
.empty-table { padding: 48px; color: var(--muted); text-align: center; font-size: 13px; }

.auth-panel { max-width: 480px; margin: 64px auto; padding: 28px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.auth-form { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: end; gap: 12px; margin-top: 24px; }
.form-error { min-height: 20px; color: var(--danger); font-size: 13px; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 30; max-width: min(420px, calc(100vw - 32px)); padding: 12px 15px; border-radius: 6px; background: #17211b; color: white; box-shadow: 0 12px 32px rgba(23, 33, 27, .2); font-size: 13px; }
.toast.error { background: #8f1d14; }

@media (max-width: 760px) {
  .topbar { height: 58px; padding: 0 14px; }
  .topbar-status #serviceText { display: none; }
  .shell { min-height: calc(100vh - 58px); display: block; }
  .sidebar { position: sticky; top: 58px; z-index: 8; display: grid; grid-template-columns: repeat(3, 1fr); padding: 8px; border-right: 0; border-bottom: 1px solid var(--line); }
  .nav-item { text-align: center; }
  .nav-item.active { box-shadow: inset 0 -3px var(--primary); }
  .content { padding: 26px 16px 64px; }
  .page-head { align-items: flex-start; }
  .page-head h1, .auth-panel h1 { font-size: 24px; }
  .metrics { grid-template-columns: 1fr; }
  .metric { min-height: 88px; border-right: 0; border-bottom: 1px solid var(--line); }
  .metric:last-child { border-bottom: 0; }
  .metric strong { margin-top: 10px; font-size: 22px; }
  .info-list div { grid-template-columns: 1fr; gap: 5px; padding: 13px 14px; }
  .form-grid { grid-template-columns: 1fr; padding: 16px; }
  .span-two { grid-column: span 1; }
  .mapping-header { display: none; }
  .mapping-row { grid-template-columns: minmax(0, 1fr) 34px; }
  .mapping-row .upstream-model { grid-column: 1; grid-row: 2; }
  .mapping-row .icon-button { grid-column: 2; grid-row: 1 / span 2; align-self: center; }
  .auth-panel { margin: 28px auto; padding: 22px; }
  .auth-form { grid-template-columns: 1fr; }
}
