:root {
  --bg: #151a24;
  --sidebar: #101521;
  --card: rgba(30, 35, 48, 0.9);
  --primary: #8f96e8;
  --accent: #f3a57e;
  --danger: #ef4444;
  --warning: #f3a57e;
  --success: #6bc9a8;
  --text-main: #e8edf5;
  --text-sub: #a8b2c5;
}

body {
  background: radial-gradient(circle at top left, #2b3142 0%, #1b202d 38%, #151a24 72%, #121722 100%) !important;
  color: var(--text-main) !important;
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif !important;
  line-height: 1.45 !important;
}

.sidebar {
  background: linear-gradient(180deg, #171b26 0%, #111724 100%) !important;
  border-right: 1px solid rgba(160, 171, 210, 0.28) !important;
  width: 280px !important;
  padding: 1.5rem !important;
  box-shadow: 8px 0 22px rgba(0, 0, 0, 0.3) !important;
  display: flex !important;
  flex-direction: column !important;
  max-height: 100dvh !important;
}

.sidebar nav {
  display: flex !important;
  flex-direction: column !important;
  gap: 2px !important;
  flex: 1 1 auto !important;
  min-height: 0 !important;
  overflow-y: auto !important;
  overflow-x: hidden !important;
  padding-bottom: 4.3rem !important;
}

.sidebar .nav-item.logout {
  display: none !important;
}

.mobile-quick-logout {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 8px !important;
  position: absolute !important;
  left: 0.75rem !important;
  right: 0.75rem !important;
  bottom: 0.75rem !important;
  bottom: calc(0.75rem + env(safe-area-inset-bottom)) !important;
  min-height: 42px !important;
  border-radius: 10px !important;
  text-decoration: none !important;
  font-weight: 700 !important;
  background: rgba(78, 37, 51, 0.95) !important;
  border: 1px solid rgba(239, 68, 68, 0.4) !important;
  color: #ffd8d8 !important;
  z-index: 1200 !important;
  visibility: visible !important;
  opacity: 1 !important;
}

@media (min-width: 1025px) {
  .mobile-quick-logout {
    display: inline-flex !important;
    position: sticky !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0.75rem !important;
    margin-top: auto !important;
    width: 100% !important;
    z-index: 1200 !important;
  }

  .sidebar {
    padding-bottom: 0.75rem !important;
  }

  .sidebar nav {
    padding-bottom: 0.5rem !important;
  }
}

.sidebar nav > div[style*="margin-top: auto"] {
  margin-top: auto !important;
}

/* Ensure desktop content fills all available space beside fixed sidebar */
@media (min-width: 1025px) {
  .sidebar + .main-content,
  .sidebar ~ .main-content {
    margin-left: 280px !important;
    width: calc(100vw - 280px) !important;
    max-width: none !important;
    padding-right: 1rem !important;
  }

  .main-content > .card,
  .main-content .card {
    width: 100% !important;
  }
}

.sidebar h2 {
  color: #dbe9f6 !important;
  font-size: 1.26rem !important;
  font-weight: 800 !important;
  line-height: 1.15 !important;
  letter-spacing: 0.01em !important;
  margin-bottom: 1rem !important;
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  padding-right: 2.5rem !important;
}

.sidebar-logo {
  width: 58px !important;
  height: 58px !important;
  object-fit: contain !important;
  flex-shrink: 0 !important;
  padding: 1px !important;
  border-radius: 12px !important;
  background: transparent !important;
  border: 1px solid rgba(187, 201, 241, 0.56) !important;
  box-shadow: 0 0 18px rgba(187, 201, 241, 0.38) !important;
  filter: brightness(1.22) contrast(1.14) saturate(1.12) !important;
}

.sidebar h2 span {
  color: #eaf7ff !important;
  text-shadow: 0 1px 8px rgba(162, 175, 231, 0.28) !important;
}

.user-box {
  background: linear-gradient(140deg, rgba(45, 51, 72, 0.86) 0%, rgba(28, 34, 49, 0.9) 100%) !important;
  border: 1px solid rgba(166, 178, 221, 0.3) !important;
  margin-top: 0.5rem !important;
  margin-bottom: 1.5rem !important;
  box-shadow: inset 0 1px 0 rgba(221, 228, 255, 0.08), 0 6px 14px rgba(0, 0, 0, 0.26) !important;
}

.user-box .u-name,
.user-box span:first-child {
  display: block !important;
  color: #dbe9f6 !important;
  font-size: 1.55rem !important;
  font-weight: 700 !important;
  line-height: 1.1 !important;
  margin-bottom: 6px !important;
  text-transform: none !important;
}

.u-role {
  background: rgba(143, 150, 232, 0.2) !important;
  color: #e0e4ff !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  min-height: 20px !important;
  padding: 2px 9px !important;
  font-size: 0.66rem !important;
  font-weight: 800 !important;
  letter-spacing: 0.04em !important;
  border-radius: 5px !important;
  border: 1px solid rgba(176, 186, 233, 0.35) !important;
  text-transform: uppercase !important;
}

.nav-item {
  display: flex !important;
  align-items: center !important;
  gap: 10px !important;
  padding: 10px 12px !important;
  font-size: 0.96rem !important;
  font-weight: 600 !important;
  line-height: 1.2 !important;
  color: #b8bfd1 !important;
  text-decoration: none !important;
  border-radius: 9px !important;
  margin-bottom: 3px !important;
  width: 100% !important;
  min-height: 38px !important;
  text-align: left !important;
  cursor: pointer !important;
  border-left: 3px solid transparent !important;
  border: 1px solid transparent !important;
  background: transparent !important;
  transition: background 0.22s ease, color 0.22s ease, border-color 0.22s ease, transform 0.18s ease !important;
}

.nav-item i {
  width: 20px !important;
  height: 20px !important;
  min-width: 20px !important;
  border-radius: 7px !important;
  text-align: center !important;
  font-size: 0.82rem !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  background: rgba(44, 50, 70, 0.58) !important;
  border: 1px solid rgba(162, 174, 216, 0.24) !important;
  color: #ccd5ea !important;
}

.nav-item.active,
.nav-item:hover {
  background: rgba(56, 64, 89, 0.85) !important;
  color: #f0f3fb !important;
  border: 1px solid rgba(178, 188, 230, 0.35) !important;
  border-left: 3px solid var(--accent) !important;
  box-shadow: inset 0 1px 0 rgba(224, 231, 255, 0.08) !important;
  transform: none !important;
}

.nav-item.active i,
.nav-item:hover i {
  background: rgba(81, 90, 125, 0.78) !important;
  border-color: rgba(193, 202, 235, 0.5) !important;
  color: #f2f5ff !important;
}

.nav-item.logout {
  margin-top: 0.15rem !important;
}

.sidebar-close {
  top: 0.75rem !important;
  right: 0.75rem !important;
  width: 34px !important;
  height: 34px !important;
  padding: 0 !important;
  border-radius: 9px !important;
  border: 1px solid rgba(170, 182, 223, 0.45) !important;
  background: rgba(65, 74, 102, 0.95) !important;
  color: #e3f6ff !important;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22) !important;
  align-items: center !important;
  justify-content: center !important;
}

.sidebar-close:hover,
.sidebar-close:focus {
  background: rgba(80, 89, 120, 0.98) !important;
  border-color: rgba(210, 218, 245, 0.82) !important;
}

.sidebar-toggle {
  align-items: center !important;
  gap: 6px !important;
  background: linear-gradient(180deg, #8f96e8 0%, #7780d7 100%) !important;
  color: #ecf9ff !important;
  border: 1px solid rgba(210, 218, 248, 0.72) !important;
  border-radius: 12px !important;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.24) !important;
  font-size: 0.92rem !important;
  font-weight: 700 !important;
  padding: 0.55rem 1rem !important;
  letter-spacing: 0.01em !important;
}

.sidebar-toggle i {
  color: #f2f5ff !important;
  font-size: 0.92rem !important;
}

.sidebar-toggle:hover,
.sidebar-toggle:focus {
  background: linear-gradient(180deg, #9aa1ef 0%, #858edf 100%) !important;
  border-color: rgba(224, 230, 251, 0.9) !important;
}

.main-content h1,
.main-content h2,
.main-content h3,
.main-content h4,
.main-content label,
.main-content strong,
.main-content p,
.main-content span,
.main-content li,
.main-content td,
.main-content th {
  color: inherit;
}

.main-content {
  color: var(--text-main) !important;
}

.card {
  background: linear-gradient(145deg, rgba(34, 40, 56, 0.94) 0%, rgba(23, 29, 43, 0.96) 100%) !important;
  border: 1px solid rgba(157, 169, 212, 0.28) !important;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.24) !important;
  backdrop-filter: blur(3px) !important;
}

.card:hover {
  border-color: rgba(186, 196, 232, 0.5) !important;
  box-shadow: 0 14px 28px rgba(0, 0, 0, 0.3) !important;
}

.filter-bar,
.node-selector,
.tabs-container {
  background: linear-gradient(145deg, rgba(33, 38, 54, 0.9) 0%, rgba(22, 28, 41, 0.92) 100%) !important;
  border: 1px solid rgba(157, 169, 212, 0.26) !important;
}

input,
select,
textarea {
  background: rgba(18, 24, 36, 0.92) !important;
  color: #dbe9f6 !important;
  border: 1px solid rgba(160, 172, 215, 0.34) !important;
}

/* Keep select arrow and text from looking crammed */
select {
  appearance: none !important;
  -webkit-appearance: none !important;
  -moz-appearance: none !important;
  padding-right: 2.55rem !important;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='none' stroke='%23dbe9f6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 8 4 4 4-4'/%3E%3C/svg%3E") !important;
  background-repeat: no-repeat !important;
  background-position: right 0.95rem center !important;
  background-size: 12px !important;
}

select[multiple],
select[size] {
  background-image: none !important;
  padding-right: 0.75rem !important;
}

input[type="date"] {
  color-scheme: dark !important;
}

.filter-bar > *,
.node-selector > * {
  min-width: 0 !important;
}

.filter-bar input,
.filter-bar select,
.filter-bar button,
.node-selector input,
.node-selector select,
.node-selector button {
  max-width: 100% !important;
}

.filter-bar input[type="date"] {
  min-width: 0 !important;
  max-width: 100% !important;
}

@supports (-webkit-touch-callout: none) and (font: -apple-system-body) {
  .filter-bar input[type="date"] {
    flex: 0 1 170px !important;
    width: 170px !important;
    min-width: 140px !important;
    max-width: min(44vw, 190px) !important;
  }
}

input[type="date"]::-webkit-calendar-picker-indicator {
  filter: brightness(0) invert(1) !important;
  opacity: 1 !important;
  cursor: pointer !important;
}

input::placeholder,
textarea::placeholder {
  color: #8eadc3 !important;
}

table th {
  color: #9fb9cb !important;
  border-bottom: 1px solid rgba(160, 172, 215, 0.2) !important;
}

table td {
  color: #dbe9f6 !important;
  border-bottom: 1px solid rgba(160, 172, 215, 0.12) !important;
}

/* Unified pagination style for all system pages */
.pagination {
  display: flex !important;
  align-items: center !important;
  justify-content: space-between !important;
  gap: 10px !important;
  flex-wrap: wrap !important;
  margin-top: 12px !important;
  width: 100% !important;
}

.pagination-links {
  display: inline-flex !important;
  align-items: center !important;
  gap: 8px !important;
  flex-wrap: wrap !important;
}

.pagination-meta,
.pagination .page-info {
  color: #a8b2c5 !important;
  font-size: 0.82rem !important;
}

.pagination-link,
.page-link,
.pagination a.page-link,
.pagination .page-link {
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  min-width: 42px !important;
  height: 36px !important;
  border-radius: 8px !important;
  text-decoration: none !important;
  font-weight: 700 !important;
  border: 1px solid rgba(160, 172, 215, 0.4) !important;
  background: rgba(18, 24, 36, 0.92) !important;
  color: #dbe9f6 !important;
  padding: 0 12px !important;
  line-height: 1 !important;
}

.pagination-link:hover,
.page-link:hover,
.pagination a.page-link:hover,
.pagination .page-link:hover {
  background: rgba(33, 42, 62, 0.98) !important;
  border-color: rgba(186, 196, 232, 0.62) !important;
  color: #f2f6ff !important;
}

.pagination-link.disabled,
.page-link.disabled,
.pagination .page-link.disabled,
.pagination .disabled {
  opacity: 0.45 !important;
  pointer-events: none !important;
}

.pagination .page-current,
.page-link.active,
.pagination .page-link.active {
  background: linear-gradient(180deg, #8f96e8 0%, #767fd6 100%) !important;
  color: #eef9ff !important;
  border-color: rgba(215, 222, 250, 0.58) !important;
}

td span[style*="background:#f1f5f9"],
td span[style*="background: #f1f5f9"],
td span[style*="background:#d1fae5"],
td span[style*="background: #d1fae5"],
td span[style*="background:#fef3c7"],
td span[style*="background: #fef3c7"],
td span[style*="background:#fee2e2"],
td span[style*="background: #fee2e2"] {
  color: #163549 !important;
  border: 1px solid rgba(22, 53, 73, 0.15) !important;
}

td span[style*="background-color:"],
.status-badge,
span[style*="background-color:"][style*="font-size: 0.75rem"] {
  color: #163549 !important;
  border: 1px solid rgba(22, 53, 73, 0.15) !important;
}

.btn,
.btn-primary,
.btn-save,
.btn-add,
.btn-update,
.btn-gen,
button[type="submit"] {
  appearance: none !important;
  -webkit-appearance: none !important;
  text-decoration: none !important;
  font-family: inherit !important;
  font-weight: 700 !important;
  line-height: 1 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 8px !important;
  min-height: 38px !important;
  padding: 0 14px !important;
  border-radius: 9px !important;
  cursor: pointer !important;
  background: linear-gradient(180deg, #8f96e8 0%, #767fd6 100%) !important;
  color: #eef9ff !important;
  border: 1px solid rgba(215, 222, 250, 0.58) !important;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.24) !important;
  transition: background 0.2s ease, transform 0.18s ease, box-shadow 0.2s ease !important;
}

.btn:hover,
.btn-primary:hover,
.btn-save:hover,
.btn-add:hover,
.btn-update:hover,
.btn-gen:hover,
button[type="submit"]:hover {
  background: linear-gradient(180deg, #9ca3ef 0%, #848ddf 100%) !important;
  transform: translateY(-1px) !important;
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.26) !important;
}

.btn:disabled,
.btn-primary:disabled,
.btn-save:disabled,
.btn-add:disabled,
.btn-update:disabled,
.btn-gen:disabled,
button[type="submit"]:disabled {
  opacity: 0.55 !important;
  cursor: not-allowed !important;
  transform: none !important;
  box-shadow: none !important;
}

/* Unified top action button sizing across pages */
.header-actions .btn,
.header-actions .btn-gen,
.header-actions .btn-export,
.header-actions a.btn,
.header-actions a.btn-gen,
.header-actions a.btn-export,
.header-actions button.btn,
.header-actions button.btn-gen,
.header-actions button.btn-export {
  min-width: 168px !important;
  height: 40px !important;
  padding: 0 14px !important;
  border-radius: 9px !important;
  font-size: 0.9rem !important;
  font-weight: 700 !important;
  line-height: 1 !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 8px !important;
  white-space: nowrap !important;
}

.header-actions .btn i,
.header-actions .btn-gen i,
.header-actions .btn-export i {
  font-size: 0.8rem !important;
  line-height: 1 !important;
}

/* Keep modal tutorial action buttons consistent and prevent fallback tiny style */
.tutorial-actions .btn,
.tutorial-actions .btn-gen,
.tutorial-actions button,
.tutorial-actions a {
  appearance: none !important;
  -webkit-appearance: none !important;
  min-width: 110px !important;
  height: 38px !important;
  padding: 0 14px !important;
  border-radius: 9px !important;
  line-height: 1 !important;
  text-decoration: none !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  white-space: nowrap !important;
}

a {
  color: #c7ccff;
}

a:hover {
  color: #f3a57e;
}

#map {
  border: 1px solid rgba(166, 178, 221, 0.35) !important;
}

@media (max-width: 768px) {
  .sidebar {
    padding: 0.8rem 0 !important;
    max-height: 100dvh !important;
  }

  .sidebar h2 {
    padding-right: 2.9rem !important;
    min-height: 34px !important;
  }

  .nav-item {
    justify-content: flex-start !important;
    padding: 9px 11px !important;
    font-size: 0.88rem !important;
    border-radius: 8px !important;
    min-height: 36px !important;
  }

  .user-box {
    display: none !important;
  }
}

@media (max-width: 600px) {
  .pagination {
    flex-direction: column !important;
    align-items: stretch !important;
  }

  .pagination-links {
    width: 100% !important;
    justify-content: space-between !important;
  }

  .pagination-link,
  .page-link,
  .pagination a.page-link,
  .pagination .page-link {
    min-width: 0 !important;
    flex: 1 1 calc(50% - 6px) !important;
    height: 36px !important;
    border-radius: 8px !important;
    font-size: 0.86rem !important;
    font-weight: 700 !important;
    padding: 0 10px !important;
    line-height: 1 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border: 1px solid rgba(160, 172, 215, 0.4) !important;
    background: rgba(18, 24, 36, 0.92) !important;
    color: #dbe9f6 !important;
  }

  .sidebar {
    padding: 0.5rem 0 !important;
    max-height: 100dvh !important;
  }

  .sidebar h2 {
    padding-right: 3rem !important;
  }

  .nav-item {
    padding: 8px 10px !important;
    font-size: 0.84rem !important;
    min-height: 34px !important;
  }

  select {
    min-height: 40px !important;
    padding-right: 2.6rem !important;
    background-position: right 1rem center !important;
    background-size: 12px !important;
  }

  .filter-bar select,
  .node-selector select {
    min-height: 40px !important;
    padding-right: 2.7rem !important;
    background-position: right 1.05rem center !important;
    background-size: 12px !important;
  }

  .header-actions .btn,
  .header-actions .btn-gen,
  .header-actions .btn-export,
  .header-actions a.btn,
  .header-actions a.btn-gen,
  .header-actions a.btn-export,
  .header-actions button.btn,
  .header-actions button.btn-gen,
  .header-actions button.btn-export {
    min-width: 140px !important;
    width: auto !important;
    max-width: 100% !important;
    flex: 0 0 auto !important;
    height: 38px !important;
    font-size: 0.84rem !important;
    padding: 0 10px !important;
  }
}

@media (max-width: 1024px), (max-height: 760px) {
  .sidebar nav .nav-item.logout {
    display: none !important;
  }

  .mobile-quick-logout {
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    position: absolute !important;
    left: 0.75rem !important;
    right: 0.75rem !important;
    bottom: 0.75rem !important;
    bottom: calc(0.75rem + env(safe-area-inset-bottom)) !important;
    min-height: 42px !important;
    border-radius: 10px !important;
    text-decoration: none !important;
    font-weight: 700 !important;
    background: rgba(78, 37, 51, 0.95) !important;
    border: 1px solid rgba(239, 68, 68, 0.4) !important;
    color: #ffd8d8 !important;
    z-index: 1200 !important;
    visibility: visible !important;
    opacity: 1 !important;
  }

  .sidebar nav {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    padding-bottom: 4.8rem !important;
  }

  .sidebar nav > div[style*="margin-top: auto"] {
    margin-top: 0.35rem !important;
  }
}

@media print {
  .sidebar,
  .sidebar-toggle,
  .sidebar-close,
  .content-overlay,
  .btn,
  .btn-primary,
  .btn-save,
  .btn-add,
  .btn-update,
  .btn-gen,
  .btn-print,
  .btn-filter,
  .header-actions,
  button[type="submit"] {
    display: none !important;
  }

  body,
  .main-content,
  .card,
  .filter-bar,
  .node-selector,
  .tabs-container {
    background: #ffffff !important;
    color: #111827 !important;
    box-shadow: none !important;
    text-shadow: none !important;
    backdrop-filter: none !important;
  }

  .main-content * {
    color: #111827 !important;
    border-color: #d1d5db !important;
  }

  .card {
    border: 1px solid #d1d5db !important;
  }

  table {
    border-collapse: collapse !important;
  }

  th,
  td {
    border-bottom: 1px solid #d1d5db !important;
  }

  a {
    color: #111827 !important;
    text-decoration: none !important;
  }

  .main-content {
    margin-left: 0 !important;
    width: 100% !important;
    padding: 0 !important;
  }
}
