:root {
  --bg: #f8f5fc;
  --surface: #ffffff;
  --surface-2: #f3eef8;
  --ink: #2d1b4e;
  --muted: #6b5b7a;
  --line: #e0d5eb;
  --brand: #9b59b6;
  --brand-dark: #8e44ad;
  --accent: #e91e63;
  /* Sidebar colors - Light Mode */
  --sidebar-bg: linear-gradient(180deg, #E6E6FA 0%, #D8BFD8 100%);
  --sidebar-text: var(--ink);
  --sidebar-nav-text: var(--muted);
  --sidebar-nav-hover-bg: rgba(155, 89, 182, 0.15);
  --sidebar-nav-active-text: var(--brand);
  --sidebar-nav-active-bg: rgba(155, 89, 182, 0.25);
  --sidebar-user-pill-text: var(--muted);
  --danger: #b42318;
  --ok: #16794c;
  --warn: #b76e00;
  --info: #2563eb;
  --shadow: 0 18px 45px rgba(45, 27, 78, 0.13);
}

body.dark-mode {
  --bg: #1a1025;
  --surface: #2d1b4e;
  --surface-2: #3d2a5e;
  --ink: #f3eef8;
  --muted: #b8a8c7;
  /* Sidebar colors - Dark Mode */
  --sidebar-bg: linear-gradient(180deg, #4B0082 0%, #6a0dad 100%);
  --sidebar-text: #fff;
  --sidebar-nav-text: rgba(255, 255, 255, 0.72);
  --sidebar-nav-hover-bg: rgba(155, 89, 182, 0.25);
  --sidebar-nav-active-text: #e6e6fa;
  --sidebar-nav-active-bg: rgba(155, 89, 182, 0.4);
  --sidebar-user-pill-text: rgba(255, 255, 255, 0.68);
  --line: #4a3a5a;
  --shadow: 0 18px 45px rgba(45, 27, 78, 0.4);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.login-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(360px, 0.8fr);
}

.login-hero {
  position: relative;
  min-height: 100vh;
  padding: 42px;
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
  color: #fff;
  background:
    linear-gradient(90deg, rgba(10, 29, 24, 0.85), rgba(10, 29, 24, 0.22)),
    url("https://images.unsplash.com/photo-1586773860418-d37222d8fce3?auto=format&fit=crop&w=1600&q=80") center / cover;
}

.login-hero h1 {
  margin: 0;
  max-width: 780px;
  font-size: clamp(2.4rem, 5vw, 5.4rem);
  line-height: 0.95;
}

.login-hero p {
  max-width: 620px;
  margin: 18px 0 0;
  font-size: 1.06rem;
  line-height: 1.7;
  color: rgba(255, 255, 255, 0.86);
}

.hero-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  max-width: 720px;
  margin-top: 34px;
}

.hero-stat {
  padding: 18px;
  border: 1px solid rgba(255, 255, 255, 0.24);
  background: rgba(255, 255, 255, 0.12);
  backdrop-filter: blur(8px);
  border-radius: 8px;
}

.hero-stat strong {
  display: block;
  font-size: 1.7rem;
}

.hero-stat span {
  color: rgba(255, 255, 255, 0.78);
  font-size: 0.86rem;
}

.login-panel {
  min-height: 100vh;
  padding: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--surface);
}

.login-card {
  width: min(100%, 430px);
}

.brand-row,
.top-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-weight: 800;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  border-radius: 10px;
  color: #fff;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  font-weight: 800;
  box-shadow: 0 4px 12px rgba(155, 89, 182, 0.3);
  transition: all 0.3s ease;
}

.brand-mark:hover {
  transform: scale(1.05) rotate(2deg);
  box-shadow: 0 6px 16px rgba(155, 89, 182, 0.4);
}

.login-card h2 {
  margin: 32px 0 8px;
  font-size: 2rem;
}

.login-card > p {
  margin: 0 0 26px;
  color: var(--muted);
  line-height: 1.6;
}

.role-tabs {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  padding: 5px;
  margin-bottom: 20px;
  background: var(--surface-2);
  border-radius: 8px;
}

.role-tabs button {
  min-height: 42px;
  color: var(--muted);
  background: transparent;
  border-radius: 7px;
  font-weight: 700;
}

.role-tabs button.active {
  color: var(--ink);
  background: var(--surface);
  box-shadow: 0 4px 12px rgba(20, 35, 29, 0.08);
}

.field {
  margin-bottom: 16px;
}

.field label {
  display: block;
  margin-bottom: 7px;
  color: var(--ink);
  font-weight: 700;
  font-size: 0.88rem;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  padding: 12px 13px;
  outline: none;
}

.field textarea {
  min-height: 108px;
  resize: vertical;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 4px rgba(15, 118, 110, 0.13);
}

.primary-btn,
.ghost-btn,
.danger-btn,
.tiny-btn {
  min-height: 42px;
  border-radius: 8px;
  padding: 0 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 800;
}

.primary-btn {
  color: #fff;
  background: var(--brand);
}

.primary-btn:hover {
  background: var(--brand-dark);
}

.ghost-btn {
  color: var(--ink);
  background: var(--surface-2);
}

.danger-btn {
  color: #fff;
  background: var(--danger);
}

.tiny-btn {
  min-height: 32px;
  padding: 0 10px;
  font-size: 0.8rem;
  color: var(--brand-dark);
  background: rgba(15, 118, 110, 0.1);
}

.action-stack,
.feedback-box {
  display: grid;
  gap: 7px;
  min-width: 150px;
}

.action-stack select,
.feedback-box select,
.feedback-box textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
}

.feedback-box textarea {
  min-height: 62px;
  resize: vertical;
}

.image-thumb {
  width: 62px;
  height: 52px;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface-2);
}

.image-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.demo-box {
  margin-top: 18px;
  padding: 14px;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--muted);
  font-size: 0.86rem;
  line-height: 1.65;
}

.app-shell {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.top-nav {
  position: sticky;
  top: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 28px;
  background: linear-gradient(180deg, var(--sidebar-bg) 0%, rgba(216, 191, 216, 0.95) 100%);
  color: var(--sidebar-text);
  border-bottom: 1px solid var(--line);
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.08);
  backdrop-filter: blur(10px);
}

.top-nav-brand {
  display: flex;
  align-items: center;
  gap: 14px;
  font-weight: 800;
}

.top-nav-brand .brand-mark {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.top-nav-menu {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  justify-content: center;
}

.top-nav-menu button {
  min-height: 44px;
  padding: 0 18px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-radius: 12px;
  color: var(--sidebar-nav-text);
  background: transparent;
  font-weight: 600;
  font-size: 0.92rem;
  white-space: nowrap;
  transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  letter-spacing: 0.01em;
  position: relative;
  overflow: hidden;
}

.top-nav-menu button::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(135deg, rgba(255,255,255,0.1) 0%, rgba(255,255,255,0) 100%);
  opacity: 0;
  transition: opacity 0.25s ease;
}

.top-nav-menu button:hover::before {
  opacity: 1;
}

.top-nav-menu button:hover {
  color: var(--sidebar-nav-active-text);
  background: var(--sidebar-nav-hover-bg);
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1);
}

.top-nav-menu button.active {
  color: var(--sidebar-nav-active-text);
  background: var(--sidebar-nav-active-bg);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.14);
  font-weight: 700;
  transform: translateY(-1px);
}

.top-nav-user {
  display: flex;
  align-items: center;
  gap: 16px;
}

.top-nav-user .ghost-btn {
  border-radius: 12px;
  transition: all 0.2s ease;
}

.top-nav-user .ghost-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.nav-dropdown {
  position: relative;
}

.nav-dropdown > button {
  position: relative;
}

.nav-dropdown::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  height: 8px;
}

.nav-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  left: 0;
  display: none;
  flex-direction: column;
  gap: 2px;
  min-width: 220px;
  padding: 8px;
  margin-top: 0;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.12);
  z-index: 200;
  animation: dropdownFade 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

@keyframes dropdownFade {
  from {
    opacity: 0;
    transform: translateY(-12px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.nav-dropdown-menu.open {
  display: flex;
}

.nav-dropdown:hover .nav-dropdown-menu {
  display: flex;
}

@media (max-width: 1050px) {
  .nav-dropdown:hover .nav-dropdown-menu {
    display: none;
  }
}

.nav-dropdown-menu button {
  min-height: 40px;
  padding: 10px 14px;
  font-size: 0.9rem;
  font-weight: 500;
  text-align: left;
  background: transparent;
  color: var(--ink);
  border-radius: 8px;
  transition: all 0.15s ease;
  display: flex;
  align-items: center;
  gap: 10px;
}

.nav-dropdown-menu button:hover {
  background: var(--surface-2);
  transform: translateX(4px);
}

.nav-dropdown-menu button.active {
  background: var(--sidebar-nav-active-bg);
  color: var(--brand);
  font-weight: 600;
}

.nav-dropdown-menu .theme-toggle,
.nav-dropdown-menu .logout-btn {
  border-top: 1px solid var(--line);
  margin-top: 4px;
  padding-top: 12px;
}

.nav-dropdown-menu .logout-btn {
  color: #ef4444;
}

.nav-dropdown-menu .logout-btn:hover {
  background: rgba(239, 68, 68, 0.1);
}

.user-pill {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--sidebar-nav-hover-bg);
  transition: all 0.2s ease;
  cursor: pointer;
  border: none;
  width: 100%;
  justify-content: flex-start;
}

.user-pill:hover {
  background: var(--sidebar-nav-active-bg);
}

.user-pill.active {
  background: var(--sidebar-nav-active-bg);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

.avatar {
  width: 40px;
  height: 40px;
  flex: 0 0 40px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--brand) 0%, var(--brand-dark) 100%);
  color: #fff;
  font-weight: 900;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(155, 89, 182, 0.3);
}

.avatar img {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
}

.user-pill strong {
  display: block;
  font-size: 0.94rem;
  color: var(--sidebar-text);
}

.user-pill span {
  color: var(--sidebar-user-pill-text);
  font-size: 0.8rem;
  font-weight: 500;
}

.app-footer {
  text-align: center;
  padding: 16px 24px;
  color: var(--muted);
  font-size: 0.85rem;
  font-weight: 500;
  border-top: 1px solid var(--line);
  background: var(--surface);
}

.main {
  min-width: 0;
  padding: 26px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 22px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(1.6rem, 3vw, 2.35rem);
}

.topbar p {
  margin: 5px 0 0;
  color: var(--muted);
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

.search {
  min-width: 270px;
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.metric {
  padding: 18px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 10px 24px rgba(24, 38, 32, 0.06);
}

.metric span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
}

.metric strong {
  display: block;
  margin-top: 7px;
  font-size: 2rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 1.35fr) minmax(320px, 0.65fr);
  gap: 16px;
}

.chart-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.chart-box {
  padding: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 32px;
}

.pie {
  width: 140px;
  height: 140px;
  border-radius: 50%;
  border: 4px solid var(--surface);
  box-shadow: 0 0 0 1px var(--line);
}

.legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.legend-item {
  display: flex;
  align-items: center;
  font-size: 0.9rem;
}

.legend-item .dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  margin-right: 12px;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 10px 24px rgba(24, 38, 32, 0.06);
  overflow-x: auto;
}

.panel-head {
  padding: 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border-bottom: 1px solid var(--line);
  min-width: max-content;
}

.panel-head h2 {
  margin: 0;
  font-size: 1.05rem;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 760px;
}

th,
td {
  padding: 3px 6px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-family: Arial, sans-serif;
  font-size: 12px;
}

th {
  color: var(--muted);
  font-size: 0.76rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

td {
  text-align: justify;
  hyphens: auto;
}

.bill-table th,
.bill-table td {
  padding: 3px;
}

td strong {
  display: block;
}

td small {
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 26px;
  padding: 0 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 800;
  white-space: nowrap;
}

.badge.open {
  color: #7a2e0e;
  background: #ffedd5;
}

.badge.assigned {
  color: #1d4ed8;
  background: #dbeafe;
}

.badge.progress {
  color: #9a3412;
  background: #fed7aa;
}

.badge.resolved {
  color: #047857;
  background: #d1fae5;
}

.badge.closed {
  color: #475569;
  background: #e2e8f0;
}

.badge.priority-high {
  color: #991b1b;
  background: #fee2e2;
}

.badge.priority-medium {
  color: #92400e;
  background: #fef3c7;
}

.badge.priority-low {
  color: #166534;
  background: #dcfce7;
}

.list {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.list-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid var(--line);
}

.list-item:last-child {
  padding-bottom: 0;
  border-bottom: 0;
}

.list-item strong {
  display: block;
  margin-bottom: 4px;
}

.work-detail-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.work-detail-card {
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.work-detail-card h3 {
  margin: 0 0 4px;
  font-size: 0.98rem;
}

.work-detail-card p,
.work-detail-card small,
.work-detail-card li {
  color: var(--muted);
}

.work-detail-card ul {
  margin: 8px 0 0 16px;
  padding: 0;
}

.list-item span,
.list-item small {
  color: var(--muted);
  line-height: 1.5;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  padding: 16px;
  width: max-content;
  min-width: 100%;
}

.form-grid .full {
  grid-column: 1 / -1;
}

.cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.person-card {
  padding: 16px;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: 0 10px 24px rgba(24, 38, 32, 0.06);
}

.person-head {
  display: flex;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.person-card h3 {
  margin: 0;
}

.person-card p {
  margin: 6px 0;
  color: var(--muted);
}

.category-strip {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.category {
  padding: 16px;
  border-radius: 8px;
  color: #fff;
}

.category.civil {
  background: #7c3f1d;
}

.category.electrical {
  background: #1d4ed8;
}

.category.horticulture {
  background: #15803d;
}

.category strong {
  display: block;
  font-size: 1.55rem;
  margin-top: 8px;
}

.empty {
  padding: 26px;
  color: var(--muted);
  text-align: center;
}

.mobile-header {
  display: none;
}

.mobile-menu-toggle {
  display: none;
}

@media (max-width: 1050px) {
  .mobile-menu-toggle {
    display: flex;
  }
  .top-nav {
    flex-wrap: wrap;
    padding: 12px 16px;
  }

  .top-nav-brand {
    width: 100%;
    margin-bottom: 8px;
  }

  .top-nav-menu {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .top-nav-menu button {
    font-size: 0.85rem;
    padding: 0 12px;
    min-height: 36px;
  }

  .top-nav-user {
    width: 100%;
    justify-content: flex-end;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
  }

  .top-nav-user .nav-dropdown {
    width: 100%;
  }

  .top-nav-user .nav-dropdown-menu {
    position: static;
    box-shadow: none;
    border: none;
    background: var(--sidebar-nav-hover-bg);
    padding: 8px;
    margin-top: 4px;
  }

  .login-shell,
  .grid-2,
  .chart-grid {
    grid-template-columns: 1fr;
  }

  .login-hero {
    min-height: 52vh;
  }

  .login-panel {
    min-height: auto;
  }

  .metrics,
  .cards {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .main {
    padding: 16px;
  }
}

@media (max-width: 720px) {
  .top-nav {
    padding: 12px;
  }

  .top-nav-menu {
    display: none;
    flex-direction: column;
    width: 100%;
    position: absolute;
    top: 100%;
    left: 0;
    background: var(--sidebar-bg);
    border-top: 1px solid var(--line);
    padding: 12px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
  }

  .top-nav-menu.open {
    display: flex;
  }

  .top-nav-menu button {
    width: 100%;
    justify-content: flex-start;
  }

  .nav-dropdown-menu {
    position: static;
    box-shadow: none;
    border: none;
    padding-left: 16px;
    margin-top: 4px;
  }

  .login-hero,
  .login-panel,
  .main {
    padding: 18px;
  }

  .hero-stats,
  .metrics,
  .cards,
  .category-strip,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  .toolbar,
  .search {
    width: 100%;
  }

  .role-tabs {
    grid-template-columns: 1fr;
  }
}
