/* Three-region layout: header, then left rail | main | right rail.
   Rails scroll independently on desktop; everything stacks on narrow viewports. */

body {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  overflow: hidden;
}

/* Header */
.topbar {
  display: flex;
  align-items: center;
  gap: var(--s-4);
  min-height: var(--header-h);
  padding: var(--s-2) var(--s-4);
  border-bottom: 1px solid var(--line);
  background: var(--bg-1);
  flex-wrap: wrap;
}
.brand { display: flex; flex-direction: column; min-width: 0; }
.brand-name { font-size: var(--fs-4); font-weight: 700; letter-spacing: 0.02em; }
.brand-sub { font-size: var(--fs-1); color: var(--text-muted); }

.readouts {
  display: flex;
  gap: var(--s-5);
  margin-left: var(--s-3);
  flex-wrap: wrap;
}
.readouts > div { display: flex; flex-direction: column; min-width: 64px; }
.readouts dt { font-size: var(--fs-1); color: var(--text-muted); white-space: nowrap; }
.readouts dd { font-size: var(--fs-5); line-height: 1.2; white-space: nowrap; }
.readouts dd .unit { font-family: var(--sans); font-size: var(--fs-1); color: var(--text-muted); margin-left: 2px; }

.sim-controls {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  margin-left: auto;
  flex-wrap: wrap;
}
.sim-controls .field { display: flex; align-items: center; gap: var(--s-1); font-size: var(--fs-1); color: var(--text-muted); }
.sim-controls .field .input { width: 76px; }
.sim-controls .divider { width: 1px; height: 22px; background: var(--line-strong); margin: 0 var(--s-1); }

/* Workspace */
.workspace {
  display: grid;
  grid-template-columns: var(--rail-left) minmax(0, 1fr) var(--rail-right);
  min-height: 0;
  overflow: hidden;
}

.rail {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-1);
  overflow: hidden;
}
.rail-left { border-right: 1px solid var(--line); }
.rail-right { border-left: 1px solid var(--line); }

.rail-head {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--line);
  min-height: 42px;
  flex-wrap: wrap;
}
.rail-head h2 { margin-right: auto; }
.rail-body { flex: 1; min-height: 0; overflow-y: auto; }

.main-area {
  min-width: 0;
  min-height: 0;
  overflow-y: auto;
  padding: var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-4);
}

.detail-head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  flex-wrap: wrap;
}
.detail-head h2 { font-size: var(--fs-5); font-weight: 600; }
.detail-head .actions { margin-left: auto; display: flex; gap: var(--s-2); }

/* Panels use a 1px border to separate data from chrome, not shadows. */
.panel {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--bg-1);
}
.panel-head {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: var(--s-2) var(--s-3);
  border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.panel-head h3 { margin-right: auto; }
.panel-body { padding: var(--s-3); }

/* Overlays */
.overlay-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 12, 0.6);
  z-index: 40;
}

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(440px, 100vw);
  background: var(--bg-1);
  border-left: 1px solid var(--line-strong);
  z-index: 50;
  display: flex;
  flex-direction: column;
  transform: translateX(0);
  transition: transform var(--t-drawer) ease-out;
}
.drawer.is-entering { transform: translateX(100%); }
.drawer-head, .modal-head {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: var(--s-3) var(--s-4);
  border-bottom: 1px solid var(--line);
}
.drawer-head h2, .modal-head h2 { margin-right: auto; font-size: var(--fs-4); }
.drawer-body, .modal-body { flex: 1; min-height: 0; overflow-y: auto; padding: var(--s-4); }
.drawer-foot, .modal-foot {
  display: flex;
  gap: var(--s-2);
  justify-content: flex-end;
  padding: var(--s-3) var(--s-4);
  border-top: 1px solid var(--line);
}

.modal {
  position: fixed;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  width: min(720px, calc(100vw - 2 * var(--s-4)));
  max-height: calc(100vh - 2 * var(--s-4));
  background: var(--bg-1);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  z-index: 60;
  display: flex;
  flex-direction: column;
}
.modal--sm { width: min(440px, calc(100vw - 2 * var(--s-4))); z-index: 70; }
.overlay-backdrop.z-top { z-index: 65; }

/* Toasts */
.toasts {
  position: fixed;
  right: var(--s-4);
  bottom: var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-2);
  z-index: 80;
  max-width: min(420px, calc(100vw - 2 * var(--s-4)));
}

/* Tablet: feed drops below the main area. */
@media (max-width: 1199px) {
  :root { --rail-left: 240px; }
  .workspace {
    grid-template-columns: var(--rail-left) minmax(0, 1fr);
    grid-template-rows: minmax(0, 1fr) 260px;
  }
  .rail-left { grid-row: 1 / 3; }
  .rail-right {
    grid-column: 2;
    grid-row: 2;
    border-left: 0;
    border-top: 1px solid var(--line);
  }
}

/* Phone: single column, page scrolls, machine list becomes a horizontal strip. */
@media (max-width: 767px) {
  body { height: auto; overflow: auto; display: block; }
  /* Not sticky on phones: the header would take a third of the viewport. */
  .topbar { position: static; }
  .readouts { gap: var(--s-3); }
  .readouts dd { font-size: var(--fs-4); }
  .sim-controls { margin-left: 0; width: 100%; }
  .workspace {
    display: flex;
    flex-direction: column;
    overflow: visible;
  }
  .rail { overflow: visible; }
  .rail-left { border-right: 0; border-bottom: 1px solid var(--line); }
  .rail-left .rail-body { overflow-x: auto; overflow-y: hidden; }
  .rail-right { border-left: 0; border-top: 1px solid var(--line); }
  .rail-right .rail-body { max-height: 320px; overflow-y: auto; }
  .main-area { overflow: visible; padding: var(--s-3); }
  .drawer { width: 100vw; }
}
