/*
 * The page is framed inside the host application, so it has to sit inside
 * whatever theme the host is wearing rather than assert one of its own. Both
 * palettes are defined here and the host says which to use -- see app.js.
 */
:root {
  color-scheme: light;
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #dfe3e8;
  --text: #1c1f23;
  --muted: #5f6b7a;
  --accent: #1867c0;
  --warn: #b25000;
  --danger: #c62828;
  --ok: #2e7d32;
  --row-hover: #f0f3f7;
  --plot-grid: #dfe3e8;
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #121212;
  --surface: #1e1e1e;
  --border: #2f2f2f;
  --text: #e6e6e6;
  --muted: #9aa4b0;
  --accent: #64b5f6;
  --warn: #ffb74d;
  --danger: #ef5350;
  --ok: #66bb6a;
  --row-hover: #262626;
  --plot-grid: #2f2f2f;
}

* { box-sizing: border-box; }

/* The `hidden` attribute is how this page shows and hides its panels, and the
   browser expresses it as `[hidden] { display: none }` in the user-agent
   stylesheet -- which any author rule setting `display` overrides, whatever its
   specificity. `.empty { display: flex }` therefore kept the "Connecting"
   message on screen underneath a table full of vessels: the attribute was being
   set correctly the whole time and had no effect. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 "Roboto", system-ui, -apple-system, "Segoe UI", sans-serif;
}

/* More room at the sides than at the top and bottom.
   The page is framed edge to edge inside the host, which has its own padding
   nowhere near it, so a table running into the frame's border reads as content
   that has been cut off. The width is capped as well: past a point the columns
   stop being a table and become a row of numbers a long way from their labels. */
.wrap {
  display: flex;
  flex-direction: column;
  height: 100vh;
  padding: 14px 24px 18px;
  gap: 12px;
  max-width: 2200px;
  margin: 0 auto;
  width: 100%;
}

@media (max-width: 700px) {
  .wrap { padding: 10px 12px 12px; }
}

.bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
}

.lamp {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: var(--muted);
  flex: none;
}
.lamp[data-state="1"] { background: var(--ok); }
.lamp[data-state="0"] { background: var(--danger); }

.title { font-weight: 600; }
.muted { color: var(--muted); }
.metric { display: flex; flex-direction: column; line-height: 1.2; }
.metric b { font-size: 16px; font-weight: 600; }
.metric span { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.grow { flex: 1; }

input[type="search"] {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 10px;
  font: inherit;
  /* It takes a share of the bar's slack rather than sitting at a fixed width.
     The placeholder names all three things the field matches, and at 220px that
     sentence was cut off -- which made it look like a search over names only.
     The floor keeps it usable when the bar wraps on a narrow window, and the
     ceiling stops a wide one from handing half the header to a search box. */
  flex: 1 1 340px;
  min-width: 220px;
  max-width: 460px;
}

/* The plan view is the thing worth looking at, and the table was taking the room
   to say it. The side column is sized so the plot is a real instrument rather
   than a thumbnail, and grows with the window; the table keeps what is left,
   which is still more than its nine columns need. */
.body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(380px, 34%);
  gap: 12px;
  flex: 1;
  min-height: 0;
}

.side {
  display: grid;
  /* The plot takes its height from its own width (it is square), so the detail
     panel gets whatever is left rather than the plot being squeezed. */
  grid-template-rows: auto minmax(120px, 1fr);
  gap: 12px;
  min-height: 0;
}

@media (max-width: 1100px) {
  .body { grid-template-columns: minmax(0, 1fr); }
  .side { display: none; }
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.scroll { overflow: auto; min-height: 0; }

table { width: 100%; border-collapse: collapse; }

/* Numbers need only their own width; the vessel name takes the slack, and the
   table stops sprawling once the plan view has its share of the window. */
th:not(.left), td:not(.left) { width: 1%; white-space: nowrap; }
th.left:first-child, td.left:first-child { width: auto; }

th {
  position: sticky;
  top: 0;
  background: var(--surface);
  text-align: right;
  font-size: 11px;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--muted);
  font-weight: 600;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th.left, td.left { text-align: left; }

td {
  text-align: right;
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}

tbody tr:hover { background: var(--row-hover); }
tbody tr[data-own="true"] td { color: var(--accent); }
tbody tr.close td.cpa, tbody tr.close td.tcpa { color: var(--danger); font-weight: 600; }

.vessel { display: flex; align-items: center; gap: 8px; }
.vessel small { display: block; color: var(--muted); font-size: 11px; }
.mark { width: 18px; text-align: center; flex: none; }

.tag {
  display: inline-block;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 5px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
.tag.warn { color: var(--warn); border-color: var(--warn); }

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  flex: 1;
  padding: 40px 20px;
  text-align: center;
  color: var(--muted);
}
.empty h2 { color: var(--text); font-size: 17px; margin: 0; font-weight: 600; }
.empty p { margin: 0; max-width: 46ch; }

.plot-panel { padding: 12px 12px 8px; }
.plot-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
svg { width: 100%; height: auto; display: block; }

/* ~ Selection.
   The table and the plan view are two views of one list, so picking a contact in
   either has to show in both -- otherwise they read as separate screens that
   happen to sit side by side. */
tbody tr { cursor: pointer; }
tbody tr.selected td { background: color-mix(in srgb, var(--accent) 14%, transparent); }
tbody tr.selected td:first-child { box-shadow: inset 3px 0 0 var(--accent); }

.detail-panel { padding: 0; }

.detail-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
}
.detail-head span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.detail-head button {
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  font-size: 10px;
  padding: 1px 6px;
  text-transform: uppercase;
}
.detail-head button:hover { color: var(--text); border-color: var(--muted); }

.detail-body { padding: 10px 14px 14px; }
.detail-hint { margin: 0; font-size: 12px; }

.detail-group {
  margin: 0 0 4px;
  padding-top: 8px;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted);
  border-top: 1px solid var(--border);
}
.detail-group:first-child { border-top: none; padding-top: 0; }

.detail-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 2px 0;
  font-size: 12.5px;
}
.detail-row dt { color: var(--muted); flex: none; }
.detail-row dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
dl { margin: 0; }
