:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --text: #1a2332;
  --muted: #5c6b7a;
  --border: #e2e8f0;
  --accent: #0d9488;
  --accent-soft: #ccfbf1;
  --danger: #dc2626;
  --warning: #d97706;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.08);
  --sidebar-w: 280px;
  --radius: 12px;
  --font: "Segoe UI", Tahoma, system-ui, sans-serif;
}

[data-theme="dark"] {
  --bg: #0f1419;
  --surface: #1a2332;
  --text: #e8edf4;
  --muted: #94a3b8;
  --border: #2d3a4f;
  --accent: #2dd4bf;
  --accent-soft: #134e4a;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

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

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem;
  border-bottom: 1px solid var(--border);
}

.sidebar-brand strong { display: block; font-size: 1rem; }
.sidebar-brand small { color: var(--muted); font-size: 0.75rem; }

.sidebar-search {
  padding: 0.75rem 1rem;
  position: relative;
}

.sidebar-search i {
  position: absolute;
  right: 1.5rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--muted);
  font-size: 0.85rem;
}

.sidebar-search input {
  width: 100%;
  padding: 0.6rem 2rem 0.6rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
}

.filter-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  padding: 0 1rem 0.75rem;
}

.chip {
  font-size: 0.7rem;
  padding: 0.25rem 0.5rem;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}

.chip.active, .chip:hover {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

.table-nav {
  flex: 1;
  overflow-y: auto;
  padding: 0 0.5rem 1rem;
}

.table-nav a {
  display: block;
  padding: 0.4rem 0.75rem;
  border-radius: 6px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.85rem;
  font-family: ui-monospace, monospace;
}

.table-nav a:hover, .table-nav a.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.logout-form { padding: 1rem; border-top: 1px solid var(--border); }

.content {
  flex: 1;
  margin-right: var(--sidebar-w);
  padding: 1.5rem 2rem 3rem;
  max-width: 1200px;
}

.hero {
  background: linear-gradient(135deg, var(--accent) 0%, #0369a1 100%);
  color: #fff;
  border-radius: var(--radius);
  padding: 1.75rem 2rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.hero h1 { margin: 0 0 0.5rem; font-size: 1.75rem; }
.hero .meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
  font-size: 0.875rem;
  opacity: 0.95;
}

.stats-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  text-align: center;
  box-shadow: var(--shadow);
}

.stat-card i { font-size: 1.5rem; color: var(--accent); margin-bottom: 0.5rem; }
.stat-card .num { font-size: 1.5rem; font-weight: 700; }
.stat-card .label { font-size: 0.75rem; color: var(--muted); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-bottom: 1.5rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 0.9rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-size: 0.85rem;
}

.btn:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost { width: 100%; justify-content: center; background: transparent; }
.btn-menu { display: none; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  box-shadow: var(--shadow);
}

.panel h2 {
  margin: 0 0 1rem;
  font-size: 1.15rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.panel h2 i { color: var(--accent); }

.mermaid-wrap {
  overflow-x: auto;
  background: var(--bg);
  border-radius: 8px;
  padding: 1rem;
}

.table-section {
  scroll-margin-top: 1rem;
  margin-bottom: 2rem;
}

.table-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.table-header h3 {
  margin: 0;
  font-family: ui-monospace, monospace;
  font-size: 1.25rem;
}

.badge {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: var(--accent-soft);
  color: var(--accent);
  margin-left: 0.35rem;
}

.badge.warn { background: #fef3c7; color: var(--warning); }
[data-theme="dark"] .badge.warn { background: #422006; }

.relations-list { font-size: 0.875rem; color: var(--muted); margin: 0.5rem 0; }
.notes-list { margin: 0.5rem 0; padding-right: 1.25rem; font-size: 0.875rem; }

.table-wrap { overflow-x: auto; }

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
}

.data-table th, .data-table td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.65rem;
  text-align: right;
}

.data-table th { background: var(--bg); font-weight: 600; }
.data-table code { font-size: 0.8rem; }

.data-table tr.hidden { display: none; }
.data-table tr.sensitive td { opacity: 0.85; }

.copy-btn {
  border: none;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  padding: 0.15rem 0.35rem;
  font-size: 0.75rem;
}

.relation-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 1rem;
}

.relation-box h4 { margin: 0 0 0.5rem; font-size: 0.9rem; color: var(--accent); }
.relation-box ul { margin: 0; padding-right: 1rem; font-size: 0.8rem; }

.warning-block {
  border-right: 4px solid var(--warning);
  padding: 0.75rem 1rem;
  margin-bottom: 0.75rem;
  background: var(--bg);
  border-radius: 0 8px 8px 0;
  font-size: 0.875rem;
}

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 400px;
  width: 100%;
  text-align: center;
  box-shadow: var(--shadow);
}

.login-card .logo { margin-bottom: 1rem; }
.login-card h1 { font-size: 1.25rem; margin: 0 0 0.25rem; }
.login-card .muted { color: var(--muted); font-size: 0.875rem; margin-bottom: 1.5rem; }
.login-card label { display: block; text-align: right; margin-bottom: 0.35rem; font-size: 0.875rem; }
.login-card input {
  width: 100%;
  padding: 0.65rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-bottom: 1rem;
  background: var(--bg);
  color: var(--text);
}

.login-card button {
  width: 100%;
  padding: 0.75rem;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 1rem;
}

.alert-error { color: var(--danger); font-size: 0.875rem; margin-bottom: 1rem; }

.method-get { color: #059669; }
.method-post { color: #2563eb; }
.method-put, .method-patch { color: #d97706; }
.method-delete { color: var(--danger); }

@media (max-width: 900px) {
  .sidebar { transform: translateX(100%); }
  .sidebar.open { transform: translateX(0); }
  .content { margin-right: 0; padding: 1rem; }
  .btn-menu { display: inline-flex; }
}

@media print {
  .sidebar, .toolbar, .logout-form, .copy-btn { display: none !important; }
  .content { margin: 0; max-width: none; }
}
