:root {
  --bg: #0f1117;
  --surface: #171a23;
  --surface-2: #1f2430;
  --border: #2a3040;
  --text: #eef1f7;
  --muted: #9aa4b8;
  --primary: #5865f2;
  --primary-hover: #4752c4;
  --success: #23a55a;
  --success-hover: #1c8849;
  --danger: #da373c;
  --danger-hover: #b62b2f;
  --warning: #f0b232;
  --radius: 12px;
}

* {
  box-sizing: border-box;
}

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

.hidden {
  display: none !important;
}

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

code {
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 6px;
  font-size: 0.85em;
}

/* Login */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at top, #1b2040 0%, var(--bg) 60%);
}

.login-card {
  width: 100%;
  max-width: 440px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 36px 32px;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
}

.brand-badge {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 14px;
  background: linear-gradient(135deg, #5865f2, #8b5cf6);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.25rem;
  color: #fff;
}

.brand-badge.sm {
  width: 38px;
  height: 38px;
  margin: 0;
  font-size: 0.95rem;
  border-radius: 10px;
}

.bot-pill {
  margin-top: 18px;
  font-size: 0.85rem;
  color: var(--muted);
}

/* Alerts */
.alert {
  padding: 12px 14px;
  border-radius: 10px;
  margin: 14px 0;
  text-align: left;
  font-size: 0.88rem;
}

.alert-danger {
  background: rgba(218, 55, 60, 0.16);
  border: 1px solid rgba(218, 55, 60, 0.45);
  color: #ff9ea1;
}

.alert-warning {
  background: rgba(240, 178, 50, 0.14);
  border: 1px solid rgba(240, 178, 50, 0.4);
  color: #ffd980;
}

/* App Shell */
.app-shell {
  display: grid;
  grid-template-columns: 270px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 16px;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-header {
  padding-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.brand-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
}

.brand-title {
  font-weight: 700;
  font-size: 1.05rem;
}

.brand-sub {
  font-size: 0.78rem;
  color: #57f287;
}

.nav-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 16px;
  flex: 1;
}

.nav-item {
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  color: var(--muted);
  padding: 11px 12px;
  border-radius: 10px;
  font-size: 0.94rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item.active {
  background: rgba(88, 101, 242, 0.2);
  color: #fff;
}

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 14px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--surface-2);
  object-fit: cover;
}

.user-name {
  font-weight: 600;
  font-size: 0.92rem;
}

.logout-link {
  color: var(--muted);
  font-size: 0.8rem;
  text-decoration: none;
}

.logout-link:hover {
  color: #ff9ea1;
}

/* Main Content */
.main-content {
  padding: 28px 34px;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.page-header h2 {
  margin: 0 0 4px;
  font-size: 1.55rem;
}

.page-header p {
  margin: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 22px;
  margin-bottom: 18px;
}

.card h3 {
  margin: 0 0 8px;
  font-size: 1.08rem;
}

.row-between {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

/* Stats */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.stat-label {
  font-size: 0.82rem;
  color: var(--muted);
}

.stat-value {
  font-size: 1.65rem;
  font-weight: 700;
  margin-top: 4px;
}

/* Forms */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 14px;
  margin-top: 12px;
}

.field {
  margin-bottom: 12px;
}

.field-label {
  display: block;
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 6px;
}

.input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 9px;
  color: var(--text);
  padding: 9px 12px;
  font-size: 0.92rem;
  font-family: inherit;
}

.input:focus {
  outline: none;
  border-color: var(--primary);
}

.input-sm {
  width: auto;
  padding: 6px 10px;
  font-size: 0.86rem;
}

.inline-action {
  display: flex;
  gap: 10px;
  margin-top: 10px;
}

.inline-action .input {
  flex: 1;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
}

.role-row {
  display: grid;
  grid-template-columns: 1fr 1fr 1.2fr auto;
  gap: 10px;
  align-items: center;
  background: var(--surface-2);
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
}

/* Toggle Switch */
.toggle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 12px;
  margin-top: 12px;
}

.toggle-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  cursor: pointer;
}

.toggle-card strong {
  display: block;
  margin-bottom: 2px;
}

.switch-inline {
  display: flex;
  align-items: center;
  gap: 10px;
  padding-top: 6px;
}

.switch {
  appearance: none;
  width: 44px;
  height: 24px;
  background: #3b4254;
  border-radius: 999px;
  position: relative;
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.18s;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  transition: transform 0.18s;
}

.switch:checked {
  background: var(--success);
}

.switch:checked::after {
  transform: translateX(20px);
}

/* Chip Picker */
.picker-box {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
}

.chip-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: rgba(88, 101, 242, 0.22);
  border: 1px solid rgba(88, 101, 242, 0.45);
  color: #dbe0ff;
  padding: 4px 9px;
  border-radius: 999px;
  font-size: 0.82rem;
}

.chip button {
  background: none;
  border: none;
  color: inherit;
  cursor: pointer;
  font-weight: 700;
  padding: 0 2px;
}

.picker-controls {
  display: flex;
  gap: 8px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: none;
  border-radius: 9px;
  padding: 9px 16px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, opacity 0.15s;
}

.btn-lg {
  padding: 12px 20px;
  font-size: 0.98rem;
}

.btn-sm {
  padding: 6px 10px;
  font-size: 0.82rem;
}

.btn-block {
  width: 100%;
}

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

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

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

.btn-secondary:hover {
  background: #282f40;
}

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

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

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

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

/* Tables */
.table-wrap {
  overflow-x: auto;
  margin-top: 10px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.table th,
.table td {
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.badge-pending { background: rgba(240, 178, 50, 0.2); color: #ffd980; }
.badge-accepted { background: rgba(35, 165, 90, 0.2); color: #7ef2a9; }
.badge-rejected,
.badge-auto_rejected { background: rgba(218, 55, 60, 0.2); color: #ff9ea1; }

.empty-state {
  text-align: center;
  padding: 80px 20px;
}

/* Toasts */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-left: 4px solid var(--primary);
  color: var(--text);
  padding: 12px 16px;
  border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  font-size: 0.9rem;
  min-width: 240px;
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }

@media (max-width: 860px) {
  .app-shell {
    grid-template-columns: 1fr;
  }
  .sidebar {
    position: static;
    height: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .main-content {
    padding: 20px 16px;
  }
  .role-row {
    grid-template-columns: 1fr;
  }
}
