:root {
  --bg: #f4f6fb;
  --sidebar: #1e293b;
  --sidebar-text: #cbd5e1;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --primary: #6366f1;
  --primary-hover: #4f46e5;
  --danger: #ef4444;
  --border: #e2e8f0;
  --success: #10b981;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}

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

.sidebar {
  width: 240px;
  background: var(--sidebar);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
.brand {
  padding: 1.25rem 1.5rem;
  font-weight: 700;
  font-size: 1.1rem;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.sidebar nav { flex: 1; padding: 1rem 0; }
.sidebar nav a {
  display: block;
  padding: .65rem 1.5rem;
  color: var(--sidebar-text);
  text-decoration: none;
}
.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar nav a.active {
  background: rgba(99,102,241,.25);
  color: #fff;
  border-right: 3px solid var(--primary);
}
.sidebar-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  justify-content: space-between;
  font-size: .875rem;
}
.sidebar-footer a { color: #94a3b8; }

.content {
  flex: 1;
  padding: 2rem;
  max-width: 1200px;
}

h1 { margin: 0 0 .25rem; font-size: 1.75rem; }
h2 { margin: 0 0 1rem; font-size: 1.15rem; }
h3 { margin: 0 0 .75rem; font-size: 1rem; }
.muted { color: var(--muted); margin: 0 0 1.5rem; }

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

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.25rem;
  box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.card-header h2 { margin: 0; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem;
  text-align: center;
}
.stat-value { font-size: 2rem; font-weight: 700; color: var(--primary); }
.stat-value-sm { font-size: 1.1rem; line-height: 1.3; word-break: break-word; }
.stat-label { color: var(--muted); font-size: .875rem; }

.breakdown-list { display: grid; gap: .85rem; }
.breakdown-row { display: grid; gap: .35rem; }
.breakdown-meta {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  font-size: .875rem;
}
.breakdown-label { flex: 1; min-width: 0; }
.breakdown-count {
  color: var(--muted);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.bar-track {
  height: 8px;
  background: #f1f5f9;
  border-radius: 999px;
  overflow: hidden;
}
.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #818cf8);
  border-radius: 999px;
  min-width: 2px;
}
.feedback-list {
  margin: .75rem 0 0;
  padding-left: 1.25rem;
  display: grid;
  gap: .65rem;
  font-size: .9rem;
}
.feedback-list li { line-height: 1.45; }
.ai-summary {
  margin-top: .75rem;
  min-height: 320px;
  background: #f8fafc;
}

.cards-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 1.25rem;
}

.btn {
  display: inline-block;
  padding: .55rem 1rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  font-size: .875rem;
  cursor: pointer;
  text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); }
.btn-secondary { background: #f1f5f9; }
.btn-danger { background: #fef2f2; color: var(--danger); border-color: #fecaca; }
.btn-sm { padding: .35rem .65rem; font-size: .8rem; }

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  margin-bottom: 1.25rem;
}
.tab {
  padding: .45rem .9rem;
  border-radius: 999px;
  background: #fff;
  border: 1px solid var(--border);
  text-decoration: none;
  color: var(--muted);
  font-size: .875rem;
}
.tab.active, .tab:hover {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.badge {
  display: inline-block;
  padding: .15rem .55rem;
  border-radius: 999px;
  background: #eef2ff;
  color: var(--primary);
  font-size: .75rem;
}
.badge-muted { background: #f1f5f9; color: var(--muted); }

.menu-list { list-style: none; padding: 0; margin: 0 0 1rem; }
.menu-item {
  display: flex;
  align-items: flex-start;
  gap: .75rem;
  padding: .85rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: .65rem;
  background: #fafbfc;
}
.menu-item.sortable-ghost { opacity: .5; background: #eef2ff; }
.drag-handle {
  cursor: grab;
  font-size: 1.25rem;
  color: var(--muted);
  user-select: none;
  padding-top: .15rem;
}
.menu-item-body { flex: 1; min-width: 0; }
.menu-item-header {
  display: flex;
  flex-wrap: wrap;
  gap: .5rem;
  align-items: center;
  margin-bottom: .35rem;
}
.menu-item-header code {
  font-size: .75rem;
  background: #f1f5f9;
  padding: .1rem .4rem;
  border-radius: 4px;
}
.menu-edit-panel {
  margin-top: .75rem;
  padding-top: .75rem;
  border-top: 1px dashed var(--border);
  display: grid;
  gap: .65rem;
}
details summary { cursor: pointer; color: var(--primary); font-size: .875rem; }

label { display: block; font-size: .875rem; font-weight: 500; margin-bottom: .35rem; }
input[type=text], input[type=password], input[type=url], input[type=file], select, textarea {
  width: 100%;
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  margin-top: .2rem;
}
textarea { resize: vertical; font-family: ui-monospace, monospace; font-size: .85rem; }
.checkbox-label { display: flex; align-items: center; gap: .5rem; font-weight: 400; }
.checkbox-label input { width: auto; margin: 0; }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: .75rem; }
.stack-form { display: grid; gap: .85rem; }
.form-actions { display: flex; gap: .5rem; flex-wrap: wrap; }
.grow { flex: 1; }

.data-table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.data-table th, .data-table td {
  text-align: left;
  padding: .65rem .5rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.data-table th { color: var(--muted); font-weight: 600; }
.preview { color: var(--muted); max-width: 360px; }
.nowrap { white-space: nowrap; }
.empty { text-align: center; color: var(--muted); padding: 2rem; }
.actions { white-space: nowrap; }
.inline-form { display: inline; }

.hint, .hint-card { font-size: .875rem; color: var(--muted); }
.hint-card ol { margin: .5rem 0 0 1.25rem; }

.alert {
  padding: .75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
}
.alert-error { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; }
.alert-success { background: #ecfdf5; color: #047857; border: 1px solid #a7f3d0; }

.settings-dl { margin: 0; }
.settings-dl dt { font-weight: 600; margin-top: .5rem; }
.settings-dl dd { margin: 0; color: var(--muted); }
.link-list { margin: 0; padding-left: 1.25rem; }
.link-list a { color: var(--primary); }

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1e293b 0%, #334155 100%);
}
.login-card {
  background: #fff;
  padding: 2rem;
  border-radius: 16px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,.25);
}
.login-card h1 { text-align: center; margin-bottom: .25rem; }
.login-card .muted { text-align: center; }
.login-card form { display: grid; gap: 1rem; margin-top: 1.5rem; }
.login-card button { width: 100%; margin-top: .5rem; }

@media (max-width: 768px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; }
  .content { padding: 1rem; }
}
