/* ===== Color Palette ===== */
:root {
  --primary: #2563EB;
  --primary-hover: #1D4ED8;
  --primary-light: #EFF6FF;
  --primary-muted: #DBEAFE;
  --bg: #FFFFFF;
  --bg-subtle: #F8FAFC;
  --bg-muted: #F1F5F9;
  --text: #1E293B;
  --text-secondary: #475569;
  --text-muted: #64748B;
  --text-faint: #94A3B8;
  --border: #E2E8F0;
  --border-light: #F1F5F9;
  --accent: #F59E0B;
  --accent-hover: #D97706;
  --success: #22C55E;
  --success-hover: #16A34A;
  --success-light: #F0FDF4;
  --error: #EF4444;
  --error-hover: #DC2626;
  --purple: #7C3AED;
  --purple-light: #F5F3FF;
  --shadow: rgba(0, 0, 0, .06);
}

/* ===== Reset & Base ===== */
[x-cloak] { display: none !important; }
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-subtle);
  color: var(--text);
  padding: 20px;
  max-width: 1100px;
  margin: 0 auto;
  line-height: 1.5;
}

h1 { font-size: 1.5rem; margin-bottom: 20px; color: var(--text); }
h2 { font-size: 1.2rem; margin-bottom: 12px; color: var(--text); }

/* ===== Layout ===== */
.card {
  background: var(--bg);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px var(--shadow);
  border: 1px solid var(--border);
}

.row { display: flex; gap: 12px; flex-wrap: wrap; }
.row > div { flex: 1; min-width: 180px; }

/* ===== Forms ===== */
label {
  display: block;
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

input, textarea, select {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .9rem;
  margin-bottom: 12px;
  color: var(--text);
  background: var(--bg);
  transition: border-color .15s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-muted);
}

/* ===== Buttons ===== */
button {
  padding: 6px 14px;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: .85rem;
  transition: background .15s, transform .1s;
}
button:active { transform: scale(.97); }
button:disabled { opacity: .4; cursor: not-allowed; }

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

.btn-sm { padding: 4px 8px; font-size: .75rem; margin-right: 2px; border-radius: 6px; }

.btn-icon {
  padding: 4px 6px;
  background: transparent;
  border: none;
  color: var(--text-faint);
  border-radius: 6px;
  cursor: pointer;
  transition: color .15s, background .15s;
}
.btn-icon:hover { color: var(--primary); background: var(--primary-light); }
.btn-icon-danger:hover { color: var(--error); background: #FEF2F2; }
.btn-icon-success { color: var(--success); }
.btn-icon-success:hover { color: var(--success-hover); background: var(--success-light); }

.btn-danger { background: var(--error); color: #fff; }
.btn-danger:hover { background: var(--error-hover); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: var(--success-hover); }

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

/* ===== Tags / Badges ===== */
.tag {
  display: inline-block;
  background: var(--primary-muted);
  color: var(--primary);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: .75rem;
  font-weight: 500;
}

.tag-role-user { background: var(--bg-muted); color: var(--text-muted); }
.tag-role-manager { background: var(--primary-muted); color: var(--primary); }
.tag-role-root { background: var(--purple-light); color: var(--purple); }

.tag-deleted {
  background: #FEF2F2;
  color: var(--error);
}

.badge-count {
  display: inline-block;
  min-width: 22px;
  text-align: center;
  background: var(--success-light);
  color: var(--success-hover);
  padding: 1px 7px;
  border-radius: 10px;
  font-size: .75rem;
  font-weight: 600;
  margin-left: 6px;
}

.empty {
  text-align: center;
  padding: 40px;
  color: var(--text-faint);
  line-height: 1.8;
}

/* ===== Tabs ===== */
.tabs { display: flex; gap: 8px; margin-bottom: 16px; }
.tabs button { border-bottom: 2px solid transparent; padding-bottom: 6px; }
.tabs .active { border-bottom-color: var(--primary); color: var(--primary); font-weight: 600; }

/* ===== Topbar (current user) ===== */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}
.topbar-user { display: flex; align-items: center; gap: 8px; font-size: .9rem; color: var(--text-secondary); }
.topbar-user .tag { margin-left: 4px; }

/* ===== User list item ===== */
.user-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  border-radius: 4px;
  transition: background .15s;
}
.user-item:last-child { border-bottom: none; }
.user-item:hover { background: var(--primary-light); }
.user-item-main { display: flex; align-items: center; gap: 6px; cursor: pointer; flex: 1; }
.user-item-name { font-weight: 500; color: var(--text); }
.user-item-email { font-size: .8rem; color: var(--text-faint); margin-left: 4px; }
.user-item-actions { display: flex; align-items: center; gap: 8px; }

/* Role select inline */
.role-select { display: flex; align-items: center; gap: 6px; }
.role-select select { width: auto; margin-bottom: 0; padding: 4px 8px; font-size: .8rem; }

/* ===== Projects (nested under user) ===== */
.user-projects { padding: 8px 16px 16px 16px; }
.project-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 8px;
}
.project-row.is-deleted { background: var(--bg-subtle); opacity: .7; }
.project-row-info { flex: 1; min-width: 0; }
.project-row-name { font-weight: 500; }
.project-row-meta { font-size: .75rem; color: var(--text-faint); margin-top: 2px; }
.project-row-actions { display: flex; gap: 4px; align-items: center; flex-shrink: 0; }

.damage-value { font-variant-numeric: tabular-nums; font-size: .8rem; color: var(--text-muted); }

/* ===== Groups ===== */
.group-members { margin-top: 12px; }
.group-member {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--border-light);
  font-size: .9rem;
}
.group-member:last-child { border-bottom: none; }

/* ===== Modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, .4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 50;
}
.modal-card { width: 500px; max-width: 90vw; }
.modal-card select { margin-bottom: 16px; }

/* ===== Flex / Text utilities ===== */
.flex-row { display: flex; gap: 8px; }
.flex-row-wrap { display: flex; gap: 12px; flex-wrap: wrap; }
.flex-row-wrap > div { flex: 1; min-width: 180px; }
.flex-end { display: flex; gap: 8px; justify-content: flex-end; }
.flex-center { display: flex; align-items: center; gap: 8px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.btn-create-col { flex: 0; min-width: auto; display: flex; align-items: flex-end; padding-bottom: 12px; }

.text-muted { color: var(--text-faint); font-size: .85em; }
.text-small { font-size: .85rem; font-weight: 600; margin-bottom: 6px; color: var(--text-secondary); }
.text-xs { font-size: .75rem; color: var(--text-faint); }
.cursor-pointer { cursor: pointer; }

/* ===== Section headers / Misc ===== */
.section-title { font-size: 1.1rem; margin-bottom: 12px; color: var(--text); }
.nowrap { white-space: nowrap; }
hr.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ===== Lucide Icons ===== */
.icon-sm { width: 14px; height: 14px; vertical-align: middle; }
.icon-btn { width: 14px; height: 14px; vertical-align: middle; margin-right: 2px; }

/* ===== Toast Notifications ===== */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 100;
  display: flex;
  flex-direction: column-reverse;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: .85rem;
  box-shadow: 0 4px 12px rgba(0,0,0,.15);
  pointer-events: auto;
  animation: toast-in .3s ease;
  max-width: 380px;
}
.toast-success { border-left: 4px solid var(--success); }
.toast-error { border-left: 4px solid var(--error); }
.toast-info { border-left: 4px solid var(--primary); }

@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

@media (max-width: 768px) {
  body { padding: 12px; }
  .card { padding: 14px; margin-bottom: 14px; }
  .row > div { min-width: 100%; }
  .toast-container { left: 12px; right: 12px; bottom: 12px; }
  .toast { max-width: 100%; }
}
