/* Network page. Builds on style.css tokens (dark theme only, like the rest of ATerminal). */

:root {
  --series-down: #3987e5; /* dataviz categorical slot 1, validated on --surface */
  --series-up: #d95926;   /* slot 2 */
  --grid: #3d2f26;
  --status-good: var(--accent-green);
  --status-warn: var(--accent-orange);
  --status-bad: var(--accent-red);
}

.net-app { height: 100%; display: flex; flex-direction: column; }
.net-subtitle { font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.net-live { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); white-space: nowrap; }
.net-live.ok .status-dot { background: var(--accent-green); box-shadow: 0 0 6px var(--accent-green); }
.net-live.error .status-dot { background: var(--accent-red); }

/* Tabs */
.net-tabs {
  display: flex; gap: 4px; padding: 8px 12px; overflow-x: auto; flex-shrink: 0;
  background: var(--surface); border-bottom: 1px solid var(--border);
  scrollbar-width: none;
}
.net-tabs::-webkit-scrollbar { display: none; }
.net-tabs [role="tab"] {
  background: none; border: 1px solid transparent; color: var(--text-muted);
  padding: 7px 14px; border-radius: 999px; font-size: 13px; font-weight: 600;
  cursor: pointer; white-space: nowrap; -webkit-tap-highlight-color: transparent;
}
.net-tabs [role="tab"]:hover { color: var(--text); }
.net-tabs [role="tab"][aria-selected="true"] { background: var(--sent-bg); color: var(--accent); border-color: rgba(255, 157, 92, 0.35); }
.net-tab-count { font-weight: 500; opacity: 0.75; }

.net-main { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior-y: contain; }
.net-inner { max-width: 1080px; margin: 0 auto; padding: 16px 16px 40px; display: flex; flex-direction: column; gap: 14px; }
.net-panel { display: flex; flex-direction: column; gap: 14px; }
.net-panel[hidden] { display: none; }

/* Cards */
.net-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; display: flex; flex-direction: column; gap: 10px; min-width: 0;
}
.net-card h2 { font-size: 15px; font-weight: 700; }
.net-card-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.net-card-accent { border-color: rgba(79, 184, 120, 0.45); }
.net-card p { line-height: 1.5; }
.net-muted { color: var(--text-muted); font-size: 13px; line-height: 1.45; }
.net-empty { color: var(--text-muted); font-size: 13px; padding: 8px 0; }
.net-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }

/* Stat tiles */
.net-tiles { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.net-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; min-width: 0; }
.net-tile-label { font-size: 12px; color: var(--text-muted); }
.net-tile-value { font-size: 22px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.net-tile-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Banner / callout */
.net-banner {
  background: rgba(239, 83, 80, 0.12); border: 1px solid rgba(239, 83, 80, 0.4); color: var(--text);
  border-radius: var(--radius-sm); padding: 10px 14px; font-size: 13px; line-height: 1.45;
}
.net-callout {
  background: rgba(226, 166, 64, 0.1); border: 1px solid rgba(226, 166, 64, 0.4);
  border-radius: var(--radius); padding: 12px 14px; font-size: 13px; line-height: 1.5;
}
.net-callout strong { color: var(--accent-orange); }

/* Chart */
.net-legend { display: flex; gap: 18px; flex-wrap: wrap; font-size: 13px; color: var(--text-muted); }
.net-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.net-legend-item strong { color: var(--text); font-variant-numeric: tabular-nums; font-size: 15px; }
.net-key { display: inline-block; width: 14px; height: 2px; border-radius: 1px; }
.net-key-down { background: var(--series-down); }
.net-key-up { background: var(--series-up); }
.net-chart { position: relative; width: 100%; outline: none; touch-action: pan-y; }
.net-chart:focus-visible { box-shadow: 0 0 0 2px var(--accent); border-radius: var(--radius-sm); }
.net-chart svg { display: block; width: 100%; }
.net-chart .axis-text { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.net-chart .end-label { fill: var(--text); font-size: 12px; }
.net-chart-tip {
  position: absolute; top: 4px; pointer-events: none; z-index: 2;
  background: var(--surface2); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 10px; font-size: 12px; min-width: 132px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
}
.net-chart-tip .tip-time { color: var(--text-muted); margin-bottom: 4px; }
.net-chart-tip .tip-row { display: flex; align-items: center; gap: 6px; }
.net-chart-tip .tip-row strong { font-variant-numeric: tabular-nums; }
.net-chart-tip .tip-row span:last-child { color: var(--text-muted); }

.net-table-wrap { max-height: 260px; overflow: auto; }
.net-table { width: 100%; border-collapse: collapse; font-size: 13px; font-variant-numeric: tabular-nums; }
.net-table th, .net-table td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.net-table th:first-child, .net-table td:first-child { text-align: left; }
.net-table th { color: var(--text-muted); font-weight: 600; position: sticky; top: 0; background: var(--surface); }

/* Ranked list (busiest) */
.net-rank { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.net-rank li { display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; align-items: baseline; }
.net-rank .rank-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.net-rank .rank-speed { font-variant-numeric: tabular-nums; font-size: 13px; text-align: right; }
.net-rank .rank-bar { grid-column: 1 / -1; height: 4px; border-radius: 2px; background: var(--surface2); overflow: hidden; }
.net-rank .rank-bar span { display: block; height: 100%; border-radius: 2px; background: var(--text-muted); }

/* Notices */
.net-notices { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.net-notice { display: grid; grid-template-columns: 22px 1fr; gap: 8px; font-size: 13px; line-height: 1.45; }
.net-notice-icon { font-weight: 700; text-align: center; }
.net-notice.good .net-notice-icon { color: var(--status-good); }
.net-notice.warn .net-notice-icon { color: var(--status-warn); }
.net-notice.bad .net-notice-icon { color: var(--status-bad); }
.net-notice .net-notice-title { font-weight: 600; }
.net-link { background: none; border: none; color: var(--accent); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

/* Facts */
.net-facts { display: grid; grid-template-columns: max-content 1fr; gap: 8px 18px; font-size: 13px; }
.net-facts dt { color: var(--text-muted); }
.net-facts dd { min-width: 0; overflow-wrap: anywhere; }

/* Devices */
.net-filter { max-width: 240px; }
.net-devices { list-style: none; display: flex; flex-direction: column; }
.net-device { border-top: 1px solid var(--border); padding: 12px 0; display: grid; grid-template-columns: 36px 1fr auto; gap: 4px 12px; align-items: center; }
.net-device:first-child { border-top: none; }
.net-device-icon {
  width: 36px; height: 36px; border-radius: 10px; background: var(--surface2);
  display: flex; align-items: center; justify-content: center; color: var(--text-muted);
}
.net-device-icon svg { width: 18px; height: 18px; }
.net-device-main { min-width: 0; }
.net-device-name { font-weight: 600; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; overflow-wrap: anywhere; }
.net-device-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; }
.net-device-speed { text-align: right; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; }
.net-device-speed .usage { font-size: 12px; color: var(--text-muted); }
.net-device-actions { grid-column: 2 / -1; display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.net-device-details { grid-column: 2 / -1; font-size: 12px; color: var(--text-muted); display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin-top: 4px; }
.net-tag { font-size: 11px; font-weight: 600; padding: 2px 7px; border-radius: 999px; background: var(--surface2); color: var(--text-muted); }
.net-tag.self { background: rgba(255, 157, 92, 0.16); color: var(--accent); }
.btn-block { color: var(--accent-red); border-color: rgba(239, 83, 80, 0.4); }

/* Generic rows */
.net-rows { list-style: none; display: flex; flex-direction: column; }
.net-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); }
.net-row:first-child { border-top: none; }
.net-row-main { min-width: 0; }
.net-row-title { font-weight: 600; overflow-wrap: anywhere; }
.net-row-sub { font-size: 12px; color: var(--text-muted); margin-top: 2px; overflow-wrap: anywhere; }
.net-pill { font-size: 12px; font-weight: 600; padding: 3px 10px; border-radius: 999px; background: var(--surface2); color: var(--text-muted); white-space: nowrap; }
.net-pill.on { color: var(--status-good); }
.net-pill.off { color: var(--text-muted); }

/* Forms */
.net-input {
  background: var(--bg); color: var(--text); border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 8px 10px; font: inherit; font-size: 14px; width: 100%; min-width: 0;
}
.net-input:focus { outline: none; border-color: var(--accent); }
.net-form { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px 12px; padding: 12px; background: var(--bg); border-radius: var(--radius-sm); border: 1px solid var(--border); }
.net-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--text-muted); min-width: 0; }
.net-form-actions { grid-column: 1 / -1; display: flex; align-items: center; justify-content: flex-end; gap: 8px; }
.net-form-error { flex: 1; color: var(--accent-red); font-size: 13px; }

/* Assistant */
.net-chips { display: flex; gap: 8px; flex-wrap: wrap; }
.net-chip {
  background: var(--surface2); color: var(--text); border: 1px solid var(--border); border-radius: 999px;
  padding: 7px 12px; font-size: 13px; cursor: pointer; -webkit-tap-highlight-color: transparent;
}
.net-chip:hover { border-color: var(--accent); }
.net-ai-log { display: flex; flex-direction: column; gap: 12px; }
.net-ai-log:empty { display: none; }
.net-msg { max-width: 92%; padding: 10px 14px; border-radius: var(--bubble-radius); line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.net-msg.user { align-self: flex-end; background: var(--sent-bg); }
.net-msg.ai { align-self: flex-start; background: var(--surface2); }
.net-msg.pending { color: var(--text-muted); display: inline-flex; align-items: center; gap: 8px; }
.net-msg.error { color: var(--accent-red); }
.net-spinner { width: 12px; height: 12px; border-radius: 50%; border: 2px solid var(--border); border-top-color: var(--accent); animation: net-spin 0.8s linear infinite; }
@keyframes net-spin { to { transform: rotate(360deg); } }
.net-action {
  align-self: flex-start; width: min(100%, 520px); border: 1px solid rgba(255, 157, 92, 0.4);
  background: var(--bg); border-radius: var(--radius); padding: 12px 14px; display: flex; flex-direction: column; gap: 8px;
}
.net-action-label { font-weight: 700; }
.net-action-reason { font-size: 13px; color: var(--text-muted); line-height: 1.45; }
.net-action-buttons { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.net-action-status { font-size: 13px; color: var(--text-muted); }
.net-action-status.done { color: var(--status-good); }
.net-action-status.failed { color: var(--status-bad); }
.net-ai-form { display: flex; gap: 8px; align-items: flex-end; }
.net-ai-form textarea { resize: none; max-height: 140px; line-height: 1.4; }

/* Dialog + toast */
.net-dialog {
  margin: auto; border: 1px solid var(--border); border-radius: var(--radius-lg); background: var(--surface);
  color: var(--text); padding: 20px; width: min(440px, calc(100vw - 32px));
}
.net-dialog::backdrop { background: rgba(0, 0, 0, 0.55); }
.net-dialog h2 { font-size: 17px; margin-bottom: 10px; }
.net-dialog-body { font-size: 14px; line-height: 1.5; color: var(--text); display: flex; flex-direction: column; gap: 8px; }
.net-dialog-body .net-muted { font-size: 13px; }
.net-dialog .error-msg { margin: 12px 0 0; }
.net-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.net-toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--surface2); border: 1px solid var(--border); border-radius: 999px;
  padding: 10px 18px; font-size: 13px; box-shadow: 0 6px 18px rgba(0, 0, 0, 0.4); max-width: calc(100vw - 32px);
}

/* Wi-Fi networks */
.net-wifi-row { flex-wrap: wrap; }
.net-wifi-secrets { flex-basis: 100%; display: flex; flex-direction: column; align-items: flex-start; gap: 8px; margin-top: 4px; }
.net-wifi-secret { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.net-secret {
  font-family: 'Cascadia Code', Consolas, monospace; font-size: 14px; user-select: all; overflow-wrap: anywhere;
  background: var(--bg); border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px;
}
.net-qr { width: 180px; height: 180px; border-radius: 8px; background: #fff; }

/* Watched devices */
.net-watch-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 340px), 1fr)); gap: 12px; }
.net-watch { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 12px; display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.net-watch-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.net-watch-titles { min-width: 0; }
.net-watch-name { font-weight: 700; overflow-wrap: anywhere; }
.btn.active { color: var(--accent); border-color: rgba(255, 157, 92, 0.45); }

/* Live map */
.net-map-legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-muted); }
.net-map-legend > span { display: inline-flex; align-items: center; gap: 6px; }
.net-key-wired { background: var(--text-muted); }
.net-key-wifi { background: repeating-linear-gradient(90deg, var(--text-muted) 0 4px, transparent 4px 7px); }
.net-map { width: 100%; }
.map-svg { display: block; width: 100%; overflow: visible; }
.map-link { stroke: var(--text-muted); stroke-opacity: 0.35; stroke-width: 1.5; }
.map-flow { transition: opacity 0.5s; }
.map-node { cursor: pointer; outline: none; -webkit-tap-highlight-color: transparent; }
.map-ring { fill: var(--surface2); stroke: var(--border); stroke-width: 1.5; }
.map-icon { color: var(--text-muted); }
.map-node:hover .map-ring, .map-node:focus-visible .map-ring { stroke: var(--text-muted); }
.map-node:focus-visible .map-ring { stroke: var(--accent); stroke-width: 2; }
.map-node.host .map-ring { stroke: rgba(255, 157, 92, 0.6); }
.map-node.watched .map-ring { stroke: var(--text); stroke-dasharray: 3 3; }
.map-node.selected .map-ring { stroke: var(--accent); stroke-width: 2.5; stroke-dasharray: none; }
.map-node.selected .map-icon { color: var(--accent); }
.map-node.blocked { opacity: 0.6; }
.map-node.blocked .map-ring { stroke: var(--accent-red); stroke-dasharray: 3 3; }
.map-label, .map-sub { paint-order: stroke; stroke: var(--surface); stroke-width: 3px; stroke-linejoin: round; }
.map-label { fill: var(--text); font-size: 12px; font-weight: 600; }
.map-sub { fill: var(--text-muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.map-node.blocked .map-sub { fill: var(--accent-red); }
.net-map-detail { border-top: 1px solid var(--border); padding-top: 12px; display: flex; flex-direction: column; gap: 10px; }
.net-map-detail .net-card-head { align-items: center; }

/* Phone */
@media (max-width: 720px) {
  .net-tiles { grid-template-columns: 1fr 1fr; }
  .net-tiles .net-tile:first-child { grid-column: 1 / -1; }
  .net-grid-2 { grid-template-columns: 1fr; }
  .net-form { grid-template-columns: 1fr 1fr; }
  .net-form .net-field:first-child { grid-column: 1 / -1; }
  .net-filter { max-width: none; }
  .net-live-text { display: none; }
  .net-inner { padding: 12px 12px 32px; }
  .net-tabs { gap: 0; padding: 8px 6px; }
  .net-tabs [role="tab"] { padding: 7px 8px; font-size: 12.5px; }
  .net-tab-count { display: none; }
}
@media (max-width: 420px) {
  .net-device { grid-template-columns: 32px 1fr; }
  .net-device-icon { width: 32px; height: 32px; }
  .net-device-speed { grid-column: 2; text-align: left; }
}
@media (forced-colors: active) {
  .net-key-down, .net-key-up { background: CanvasText; }
}
