/*
 * EcoIlluminate — Global Design System
 * Institutional eco-gov aesthetic following DOST GWTD guidelines.
 * Replaces common.css as the single authoritative stylesheet.
 *
 * Structure:
 *   1.  Font Import
 *   2.  Design Tokens (:root)
 *   3.  Global Base
 *   4.  Sidebar
 *   5.  Navbar
 *   6.  Cards
 *   7.  Tables & DataTables
 *   8.  Buttons
 *   9.  Badges & Status Indicators
 *   10. Forms
 *   11. Login / Auth Pages
 *   12. Responsive
 */

/* ============================================================
   1. FONT IMPORT
   ============================================================ */
@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans+Condensed:wght@600;700&display=swap');


/* ============================================================
   2. DESIGN TOKENS
   ============================================================ */
:root {
  /* --- Brand Palette --- */
  --eco-primary:     #1b4d3e;
  --eco-secondary:   #2d5f4e;
  --eco-light:       #8fbc8f;
  --eco-highlight:   #9dc88d;
  --eco-uv:          #9b8fc9;
  --eco-accent:      #3d9970;

  /* --- Surfaces --- */
  --surface-body:    #f4f7f5;
  --surface-card:    #ffffff;
  --surface-sidebar: #1a2e26;
  --surface-navbar:  #ffffff;

  /* --- Text --- */
  --text-primary:    #1a2e26;
  --text-secondary:  #4a6358;
  --text-muted:      #7a9187;
  --text-on-dark:    #e8f0ec;

  /* --- Borders --- */
  --border-color:       #dce8e2;
  --border-color-strong: #b0c8be;

  /* --- Risk Semantic --- */
  --risk-low:      #2d7a4f;
  --risk-moderate: #b07d00;
  --risk-high:     #c05500;
  --risk-critical: #b52828;

  /* --- Spacing --- */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-6: 1.5rem;
  --space-8: 2rem;

  /* --- Border Radii --- */
  --radius-sm: 4px;
  --radius-md: 6px;
  --radius-lg: 10px;

  /* --- Shadows --- */
  --shadow-sm:   0 1px 3px rgba(27,77,62,0.07), 0 1px 2px rgba(27,77,62,0.05);
  --shadow-md:   0 4px 12px rgba(27,77,62,0.10);
  --shadow-card: 0 0 0 1px var(--border-color), 0 2px 8px rgba(27,77,62,0.06);

  /* --- Transitions --- */
  --transition-fast: 0.15s ease;
  --transition-base: 0.2s ease;
}


/* ============================================================
   3. GLOBAL BASE
   ============================================================ */
html {
  scroll-behavior: smooth;
}

body {
  background-color: var(--surface-body) !important;
  color: var(--text-primary);
  font-family: 'Source Sans 3', 'Segoe UI', sans-serif;
}

/* Selection highlight */
::selection {
  background-color: var(--eco-light);
  color: var(--text-primary);
}

/* Thin branded scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: var(--surface-body);
}
::-webkit-scrollbar-thumb {
  background-color: var(--eco-light);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
  background-color: var(--eco-secondary);
}

/* Links */
a {
  color: var(--eco-primary);
  text-decoration: none;
}
a:hover {
  color: var(--eco-accent);
}


/* ============================================================
   4. SIDEBAR
   ============================================================ */
.app-sidebar {
  background-color: var(--surface-sidebar) !important;
}

/* Override AdminLTE's bg-body-secondary theme on sidebar */
.app-sidebar.bg-body-secondary {
  --bs-body-bg: var(--surface-sidebar);
  background-color: var(--surface-sidebar) !important;
}

/* Brand area */
.app-sidebar .sidebar-brand {
  border-bottom: 1px solid rgba(232,240,236,0.1);
  padding: var(--space-4) var(--space-4);
}

.app-sidebar .brand-text {
  color: var(--text-on-dark) !important;
  font-family: 'IBM Plex Sans Condensed', sans-serif;
  font-weight: 600;
  font-size: 1.1rem;
  letter-spacing: 0.5px;
}

.app-sidebar .brand-image {
  opacity: 0.9 !important;
}

/* Nav items */
.app-sidebar .sidebar-menu .nav-link {
  color: rgba(232,240,236,0.75);
  font-family: 'Source Sans 3', sans-serif;
  font-size: 0.9rem;
  font-weight: 400;
  padding: 0.55rem 1rem;
  border-radius: var(--radius-sm);
  margin: 1px 0.5rem;
  transition: background-color var(--transition-fast), color var(--transition-fast), border-left-color var(--transition-fast);
  border-left: 3px solid transparent;
}

.app-sidebar .sidebar-menu .nav-link:hover {
  background-color: rgba(61,153,112,0.12) !important;
  color: var(--text-on-dark) !important;
  border-left-color: rgba(61,153,112,0.4);
}

.app-sidebar .sidebar-menu .nav-link.active {
  background-color: var(--eco-primary) !important;
  color: #ffffff !important;
  font-weight: 600;
  border-left: 3px solid var(--eco-accent);
}

.app-sidebar .nav-icon {
  color: inherit;
  opacity: 0.85;
  margin-right: var(--space-2);
  font-size: 1rem;
  width: 1.25rem;
  text-align: center;
}

.app-sidebar .sidebar-menu .nav-link.active .nav-icon {
  opacity: 1;
}


/* ============================================================
   5. NAVBAR (TOP BAR)
   ============================================================ */
.app-header {
  background-color: var(--surface-navbar) !important;
  border-bottom: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
}

/* Override AdminLTE bg-body */
.app-header.bg-body {
  --bs-body-bg: var(--surface-navbar);
  background-color: var(--surface-navbar) !important;
}

/* Breadcrumb */
.breadcrumb {
  font-size: 0.82rem;
  margin-bottom: 0;
}
.breadcrumb-item a {
  color: var(--text-muted);
  text-decoration: none;
}
.breadcrumb-item a:hover {
  color: var(--eco-primary);
}
.breadcrumb-item.active {
  color: var(--eco-primary);
  font-weight: 600;
}
.breadcrumb-item + .breadcrumb-item::before {
  color: var(--text-muted);
}

/* Page / Content header title */
.app-content-header h3,
.app-content-header h1,
.content-title {
  font-family: 'IBM Plex Sans Condensed', sans-serif;
  font-weight: 700;
  font-size: 1.6rem;
  color: var(--text-primary);
  letter-spacing: 0.2px;
}

/* Navbar bell icon hover */
.app-header .nav-link:hover {
  color: var(--eco-accent) !important;
}

/* User menu header gradient */
.dropdown-menu .user-header {
  background: linear-gradient(135deg, var(--eco-primary) 0%, var(--eco-secondary) 100%) !important;
}


/* ============================================================
   6. CARDS
   ============================================================ */
.card {
  border: none !important;
  border-top: 3px solid var(--eco-primary);
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-card);
  background-color: var(--surface-card);
  transition: box-shadow var(--transition-base);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-header {
  background-color: var(--surface-body) !important;
  border-bottom: 1px solid var(--border-color);
  border-radius: calc(var(--radius-lg) - 3px) calc(var(--radius-lg) - 3px) 0 0 !important;
  font-family: 'Source Sans 3', sans-serif;
  font-weight: 600;
  color: var(--text-primary);
  padding: var(--space-4) var(--space-6);
}

.card-body {
  padding: var(--space-6);
}

.card-footer {
  background-color: var(--surface-body);
  border-top: 1px solid var(--border-color);
  padding: var(--space-4) var(--space-6);
}

/* Small/info stat cards (dashboard widgets) */
.small-box {
  border-radius: var(--radius-lg) !important;
  border-top: 3px solid var(--eco-primary);
  box-shadow: var(--shadow-card) !important;
  overflow: hidden;
}

.small-box .small-box-footer {
  background-color: rgba(0,0,0,0.08) !important;
}


/* ============================================================
   7. TABLES & DATATABLES
   ============================================================ */

/* Base table styling */
.table {
  color: var(--text-primary);
  border-color: var(--border-color);
  font-size: 0.9rem;
}

.table thead th {
  background-color: var(--surface-body) !important;
  color: var(--text-secondary);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  border-bottom: 2px solid var(--border-color-strong) !important;
  border-color: var(--border-color);
  white-space: nowrap;
  padding: 0.65rem 0.75rem;
}

/* Override Bootstrap table-light on thead */
.table thead.table-light th {
  background-color: var(--surface-body) !important;
  color: var(--text-secondary);
}

.table tbody td {
  border-color: var(--border-color);
  vertical-align: middle;
  padding: 0.6rem 0.75rem;
}

.table-striped > tbody > tr:nth-of-type(odd) > td {
  background-color: rgba(27,77,62,0.025);
}

.table-hover > tbody > tr:hover > td {
  background-color: rgba(27,77,62,0.05) !important;
}

.table-bordered {
  border-color: var(--border-color);
}

/* DataTables wrapper */
.dataTables_wrapper {
  font-size: 0.88rem;
}

/* DataTables length + filter row */
.dataTables_length label,
.dataTables_filter label {
  color: var(--text-secondary);
  font-size: 0.85rem;
}

.dataTables_filter input[type="search"] {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.35rem 0.65rem;
  font-size: 0.85rem;
  color: var(--text-primary);
  background-color: var(--surface-card);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
}
.dataTables_filter input[type="search"]:focus {
  border-color: var(--eco-accent);
  box-shadow: 0 0 0 3px rgba(61,153,112,0.15);
}

.dataTables_length select {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.3rem 0.5rem;
  font-size: 0.85rem;
  color: var(--text-primary);
  background-color: var(--surface-card);
}

/* DataTables info text */
.dataTables_info {
  color: var(--text-muted);
  font-size: 0.82rem;
}

/* DataTables pagination */
.dataTables_paginate .paginate_button {
  border-radius: var(--radius-sm) !important;
  font-size: 0.82rem !important;
  padding: 0.3rem 0.6rem !important;
  margin: 0 2px !important;
  color: var(--eco-primary) !important;
  border: 1px solid var(--border-color) !important;
  background: transparent !important;
  transition: background-color var(--transition-fast), color var(--transition-fast);
}
.dataTables_paginate .paginate_button:hover {
  background-color: var(--surface-body) !important;
  border-color: var(--border-color-strong) !important;
  color: var(--eco-primary) !important;
}
.dataTables_paginate .paginate_button.current,
.dataTables_paginate .paginate_button.current:hover {
  background: var(--eco-primary) !important;
  border-color: var(--eco-primary) !important;
  color: #ffffff !important;
  font-weight: 600;
}
.dataTables_paginate .paginate_button.disabled,
.dataTables_paginate .paginate_button.disabled:hover {
  opacity: 0.4;
  cursor: default;
  background: transparent !important;
}


/* ============================================================
   8. BUTTONS
   ============================================================ */

/* Shared button base */
.btn {
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.875rem;
  padding: 0.4rem 0.9rem;
  transition: all var(--transition-base);
}

/* Primary — eco-primary gradient */
.btn-primary {
  background: linear-gradient(135deg, var(--eco-primary) 0%, var(--eco-secondary) 100%);
  border: none;
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(27,77,62,0.2);
}
.btn-primary:hover,
.btn-primary:focus {
  background: linear-gradient(135deg, var(--eco-secondary) 0%, var(--eco-accent) 100%);
  box-shadow: 0 4px 8px rgba(27,77,62,0.3);
  color: #ffffff;
}
.btn-primary:active {
  background: var(--eco-primary);
  box-shadow: none;
}

/* Success — risk-low green */
.btn-success {
  background-color: var(--risk-low);
  border-color: var(--risk-low);
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(45,122,79,0.2);
}
.btn-success:hover,
.btn-success:focus {
  background-color: #235f3c;
  border-color: #235f3c;
  box-shadow: 0 4px 8px rgba(45,122,79,0.3);
  color: #ffffff;
}

/* Warning — risk-moderate amber */
.btn-warning {
  background-color: var(--risk-moderate);
  border-color: var(--risk-moderate);
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(176,125,0,0.2);
}
.btn-warning:hover,
.btn-warning:focus {
  background-color: #8c6200;
  border-color: #8c6200;
  box-shadow: 0 4px 8px rgba(176,125,0,0.3);
  color: #ffffff;
}

/* Danger — risk-critical red */
.btn-danger {
  background-color: var(--risk-critical);
  border-color: var(--risk-critical);
  color: #ffffff;
  box-shadow: 0 2px 4px rgba(181,40,40,0.2);
}
.btn-danger:hover,
.btn-danger:focus {
  background-color: #8f1f1f;
  border-color: #8f1f1f;
  box-shadow: 0 4px 8px rgba(181,40,40,0.3);
  color: #ffffff;
}

/* Secondary — outlined eco-primary */
.btn-secondary {
  background-color: transparent;
  border: 1px solid var(--eco-primary);
  color: var(--eco-primary);
  box-shadow: none;
}
.btn-secondary:hover,
.btn-secondary:focus {
  background-color: var(--eco-primary);
  border-color: var(--eco-primary);
  color: #ffffff;
}

/* Info */
.btn-info {
  background-color: #0077a8;
  border-color: #0077a8;
  color: #ffffff;
}
.btn-info:hover,
.btn-info:focus {
  background-color: #005f86;
  border-color: #005f86;
  color: #ffffff;
}

/* Auth button — login/register pages */
.btn-auth {
  background: linear-gradient(135deg, var(--eco-primary) 0%, var(--eco-secondary) 100%);
  border: none;
  color: #ffffff;
  font-weight: 600;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  box-shadow: 0 4px 8px rgba(27,77,62,0.3);
  border-radius: var(--radius-md);
  transition: all 0.3s ease;
}
.btn-auth:hover {
  background: linear-gradient(135deg, var(--eco-secondary) 0%, var(--eco-accent) 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(27,77,62,0.4);
  color: #ffffff;
}
.btn-auth:active {
  transform: translateY(0);
  box-shadow: 0 2px 4px rgba(27,77,62,0.3);
}

/* Remove Bootstrap blue bleed from table action buttons */
.btn-default,
.btn-flat {
  color: var(--text-primary);
  background-color: transparent;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}
.btn-default:hover,
.btn-flat:hover {
  background-color: var(--surface-body);
  border-color: var(--border-color-strong);
  color: var(--eco-primary);
}

/* Small buttons in table action cells */
.table .btn-sm {
  padding: 0.25rem 0.55rem;
  font-size: 0.78rem;
  border-radius: var(--radius-sm);
}


/* ============================================================
   9. BADGES & STATUS INDICATORS
   ============================================================ */

/* Override Bootstrap's default primary/success badge colors */
.badge.bg-primary {
  background-color: var(--eco-primary) !important;
}
.badge.bg-success {
  background-color: var(--risk-low) !important;
}
.badge.bg-warning {
  background-color: var(--risk-moderate) !important;
  color: #ffffff !important;
}
.badge.bg-danger {
  background-color: var(--risk-critical) !important;
}
.badge.bg-secondary {
  background-color: var(--text-muted) !important;
}

/* Risk level badges (used in crop management) */
.badge-risk-low {
  background-color: var(--risk-low);
  color: #ffffff;
}
.badge-risk-moderate {
  background-color: var(--risk-moderate);
  color: #ffffff;
}
.badge-risk-high {
  background-color: var(--risk-high);
  color: #ffffff;
}
.badge-risk-critical {
  background-color: var(--risk-critical);
  color: #ffffff;
}

/* Role badges — distinct but harmonious */
.badge-role-admin {
  background-color: var(--eco-primary);
  color: #ffffff;
}
.badge-role-rcpc {
  background-color: #2b5f8a;
  color: #ffffff;
}
.badge-role-mao {
  background-color: #6a4e8a;
  color: #ffffff;
}
.badge-role-coop {
  background-color: #2e7a6b;
  color: #ffffff;
}
.badge-role-philrice {
  background-color: #7a6e2e;
  color: #ffffff;
}

/* Status indicator dots */
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: var(--space-1);
  vertical-align: middle;
}
.status-dot.active   { background-color: var(--risk-low); }
.status-dot.inactive { background-color: var(--text-muted); }
.status-dot.warning  { background-color: var(--risk-moderate); }
.status-dot.danger   { background-color: var(--risk-critical); }


/* ============================================================
   10. FORMS
   ============================================================ */
.form-label,
label {
  font-family: 'Source Sans 3', sans-serif;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-secondary);
  margin-bottom: var(--space-1);
}

.form-control,
.form-select {
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  background-color: var(--surface-card);
  font-size: 0.9rem;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

/* Restore eco focus ring (overrides common.css's box-shadow:none !important) */
.form-control:focus,
.form-select:focus {
  border-color: var(--eco-accent) !important;
  box-shadow: 0 0 0 3px rgba(61,153,112,0.15) !important;
  outline: none;
}

.form-control::placeholder {
  color: var(--text-muted);
  opacity: 0.8;
}

.form-control:disabled,
.form-select:disabled {
  background-color: var(--surface-body);
  color: var(--text-muted);
  cursor: not-allowed;
}

/* Form text / helper */
.form-text {
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* Invalid state */
.form-control.is-invalid,
.form-select.is-invalid {
  border-color: var(--risk-critical);
}
.invalid-feedback {
  color: var(--risk-critical);
  font-size: 0.8rem;
}

/* Valid state */
.form-control.is-valid,
.form-select.is-valid {
  border-color: var(--risk-low);
}

/* Input groups */
.input-group-text {
  background-color: var(--surface-body);
  border-color: var(--border-color);
  color: var(--text-secondary);
}

/* Checkboxes / radios */
.form-check-input:checked {
  background-color: var(--eco-primary);
  border-color: var(--eco-primary);
}
.form-check-input:focus {
  box-shadow: 0 0 0 3px rgba(61,153,112,0.15);
  border-color: var(--eco-accent);
}

/* Section headers inside forms (register page) */
.text-muted.fw-bold {
  color: var(--eco-primary) !important;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 2px solid var(--eco-secondary);
  padding-bottom: var(--space-2);
}


/* ============================================================
   11. LOGIN / AUTH PAGES
   ============================================================ */
.login-page,
body.login-page {
  background-color: var(--surface-body) !important;
  /* Subtle diagonal texture — very faint green grid lines */
  background-image:
    repeating-linear-gradient(
      45deg,
      rgba(27,77,62,0.025) 0px,
      rgba(27,77,62,0.025) 1px,
      transparent 1px,
      transparent 50px
    ),
    repeating-linear-gradient(
      -45deg,
      rgba(27,77,62,0.015) 0px,
      rgba(27,77,62,0.015) 1px,
      transparent 1px,
      transparent 50px
    ) !important;
}

/* Override AdminLTE's bg-body-secondary on login page */
.login-page.bg-body-secondary {
  --bs-body-bg: var(--surface-body);
  background-color: var(--surface-body) !important;
}

/* Login card */
.login-page .card {
  border-radius: var(--radius-lg) !important;
  box-shadow: var(--shadow-md) !important;
  border-top: 3px solid var(--eco-primary);
  max-width: 420px;
  margin: 0 auto;
}

/* Logo */
.logo-img {
  width: 120px;
  height: 120px;
  object-fit: contain;
}

/* EcoIlluminate system title */
.system-title {
  background: linear-gradient(135deg, var(--eco-primary) 0%, var(--eco-secondary) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  font-family: 'IBM Plex Sans Condensed', sans-serif;
  font-weight: 700;
  font-size: 2.4rem;
  letter-spacing: 0.5px;
  margin-bottom: 0 !important;
}

/* Fallback for browsers without background-clip: text support */
@supports not (-webkit-background-clip: text) {
  .system-title {
    color: var(--eco-primary);
    -webkit-text-fill-color: unset;
  }
}


/* ============================================================
   12. RESPONSIVE
   ============================================================ */

/* Tablet */
@media (max-width: 768px) {
  .logo-img {
    width: 100px;
    height: 100px;
  }

  .system-title {
    font-size: 2rem;
  }

  .container-fluid {
    padding: 1rem;
  }

  .card {
    margin: 0.5rem;
  }

  .card-body {
    padding: var(--space-4);
  }

  /* Table horizontal scroll on mobile */
  .table-responsive-mobile {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  /* DataTables — wrap filter/length row */
  .dataTables_wrapper .row {
    flex-direction: column;
  }
}

/* Mobile */
@media (max-width: 480px) {
  .logo-img {
    width: 80px;
    height: 80px;
  }

  .system-title {
    font-size: 1.8rem;
  }

  .app-content-header h3,
  .app-content-header h1,
  .content-title {
    font-size: 1.3rem;
  }

  .btn {
    font-size: 0.82rem;
    padding: 0.35rem 0.7rem;
  }

  /* Sidebar holds its color on collapse */
  .app-sidebar {
    background-color: var(--surface-sidebar) !important;
  }
}
