/* Tunnels (tunnels-ui.js): the button in a header, the list behind it (also in a session's side
   panel and in Settings › AWS), and the dialog that makes one or points it somewhere else. */

/* How a tunnel stands, as a dot: green and steady when open, amber and breathing while it opens,
   red when it failed, a quiet ring when closed. */
.tn-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: transparent; box-shadow: inset 0 0 0 1.5px var(--text-4); }
.tn-dot[data-tone="open"] { background: var(--success); box-shadow: 0 0 0 3px color-mix(in srgb, var(--success) 20%, transparent); }
.tn-dot[data-tone="opening"] { background: var(--warn); box-shadow: none; animation: tn-pulse 1.1s ease-in-out infinite; }
.tn-dot[data-tone="failed"] { background: var(--danger); box-shadow: none; }
@keyframes tn-pulse { 50% { opacity: .3; } }

/* The button in a header. */
.tn-btn { display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 9px; border-radius: 14px; font-size: 13px; line-height: 18px; color: var(--text-2); white-space: nowrap; }
.tn-btn:hover, .tn-btn[aria-expanded="true"] { background: var(--fill); color: var(--text); }
.tn-btn svg { flex: none; }
.tn-btn .tn-dot[data-tone="open"] { margin: 0 2px; }
.tn-btn-count { font-size: 12px; line-height: 18px; color: var(--text); font-variant-numeric: tabular-nums; }

/* Its popover: wide enough for a row, never wider than a phone. */
.popover.tn-pop { width: min(420px, calc(100vw - 16px)); padding: 0; }
.tn-pop-head { padding: 14px 16px 10px; }
.tn-pop-head p { margin-top: 1px; font-size: 12px; line-height: 17px; color: var(--text-3); }
.tn-pop .tn-panel { border: 0; border-top: 1px solid var(--border-3); border-radius: 0; background: none; max-height: min(560px, calc(100vh - 160px)); max-height: min(560px, calc(100dvh - 160px)); overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; }
.tn-pop .tn-row, .tn-pop .tn-notice, .tn-pop .tn-foot, .tn-pop .tn-empty, .tn-pop .tn-note { padding-left: 16px; padding-right: 16px; }

/* The list. */
.tn-panel { display: flex; flex-direction: column; min-width: 0; border: 1px solid var(--border-3); border-radius: 12px; background: var(--surface); font-size: 13px; line-height: 18px; color: var(--text-2); text-align: left; }
.tn-list { display: flex; flex-direction: column; min-width: 0; }
.tn-row { min-width: 0; padding: 12px 14px; }
.tn-row + .tn-row { border-top: 1px solid var(--border-3); }
.tn-main { display: flex; align-items: flex-start; gap: 10px; min-width: 0; }
.tn-main > .tn-dot { margin-top: 5px; }
.tn-text { flex: 1 1 0; min-width: 0; }
.tn-title { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 8px; }
.tn-name { min-width: 0; font-size: 14px; line-height: 18px; font-weight: 500; color: var(--text); overflow-wrap: anywhere; }
.tn-kind { flex: none; padding: 0 6px; border-radius: 5px; background: var(--fill); font-size: 11px; line-height: 16px; color: var(--text-2); white-space: nowrap; }
.tn-where { margin-top: 1px; font-size: 12px; line-height: 17px; color: var(--text-2); overflow-wrap: anywhere; }
.tn-through { color: var(--text-3); }
/* The menu and the switch sit on the first line of the name, whatever wraps beside them. */
.tn-more { margin: -3px 0; }
.tn-switch[aria-busy="true"] { cursor: progress; }
.tn-switch[aria-busy="true"] .switch-knob { animation: tn-pulse 1.1s ease-in-out infinite; }

/* Under the name, in line with it: where it listens, what it did last, its history. */
.tn-reach, .tn-says, .tn-history { margin-left: 18px; }
.tn-reach { display: flex; flex-direction: column; gap: 4px; margin-top: 8px; }
.tn-copy { display: flex; align-items: center; gap: 4px; min-width: 0; min-height: 28px; padding: 0 2px 0 9px; border-radius: 8px; background: var(--fill); }
.tn-code { flex: 1 1 0; min-width: 0; font: 12px/18px var(--mono); color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; user-select: all; }
.tn-copy-btn[data-copied="true"] { color: var(--success); }
.tn-says { margin-top: 6px; font-size: 12px; line-height: 17px; color: var(--text-3); overflow-wrap: anywhere; }
.tn-says[data-tone="open"], .tn-says[data-tone="opening"] { color: var(--text-2); }
.tn-says[data-tone="failed"] { color: var(--danger); }
.tn-history { display: flex; flex-direction: column; gap: 3px; margin-top: 8px; padding-top: 8px; border-top: 1px dashed var(--border-3); font-size: 12px; line-height: 17px; }
.tn-event { display: flex; gap: 10px; min-width: 0; }
.tn-event-at { flex: none; width: 124px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.tn-event-what { flex: 1 1 0; min-width: 0; color: var(--text-2); overflow-wrap: anywhere; }
.tn-event[data-type="failed"] .tn-event-what { color: var(--danger); }
.tn-env { margin-top: 4px; color: var(--text-3); overflow-wrap: anywhere; }
.tn-env code { font: 11px/17px var(--mono); color: var(--text-2); }

/* What is missing before any tunnel can open. */
.tn-notice { display: flex; align-items: center; gap: 12px; padding: 10px 14px; border-bottom: 1px solid var(--border-3); font-size: 12px; line-height: 17px; color: var(--warn); }
.tn-notice-text { flex: 1 1 0; min-width: 0; }
.tn-notice ul { margin: 2px 0 0; padding-left: 16px; }
.tn-notice .btn { flex: none; }

.tn-empty, .tn-note { padding: 16px 14px 4px; font-size: 13px; line-height: 19px; color: var(--text-3); }
.tn-note { padding-bottom: 16px; }
.tn-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px 12px; padding: 10px 14px 12px; border-top: 1px solid var(--border-3); }
.tn-empty + .tn-foot { border-top: 0; }
.tn-new svg { flex: none; }

/* In a session's side panel: the same rows, tighter. */
.tn-panel[data-compact="true"] .tn-row { padding: 10px 12px; }
.tn-panel[data-compact="true"] .tn-name { font-size: 13px; }
.tn-panel[data-compact="true"] :is(.tn-notice, .tn-foot) { padding-left: 12px; padding-right: 12px; }
.tn-panel[data-compact="true"] :is(.tn-empty, .tn-note) { padding-left: 12px; padding-right: 12px; }
.tn-panel[data-compact="true"] .tn-event-at { width: auto; }
.tn-panel[data-compact="true"] .tn-event { flex-wrap: wrap; gap: 0 8px; }

/* The dialog: held to the window, scrolling inside. */
.modal.small.tn-dialog { width: min(480px, 100%); max-height: calc(100vh - 32px); max-height: calc(100dvh - 32px); }
.dialog-body.tn-form { min-height: 0; gap: 14px; overflow-y: auto; overscroll-behavior: contain; }
.tn-form small { font-size: 12px; line-height: 16px; color: var(--text-3); }
.tn-form .form-error { margin: 0; overflow-wrap: anywhere; }
.tn-group { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.tn-group-label { font-size: 13px; line-height: 18px; color: var(--text); }
.tn-group .tn-field > span { font-size: 12px; line-height: 16px; color: var(--text-3); }
.tn-picks { display: flex; flex-wrap: wrap; gap: 6px; }
.tn-pick { height: 30px; padding: 0 12px; border-radius: 15px; background: var(--fill); font-size: 13px; color: var(--text); white-space: nowrap; }
.tn-pick:hover { background: var(--fill-hover); }
.tn-pick[aria-checked="true"] { background: var(--cta); color: var(--cta-text); }
.tn-pair { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; align-items: start; }
.tn-pair.tn-hostport { grid-template-columns: minmax(0, 1fr) 96px; }
.tn-hint { margin-top: -2px; }
.tn-advanced > summary { width: fit-content; margin-left: -8px; padding: 4px 8px; border-radius: 8px; font-size: 13px; line-height: 18px; color: var(--text-2); cursor: pointer; }
.tn-advanced > summary:hover { color: var(--text); }
.tn-advanced-body { display: flex; flex-direction: column; gap: 12px; padding-top: 8px; }
.tn-switch-row { display: flex; align-items: center; justify-content: space-between; gap: 16px; min-width: 0; }
.tn-switch-text { display: flex; flex-direction: column; gap: 2px; min-width: 0; font-size: 13px; line-height: 18px; color: var(--text); }

@media (max-width: 767px) {
  /* 44 px to touch, the text keeps its place. */
  .tn-btn { height: 44px; min-width: 44px; justify-content: center; padding: 0 10px; border-radius: 10px; }
  .popover.tn-pop { width: calc(100vw - 16px); }
  .tn-main { gap: 8px; }
  .tn-more, .tn-switch { margin: -13px 0; }
  .tn-main > .tn-more { margin-right: -4px; }
  .tn-copy { min-height: 44px; padding-left: 12px; }
  .tn-copy-btn { margin-right: -2px; }
  .tn-code { font-size: 13px; }
  .tn-notice { flex-wrap: wrap; }
  .tn-notice .btn { flex: 1 1 100%; height: 44px; border-radius: 22px; }
  .tn-foot .btn { height: 44px; padding: 0 16px; border-radius: 22px; }
  .tn-event { flex-wrap: wrap; gap: 0 8px; }
  .tn-event-at { width: auto; }
  .modal.small.tn-dialog { width: calc(100% - 32px); max-height: calc(100vh - 32px - var(--safe-top) - var(--safe-bottom)); max-height: calc(100dvh - 32px - var(--safe-top) - var(--safe-bottom)); }
  .dialog-body.tn-form { padding: 20px 16px; }
  /* 16px keeps a phone from zooming in when a box is tapped. */
  .tn-form .field.mono { font-size: 16px; }
  .tn-pick { height: 44px; padding: 0 16px; border-radius: 22px; font-size: 14px; }
  .tn-pair { grid-template-columns: minmax(0, 1fr); }
  .tn-pair.tn-hostport { grid-template-columns: minmax(0, 1fr) 88px; }
  .tn-advanced > summary { padding: 13px 8px; }
}

@media (prefers-reduced-motion: reduce) {
  .tn-dot[data-tone="opening"], .tn-switch[aria-busy="true"] .switch-knob { animation: none; }
}
