/* TKCA AquaTrack - Main Stylesheet */
@import url('https://fonts.googleapis.com/css2?family=Nunito:wght@300;400;600;700;800&family=Poppins:wght@400;500;600;700&display=swap');

:root {
  --teal:        #5BBFC4;
  --teal-dark:   #3D9EA3;
  --teal-light:  #D0EDEF;
  --sage:        #A8D5B5;
  --sage-light:  #E1F2E6;
  --yellow:      #EDE86B;
  --yellow-light:#FAFAD2;
  --coral:       #E8786B;
  --coral-dark:  #C85A4E;
  --peach:       #E89C82;
  --gray-light:  #CECECE;
  --gray-bg:     #F5F7F8;
  --white:       #FFFFFF;
  --text-dark:   #2C3E50;
  --text-mid:    #5A6A7A;
  --text-light:  #8A9BAA;
  --shadow-sm:   0 2px 8px rgba(91,191,196,0.12);
  --shadow-md:   0 4px 20px rgba(91,191,196,0.18);
  --shadow-lg:   0 8px 40px rgba(44,62,80,0.12);
  --radius-sm:   8px;
  --radius-md:   14px;
  --radius-lg:   20px;
  --radius-xl:   28px;
  --font-main:   'Nunito', sans-serif;
  --font-head:   'Poppins', sans-serif;
  --transition:  all 0.25s cubic-bezier(0.4,0,0.2,1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

body {
  font-family: var(--font-main);
  background: var(--gray-bg);
  color: var(--text-dark);
  min-height: 100vh;
  line-height: 1.6;
}

/* ── NAV ── */
.navbar {
  background: var(--white);
  border-bottom: 3px solid var(--teal-light);
  position: sticky; top: 0; z-index: 1000;
  box-shadow: var(--shadow-sm);
  /* Needed so the mobile dropdown positions relative to the navbar */
  isolation: isolate;
}
.navbar-inner {
  max-width: 1100px; margin: 0 auto;
  display: flex; align-items: center; gap: 12px;
  padding: 0 20px; height: 64px;
}
.nav-logo {
  display: flex; align-items: center; gap: 10px;
  text-decoration: none; flex-shrink: 0;
}
.nav-logo-img { width: 38px; height: 38px; border-radius: 50%; object-fit: cover; }
.nav-logo-text { font-family: var(--font-head); font-weight: 700; font-size: 1.15rem; color: var(--teal-dark); }
.nav-logo-text span { color: var(--coral); }

.nav-links { display: flex; gap: 4px; margin-left: auto; }
.nav-link {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: var(--radius-sm);
  text-decoration: none; font-weight: 600; font-size: 0.88rem;
  color: var(--text-mid); transition: var(--transition);
}
.nav-link:hover, .nav-link.active {
  background: var(--teal-light); color: var(--teal-dark);
}
.nav-link svg { width: 16px; height: 16px; }

.nav-toggle {
  display: none; background: none; border: none; cursor: pointer;
  padding: 8px; border-radius: var(--radius-sm);
  color: var(--teal-dark);
}
.nav-toggle:hover { background: var(--teal-light); }

/* ── HERO BANNER ── */
.page-hero {
  background: linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 60%, #2C7A7E 100%);
  color: white; padding: 36px 20px 30px;
  position: relative; overflow: hidden;
}
.page-hero::before {
  content: ''; position: absolute; inset: 0;
  background: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cg fill='none' fill-rule='evenodd'%3E%3Cg fill='%23ffffff' fill-opacity='0.05'%3E%3Ccircle cx='30' cy='30' r='20'/%3E%3C/g%3E%3C/g%3E%3C/svg%3E");
  pointer-events: none;
}
.page-hero-inner { max-width: 1100px; margin: 0 auto; position: relative; }
.page-hero h1 { font-family: var(--font-head); font-weight: 700; font-size: 1.8rem; }
.page-hero p { opacity: 0.88; margin-top: 4px; font-size: 0.95rem; }

/* ── MAIN LAYOUT ── */
.main-wrap { max-width: 1100px; margin: 0 auto; padding: 28px 16px 60px; }

/* ── CARDS ── */
.card {
  background: var(--white);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: var(--transition);
}
.card:hover { box-shadow: var(--shadow-md); }
.card-header {
  padding: 18px 24px 14px;
  border-bottom: 2px solid var(--gray-bg);
  display: flex; align-items: center; gap: 10px;
}
.card-header h2 { font-family: var(--font-head); font-weight: 600; font-size: 1.05rem; color: var(--text-dark); }
.card-header .card-icon {
  width: 36px; height: 36px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  background: var(--teal-light); color: var(--teal-dark);
  flex-shrink: 0;
}
.card-body { padding: 24px; }

/* ── FORM ELEMENTS ── */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.form-full { grid-column: 1 / -1; }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label {
  font-weight: 700; font-size: 0.82rem; color: var(--text-mid);
  text-transform: uppercase; letter-spacing: 0.05em;
  display: flex; align-items: center; gap: 6px;
}
.form-label .required { color: var(--coral); }

.form-control {
  padding: 11px 14px;
  border: 2px solid #E8ECEF;
  border-radius: var(--radius-sm);
  font-family: var(--font-main);
  font-size: 0.95rem;
  color: var(--text-dark);
  background: var(--white);
  transition: var(--transition);
  width: 100%;
  outline: none;
}
.form-control:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(91,191,196,0.15);
}
.form-control:read-only {
  background: var(--gray-bg);
  color: var(--text-mid);
  cursor: not-allowed;
}
.form-control.is-invalid { border-color: var(--coral); }
.form-hint { font-size: 0.78rem; color: var(--text-light); }

select.form-control { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%235BBFC4' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 38px;
}

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 11px 22px; border-radius: var(--radius-sm);
  font-family: var(--font-main); font-weight: 700; font-size: 0.92rem;
  border: 2px solid transparent; cursor: pointer;
  text-decoration: none; transition: var(--transition);
  line-height: 1;
}
.btn-primary {
  background: var(--teal); color: white; border-color: var(--teal);
}
.btn-primary:hover { background: var(--teal-dark); border-color: var(--teal-dark); transform: translateY(-1px); box-shadow: 0 4px 12px rgba(91,191,196,0.4); }

.btn-danger { background: var(--coral); color: white; border-color: var(--coral); }
.btn-danger:hover { background: var(--coral-dark); border-color: var(--coral-dark); }

.btn-warning { background: var(--yellow); color: var(--text-dark); border-color: var(--yellow); }
.btn-warning:hover { filter: brightness(0.95); }

.btn-outline {
  background: transparent; color: var(--teal); border-color: var(--teal);
}
.btn-outline:hover { background: var(--teal-light); }

.btn-sm { padding: 7px 14px; font-size: 0.82rem; }
.btn-lg { padding: 14px 28px; font-size: 1rem; }
.btn-block { width: 100%; justify-content: center; }

/* ── RANGE INDICATORS ── */
.reading-bar {
  display: flex; align-items: center; gap: 8px;
  margin-top: 4px;
}
.reading-status {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px;
  font-size: 0.75rem; font-weight: 700;
}
.status-good { background: var(--sage-light); color: #3A7A4A; }
.status-warn { background: var(--yellow-light); color: #7A6A10; }
.status-bad  { background: #FDE8E8; color: var(--coral-dark); }

/* ── TABLES ── */
.table-wrap { overflow-x: auto; border-radius: var(--radius-md); }
table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
thead { background: linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 100%); }
thead th { color: white; font-family: var(--font-head); font-weight: 600;
  padding: 13px 16px; text-align: left; font-size: 0.82rem; text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }
tbody tr { border-bottom: 1px solid #F0F3F5; transition: var(--transition); }
tbody tr:hover { background: var(--teal-light); }
tbody td { padding: 12px 16px; color: var(--text-dark); }
tbody tr:last-child { border-bottom: none; }

/* ── BADGES ── */
.badge {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  font-size: 0.75rem; font-weight: 700; white-space: nowrap;
}
.badge-pool     { background: var(--teal-light); color: var(--teal-dark); }
.badge-jacuzzi  { background: var(--sage-light); color: #3A7A4A; }
.badge-hot-tub  { background: #FDE8E8; color: var(--coral-dark); }

/* ── ALERTS ── */
.alert {
  padding: 13px 18px; border-radius: var(--radius-sm); margin-bottom: 18px;
  display: flex; align-items: flex-start; gap: 10px;
  font-weight: 600; font-size: 0.9rem;
}
.alert-success { background: var(--sage-light); color: #2D6A3F; border-left: 4px solid var(--sage); }
.alert-error   { background: #FDE8E8; color: var(--coral-dark); border-left: 4px solid var(--coral); }
.alert-info    { background: var(--teal-light); color: var(--teal-dark); border-left: 4px solid var(--teal); }
.alert-warning { background: var(--yellow-light); color: #7A6A10; border-left: 4px solid var(--yellow); }

/* ── STATS GRID ── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--white); border-radius: var(--radius-md);
  padding: 20px; box-shadow: var(--shadow-sm);
  display: flex; flex-direction: column; gap: 6px;
  border-top: 4px solid var(--teal);
}
.stat-card:nth-child(2) { border-top-color: var(--coral); }
.stat-card:nth-child(3) { border-top-color: var(--sage); }
.stat-card:nth-child(4) { border-top-color: var(--yellow); }
.stat-number { font-family: var(--font-head); font-size: 2rem; font-weight: 700; color: var(--teal-dark); }
.stat-card:nth-child(2) .stat-number { color: var(--coral-dark); }
.stat-card:nth-child(3) .stat-number { color: #3A7A4A; }
.stat-card:nth-child(4) .stat-number { color: #7A6A10; }
.stat-label { font-size: 0.82rem; font-weight: 700; color: var(--text-light); text-transform: uppercase; letter-spacing: 0.05em; }

/* ── FILTER BAR ── */
.filter-bar {
  background: var(--white); border-radius: var(--radius-md);
  padding: 18px 20px; box-shadow: var(--shadow-sm);
  display: flex; flex-wrap: wrap; gap: 14px; align-items: flex-end;
  margin-bottom: 20px;
}
.filter-group { display: flex; flex-direction: column; gap: 5px; min-width: 160px; flex: 1; }
.filter-label { font-size: 0.78rem; font-weight: 700; color: var(--text-mid); text-transform: uppercase; letter-spacing: 0.05em; }

/* ── TABS ── */
.tabs { display: flex; gap: 4px; border-bottom: 2px solid #E8ECEF; margin-bottom: 24px; overflow-x: auto; }
.tab {
  padding: 10px 18px; font-weight: 700; font-size: 0.88rem;
  color: var(--text-mid); cursor: pointer; border-bottom: 3px solid transparent;
  margin-bottom: -2px; white-space: nowrap; transition: var(--transition);
  background: none; border-top: none; border-left: none; border-right: none;
  font-family: var(--font-main);
}
.tab:hover { color: var(--teal); }
.tab.active { color: var(--teal-dark); border-bottom-color: var(--teal); }

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(44,62,80,0.5);
  backdrop-filter: blur(4px); z-index: 2000;
  display: flex; align-items: center; justify-content: center;
  padding: 16px; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.modal-overlay.active { opacity: 1; pointer-events: all; }
.modal {
  background: var(--white); border-radius: var(--radius-xl);
  max-width: 560px; width: 100%;
  box-shadow: var(--shadow-lg);
  transform: translateY(20px); transition: transform 0.25s ease;
  max-height: 90vh; overflow-y: auto;
}
.modal-overlay.active .modal { transform: translateY(0); }
.modal-header {
  padding: 20px 24px 16px;
  border-bottom: 2px solid var(--gray-bg);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-family: var(--font-head); font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; padding: 4px; color: var(--text-light); font-size: 1.2rem; border-radius: 4px; }
.modal-close:hover { background: var(--gray-bg); color: var(--text-dark); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 2px solid var(--gray-bg); display: flex; gap: 10px; justify-content: flex-end; }

/* ── LOGIN PAGE ── */
.login-wrap {
  min-height: 100vh;
  background: linear-gradient(135deg, var(--teal) 0%, var(--teal-dark) 50%, #1F5F63 100%);
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.login-card {
  background: var(--white); border-radius: var(--radius-xl);
  padding: 40px 36px; width: 100%; max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
}
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo img { width: 70px; height: 70px; border-radius: 50%; object-fit: cover; margin-bottom: 10px; }
.login-logo h1 { font-family: var(--font-head); font-size: 1.4rem; color: var(--teal-dark); }
.login-logo p { font-size: 0.85rem; color: var(--text-light); }

/* ── ADMIN SIDEBAR LAYOUT ── */
.admin-layout { display: flex; min-height: calc(100vh - 64px); }
.sidebar {
  width: 240px; flex-shrink: 0;
  background: var(--text-dark);
  padding: 20px 0;
  position: sticky; top: 64px; height: calc(100vh - 64px);
  overflow-y: auto;
}
.sidebar-section-title {
  color: var(--text-light); font-size: 0.7rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.1em;
  padding: 12px 20px 6px;
}
.sidebar-link {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 20px; color: rgba(255,255,255,0.7);
  text-decoration: none; font-weight: 600; font-size: 0.88rem;
  transition: var(--transition); border-left: 3px solid transparent;
}
.sidebar-link:hover { color: white; background: rgba(255,255,255,0.08); }
.sidebar-link.active { color: white; background: rgba(91,191,196,0.2); border-left-color: var(--teal); }
.sidebar-link svg { width: 17px; height: 17px; opacity: 0.8; }
.admin-content { flex: 1; padding: 28px 24px; overflow-x: hidden; }

/* ── PAGINATION ── */
.pagination { display: flex; gap: 6px; justify-content: center; margin-top: 20px; flex-wrap: wrap; }
.page-btn {
  min-width: 36px; height: 36px; border-radius: var(--radius-sm);
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem; cursor: pointer;
  border: 2px solid #E8ECEF; background: var(--white); color: var(--text-mid);
  transition: var(--transition);
}
.page-btn:hover, .page-btn.active { background: var(--teal); color: white; border-color: var(--teal); }
.page-btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ── EMPTY STATE ── */
.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-light);
}
.empty-state svg { width: 64px; height: 64px; opacity: 0.3; margin-bottom: 12px; }
.empty-state h3 { font-size: 1.1rem; color: var(--text-mid); margin-bottom: 6px; }

/* ── FLOATING SAVE FEEDBACK ── */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 3000;
  background: var(--text-dark); color: white;
  padding: 13px 20px; border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg); font-weight: 600; font-size: 0.9rem;
  display: flex; align-items: center; gap: 10px;
  transform: translateY(80px); opacity: 0; transition: all 0.35s cubic-bezier(0.4,0,0.2,1);
  max-width: 340px;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-left: 4px solid var(--sage); }
.toast.error   { border-left: 4px solid var(--coral); }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .form-grid { grid-template-columns: 1fr; }
  .nav-links { display: none; flex-direction: column; position: absolute; top: 64px; left: 0; right: 0; background: white; padding: 12px; box-shadow: var(--shadow-md); border-top: 2px solid var(--teal-light); }
  .nav-links.open { display: flex; }
  .nav-toggle { display: flex; align-items: center; justify-content: center; margin-left: auto; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .admin-layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; display: flex; flex-wrap: wrap; padding: 10px; gap: 4px; }
  .sidebar-section-title { display: none; }
  .sidebar-link { padding: 8px 12px; border-radius: var(--radius-sm); border-left: none; font-size: 0.82rem; }
  .admin-content { padding: 16px; }
  .page-hero h1 { font-size: 1.4rem; }
  .filter-bar { flex-direction: column; }
  .filter-group { min-width: 100%; }
  .modal { margin: 0; border-radius: var(--radius-lg) var(--radius-lg) 0 0; align-self: flex-end; max-width: 100%; }
  .modal-overlay { align-items: flex-end; }
  .toast { left: 16px; right: 16px; bottom: 16px; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .card-body { padding: 16px; }
  .login-card { padding: 28px 20px; }
}

/* ── PRINT STYLES ── */
@media print {
  .navbar, .filter-bar, .btn, .nav-links { display: none !important; }
  .card { box-shadow: none; border: 1px solid #ddd; }
  .page-hero { background: white !important; color: black !important; }
  body { background: white; }
}

/* ── LOADING ── */
.spinner {
  width: 24px; height: 24px; border-radius: 50%;
  border: 3px solid var(--teal-light);
  border-top-color: var(--teal);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── CHART PLACEHOLDER ── */
.chart-wrap { position: relative; height: 280px; }

/* ── READING VALUE PILLS ── */
.value-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 20px; font-weight: 700; font-size: 0.85rem;
}
.pill-good { background: var(--sage-light); color: #2D6A3F; }
.pill-warn { background: var(--yellow-light); color: #7A6A10; }
.pill-bad  { background: #FDE8E8; color: var(--coral-dark); }

/* ── DIVIDER ── */
.divider { border: none; border-top: 2px solid var(--gray-bg); margin: 20px 0; }

/* ── SORTABLE TABLES ── */
thead th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  padding-right: 28px;
  position: relative;
  transition: var(--transition);
}
thead th.sortable:hover { background: rgba(255,255,255,0.15); }
thead th.sortable::after {
  content: '⇅';
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.45;
  font-size: 0.85rem;
  font-style: normal;
}
thead th.sort-asc::after  { content: '↑'; opacity: 1; }
thead th.sort-desc::after { content: '↓'; opacity: 1; }

/* ── SORTABLE TABLES ── */
thead th.sortable {
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
  position: relative;
  padding-right: 26px;
  transition: var(--transition);
}
thead th.sortable:hover { background: rgba(255,255,255,0.15); }
thead th.sortable::after {
  content: '⇅';
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  opacity: 0.4;
  font-size: 0.75rem;
}
thead th.sortable.asc::after  { content: '↑'; opacity: 1; }
thead th.sortable.desc::after { content: '↓'; opacity: 1; }
thead th.sortable.asc,
thead th.sortable.desc { background: rgba(255,255,255,0.18); }
