:root {
  --color-primary: #2563eb;
  --color-primary-hover: #1d4ed8;
  --color-danger: #dc2626;
  --color-danger-hover: #b91c1c;
  --color-success: #16a34a;
  --color-bg: #f8fafc;
  --color-surface: #ffffff;
  --color-border: #e2e8f0;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --radius: 6px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
}

*, *::before, *::after { box-sizing: border-box; }

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

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 0 16px;
}

/* Navbar */
.navbar {
  background: var(--color-primary);
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-container {
  display: flex;
  align-items: center;
  gap: 24px;
  height: 52px;
}
.nav-brand {
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  text-decoration: none;
}
.nav-links { display: flex; gap: 4px; }
.nav-link {
  color: rgba(255,255,255,0.8);
  text-decoration: none;
  padding: 6px 12px;
  border-radius: var(--radius);
  font-size: 14px;
}
.nav-link:hover, .nav-link.active {
  color: #fff;
  background: rgba(255,255,255,0.15);
}

/* Flash */
.flash {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin: 16px 0;
  font-size: 14px;
}
.flash-notice { background: #dcfce7; color: #166534; }
.flash-alert { background: #fef2f2; color: #991b1b; }

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 24px 0 16px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header h1 { margin: 0; font-size: 22px; }
.header-actions { display: flex; gap: 8px; }

/* Buttons */
.btn {
  display: inline-block;
  padding: 8px 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  color: var(--color-text);
  font-size: 14px;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.4;
}
.btn:hover { background: #f1f5f9; }
.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border-color: var(--color-primary);
}
.btn-primary:hover { background: var(--color-primary-hover); }
.btn-danger {
  background: var(--color-danger);
  color: #fff;
  border-color: var(--color-danger);
}
.btn-danger:hover { background: var(--color-danger-hover); }
.btn-sm { padding: 4px 10px; font-size: 13px; }

/* Search */
.search-form {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}
.search-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
}

/* Cards */
.card-list { display: flex; flex-direction: column; gap: 12px; }
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
}
.card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.card-title-link {
  font-weight: 600;
  font-size: 16px;
  color: var(--color-primary);
  text-decoration: none;
}
.card-title-link:hover { text-decoration: underline; }
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  background: #e2e8f0;
  color: var(--color-text-muted);
}
.card-meta { display: flex; flex-wrap: wrap; gap: 12px; font-size: 13px; color: var(--color-text-muted); }
.card-actions { margin-top: 12px; display: flex; gap: 8px; }

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

/* Forms */
.form-section {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 16px;
}
.form-section legend {
  font-weight: 600;
  font-size: 15px;
  padding: 0 8px;
}
.form-row {
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}
.form-group {
  flex: 1;
  min-width: 200px;
  margin-bottom: 12px;
}
.form-group-narrow { flex: 0 0 auto; min-width: auto; display: flex; align-items: flex-end; }
.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-muted);
  margin-bottom: 4px;
}
.form-control {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  background: #fff;
}
.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 2px rgba(37,99,235,0.15);
}
textarea.form-control { resize: vertical; }
select.form-control { appearance: auto; }

.form-errors {
  background: #fef2f2;
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  padding: 12px 16px;
  margin-bottom: 16px;
  color: #991b1b;
  font-size: 14px;
}
.form-errors ul { margin: 4px 0 0 16px; padding: 0; }

.form-actions {
  display: flex;
  gap: 8px;
  margin: 24px 0;
}

/* Checkboxes */
.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 16px;
}
.checkbox-group-scroll {
  max-height: 300px;
  overflow-y: auto;
  flex-direction: column;
}
.checkbox-label {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
  cursor: pointer;
}

/* Nested rows */
.nested-row {
  border-bottom: 1px solid var(--color-border);
  padding-bottom: 8px;
  margin-bottom: 8px;
}

/* Autocomplete */
.autocomplete-results {
  display: none;
  position: absolute;
  z-index: 50;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  max-height: 250px;
  overflow-y: auto;
  width: 100%;
}
.autocomplete-results.open { display: block; }
.autocomplete-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
}
.autocomplete-item:hover { background: #f1f5f9; }
.autocomplete-subtitle {
  display: block;
  font-size: 12px;
  color: var(--color-text-muted);
}
.autocomplete-details {
  font-size: 13px;
  color: var(--color-text-muted);
  margin-top: 4px;
  padding: 4px 0;
}
.autocomplete-empty {
  padding: 12px;
  color: var(--color-text-muted);
  font-size: 14px;
  text-align: center;
}
[data-controller="autocomplete"] { position: relative; }

/* Data tables */
.data-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 14px;
}
.data-table th, .data-table td {
  padding: 8px 12px;
  text-align: left;
  border-bottom: 1px solid var(--color-border);
}
.data-table th {
  background: #f8fafc;
  font-weight: 600;
  font-size: 13px;
  color: var(--color-text-muted);
}

/* Show page */
.show-grid { margin-top: 16px; }
.detail-list {
  display: grid;
  grid-template-columns: 160px 1fr;
  gap: 4px 12px;
  font-size: 14px;
}
.detail-list dt { color: var(--color-text-muted); font-weight: 500; }
.detail-list dd { margin: 0; }

.tag-list { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  display: inline-block;
  padding: 3px 10px;
  background: #eff6ff;
  color: var(--color-primary);
  border-radius: 12px;
  font-size: 13px;
}

.result-count { font-size: 14px; color: var(--color-text-muted); }
.hint-text { font-size: 14px; color: var(--color-text-muted); }

/* Print */
@media print {
  .navbar, .btn, .search-form, .card-actions, .form-actions { display: none !important; }
  .container { max-width: 100%; }
  .form-section { break-inside: avoid; border: 1px solid #ccc; }
}

/* Mobile */
@media (max-width: 600px) {
  .form-row { flex-direction: column; gap: 0; }
  .form-group { min-width: 100%; }
  .page-header { flex-direction: column; align-items: flex-start; }
  .detail-list { grid-template-columns: 1fr; }
  .detail-list dt { font-weight: 600; margin-top: 8px; }
  .nav-container { gap: 12px; }
  .nav-link { padding: 4px 8px; font-size: 13px; }
}
