* {
  box-sizing: border-box;
}

body {
  font-family: Segoe UI, Arial, sans-serif;
  margin: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

#app-header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.5rem 1rem;
  background: #1565c0;
  color: white;
}

#app-header h1 {
  font-size: 1.1rem;
  margin: 0;
  flex: 1;
}

#hamburger-button {
  font-size: 1.25rem;
  background: none;
  border: none;
  color: white;
  cursor: pointer;
}

#connection-status,
#idle-status {
  font-size: 0.85rem;
  opacity: 0.85;
}

/* Invisible wrapper by default -- its children lay out as direct flex items of #app-header, exactly as if
   this div didn't exist. Only mobile turns it into an actual flex column (see below). */
#header-status {
  display: contents;
}

#app-layout {
  flex: 1;
  display: grid;
  grid-template-columns: 260px 5px 1fr 5px 320px;
  min-height: 0;
}

#resource-tree,
#resource-grid,
#resource-detail {
  overflow: auto;
  padding: 0.5rem;
}

#resource-tree {
  border-right: 1px solid #ddd;
  white-space: nowrap;
}

#resource-detail {
  border-left: 1px solid #ddd;
}

.pane-resizer {
  cursor: col-resize;
  background: #ddd;
  /* Without this, a touch-drag on the divider can be captured by the browser as a page scroll/zoom gesture
     instead of reaching pane-resizer.js's pointermove handler. */
  touch-action: none;
}

.pane-resizer:hover,
.pane-resizer.dragging {
  background: #90caf9;
}

.tree-children {
  list-style: none;
  margin: 0;
  padding-left: 1rem;
}

.tree-node {
  cursor: pointer;
  padding: 0.1rem 0;
}

.tree-toggle {
  display: inline-block;
  width: 1rem;
  cursor: pointer;
  user-select: none;
}

.tree-label.selected,
.tree-node.selected > .tree-label {
  font-weight: bold;
  background: #e3f2fd;
}

.resource-icon {
  vertical-align: middle;
  margin-right: 0.25rem;
}

/* Toggled by the hamburger menu's "Show tree icons" checkbox -- pure CSS so it doesn't require re-rendering
   the tree. Grid icons are always shown (no toggle requested for those). Targets .resource-tile too (see
   resource-tile.js) so the whole composite tile -- not just its base icon -- disappears together. */
#resource-tree.hide-icons .resource-icon,
#resource-tree.hide-icons .resource-tile {
  display: none;
}

/* resource-tile.js's composite icon: a base type icon with a top-left "connected" checkmark and a bottom-right
   status overlay, mirroring the desktop GUI's tree (see MainWindow.xaml's LargeXxxTreeItem templates). */
.resource-tile {
  position: relative;
  display: inline-block;
  vertical-align: middle;
  margin-right: 0.35rem;
  flex-shrink: 0;
}

.resource-tile .tile-base-icon {
  display: block;
  margin-right: 0;
}

.resource-tile .tile-connected-overlay {
  position: absolute;
  top: -2px;
  left: -4px;
  height: auto;
}

.resource-tile .tile-status-overlay {
  position: absolute;
  right: -4px;
  bottom: -1px;
  margin-right: 0;
}

.status-icon {
  vertical-align: middle;
  margin-right: 0.35rem;
}

/* Starting/Stopping bake a small horizontal nudge into their own rotation keyframes -- rather than a plain
   rotate(), which left them looking off-center against the static Running/Stopped icons next to them. */
@keyframes status-icon-spin-starting {
  from {
    transform: translateX(1px) rotate(0deg);
  }
  to {
    transform: translateX(1px) rotate(360deg);
  }
}

@keyframes status-icon-spin-stopping {
  from {
    transform: translateX(1px) rotate(0deg);
  }
  to {
    transform: translateX(1px) rotate(360deg);
  }
}

.status-icon-spin-starting {
  animation: status-icon-spin-starting 4.5s linear infinite;
}

.status-icon-spin-stopping {
  animation: status-icon-spin-stopping 4.5s linear infinite;
}

.tree-error,
.grid-error,
.detail-error {
  color: #b00020;
}

.service-status {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.service-status.service-checking {
  color: #666;
  font-style: italic;
}

.service-status.service-available {
  color: #1a7f37;
  font-weight: bold;
}

.grid-toolbar {
  padding: 0.3rem 0.5rem;
  font-size: 0.9rem;
}

.grid-toolbar label {
  cursor: pointer;
}

/* table-layout: fixed makes the column widths below authoritative regardless of content or zoom level -- with
   the browser's default "auto" table layout, column widths are re-guessed from content on every render, which
   is exactly why this previously needed a maximized window at a specific zoom level to avoid the Status
   column (icon + text) wrapping onto two lines and making that row taller than its neighbors. */
#resource-grid table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
}

#resource-grid th,
#resource-grid td {
  text-align: left;
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid #eee;
  font-size: 0.9rem;
}

/* Data cells never wrap -- a long value truncates with an ellipsis instead, so no single row can end up
   taller than the rest. Headers are left free to wrap (a two-line "Scheduled Stop" header is harmless, unlike
   a wrapped Status cell repeated down every row). */
#resource-grid td {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Column order: icon, name, status, description, users, scheduled stop, connected. Name is narrower and
   Status wider than their old auto-sized widths -- the icon+text Status cell was the one that actually
   wrapped in practice. */
#resource-grid th:nth-child(1),
#resource-grid td:nth-child(1) {
  width: 3%;
}

/* The icon column has no text to truncate -- undo the ellipsis rule above so a too-narrow cell just clips
   instead of drawing "..." over the icon. */
#resource-grid td:nth-child(1) {
  overflow: visible;
  text-overflow: clip;
}

#resource-grid th:nth-child(2),
#resource-grid td:nth-child(2) {
  width: 15%;
}

#resource-grid th:nth-child(3),
#resource-grid td:nth-child(3) {
  width: 12%;
}

/* Anchors the status-filter-panel dropdown below the Status header instead of below the whole table. */
.status-filter-header {
  position: relative;
}

.status-filter-trigger {
  cursor: pointer;
  user-select: none;
}

.status-filter-panel {
  position: absolute;
  top: 100%;
  left: 0;
  background: white;
  color: #222;
  border: 1px solid #ccc;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  padding: 0.4rem 0.6rem;
  z-index: 1100;
  font-weight: normal;
  white-space: nowrap;
}

.status-filter-panel label {
  display: block;
  padding: 0.25rem 0;
  cursor: pointer;
}

#resource-grid th:nth-child(4),
#resource-grid td:nth-child(4) {
  width: 40%;
}

#resource-grid th:nth-child(5),
#resource-grid td:nth-child(5) {
  width: 8%;
}

#resource-grid th:nth-child(6),
#resource-grid td:nth-child(6) {
  width: 14%;
}

#resource-grid th:nth-child(7),
#resource-grid td:nth-child(7) {
  width: 8%;
}

#resource-grid tbody tr:hover {
  background: #f5f5f5;
  cursor: pointer;
}

#resource-grid tbody tr.selected {
  background: #e3f2fd;
}

.detail-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.detail-header h2 {
  margin: 0;
}

/* .detail-pane (not #resource-detail) so the same rules apply to both the desktop detail aside and
   MobileNav's own detail screen -- both wrap ResourceDetail.buildContent()'s output in this class. */
.detail-pane dl {
  margin: 0;
}

.detail-pane dt {
  font-weight: bold;
  margin-top: 0.5rem;
}

.detail-pane dd {
  margin: 0 0 0.25rem 0;
}

.detail-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin: 0.75rem 0;
}

.detail-actions button {
  padding: 0.3rem 0.6rem;
  cursor: pointer;
}

.detail-actions button:disabled {
  cursor: default;
  opacity: 0.75;
}

.modal-box label {
  display: block;
  font-weight: bold;
  margin-top: 0.75rem;
}

/* Wraps a number input with explicit step buttons -- see number-stepper.js. */
.number-stepper {
  display: flex;
  align-items: stretch;
  gap: 0.25rem;
  margin-top: 0.25rem;
}

.number-stepper input {
  flex: 1 1 auto;
  width: auto;
  margin-top: 0;
  text-align: center;
}

.number-stepper button {
  flex: 0 0 auto;
  width: 2.25rem;
  font-size: 1.1rem;
  cursor: pointer;
}

.modal-box textarea,
.modal-box input {
  width: 100%;
  box-sizing: border-box;
  margin-top: 0.25rem;
}

.modal-box dl {
  display: grid;
  grid-template-columns: max-content 1fr;
  column-gap: 0.75rem;
  row-gap: 0.35rem;
  margin: 0.75rem 0;
  align-items: baseline;
}

.modal-box dt {
  font-weight: bold;
  white-space: nowrap;
}

.modal-box dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.modal-actions {
  margin-top: 1rem;
  display: flex;
  gap: 0.5rem;
}

.modal-note {
  font-size: 0.85rem;
  color: #666;
  font-weight: normal;
}

.context-menu {
  position: absolute;
  list-style: none;
  margin: 0;
  padding: 0.25rem 0;
  background: white;
  border: 1px solid #ccc;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  z-index: 1100;
  min-width: 10rem;
}

.context-menu li {
  padding: 0.4rem 1rem;
  cursor: pointer;
}

.context-menu li:hover {
  background: #e3f2fd;
}

.context-menu li.disabled {
  color: #999;
  cursor: default;
}

.context-menu li.disabled:hover {
  background: none;
}

#hamburger-panel {
  position: absolute;
  top: 100%;
  left: 0;
  background: white;
  color: #222;
  border: 1px solid #ccc;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  min-width: 12rem;
  z-index: 1100;
}

#hamburger-panel button {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.6rem 1rem;
  background: none;
  border: none;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  font-size: 0.95rem;
}

#hamburger-panel button:last-child {
  border-bottom: none;
}

#hamburger-panel button:hover {
  background: #f0f0f0;
}

.hamburger-section-label {
  padding: 0.6rem 1rem 0.2rem;
  font-size: 0.75rem;
  font-weight: bold;
  color: #888;
  text-transform: uppercase;
}

/* No divider between the "View" section's two options -- they read as one group, not two separate items.
   Needs the #hamburger-panel prefix to out-specificity the #hamburger-panel button rule above it. */
#hamburger-panel #hamburger-view-all {
  border-bottom: none;
}

.hamburger-checkbox-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid #eee;
  font-size: 0.95rem;
  cursor: pointer;
}

.hamburger-checkbox-item:hover {
  background: #f0f0f0;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal-box {
  background: white;
  border-radius: 4px;
  padding: 1.5rem 2rem;
  max-width: 24rem;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
}

/* For modals whose content doesn't fit the default width comfortably -- e.g. the Users table's 3 columns. */
.modal-box-wide {
  max-width: 34rem;
}

#users-table {
  width: 100%;
  border-collapse: collapse;
  margin: 0.75rem 0;
}

#users-table th,
#users-table td {
  text-align: left;
  padding: 0.3rem 0.5rem;
  border-bottom: 1px solid #eee;
  font-size: 0.9rem;
}

.modal-box h2 {
  margin-top: 0;
}

/* Lets Dialogs.alert/confirm messages use "\n\n" for a blank line (e.g. server-messages.js's "From X at
   Y:\n\n<text>") instead of the newline just collapsing away like normal HTML whitespace. */
#dialogs-message {
  white-space: pre-line;
}

/* Layout switching -- see index.html's inline head script (sets html.mobile-layout/html.desktop-layout before
   app.css is even requested, so there's no flash of the wrong layout) and hamburger-menu.js's switch buttons. */
html.desktop-layout .mobile-only {
  display: none !important;
}

html.mobile-layout .desktop-only {
  display: none !important;
}

#mobile-app {
  display: none;
}

html.mobile-layout #app-layout {
  display: none;
}

html.mobile-layout #mobile-app {
  display: block;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

/* Tight header on phone screens -- there's no room for the full title next to both status spans. */
html.mobile-layout #app-header h1 {
  font-size: 0.95rem;
}

html.mobile-layout #idle-status,
html.mobile-layout #connection-status {
  font-size: 0.75rem;
}

/* Right-flush stack instead of a wide inline row -- "Connected" on top, "Next auto-disconnect: ..." below it,
   both hugging the right edge next to the hamburger/title. The explicit order overrides #idle-status coming
   first in the markup (it needs to precede #connection-status there for the desktop row's reading order). */
html.mobile-layout #header-status {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  line-height: 1.2;
}

html.mobile-layout #connection-status {
  order: 1;
}

html.mobile-layout #idle-status {
  order: 2;
}

.mobile-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  border-bottom: 1px solid #ddd;
  position: sticky;
  top: 0;
  background: white;
  /* Without an explicit z-index, this sticky header shares the same implicit paint layer as the resource
     tiles' absolutely-positioned status/connected overlays (resource-tile.js) -- since a row further down the
     list comes later in the DOM, its overlay would otherwise paint on top of the header once scrolling makes
     them visually overlap. */
  z-index: 2;
}

.mobile-header h2 {
  margin: 0;
  font-size: 1rem;
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mobile-back-button {
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  flex-shrink: 0;
}

.mobile-list {
  display: flex;
  flex-direction: column;
}

.mobile-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.75rem;
  border-bottom: 1px solid #eee;
  cursor: pointer;
  min-height: 2.75rem;
}

.mobile-row:active {
  background: #f0f0f0;
}

.mobile-row-label {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.mobile-row-chevron {
  color: #999;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.mobile-error {
  color: #b00020;
  padding: 0.75rem;
}

.mobile-empty {
  color: #666;
  padding: 0.75rem;
}

/* MobileNav's detail screen reuses .detail-pane/.detail-header/.detail-actions verbatim (see mobile-nav.js),
   just wrapped in its own scrollable full-width container instead of the desktop's narrow side aside. */
#mobile-app .detail-pane {
  padding: 0.75rem;
}
