:root {
  --brand: #16a34a;
  --brand-dark: #15803d;
  --brand-light: #dcfce7;
  --accent: #0f172a;
  --sidebar-bg: linear-gradient(180deg, #0f172a 0%, #134e4a 100%);
  --sidebar-fg: #cbd5e1;
  --sidebar-fg-dim: #64748b;
  --sidebar-active-bg: rgba(34,197,94,.22);
  --sidebar-active-fg: #4ade80;
  --bg: #f1f5f9;
  --card-bg: #ffffff;
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --shadow-sm: 0 1px 3px rgba(15,23,42,.06);
  --shadow: 0 4px 12px rgba(15,23,42,.08);
  --shadow-lg: 0 10px 30px rgba(15,23,42,.12);
  --radius: 12px;
  --sidebar-w: 248px;

  /* Color palette for chips / cards / accents */
  --c-blue: #3b82f6;
  --c-blue-dark: #1d4ed8;
  --c-amber: #f59e0b;
  --c-amber-dark: #b45309;
  --c-purple: #a855f7;
  --c-purple-dark: #6d28d9;
  --c-red: #ef4444;
  --c-red-dark: #b91c1c;
  --c-cyan: #06b6d4;
  --c-cyan-dark: #0e7490;
  --c-pink: #ec4899;
  --c-pink-dark: #be185d;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', 'Segoe UI', Tahoma, system-ui, sans-serif;
  background: var(--bg);
  background-image:
    radial-gradient(at 0% 0%, rgba(16,185,129,.05) 0, transparent 40%),
    radial-gradient(at 100% 100%, rgba(59,130,246,.05) 0, transparent 40%);
  background-attachment: fixed;
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand); text-decoration: none; }
a:hover { color: var(--brand-dark); }

/* ============ Layout shell ============ */
.app-shell { display: flex; min-height: 100vh; }

/* ============ Sidebar ============ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-fg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 1030;
  transition: transform .25s ease;
  overflow-y: auto;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  background: rgba(0,0,0,.15);
}
.brand-text .brand-title { font-weight: 700; color: #fff; font-size: 1rem; line-height: 1.1; }
.brand-text .brand-sub { color: #94a3b8; font-size: .7rem; letter-spacing: .5px; text-transform: uppercase; margin-top: 2px; }

.sidebar-nav { flex: 1; padding: 12px 10px; }
.nav-section {
  color: #94a3b8;
  font-size: .68rem; font-weight: 700;
  letter-spacing: 1.4px; text-transform: uppercase;
  padding: 14px 12px 6px;
}
.sidebar .nav-link {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px;
  margin: 2px 0;
  color: #cbd5e1;
  border-radius: 8px;
  font-weight: 500; font-size: .89rem;
  transition: all .15s;
  position: relative;
}
.sidebar .nav-link i { font-size: 1.05rem; width: 18px; text-align: center; }
.sidebar .nav-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar .nav-link.active {
  background: linear-gradient(90deg, rgba(34,197,94,.25), rgba(34,197,94,.05));
  color: #4ade80;
}
.sidebar .nav-link.active::before {
  content: ""; position: absolute;
  left: -10px; top: 8px; bottom: 8px;
  width: 3px; background: var(--brand); border-radius: 0 3px 3px 0;
}
.sidebar .nav-link.logout { color: #fca5a5; }
.sidebar .nav-link.logout:hover { background: rgba(239,68,68,.15); color: #fecaca; }

.sidebar-footer { padding: 10px; border-top: 1px solid rgba(255,255,255,.08); }

/* ============ Main column ============ */
.main-col {
  flex: 1;
  margin-left: var(--sidebar-w);
  display: flex; flex-direction: column;
  min-width: 0;
}

.topbar {
  background: linear-gradient(90deg, #ffffff 0%, #f8fafc 100%);
  border-bottom: 1px solid var(--border);
  height: 60px;
  display: flex; align-items: center;
  padding: 0 24px; gap: 16px;
  position: sticky; top: 0; z-index: 20;
  box-shadow: var(--shadow-sm);
}
.topbar-title { font-weight: 600; font-size: 1.05rem; flex: 1; color: var(--text); }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.btn-icon {
  background: transparent; border: 0;
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px;
  color: var(--text-muted); cursor: pointer;
  font-size: 1.4rem;
}
.btn-icon:hover { background: var(--bg); color: var(--text); }

.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 4px 12px 4px 4px;
  background: var(--bg);
  border-radius: 999px;
}
.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  color: #fff;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: .85rem;
}

.content { padding: 24px; flex: 1; }
.footer {
  text-align: center; padding: 14px;
  color: var(--text-muted); font-size: .8rem;
  border-top: 1px solid var(--border);
  background: #fff;
}

/* ============ Page header (colorful gradient banner per page) ============ */
.page-header {
  display: flex; align-items: center; gap: 16px;
  flex-wrap: wrap;
  background: linear-gradient(135deg, #16a34a 0%, #0d9488 60%, #0891b2 100%);
  color: #fff;
  padding: 20px 22px;
  border-radius: var(--radius);
  margin-bottom: 20px;
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.page-header::after {
  content: "";
  position: absolute; right: -40px; top: -40px;
  width: 180px; height: 180px;
  background: rgba(255,255,255,.08);
  border-radius: 50%;
}
.page-header h2, .page-header h3 { color: #fff; margin: 0; font-weight: 700; }
.page-header .subtitle { opacity: .85; font-size: .85rem; }
.page-header .header-actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.page-header .header-actions .btn { background: rgba(255,255,255,.18); border-color: rgba(255,255,255,.35); color: #fff; position: relative; z-index: 1; }
.page-header .header-actions .btn:hover { background: rgba(255,255,255,.3); color: #fff; }
.page-header .header-actions .btn-light { background: #fff !important; color: #15803d !important; border-color: #fff !important; font-weight: 600; }
.page-header .header-actions .btn-light:hover { background: #f0fdf4 !important; color: #14532d !important; }

/* ============ Cards ============ */
.card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card-bg);
  box-shadow: var(--shadow-sm);
  transition: box-shadow .2s;
}
.card:hover { box-shadow: var(--shadow); }
.card-header {
  background: linear-gradient(90deg, #f8fafc, #ffffff);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  padding: 14px 18px;
}

/* ============ Stat cards ============ */
.stat-card {
  padding: 18px 20px;
  display: flex; align-items: center; gap: 16px;
  border-left: 0;
  position: relative; overflow: hidden;
}
.stat-card::before {
  content: ""; position: absolute;
  inset: 0; opacity: .04;
  background: var(--stat-grad, linear-gradient(135deg, #22c55e, #15803d));
}
.stat-card .stat-icon {
  width: 52px; height: 52px;
  border-radius: 14px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.5rem; color: #fff; flex-shrink: 0;
  background: var(--stat-grad, linear-gradient(135deg, #22c55e, #15803d));
  box-shadow: 0 6px 14px rgba(0,0,0,.1);
}
.stat-card.green  { --stat-grad: linear-gradient(135deg, #22c55e, #15803d); }
.stat-card.blue   { --stat-grad: linear-gradient(135deg, #3b82f6, #1d4ed8); }
.stat-card.amber  { --stat-grad: linear-gradient(135deg, #f59e0b, #b45309); }
.stat-card.purple { --stat-grad: linear-gradient(135deg, #a855f7, #6d28d9); }
.stat-card.red    { --stat-grad: linear-gradient(135deg, #ef4444, #b91c1c); }
.stat-card.cyan   { --stat-grad: linear-gradient(135deg, #06b6d4, #0e7490); }
.stat-card.pink   { --stat-grad: linear-gradient(135deg, #ec4899, #be185d); }
.stat-card .stat-label {
  color: var(--text-muted); font-size: .72rem;
  text-transform: uppercase; letter-spacing: .6px;
  font-weight: 600; margin-bottom: 2px;
}
.stat-card .stat-value { font-size: 1.7rem; font-weight: 700; color: var(--text); line-height: 1.1; }

/* ============ Tables ============ */
.table { margin: 0; --bs-table-bg: transparent; font-size: .88rem; }
.table thead th {
  background: linear-gradient(180deg, #f1f5f9, #e2e8f0) !important;
  color: #334155 !important;
  font-weight: 700; font-size: .72rem;
  text-transform: uppercase; letter-spacing: .5px;
  border-bottom: 2px solid var(--border);
  padding: 12px 14px;
  white-space: nowrap;
}
.table tbody td { padding: 12px 14px; vertical-align: middle; border-color: var(--border); }
.table-hover tbody tr:hover { background: #f1f5f9; }

/* All tables in cards/panels become responsive automatically */
.card .table:not(.table-responsive .table) { width: 100%; }
.card > .table, .card > .table-hover {
  display: block; overflow-x: auto; -webkit-overflow-scrolling: touch;
}

/* ============ Buttons ============ */
.btn { font-weight: 500; border-radius: 8px; padding: .45rem 1rem; font-size: .88rem; transition: all .15s; }
.btn:hover { transform: translateY(-1px); }
.btn-success, .btn-brand {
  background: linear-gradient(135deg, var(--brand), var(--brand-dark));
  border-color: var(--brand-dark); color: #fff;
}
.btn-success:hover, .btn-brand:hover {
  background: linear-gradient(135deg, var(--brand-dark), #14532d);
  border-color: var(--brand-dark); color: #fff;
}
.btn-primary { background: linear-gradient(135deg, #3b82f6, #1d4ed8); border-color: #1d4ed8; }
.btn-primary:hover { background: linear-gradient(135deg, #1d4ed8, #1e40af); border-color: #1e40af; }
.btn-danger { background: linear-gradient(135deg, #ef4444, #b91c1c); border-color: #b91c1c; }
.btn-secondary { background: #64748b; border-color: #475569; }
.btn-secondary:hover { background: #475569; border-color: #334155; }
.btn-warning { background: linear-gradient(135deg, #f59e0b, #b45309); border-color: #b45309; color: #fff; }
.btn-warning:hover { color: #fff; }
.btn-sm { padding: .3rem .65rem; font-size: .78rem; }

.btn-outline-primary, .btn-outline-secondary, .btn-outline-danger {
  background: #fff; border: 1px solid var(--border); color: var(--text);
}
.btn-outline-primary:hover { background: var(--c-blue); border-color: var(--c-blue); color: #fff; }
.btn-outline-secondary:hover { background: #64748b; border-color: #64748b; color: #fff; }
.btn-outline-danger { color: var(--c-red); }
.btn-outline-danger:hover { background: var(--c-red); border-color: var(--c-red); color: #fff; }

/* ============ Forms ============ */
.form-control, .form-select {
  border-radius: 8px;
  border: 1px solid var(--border);
  padding: .5rem .75rem;
  font-size: .9rem;
  background: #fff;
}
.form-control:focus, .form-select:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px var(--brand-light);
}
.form-label { font-weight: 600; font-size: .8rem; color: #334155; margin-bottom: 4px; }
.form-control[readonly], .form-control:disabled, .form-select:disabled { background: #f1f5f9; }

/* ============ Badges ============ */
.badge { font-weight: 600; font-size: .72rem; padding: .4em .65em; border-radius: 6px; }
.bg-success { background: linear-gradient(135deg, #22c55e, #15803d) !important; }
.bg-info    { background: linear-gradient(135deg, #06b6d4, #0e7490) !important; color: #fff !important; }
.bg-warning { background: linear-gradient(135deg, #f59e0b, #b45309) !important; color: #fff !important; }
.bg-danger  { background: linear-gradient(135deg, #ef4444, #b91c1c) !important; }
.bg-secondary { background: linear-gradient(135deg, #64748b, #334155) !important; }
.bg-primary { background: linear-gradient(135deg, #3b82f6, #1d4ed8) !important; }

/* ============ Alerts ============ */
.alert { border-radius: var(--radius); border: 0; padding: .85rem 1rem; border-left: 4px solid; }
.alert-success { background: #dcfce7; color: #14532d; border-left-color: #16a34a; }
.alert-danger  { background: #fee2e2; color: #7f1d1d; border-left-color: #dc2626; }
.alert-warning { background: #fef3c7; color: #78350f; border-left-color: #f59e0b; }
.alert-info    { background: #dbeafe; color: #1e3a8a; border-left-color: #3b82f6; }

/* ============ List groups ============ */
.list-group-item {
  border-color: var(--border);
  padding: .7rem 1rem;
}
.list-group-numbered > .list-group-item::before { color: var(--brand); font-weight: 700; }

/* ============ Login page ============ */
.login-wrapper {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  background:
    radial-gradient(at 20% 20%, rgba(34,197,94,.4) 0, transparent 40%),
    radial-gradient(at 80% 80%, rgba(59,130,246,.3) 0, transparent 40%),
    linear-gradient(135deg, #064e3b 0%, #0f172a 60%, #1e293b 100%);
  padding: 20px;
}
.login-card {
  max-width: 420px; width: 100%;
  padding: 2.4rem 2rem;
  border-radius: 18px;
  background: #fff;
  box-shadow: 0 25px 60px rgba(0,0,0,.4);
  border: 0;
}

.profile-photo {
  width: 120px; height: 120px;
  border-radius: 50%;
  object-fit: cover;
  border: 4px solid #fff;
  box-shadow: 0 0 0 3px var(--brand), var(--shadow);
}
.question-row {
  background: linear-gradient(180deg, #f8fafc, #ffffff);
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 12px;
}

/* Welcome / hero card */
.welcome-card {
  background: linear-gradient(135deg, #16a34a 0%, #059669 50%, #0891b2 100%);
  color: #fff;
  border: 0;
  padding: 24px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  position: relative;
  overflow: hidden;
}
.welcome-card::after {
  content: ""; position: absolute;
  right: -60px; bottom: -60px;
  width: 200px; height: 200px;
  background: rgba(255,255,255,.08);
  border-radius: 50%;
}
.welcome-card h3 { color: #fff; }

/* Action toolbar (above tables) - wraps nicely on mobile */
.toolbar {
  display: flex; flex-wrap: wrap; gap: 8px;
  align-items: center;
  margin-bottom: 16px;
}
.toolbar .spacer { flex: 1 1 auto; }

/* ============ Responsive ============ */
@media (max-width: 991.98px) {
  .sidebar { transform: translateX(-100%); box-shadow: 0 0 30px rgba(0,0,0,.4); }
  .sidebar.open { transform: translateX(0); }
  .main-col { margin-left: 0; }
  .content { padding: 14px; }
  .topbar { padding: 0 14px; }
  .page-header { padding: 16px; }
  .page-header h2 { font-size: 1.2rem; }
  .stat-card .stat-value { font-size: 1.35rem; }
  .stat-card .stat-icon { width: 44px; height: 44px; font-size: 1.2rem; }
  .table { font-size: .82rem; }
  .table thead th, .table tbody td { padding: 10px 10px; }
  .btn { padding: .42rem .8rem; }
  .user-chip { padding: 0; background: transparent; }
}

@media (max-width: 575.98px) {
  .page-header { flex-direction: column; align-items: flex-start; }
  .page-header .header-actions { margin-left: 0; width: 100%; }
  .page-header .header-actions .btn { flex: 1 1 auto; }
  h2, h3 { font-size: 1.15rem; }
  .stat-card { padding: 14px; }
  .card { border-radius: 10px; }
  .toolbar { gap: 6px; }
  .toolbar .btn { font-size: .78rem; padding: .35rem .65rem; }
}

/* Touch-friendly action buttons in tables on mobile */
@media (max-width: 767.98px) {
  .table .btn-sm { padding: .35rem .55rem; }
}

/* Mobile sidebar overlay */
@media (max-width: 991.98px) {
  .sidebar.open ~ .main-col::before {
    content: "";
    position: fixed; inset: 0;
    background: rgba(0,0,0,.4);
    z-index: 1029;
  }
}

/* ============ Print ============ */
@media print {
  .sidebar, .topbar, .footer, .btn, .page-header .header-actions { display: none !important; }
  .main-col { margin-left: 0; }
  body { background: #fff; }
  .page-header { background: #fff; color: #000; box-shadow: none; }
  .page-header h2 { color: #000; }}

/* ============ Entity card (cards-grid view) ============ */
.entity-card { transition: transform .15s, box-shadow .15s; border: 1px solid var(--border); }
.entity-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(0,0,0,.08); }
.entity-icon {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; flex-shrink: 0;
}

/* ============ Question rows in template builder ============ */
.question-row { border-left: 4px solid var(--brand); }
.question-row .card-body { padding: .9rem 1rem; }
