/* ============================================================
   NCS — Action Events — Main Stylesheet
   Covers: admin layout, sidebar, dashboard, forms, tables,
           alerts, badges, login page, error pages.
   Color tokens use CSS custom properties so tenant branding
   can be overridden via a <style> block in main.ejs if needed.
   ============================================================ */

:root {
  --primary:       #F5C518;
  --primary-dark:  #D4A800;
  --secondary:     #1A1A1A;
  --accent:        #FFFFFF;
  --sidebar-bg:    #1A1A1A;
  --sidebar-text:  #D0D0D0;
  --sidebar-hover: #2D2D2D;
  --sidebar-active:#F5C518;
  --body-bg:       #F4F5F7;
  --card-bg:       #FFFFFF;
  --border:        #E0E0E0;
  --text:          #333333;
  --text-muted:    #888888;
  --success:       #27AE60;
  --warning:       #F39C12;
  --danger:        #E74C3C;
  --info:          #3498DB;
  --sidebar-width: 230px;
  --header-height: 0px;
  --radius:        6px;
  --shadow:        0 2px 6px rgba(0,0,0,0.08);
  --font:          'Inter', system-ui, -apple-system, sans-serif;
}

/* ── Reset & Base ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 15px; }
body { font-family: var(--font); color: var(--text); background: var(--body-bg); line-height: 1.6; }
a { color: var(--primary-dark); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
table { border-collapse: collapse; width: 100%; }

/* ── Admin App Layout ─────────────────────────────────────── */
.ncs-app { display: flex; min-height: 100vh; }

.page-wrapper {
  margin-left: var(--sidebar-width);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.main-content {
  flex: 1;
  padding: 28px 32px;
  max-width: 1400px;
}

/* ── Sidebar ──────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 16px 12px;
  border-bottom: 1px solid #2D2D2D;
}

.sidebar-logo { height: 36px; }
.sidebar-name { color: #FFFFFF; font-weight: 700; font-size: 0.85rem; margin-left: 8px; }
.sidebar-brand { display: flex; align-items: center; }

.sidebar-toggle { display: none; background: none; border: none; color: var(--sidebar-text); font-size: 1.2rem; cursor: pointer; }

.sidebar-nav { list-style: none; padding: 8px 0; flex: 1; }

.nav-section-label {
  padding: 16px 16px 4px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #666;
}

.nav-item a {
  display: flex;
  align-items: center;
  padding: 9px 16px;
  color: var(--sidebar-text);
  font-size: 0.875rem;
  border-radius: 0;
  transition: background 0.15s, color 0.15s;
  gap: 10px;
}

.nav-item a:hover, .nav-item.active a {
  background: var(--sidebar-hover);
  color: #FFFFFF;
  text-decoration: none;
}

.nav-item.active a {
  border-left: 3px solid var(--primary);
  background: #252525;
}

.nav-icon { font-size: 1rem; width: 20px; text-align: center; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid #2D2D2D;
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-chip { display: flex; align-items: center; gap: 8px; flex: 1; min-width: 0; }

.user-avatar {
  width: 30px; height: 30px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--secondary);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
  flex-shrink: 0;
}

.user-info { min-width: 0; }
.user-name { display: block; color: #FFF; font-size: 0.8rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { display: block; color: #888; font-size: 0.7rem; }

.btn-logout { color: #888; font-size: 1rem; padding: 4px; }
.btn-logout:hover { color: var(--danger); }

/* ── Page Headers ─────────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.page-title { font-size: 1.4rem; font-weight: 700; color: var(--secondary); }
.page-subtitle { font-size: 0.85rem; color: var(--text-muted); margin-top: 2px; }

/* ── Cards ────────────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.card-title { font-size: 0.95rem; font-weight: 600; }

/* ── Stat Widgets ─────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
}

.stat-label { font-size: 0.75rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 1.9rem; font-weight: 800; color: var(--secondary); margin-top: 4px; }
.stat-sub   { font-size: 0.75rem; color: var(--text-muted); margin-top: 2px; }

/* ── Tables ───────────────────────────────────────────────── */
.table-wrapper {
  background: var(--card-bg);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  overflow: hidden;
}

.table-responsive { overflow-x: auto; }

.data-table { width: 100%; font-size: 0.875rem; }
.data-table thead th {
  background: #FAFAFA;
  padding: 10px 14px;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table tbody td {
  padding: 10px 14px;
  border-bottom: 1px solid #F0F0F0;
  vertical-align: middle;
}

.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: #FAFAFA; }

.table-actions { display: flex; gap: 6px; flex-wrap: nowrap; }

/* ── Buttons ──────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  border: 1px solid transparent;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s, color 0.15s;
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
}

.btn:hover { text-decoration: none; }

.btn-primary   { background: var(--primary); color: var(--secondary); border-color: var(--primary); font-weight: 700; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }

.btn-secondary { background: #FFF; color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: #F5F5F5; }

.btn-danger    { background: var(--danger); color: #FFF; border-color: var(--danger); }
.btn-danger:hover { background: #C0392B; }

.btn-success   { background: var(--success); color: #FFF; border-color: var(--success); }
.btn-sm        { padding: 4px 10px; font-size: 0.8rem; }
.btn-block     { width: 100%; justify-content: center; }

/* ── Forms ────────────────────────────────────────────────── */
.form-group  { margin-bottom: 16px; }
.form-row    { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.form-label  { display: block; font-size: 0.8rem; font-weight: 600; margin-bottom: 5px; color: var(--text); }
.form-required::after { content: ' *'; color: var(--danger); }

.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-family: var(--font);
  color: var(--text);
  background: #FFF;
  transition: border-color 0.15s;
  appearance: none;
}

.form-control:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px rgba(245,197,24,0.2); }
.form-control:disabled { background: #F5F5F5; color: var(--text-muted); }

textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23888' d='M6 8L1 3h10z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; padding-right: 30px; }

.form-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 3px; }
.form-error { font-size: 0.75rem; color: var(--danger); margin-top: 3px; }

/* ── Alerts / Flash ───────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  font-size: 0.875rem;
}

.alert-success { background: #EBF9F1; border: 1px solid #A8E6C0; color: #1A5C36; }
.alert-error   { background: #FDEDEC; border: 1px solid #F5B7B1; color: #922B21; }
.alert-warning { background: #FEF9E7; border: 1px solid #F9E4A0; color: #7D6608; }
.alert-info    { background: #EBF5FB; border: 1px solid #AED6F1; color: #1A5276; }
.alert-close   { background: none; border: none; cursor: pointer; font-size: 1.1rem; color: inherit; flex-shrink: 0; line-height: 1; }

/* ── Badges / Chips ───────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 0.7rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge-success  { background: #EBF9F1; color: #1A5C36; }
.badge-warning  { background: #FEF9E7; color: #7D6608; }
.badge-danger   { background: #FDEDEC; color: #922B21; }
.badge-info     { background: #EBF5FB; color: #1A5276; }
.badge-neutral  { background: #F0F0F0; color: #555; }
.badge-primary  { background: var(--primary); color: var(--secondary); }

/* Margin status badges */
.margin-good    { background: #EBF9F1; color: #1A5C36; }
.margin-warning { background: #FEF9E7; color: #7D6608; }
.margin-low     { background: #FDEDEC; color: #922B21; }

/* Task type chip (color set inline via style attribute from DB) */
.task-chip {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 0.7rem;
  font-weight: 600;
  color: #FFF;
  white-space: nowrap;
}

/* Non-profit badge */
.nonprofit-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  background: #EBF9F1;
  border: 1px solid #A8E6C0;
  border-radius: 100px;
  font-size: 0.75rem;
  font-weight: 700;
  color: #1A5C36;
}

/* ── Pagination ───────────────────────────────────────────── */
.pagination { display: flex; align-items: center; gap: 4px; flex-wrap: wrap; margin-top: 16px; font-size: 0.85rem; }
.page-btn {
  padding: 5px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  background: #FFF;
}
.page-btn:hover { background: #F5F5F5; text-decoration: none; }
.page-btn.active { background: var(--primary); border-color: var(--primary); color: var(--secondary); font-weight: 700; }
.page-btn.disabled { color: var(--text-muted); pointer-events: none; background: #FAFAFA; }
.page-ellipsis { padding: 5px 4px; color: var(--text-muted); }
.page-info { margin-left: 8px; color: var(--text-muted); }

/* ── Login Page ───────────────────────────────────────────── */
.login-page {
  background: var(--secondary);
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.login-container { width: 100%; max-width: 400px; }

.login-card {
  background: #FFF;
  border-radius: 10px;
  padding: 40px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.25);
}

.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo img { max-height: 70px; }
.login-title { text-align: center; font-size: 1.4rem; font-weight: 800; margin-bottom: 4px; }
.login-subtitle { text-align: center; color: var(--text-muted); font-size: 0.85rem; margin-bottom: 24px; }

.login-footer { text-align: center; margin-top: 20px; color: #888; font-size: 0.8rem; }
.login-footer a { color: #AAA; }

/* ── Error Pages ──────────────────────────────────────────── */
.error-page { background: var(--secondary); color: #FFF; min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.error-container { text-align: center; }
.error-code { font-size: 6rem; font-weight: 900; color: var(--primary); line-height: 1; }
.error-message { font-size: 1.1rem; color: #CCC; margin: 16px 0 24px; }

/* ── Misc utilities ───────────────────────────────────────── */
.text-muted   { color: var(--text-muted); }
.text-right   { text-align: right; }
.text-center  { text-align: center; }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.font-bold    { font-weight: 700; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.flex { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 900px) {
  .sidebar { transform: translateX(-100%); transition: transform 0.2s; }
  .sidebar.open { transform: translateX(0); }
  .page-wrapper { margin-left: 0; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .main-content { padding: 16px; }
}

@media (max-width: 600px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .data-table thead { display: none; }
  .data-table td { display: block; text-align: right; padding: 6px 12px; }
  .data-table td::before { content: attr(data-label); float: left; font-weight: 600; font-size: 0.75rem; color: var(--text-muted); }
}
