:root {
  --background: #fafafa;
  --foreground: #18181b;
  --card: #ffffff;
  --card-foreground: #18181b;
  --muted: #f4f4f5;
  --muted-foreground: #71717a;
  --border: #e4e4e7;
  --input: #d4d4d8;
  --primary: #18181b;
  --primary-foreground: #ffffff;
  --secondary: #f8f8f8;
  --accent: #f4f4f5;
  --accent-foreground: #27272a;
  --success: #047857;
  --warning: #a16207;
  --danger: #dc2626;
  --radius: 8px;
  --shadow: 0 12px 32px rgba(24, 24, 27, .08);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
  color: var(--foreground);
  background: var(--background);
}

button, input, select { font: inherit; }

button { cursor: pointer; }

input, select {
  min-width: 0;
  width: 100%;
  border: 1px solid var(--input);
  border-radius: 6px;
  padding: 9px 10px;
  color: var(--foreground);
  background: var(--card);
  outline: none;
}

input:focus, select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(24, 24, 27, .08);
}

label {
  display: grid;
  gap: 7px;
  color: var(--foreground);
  font-size: 13px;
  font-weight: 500;
}

.hidden { display: none !important; }

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  border: 1px solid var(--primary);
  border-radius: 6px;
  background: var(--primary);
  color: var(--primary-foreground);
  padding: 8px 13px;
  font-weight: 600;
  line-height: 1;
  white-space: nowrap;
}

.button:hover { opacity: .92; }

.button:disabled {
  cursor: not-allowed;
  opacity: .62;
}

.button.outline {
  border-color: var(--border);
  background: var(--card);
  color: var(--foreground);
}

.button.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted-foreground);
}

.button.danger {
  border-color: rgba(220, 38, 38, .22);
  background: #fef2f2;
  color: var(--danger);
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--card);
  color: var(--muted-foreground);
  font-size: 20px;
  line-height: 1;
}

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

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

.login-brand, .brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  display: inline-grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  background: var(--primary);
  color: var(--primary-foreground);
  font-weight: 700;
  letter-spacing: 0;
}

.login-panel h1, .brand strong {
  margin: 0;
  font-size: 20px;
}

.login-panel p, .brand span, .panel-header p, .section-toolbar p, .dialog-header p {
  margin: 4px 0 0;
  color: var(--muted-foreground);
  font-size: 13px;
}

.form-message {
  min-height: 18px;
  color: var(--danger);
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 238px minmax(0, 1fr);
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  background: var(--card);
  border-right: 1px solid var(--border);
  padding: 18px 14px;
}

.nav-list {
  display: grid;
  gap: 6px;
}

.nav {
  width: 100%;
  min-height: 36px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted-foreground);
  padding: 8px 10px;
  text-align: left;
  font-weight: 600;
}

.nav.active, .nav:hover {
  background: var(--muted);
  color: var(--foreground);
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 8px;
}

.content {
  min-width: 0;
  padding: 22px;
}

.topbar, .section-toolbar, .panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.topbar {
  margin-bottom: 18px;
}

.topbar h2, .section-toolbar h3, .panel-header h3, .dialog-header h3 {
  margin: 0;
  font-size: 20px;
}

.topbar p {
  margin: 5px 0 0;
  color: var(--muted-foreground);
  font-size: 13px;
}

.actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
}

.metric-card, .panel, .log-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.metric-card {
  padding: 16px;
  min-width: 0;
}

.metric-card span {
  display: block;
  color: var(--muted-foreground);
  font-size: 13px;
}

.metric-card strong {
  display: block;
  margin-top: 8px;
  font-size: 24px;
  overflow-wrap: anywhere;
}

.chart-wrap {
  height: 334px;
  margin-top: 14px;
  padding: 14px;
}

#trafficChart {
  width: 100%;
  height: calc(100% - 58px);
  display: block;
}

.section-toolbar {
  margin-bottom: 12px;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

th {
  background: var(--secondary);
  color: var(--muted-foreground);
  font-size: 12px;
  font-weight: 700;
}

tbody tr:hover {
  background: #fafafa;
}

td a {
  color: var(--foreground);
  text-decoration: underline;
  text-underline-offset: 3px;
  margin-right: 8px;
}

.row-title {
  display: grid;
  gap: 4px;
}

.muted {
  color: var(--muted-foreground);
  font-size: 12px;
}

.row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.row-actions .button {
  min-height: 30px;
  padding: 6px 9px;
  font-size: 12px;
}

.cell-input, .cell-select {
  width: 100%;
  min-width: 110px;
  margin-top: 4px;
  padding: 7px 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 2px 9px;
  background: var(--muted);
  color: var(--foreground);
  white-space: nowrap;
  font-size: 12px;
  font-weight: 700;
}

.badge.success {
  background: #ecfdf5;
  color: var(--success);
}

.badge.warn {
  background: #fffbeb;
  color: var(--warning);
}

.progress {
  width: 120px;
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--muted);
  margin-top: 8px;
}

.progress span {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--primary);
}

.logs {
  display: grid;
  gap: 8px;
}

.log-item {
  padding: 12px;
}

.empty-state {
  display: grid;
  min-height: 96px;
  place-items: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
  color: var(--muted-foreground);
  background: var(--card);
  font-size: 13px;
}

.log-item span {
  color: var(--muted-foreground);
  margin-right: 8px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(24, 24, 27, .42);
}

.dialog-card {
  position: relative;
  z-index: 1;
  width: min(680px, 100%);
  display: grid;
  gap: 18px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}

.dialog-header, .dialog-footer {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.dialog-footer {
  justify-content: flex-end;
}

.field-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.field-grid.single {
  grid-template-columns: 1fr;
}

.wide-field {
  grid-column: 1 / -1;
}

.modal-open {
  overflow: hidden;
}

@media (max-width: 960px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky;
    height: auto;
    z-index: 2;
  }
  .nav-list {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
  .sidebar-footer {
    grid-template-columns: 1fr 1fr;
  }
  .metrics { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .topbar, .section-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }
  .actions { justify-content: flex-start; }
}

@media (max-width: 620px) {
  .content { padding: 14px; }
  .metrics, .field-grid { grid-template-columns: 1fr; }
  .nav-list { grid-template-columns: 1fr 1fr; }
  .dialog-footer { flex-direction: column-reverse; }
  .dialog-footer .button { width: 100%; }
}
