:root {
  --crely-primary: #1a56db;
  --crely-primary-dark: #1e40af;
  --crely-secondary: #6b7280;
  --crely-success: #059669;
  --crely-warning: #d97706;
  --crely-danger: #dc2626;
  --crely-info: #2563eb;
  --crely-bg: #f9fafb;
  --crely-card: #ffffff;
  --crely-border: #e5e7eb;
  --crely-text: #111827;
  --crely-text-muted: #6b7280;
  --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--crely-bg);
  color: var(--crely-text);
  line-height: 1.5;
}

/* Layout */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 240px; background: var(--crely-primary-dark); color: white;
  padding: 1rem 0; flex-shrink: 0;
}
.sidebar-brand { padding: 0 1rem 1.5rem; font-size: 1.1rem; font-weight: 700; }
.sidebar-brand span { color: #93c5fd; }
.sidebar a {
  display: block; padding: 0.6rem 1rem; color: rgba(255,255,255,0.8);
  text-decoration: none; font-size: 0.9rem; transition: background 0.15s;
}
.sidebar a:hover, .sidebar a.active { background: rgba(255,255,255,0.1); color: white; }
.sidebar a svg { width: 18px; height: 18px; margin-right: 8px; vertical-align: middle; }

.main-content { flex: 1; padding: 1.5rem 2rem; overflow-y: auto; }

/* Cards */
.card {
  background: var(--crely-card); border: 1px solid var(--crely-border);
  border-radius: var(--radius); padding: 1.25rem; margin-bottom: 1rem;
}
.card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1rem; padding-bottom: 0.75rem; border-bottom: 1px solid var(--crely-border);
}
.card-title { font-size: 1rem; font-weight: 600; }

/* Stat cards */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card {
  background: var(--crely-card); border: 1px solid var(--crely-border);
  border-radius: var(--radius); padding: 1rem; text-align: center;
}
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1.2; }
.stat-label { font-size: 0.8rem; color: var(--crely-text-muted); margin-top: 0.25rem; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th { background: #f3f4f6; font-weight: 600; text-align: left; padding: 0.6rem 0.75rem; border-bottom: 2px solid var(--crely-border); }
td { padding: 0.6rem 0.75rem; border-bottom: 1px solid var(--crely-border); }
tr:hover { background: #f9fafb; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label { display: block; font-size: 0.85rem; font-weight: 500; margin-bottom: 0.3rem; color: var(--crely-text-muted); }
.form-group input, .form-group select, .form-group textarea {
  width: 100%; padding: 0.5rem 0.75rem; border: 1px solid var(--crely-border);
  border-radius: var(--radius); font-size: 0.9rem; background: white;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
  outline: none; border-color: var(--crely-primary); box-shadow: 0 0 0 3px rgba(26,86,219,0.1);
}
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 1rem; }

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0.5rem 1rem; border: none; border-radius: var(--radius);
  font-size: 0.875rem; font-weight: 500; cursor: pointer; transition: background 0.15s;
  text-decoration: none;
}
.btn-primary { background: var(--crely-primary); color: white; }
.btn-primary:hover { background: var(--crely-primary-dark); }
.btn-success { background: var(--crely-success); color: white; }
.btn-warning { background: var(--crely-warning); color: white; }
.btn-danger { background: var(--crely-danger); color: white; }
.btn-secondary { background: #e5e7eb; color: var(--crely-text); }
.btn-sm { padding: 0.3rem 0.6rem; font-size: 0.8rem; }

/* Badges */
.badge {
  display: inline-block; padding: 0.15rem 0.5rem; border-radius: 9999px;
  font-size: 0.75rem; font-weight: 600;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-secondary { background: #e5e7eb; color: #374151; }

/* Page header */
.page-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 1.5rem;
}
.page-title { font-size: 1.5rem; font-weight: 700; }

/* Toast / HTMX */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator { display: inline-block; }
.toast {
  position: fixed; top: 1rem; right: 1rem; padding: 0.75rem 1.25rem;
  background: var(--crely-success); color: white; border-radius: var(--radius);
  z-index: 9999; animation: fadeIn 0.3s;
}
@keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { width: 60px; }
  .sidebar a span { display: none; }
  .sidebar-brand span { display: none; }
  .main-content { padding: 1rem; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}
