:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --text: #1a1a1a;
  --muted: #555555;
  --border: #e5e7eb;
  --th-bg: #eceef1;
  --shadow: rgba(0, 0, 0, 0.1);
  --link: #2563eb;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #16181d;
    --surface: #1f232b;
    --text: #e6e8eb;
    --muted: #9aa1ab;
    --border: #2d323b;
    --th-bg: #262b33;
    --shadow: rgba(0, 0, 0, 0.4);
    --link: #60a5fa;
  }
}

:root[data-theme="dark"] {
  --bg: #16181d;
  --surface: #1f232b;
  --text: #e6e8eb;
  --muted: #9aa1ab;
  --border: #2d323b;
  --th-bg: #262b33;
  --shadow: rgba(0, 0, 0, 0.4);
  --link: #60a5fa;
}

* {
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.4;
  margin: 0;
  padding: 0 1.5rem 1.25rem;
}

header {
  padding: 1rem 0 0.75rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.header-actions {
  display: flex;
  gap: 0.5rem;
}

h1 {
  font-size: 1.4rem;
  margin: 0;
}

h1 a {
  color: inherit;
  text-decoration: none;
}

h2 {
  font-size: 1.15rem;
  margin: 0 0 0.2rem;
}

a {
  color: var(--link);
}

.breadcrumb {
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
}

.breadcrumb a {
  text-decoration: none;
}

.system-description {
  color: var(--muted);
  margin: 0 0 0.3rem;
  font-size: 0.9rem;
}

.page-hint {
  color: var(--muted);
  margin: 1.5rem 0 0;
  font-size: 0.75rem;
  text-align: center;
}

.system-email {
  color: var(--muted);
  margin: 0 0 0.6rem;
  font-size: 0.85rem;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}

.icon-button {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.3rem 0.7rem;
  font-size: 0.95rem;
  cursor: pointer;
}

.hamburger-button {
  display: inline-block;
}

.mobile-menu {
  display: none;
}

.mobile-menu.open {
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 3.5rem;
  right: 1.5rem;
  min-width: 12rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 4px 16px var(--shadow);
  z-index: 1000;
  overflow: hidden;
}

:root[data-nav-side="left"] .mobile-menu.open {
  right: auto;
  left: 1.5rem;
}

.mobile-menu form {
  display: contents;
}

.mobile-menu button,
.mobile-menu a {
  display: flex;
  align-items: center;
  font: inherit;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  text-decoration: none;
  padding: 0.7rem 1rem;
  cursor: pointer;
  transition: background-color 0.1s ease;
}

.menu-icon {
  display: inline-block;
  min-width: 1.5rem;
  margin-right: 0.5rem;
  text-align: center;
}

.mobile-menu button:hover,
.mobile-menu a:hover {
  background: var(--th-bg);
}

.mobile-menu .menu-divider {
  border-top: 1px solid var(--border);
}

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

table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  box-shadow: 0 1px 3px var(--shadow);
}

th, td {
  text-align: left;
  padding: 0.4rem 0.7rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

th {
  background: var(--th-bg);
  font-weight: 600;
}

tr:last-child td {
  border-bottom: none;
}

.raw-content {
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.85rem;
  margin: 0;
}

/* CCUs and RTUs are separate <table> elements but meant to read as one aligned
   grid when stacked - table-layout: auto sizes each table's columns from its own
   content, which drifts out of alignment whenever the two tables' text lengths
   differ (e.g. a short CCU name vs. longer siren names). Fixed, shared percentage
   widths keep both tables' 5 columns lined up regardless of content. */
.rtu-ccu-table {
  table-layout: fixed;
}

.rtu-ccu-table th:nth-child(1) {
  width: 15%;
}

.rtu-ccu-table th:nth-child(2) {
  width: 7%;
}

.rtu-ccu-table th:nth-child(3) {
  width: 22%;
}

.rtu-ccu-table th:nth-child(4) {
  width: 20%;
}

.rtu-ccu-table th:nth-child(5) {
  width: 36%;
}

.badge {
  display: inline-block;
  padding: 0.15rem 0.6rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: capitalize;
  color: #fff;
  margin-right: 0.3rem;
}

.badge:last-child {
  margin-right: 0;
}

.badge-operational {
  background: #1a7f37;
}

.badge-dead {
  background: #6b7280;
  color: #f3f4f6;
  cursor: help;
}

.badge-warning {
  background: #d69e00;
  color: #1a1a1a;
  cursor: help;
}

.badge-ok {
  background: #1a7f37;
}

.badge-supervisory {
  background: #d69e00;
  color: #1a1a1a;
  cursor: help;
}

.badge-alarm {
  background: #8a1f1f;
  cursor: help;
}

.tooltip {
  cursor: help;
}

.tooltip::after {
  content: attr(data-tooltip);
  /* Fixed (viewport-relative) positioning, driven by --tooltip-x/--tooltip-y set in
     JS from the trigger's on-screen position. Unlike absolute positioning against an
     ancestor, this can't be clipped by, or add scrollable width to, a scrolling
     ancestor like .table-scroll. */
  position: fixed;
  left: var(--tooltip-x, 0px);
  top: var(--tooltip-y, 0px);
  transform: translate(-50%, -100%);
  background: var(--text);
  color: var(--bg);
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  font-size: 0.75rem;
  font-weight: 400;
  text-transform: none;
  white-space: pre-line;
  width: max-content;
  max-width: 16rem;
  box-shadow: 0 4px 16px var(--shadow);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s ease;
  z-index: 10;
}

.tooltip:hover::after,
.tooltip:focus::after {
  opacity: 1;
}

.tooltip.tooltip-flip::after {
  transform: translate(-50%, 0.5rem);
}

.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.list-cards {
  display: none;
  flex-direction: column;
  gap: 0.6rem;
}

.list-card {
  background: var(--surface);
  box-shadow: 0 1px 3px var(--shadow);
  border-radius: 8px;
  padding: 0.7rem 0.9rem;
}

.list-card-name {
  font-weight: 600;
  margin-bottom: 0.4rem;
}

.list-card-badges {
  margin-bottom: 0.5rem;
}

.list-card-row {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.list-card-row > span:last-child {
  min-width: 0;
  overflow-wrap: break-word;
  text-align: right;
}

.list-card-row:not(:last-child) {
  margin-bottom: 0.15rem;
}

.ticket-recent {
  background: #8a1f1f;
  color: #fff;
}

.ticket-stale {
  background: #6b7280;
  color: #f3f4f6;
}

.empty-state {
  color: var(--muted);
}

.pagination {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 0.7rem;
  font-size: 0.9rem;
}

.pagination a {
  text-decoration: none;
}

.pagination-status {
  color: var(--muted);
}

.edit-form {
  display: flex;
  flex-direction: column;
  max-width: 28rem;
  background: var(--surface);
  box-shadow: 0 1px 3px var(--shadow);
  padding: 0.8rem 1rem;
}

.edit-form label {
  font-size: 0.85rem;
  font-weight: 600;
  margin: 0.5rem 0 0.25rem;
}

.edit-form input,
.edit-form select,
.edit-form textarea {
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.5rem 0.6rem;
}

.edit-form input[readonly] {
  background: var(--border);
  color: var(--muted);
  cursor: default;
}

.form-actions {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-top: 0.9rem;
}

.form-actions button {
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: var(--link);
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  cursor: pointer;
}

.button-secondary {
  text-decoration: none;
}

.button-primary {
  display: inline-block;
  font-weight: 600;
  color: #fff;
  background: var(--link);
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  text-decoration: none;
}

.delete-form {
  max-width: 28rem;
  margin-top: 0.7rem;
}

.button-danger,
.form-actions .button-danger {
  font: inherit;
  font-weight: 600;
  color: #fff;
  background: #8a1f1f;
  border: none;
  border-radius: 6px;
  padding: 0.5rem 1rem;
  cursor: pointer;
}

.error {
  color: #fff;
  background: #8a1f1f;
  border-radius: 6px;
  padding: 0.5rem 0.8rem;
  font-size: 0.9rem;
  max-width: 28rem;
}

.toast {
  position: fixed;
  top: 1.5rem;
  left: 50%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem 1.8rem;
  box-shadow: 0 4px 16px var(--shadow);
  font-size: 1.15rem;
  font-weight: 600;
  opacity: 0;
  transform: translateX(-50%) translateY(-0.5rem);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 1000;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

@media (max-width: 640px) {
  .col-description {
    display: none;
  }

  .desktop-table {
    display: none;
  }

  .list-cards {
    display: flex;
  }

  #sync-button,
  #theme-toggle {
    display: none;
  }

  :root[data-nav-side="left"] .header-actions {
    order: -1;
  }

  .mobile-menu .mobile-only {
    display: block;
  }
}
