:root {
  --bg: #f7f8fa;
  --card-bg: #fff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --error-bg: #fee2e2;
  --error-text: #991b1b;
  --error-border: #fecaca;
}

* {
  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;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 24px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
}

.topbar .brand {
  font-weight: 600;
  font-size: 1.1em;
  text-decoration: none;
  color: var(--text);
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar nav a {
  color: var(--primary);
  text-decoration: none;
}

.topbar nav .user {
  color: var(--muted);
  font-size: 0.95em;
}

.page {
  display: flex;
  min-height: calc(100vh - 56px);
}

.sidebar {
  width: 200px;
  flex-shrink: 0;
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  padding: 16px 0;
}

.sidebar ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar li a {
  display: block;
  padding: 8px 24px;
  color: var(--text);
  text-decoration: none;
  font-size: 0.95em;
  border-left: 3px solid transparent;
}

.sidebar li a:hover {
  background: var(--bg);
}

.sidebar li a.active {
  background: var(--bg);
  border-left-color: var(--primary);
  color: var(--primary);
  font-weight: 500;
}

main {
  flex: 1;
  padding: 24px;
  max-width: 1100px;
}

main.with-sidebar {
  padding: 24px 32px;
}

main:not(.with-sidebar) {
  margin: 24px auto;
  padding: 0 24px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 24px;
  margin-bottom: 16px;
}

.card.narrow {
  max-width: 420px;
  margin: 48px auto;
}

h1 {
  margin-top: 0;
  font-size: 1.4em;
}

label {
  display: block;
  margin-bottom: 12px;
  font-size: 0.9em;
  color: var(--muted);
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
textarea,
select {
  display: block;
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 1em;
  font-family: inherit;
  margin-top: 4px;
  color: var(--text);
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

button,
.btn {
  display: inline-block;
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 10px 16px;
  border-radius: 6px;
  font-size: 1em;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
}

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

button.link {
  background: none;
  color: var(--primary);
  padding: 0;
  font-size: inherit;
  font-weight: normal;
}

button.link:hover {
  background: none;
  text-decoration: underline;
}

form.inline {
  display: inline;
}

.flash {
  padding: 10px 14px;
  border-radius: 6px;
  margin-bottom: 16px;
  font-size: 0.95em;
}

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

.muted {
  color: var(--muted);
  font-size: 0.9em;
}

.role-badge {
  background: #e0e7ff;
  color: #3730a3;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75em;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  font-weight: 600;
}

.flash.success {
  background: #d1fae5;
  color: #065f46;
  border: 1px solid #6ee7b7;
}

.flash.info {
  background: #dbeafe;
  color: #1e40af;
  border: 1px solid #93c5fd;
}

table.entity-list {
  width: 100%;
  border-collapse: collapse;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

table.entity-list th,
table.entity-list td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  font-size: 0.95em;
}

table.entity-list th {
  background: var(--bg);
  font-weight: 600;
  color: var(--muted);
  font-size: 0.85em;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

table.entity-list tr:last-child td {
  border-bottom: none;
}

table.entity-list a {
  color: var(--primary);
  text-decoration: none;
}

table.entity-list a:hover {
  text-decoration: underline;
}

.list-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.list-header h1 {
  margin: 0;
}

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

.btn-secondary:hover {
  background: var(--bg);
}

.btn-danger {
  background: #ef4444;
  color: white;
}

.btn-danger:hover {
  background: #dc2626;
}

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

label.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 1em;
}

label.checkbox input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.error {
  color: var(--error-text);
  font-size: 0.85em;
  display: block;
  margin-top: 4px;
}

.detail-grid {
  display: grid;
  grid-template-columns: 200px 1fr;
  gap: 8px 16px;
  margin: 16px 0;
}

.detail-grid dt {
  color: var(--muted);
  font-size: 0.9em;
}

.detail-grid dd {
  margin: 0;
}

.note-list {
  margin-top: 24px;
}

.note {
  border-left: 3px solid var(--border);
  padding: 8px 12px;
  margin-bottom: 12px;
  background: var(--bg);
}

.note.system {
  border-left-color: #94a3b8;
  font-style: italic;
}

.note .meta {
  font-size: 0.85em;
  color: var(--muted);
  margin-bottom: 4px;
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 16px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.85em;
  background: #f3f4f6;
  color: #374151;
}

.badge-good {
  background: #d1fae5;
  color: #065f46;
}

.badge-bad {
  background: #fee2e2;
  color: #991b1b;
}

.badge-warn {
  background: #fef3c7;
  color: #92400e;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.kpi {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
}

.kpi .label {
  color: var(--muted);
  font-size: 0.85em;
  margin-bottom: 4px;
}

.kpi .value {
  font-size: 1.6em;
  font-weight: 600;
}
