/* WaterShed Command Center — Mobile-First Design */

:root {
  /* Brand */
  --green-dark: #1b4332;
  --green: #2d6a4f;
  --green-mid: #40916c;
  --green-light: #74c69d;
  --green-pale: #d8f3dc;

  /* Semantic — light mode */
  --bg: #f8f9fa;
  --bg-card: #ffffff;
  --bg-subtle: #f1f3f4;
  --bg-hover: #e9ecef;
  --text: #212529;
  --text-secondary: #495057;
  --text-muted: #6c757d;
  --border: #dee2e6;
  --border-light: #e9ecef;

  /* Status */
  --red: #dc3545;
  --red-light: #f8d7da;
  --red-text: #721c24;
  --yellow: #ffc107;
  --yellow-light: #fff3cd;
  --yellow-text: #664d03;
  --blue: #0d6efd;
  --blue-light: #cfe2ff;
  --blue-text: #084298;

  --radius: 10px;
  --shadow: 0 2px 8px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.12);
  --nav-height: 60px;
}

[data-theme="dark"] {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-subtle: #22263a;
  --bg-hover: #2a2f47;
  --text: #e8eaf0;
  --text-secondary: #b0b8cc;
  --text-muted: #6b7799;
  --border: #2e3450;
  --border-light: #252945;
  --green-pale: rgba(45,106,79,0.35);
  --red-light: rgba(220,53,69,0.25);
  --red-text: #f5a0a8;
  --yellow-light: rgba(255,193,7,0.2);
  --yellow-text: #f0c040;
  --blue-light: rgba(13,110,253,0.25);
  --blue-text: #7eb3ff;
  --shadow: 0 2px 8px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.55);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  min-height: 100vh;
  transition: background 0.2s, color 0.2s;
}

a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---- Top Nav ---- */
.nav {
  background: var(--green-dark);
  color: white;
  height: var(--nav-height);
  display: flex;
  align-items: center;
  padding: 0 16px;
  position: sticky;
  top: 0;
  z-index: 100;
  gap: 12px;
}

.nav-brand {
  font-size: 1.1rem;
  font-weight: 700;
  color: white;
  text-decoration: none;
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-toggle {
  background: none;
  border: none;
  color: white;
  font-size: 1.5rem;
  cursor: pointer;
  padding: 4px 8px;
  border-radius: 6px;
  line-height: 1;
}
.nav-toggle:hover { background: rgba(255,255,255,0.1); }

.nav-profile { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.nav-profile-name {
  color: rgba(255,255,255,0.85);
  font-size: 0.82rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.nav-profile-num {
  font-size: 0.7rem;
  color: rgba(255,255,255,0.55);
  font-weight: 600;
  letter-spacing: 0.04em;
}
.nav-profile-select {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.25);
  border-radius: 6px;
  color: white;
  font-size: 0.82rem;
  padding: 3px 24px 3px 8px;
  cursor: pointer;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' viewBox='0 0 10 6'%3E%3Cpath fill='rgba(255,255,255,0.7)' d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  max-width: 200px;
}
.nav-profile-select:focus { outline: none; border-color: rgba(255,255,255,0.5); }
.nav-profile-select option { background: var(--green-dark); color: white; }

.dark-toggle {
  background: none;
  border: 1.5px solid rgba(255,255,255,0.35);
  color: white;
  font-size: 1rem;
  cursor: pointer;
  padding: 4px 9px;
  border-radius: 20px;
  line-height: 1.4;
  flex-shrink: 0;
  transition: background 0.15s, border-color 0.15s;
}
.dark-toggle:hover { background: rgba(255,255,255,0.15); border-color: rgba(255,255,255,0.6); }

/* ---- Sidebar ---- */
.sidebar {
  position: fixed;
  top: var(--nav-height);
  left: -260px;
  width: 260px;
  height: calc(100vh - var(--nav-height));
  background: var(--green-dark);
  z-index: 200;
  transition: left 0.25s ease;
  overflow-y: auto;
  padding: 12px 0;
}
.sidebar.open { left: 0; }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 199;
}
.sidebar-overlay.open { display: block; }

.sidebar-nav a {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  color: rgba(255,255,255,0.85);
  text-decoration: none;
  font-size: 1rem;
  transition: background 0.15s;
}
.sidebar-nav a:hover,
.sidebar-nav a.active {
  background: rgba(255,255,255,0.12);
  color: white;
}
.sidebar-nav a .icon { font-size: 1.25rem; width: 24px; text-align: center; }
.sidebar-divider { border-top: 1px solid rgba(255,255,255,0.1); margin: 8px 0; }

/* ---- Main Content ---- */
.main {
  padding: 16px;
  max-width: 1200px;
  margin: 0 auto;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 20px;
}
.page-title { font-size: 1.5rem; font-weight: 700; color: var(--text); }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: none;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: filter 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:active { transform: scale(0.97); }
.btn:hover { filter: brightness(1.08); text-decoration: none; }

.btn-primary   { background: var(--green); color: white; }
.btn-secondary { background: var(--bg-hover); color: var(--text-secondary); }
.btn-danger    { background: var(--red); color: white; }
.btn-warning   { background: var(--yellow); color: #1a1200; }
.btn-info      { background: var(--blue); color: white; }
.btn-ghost     { background: transparent; border: 2px solid var(--green); color: var(--green); }
.btn-sm        { padding: 6px 12px; font-size: 0.85rem; }
.btn-lg        { padding: 14px 24px; font-size: 1.05rem; }
.btn-block     { width: 100%; justify-content: center; }

/* ---- Cards ---- */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  margin-bottom: 12px;
  border: 1px solid var(--border-light);
}
.card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 10px;
}
.card-title { font-weight: 700; font-size: 1.05rem; }
.card-subtitle { font-size: 0.85rem; color: var(--text-muted); }
.card-body { font-size: 0.95rem; }
.card-meta { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 8px; }
.card-meta-item { font-size: 0.85rem; color: var(--text-muted); }
.card-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }

/* ---- Stat Cards (dashboard) ---- */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.stat-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  text-align: center;
  border: 1px solid var(--border-light);
}
.stat-number { font-size: 2rem; font-weight: 800; color: var(--green); }
.stat-label  { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-top: 2px; }
.stat-card.warning .stat-number { color: #d97706; }
.stat-card.danger  .stat-number { color: var(--red); }

/* ---- Quick Actions ---- */
.quick-actions {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}
.quick-action {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 20px 12px;
  background: var(--bg-card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  text-decoration: none;
  color: var(--text);
  font-weight: 600;
  font-size: 0.9rem;
  text-align: center;
  transition: box-shadow 0.15s, transform 0.1s;
  border: 1px solid var(--border-light);
}
.quick-action:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); text-decoration: none; }
.quick-action .icon { font-size: 2rem; }

/* ---- Badges / Status ---- */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-active    { background: var(--green-pale); color: var(--green); }
.badge-paused    { background: var(--yellow-light); color: var(--yellow-text); }
.badge-cancelled { background: var(--red-light); color: var(--red-text); }
.badge-draft     { background: var(--bg-hover); color: var(--text-muted); }
.badge-sent      { background: var(--blue-light); color: var(--blue-text); }
.badge-paid      { background: var(--green-pale); color: var(--green); }
.badge-overdue   { background: var(--red-light); color: var(--red-text); }
.badge-scheduled { background: var(--blue-light); color: var(--blue-text); }
.badge-completed { background: var(--green-pale); color: var(--green); }
.badge-skipped   { background: var(--bg-hover); color: var(--text-muted); }

/* Role badges — used in users page and sidebar */
.role-badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 20px;
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.role-admin    { background: #fee2e2; color: #b91c1c; }
.role-manager  { background: #dbeafe; color: #1d4ed8; }
.role-tech     { background: #d1fae5; color: #065f46; }
.role-readonly { background: #f3f4f6; color: #6b7280; }
.role-user     { background: #dbeafe; color: #1d4ed8; }

/* Role reference cards on users page */
.role-ref-card { padding: 12px; background: var(--bg-hover); border-radius: 8px; }

/* Smaller form control variant */
.form-control-sm {
  padding: 4px 8px;
  font-size: 0.85rem;
  height: auto;
}

/* ---- Forms ---- */
.form-section { margin-bottom: 24px; }
.form-section-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--green-mid);
  border-bottom: 2px solid var(--green-pale);
  padding-bottom: 6px;
  margin-bottom: 14px;
}
[data-theme="dark"] .form-section-title { color: var(--green-light); }

.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}
.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 1rem;
  background: var(--bg-card);
  color: var(--text);
  transition: border-color 0.15s, background 0.2s;
  -webkit-appearance: none;
}
.form-control:focus {
  outline: none;
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(45,106,79,0.18);
}
select.form-control { cursor: pointer; }
textarea.form-control { min-height: 100px; resize: vertical; }
.form-hint { font-size: 0.82rem; color: var(--text-muted); margin-top: 3px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---- Alerts / Flash ---- */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 16px;
  font-size: 0.95rem;
}
.alert-success { background: var(--green-pale); color: var(--green-dark); }
.alert-error   { background: var(--red-light); color: var(--red-text); }
.alert-warning { background: var(--yellow-light); color: var(--yellow-text); }
.alert-info    { background: var(--blue-light); color: var(--blue-text); }

[data-theme="dark"] .alert-success { color: var(--green-light); }

/* ---- Table ---- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
th {
  background: var(--bg-subtle);
  color: var(--text-secondary);
  font-weight: 700;
  padding: 10px 12px;
  text-align: left;
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
td { padding: 10px 12px; border-bottom: 1px solid var(--border-light); vertical-align: middle; color: var(--text); }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-subtle); }

/* ---- Search / Filter Bar ---- */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.search-bar .form-control { flex: 1; min-width: 150px; }

/* ---- Section labels ---- */
.section-label {
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  margin-bottom: 8px;
  margin-top: 16px;
}

/* ---- Empty state ---- */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}
.empty-state .icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state p { margin-bottom: 16px; }

/* ---- Print invoice ---- */
@media print {
  .nav, .sidebar, .sidebar-overlay, .no-print { display: none !important; }
  body { background: white; font-size: 14px; color: black; }
  .main { padding: 0; max-width: none; }
  .card { box-shadow: none; border: 1px solid #ddd; background: white; }
  .btn { display: none; }
}

.invoice-print-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  gap: 16px;
}
.invoice-table th, .invoice-table td { padding: 8px 12px; }
.invoice-totals { text-align: right; margin-top: 12px; }
.invoice-totals .total-row { font-size: 1.2rem; font-weight: 800; color: var(--green-dark); }
[data-theme="dark"] .invoice-totals .total-row { color: var(--green-light); }

/* ---- Login page ---- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--green-dark);
  padding: 24px;
}
.login-card {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 32px 28px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow-md);
}
.login-logo { text-align: center; margin-bottom: 24px; }
.login-logo h1 { font-size: 1.4rem; color: var(--green-dark); margin-top: 8px; }
[data-theme="dark"] .login-logo h1 { color: var(--green-light); }
.login-logo-icon { width: 80px; height: 80px; border-radius: 16px; display: block; margin: 0 auto 12px; }
.nav-brand-icon { width: 28px; height: 28px; border-radius: 6px; vertical-align: middle; margin-right: 4px; flex-shrink: 0; }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 4px; margin-bottom: 16px; flex-wrap: wrap; }
.tab {
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  color: var(--text-secondary);
  background: var(--bg-hover);
  transition: background 0.15s;
}
.tab.active, .tab:hover { background: var(--green); color: white; text-decoration: none; }

/* ---- Detail page ---- */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 16px;
}
.detail-field { margin-bottom: 12px; }
.detail-label { font-size: 0.82rem; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; }
.detail-value { font-size: 1rem; color: var(--text); margin-top: 2px; }

/* ---- Responsive ---- */
@media (min-width: 640px) {
  .stats-grid { grid-template-columns: repeat(3, 1fr); }
  .quick-actions { grid-template-columns: repeat(4, 1fr); }
  .form-row { grid-template-columns: 1fr 1fr; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
}

@media (min-width: 900px) {
  .main { padding: 24px 32px; }
  .stats-grid { grid-template-columns: repeat(6, 1fr); }
  .sidebar {
    position: sticky;
    top: var(--nav-height);
    left: 0;
    height: calc(100vh - var(--nav-height));
    display: block;
  }
  .sidebar-overlay { display: none !important; }
  .nav-toggle { display: none; }
  .layout { display: flex; }
  .layout .sidebar { flex: 0 0 240px; }
  .layout .main-wrap { flex: 1; min-width: 0; }
}

/* ---- Utility ---- */
.text-muted  { color: var(--text-muted); }
.text-sm     { font-size: 0.85rem; }
.text-center { text-align: center; }
.mt-0  { margin-top: 0; }
.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.gap-8 { gap: 8px; }
.flex  { display: flex; }
.flex-wrap { flex-wrap: wrap; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.hidden { display: none; }

/* ---- Service Setup ---- */
.service-check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 8px; }
.service-check-label { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; cursor: pointer; transition: background 0.15s; }
.service-check-label:hover { background: var(--green-bg); }
.service-check-label input[type=checkbox] { width: 16px; height: 16px; margin-bottom: 4px; }
.service-check-name { font-weight: 600; font-size: 0.9rem; }
.service-check-desc { font-size: 0.78rem; color: var(--text-muted); }

/* ---- Module Review ---- */
.implication-row { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; border-bottom: 1px solid var(--border); cursor: pointer; }
.implication-row:last-child { border-bottom: none; }
.implication-row input[type=checkbox] { margin-top: 3px; flex-shrink: 0; }
.implication-body { flex: 1; }
.implication-header { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.implication-label { font-weight: 600; font-size: 0.9rem; }
.implication-reason { font-size: 0.8rem; color: var(--text-muted); margin-top: 3px; }

/* ---- Module Settings ---- */
.module-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 16px; }
.module-card { transition: box-shadow 0.15s; }
.module-card-on { border-left: 3px solid var(--green-mid); }
.toggle-switch { position: relative; display: inline-flex; align-items: center; cursor: pointer; }
.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track { width: 42px; height: 24px; background: var(--border); border-radius: 12px; position: relative; transition: background 0.2s; }
.toggle-switch input:checked + .toggle-track { background: var(--green-mid); }
.toggle-thumb { width: 18px; height: 18px; background: white; border-radius: 50%; position: absolute; top: 3px; left: 3px; transition: left 0.2s; box-shadow: 0 1px 3px rgba(0,0,0,0.2); }
.toggle-switch input:checked + .toggle-track .toggle-thumb { left: 21px; }

/* ---- Category list ---- */
.cat-list { display: flex; flex-direction: column; gap: 6px; }
.cat-item { display: flex; align-items: center; justify-content: space-between; padding: 6px 10px; background: var(--surface-alt, #f9f9f9); border-radius: 6px; font-size: 0.88rem; }
[data-theme="dark"] .cat-item { background: rgba(255,255,255,0.05); }
