:root {
  --bg: #f4f6f8;
  --panel: #ffffff;
  --text: #17202a;
  --muted: #687385;
  --line: #dfe4ea;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --primary-soft: #eaf1ff;
  --success: #0f8a5f;
  --warning: #b7791f;
  --danger: #c24132;
  --danger-soft: #fff1ee;
  --radius: 8px;
  font-family: "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  color: var(--text);
  background: var(--bg);
}

button, input, select {
  font: inherit;
}

button {
  border: 0;
  border-radius: 6px;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

input, select {
  height: 36px;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 0 10px;
  background: #fff;
  color: var(--text);
}

input:focus, select:focus {
  outline: 2px solid rgba(37, 99, 235, 0.16);
  border-color: var(--primary);
}

.hidden { display: none !important; }

.login-view {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background:
    linear-gradient(120deg, rgba(37, 99, 235, 0.08), transparent 42%),
    var(--bg);
}

.login-panel {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 28px;
  box-shadow: 0 18px 48px rgba(18, 27, 38, 0.12);
}

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

.brand-mark.small {
  width: 36px;
  height: 36px;
  font-size: 13px;
}

.login-panel h1 {
  margin: 18px 0 6px;
  font-size: 26px;
}

.login-panel p {
  margin: 0 0 22px;
  color: var(--muted);
}

.login-panel label {
  display: grid;
  gap: 8px;
  color: var(--muted);
  font-size: 14px;
}

.login-panel input {
  width: 100%;
  height: 42px;
}

.primary-btn, .secondary-btn, .ghost-btn, .danger-btn {
  height: 36px;
  padding: 0 14px;
}

.primary-btn {
  background: var(--primary);
  color: #fff;
}

.primary-btn:hover { background: var(--primary-dark); }

.secondary-btn {
  background: var(--primary-soft);
  color: var(--primary-dark);
}

.ghost-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--line);
}

.danger-btn {
  background: var(--danger-soft);
  color: var(--danger);
}

#loginBtn {
  width: 100%;
  margin-top: 16px;
  height: 42px;
}

.message {
  margin-top: 12px;
  min-height: 20px;
  color: var(--danger);
  font-size: 14px;
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 220px 1fr;
}

.sidebar {
  background: #111827;
  color: #fff;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

.sidebar-brand {
  display: flex;
  gap: 10px;
  align-items: center;
}

.sidebar-brand span {
  display: block;
  margin-top: 2px;
  color: #aeb8c7;
  font-size: 12px;
}

.nav-item {
  width: 100%;
  text-align: left;
  height: 38px;
  background: rgba(255,255,255,0.08);
  color: #fff;
  padding: 0 12px;
}

.sidebar .ghost-btn {
  margin-top: auto;
  color: #cbd5e1;
  border-color: rgba(255,255,255,0.16);
}

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

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 18px;
}

.topbar h2 {
  margin: 0;
  font-size: 24px;
}

.topbar p {
  margin: 4px 0 0;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 10px;
}

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

.stat-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
}

.stat-card span {
  color: var(--muted);
  font-size: 13px;
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: 28px;
}

.stat-card.danger strong { color: var(--danger); }

.toolbar, .table-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
}

.toolbar {
  padding: 14px;
  margin-bottom: 14px;
  display: grid;
  gap: 12px;
}

.filter-row, .create-row {
  display: grid;
  gap: 10px;
}

.filter-row {
  grid-template-columns: 1fr 140px 140px;
}

.create-row {
  grid-template-columns: 220px 1fr 90px 96px;
}

.table-card {
  overflow: hidden;
}

.table-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.table-head span {
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  overflow: auto;
}

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

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

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
  background: #fafbfc;
}

td {
  font-size: 14px;
}

.code-cell {
  font-family: Consolas, monospace;
  font-weight: 600;
}

.muted {
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 24px;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  background: var(--primary-soft);
  color: var(--primary-dark);
}

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

.badge.danger {
  background: var(--danger-soft);
  color: var(--danger);
}

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

.link-btn {
  background: transparent;
  color: var(--primary);
  padding: 0;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  background: #111827;
  color: #fff;
  padding: 10px 14px;
  border-radius: 6px;
  box-shadow: 0 10px 30px rgba(0,0,0,0.18);
}

dialog {
  width: min(720px, calc(100vw - 40px));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0;
}

dialog::backdrop {
  background: rgba(15, 23, 42, 0.36);
}

.dialog-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--line);
}

.dialog-head button {
  width: 30px;
  height: 30px;
  background: transparent;
  font-size: 20px;
}

#detailContent {
  margin: 0;
  padding: 16px;
  max-height: 65vh;
  overflow: auto;
  white-space: pre-wrap;
  font-family: Consolas, monospace;
  font-size: 13px;
}

@media (max-width: 920px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar {
    flex-direction: row;
    align-items: center;
  }
  .sidebar nav { display: none; }
  .sidebar .ghost-btn { margin-left: auto; margin-top: 0; }
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .filter-row, .create-row { grid-template-columns: 1fr; }
  .topbar { align-items: flex-start; flex-direction: column; }
}
