:root {
  --bg: #f4f6f9;
  --surface: #ffffff;
  --text: #1a2332;
  --muted: #5c6b7a;
  --accent: #2563eb;
  --accent-soft: #dbeafe;
  --border: #e2e8f0;
  --success: #059669;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(15, 23, 42, 0.06);
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

header {
  background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
  color: #fff;
  padding: 1.25rem 1.25rem 1.75rem;
}

.header-row {
  max-width: 1100px;
  margin: 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}

.auth-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.4rem;
}

.auth-user {
  font-size: 0.85rem;
  opacity: 0.95;
  margin-right: 0.25rem;
}

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.82rem;
}

.hint {
  font-size: 0.88rem;
  color: var(--muted);
  margin: 0 0 1rem;
}

.modal-wide {
  max-width: 640px;
}

.admin-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

header h1 {
  margin: 0 0 0.35rem;
  font-size: 1.65rem;
  font-weight: 700;
}

header p {
  margin: 0;
  opacity: 0.9;
  font-size: 0.95rem;
  max-width: 42rem;
}

.badge {
  display: inline-block;
  background: rgba(255,255,255,0.2);
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  font-size: 0.75rem;
  margin-top: 0.6rem;
}

.layout {
  max-width: 1100px;
  margin: -1.25rem auto 2rem;
  padding: 0 1rem;
  display: grid;
  grid-template-columns: 240px 1fr;
  gap: 1.25rem;
}

@media (max-width: 768px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

.sidebar {
  padding: 1rem;
  align-self: start;
  position: sticky;
  top: 1rem;
}

.sidebar h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 0 0 0.75rem;
}

.cat-list {
  list-style: none;
  padding: 0;
  margin: 0 0 1rem;
}

.cat-list li {
  margin-bottom: 0.25rem;
}

.cat-list button {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  padding: 0.45rem 0.6rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.88rem;
  color: var(--text);
}

.cat-list button:hover { background: var(--bg); }
.cat-list button.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.cat-count {
  float: right;
  color: var(--muted);
  font-size: 0.8rem;
}

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

#search {
  flex: 1;
  min-width: 200px;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.95rem;
}

.btn {
  padding: 0.55rem 1rem;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}

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

.btn-primary:hover { filter: brightness(1.05); }

.btn-ghost {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
}

.terms {
  padding: 0.5rem 0;
  max-height: calc(100vh - 220px);
  overflow-y: auto;
}

.term-card {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.15s;
}

.term-card:hover { background: #f8fafc; }
.term-card:last-child { border-bottom: none; }

.term-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem;
  margin-bottom: 0.35rem;
}

.term-title {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--accent);
}

.term-expansion {
  font-size: 0.85rem;
  color: var(--muted);
  font-style: italic;
}

.term-def {
  font-size: 0.92rem;
  margin: 0;
}

.tag {
  display: inline-block;
  font-size: 0.7rem;
  padding: 0.15rem 0.45rem;
  background: var(--bg);
  border-radius: 4px;
  color: var(--muted);
  margin-right: 0.25rem;
}

.empty {
  padding: 2rem;
  text-align: center;
  color: var(--muted);
}

.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-backdrop.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
  box-shadow: var(--shadow);
}

.modal h3 { margin-top: 0; }

.form-row {
  margin-bottom: 0.85rem;
}

.form-row label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  margin-bottom: 0.3rem;
  color: var(--muted);
}

.form-row input,
.form-row textarea,
.form-row select {
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}

.form-row textarea { min-height: 100px; resize: vertical; }

.form-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

.detail {
  padding: 1.25rem;
}

.detail h2 { margin: 0 0 0.25rem; color: var(--accent); }

.meta {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 1rem;
}

.notice {
  font-size: 0.82rem;
  color: var(--muted);
  padding: 0.65rem 1rem;
  background: #fffbeb;
  border-top: 1px solid #fde68a;
}

footer {
  text-align: center;
  padding: 1.5rem;
  font-size: 0.8rem;
  color: var(--muted);
}

footer a { color: var(--accent); }
