:root {
  --bg: #f7f4ef;
  --surface: #fffdf9;
  --border: #e8dfd3;
  --text: #2c2419;
  --muted: #7a6f62;
  --accent: #b33a2a;
  --accent-soft: #f3e4df;
  --gold: #c49a3c;
  --ok: #2d6a4f;
  --warn: #b86e00;
  --danger: #a4161a;
  --shadow: 0 8px 24px rgba(44, 36, 25, 0.08);
  --radius: 12px;
  --font: "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: var(--font);
  color: var(--text);
  background: linear-gradient(135deg, #f7f4ef 0%, #efe8dc 100%);
}

.app { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  background: #2c2419;
  color: #f5efe6;
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  flex-shrink: 0;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 28px;
  padding: 8px;
}
.brand-icon {
  width: 42px;
  height: 42px;
  border-radius: 10px;
  background: var(--accent);
  display: grid;
  place-items: center;
  font-weight: 700;
  font-size: 20px;
}
.brand small { display: block; opacity: 0.65; font-size: 11px; margin-top: 2px; }

.nav-item {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: inherit;
  padding: 12px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  margin-bottom: 4px;
}
.nav-item:hover { background: rgba(255,255,255,0.08); }
.nav-item.active { background: var(--accent); color: #fff; }

.sidebar-foot { margin-top: auto; padding-top: 16px; }
.token-field { display: block; font-size: 12px; }
.token-field input {
  width: 100%;
  margin-top: 6px;
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(0,0,0,0.2);
  color: #fff;
}

.main { flex: 1; padding: 24px 28px 40px; overflow: auto; }

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}
.topbar h1 { margin: 0; font-size: 24px; font-weight: 600; }
.refresh-hint { font-size: 12px; color: var(--muted); margin-right: 12px; }

.view { display: none; }
.view.active { display: block; }

.btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  padding: 8px 14px;
  border-radius: 8px;
  cursor: pointer;
  font-size: 13px;
}
.btn:hover { border-color: #cbbfb0; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { filter: brightness(1.05); }
.btn-ghost { background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-danger { color: var(--danger); border-color: #e8c4c4; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card-label { font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.card-value { font-size: 28px; font-weight: 700; line-height: 1.1; }
.card-sub { font-size: 12px; color: var(--muted); margin-top: 6px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 20px;
  box-shadow: var(--shadow);
}
.panel h3 { margin: 0 0 14px; font-size: 16px; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
}
.toolbar input, .toolbar select {
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
}
.toolbar input[type="search"] { min-width: 220px; flex: 1; max-width: 360px; }

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.data-table th, .data-table td {
  border-bottom: 1px solid var(--border);
  padding: 10px 8px;
  text-align: left;
  vertical-align: top;
}
.data-table th { color: var(--muted); font-weight: 600; font-size: 12px; }
.data-table tr:hover td { background: #faf6f0; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
}
.badge-auto { background: #e8f0ea; color: var(--ok); }
.badge-reviewed { background: #e8edf5; color: #3d5a80; }
.badge-conflict { background: #fde8e8; color: var(--danger); }
.badge-pending { background: #fff3cd; color: var(--warn); }

.pager {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  font-size: 13px;
  color: var(--muted);
}

.kv-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
  margin-bottom: 16px;
}
.kv { background: #faf6f0; border-radius: 8px; padding: 10px 12px; }
.kv dt { font-size: 11px; color: var(--muted); margin-bottom: 4px; }
.kv dd { margin: 0; font-size: 13px; word-break: break-all; }

.entity-dialog {
  border: none;
  border-radius: var(--radius);
  padding: 0;
  width: min(920px, 94vw);
  max-height: 90vh;
  box-shadow: 0 24px 64px rgba(0,0,0,0.2);
}
.entity-dialog::backdrop { background: rgba(44,36,25,0.45); }
.dialog-inner { display: flex; flex-direction: column; max-height: 90vh; }
.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.dialog-header h2 { margin: 0; font-size: 18px; }
.dialog-body {
  padding: 16px 20px 24px;
  overflow: auto;
  background: var(--bg);
}

.section-title {
  font-size: 14px;
  font-weight: 600;
  margin: 18px 0 10px;
  color: var(--accent);
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: #2c2419;
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13px;
  z-index: 100;
}

.auth-gate {
  position: fixed;
  inset: 0;
  background: rgba(44, 36, 25, 0.55);
  display: grid;
  place-items: center;
  z-index: 200;
  padding: 20px;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px;
  max-width: 420px;
  width: 100%;
  box-shadow: var(--shadow);
}
.auth-card h2 { margin: 0 0 10px; font-size: 20px; }
.auth-card p { margin: 0 0 16px; font-size: 14px; color: var(--muted); line-height: 1.5; }
.auth-card input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 12px;
  font-size: 14px;
}
.auth-card .btn { width: 100%; }

.token-field .btn-sm { font-size: 12px; padding: 8px; }

.empty { text-align: center; padding: 40px; color: var(--muted); }
.loading { text-align: center; padding: 48px; color: var(--muted); }

@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; }
  .main { padding: 16px; }
}
