/* OmnyGrid web UI kit — design tokens, base, layout, components, modal, toasts.
 *
 * Shipped by `package:omnyshell_web` and installed into a consuming app with
 * `dart run omnyshell_web:copy_assets`. The widgets in `ui_kit.dart` are styled
 * by the class names defined here, so an app that imports them must ship this
 * file or they render unstyled.
 *
 * Terminal chrome lives in `terminal.css`. */

/* ── Design tokens ─────────────────────────────────────────────────────── */
:root {
  --font-sans: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto,
    Helvetica, Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas,
    "Liberation Mono", monospace;

  --radius: 10px;
  --radius-sm: 6px;
  --space: 16px;
  --maxw: 1100px;

  /* Light palette (default). */
  --bg: #f6f7f9;
  --bg-elevated: #ffffff;
  --bg-sunken: #eceef1;
  --fg: #1b1f24;
  --fg-muted: #5c6670;
  --border: #d8dce1;
  --border-strong: #c2c8cf;
  --accent: #2563eb;
  --accent-fg: #ffffff;
  --accent-weak: #e8f0fe;
  --success: #15803d;
  --success-weak: #e6f4ea;
  --danger: #b91c1c;
  --danger-weak: #fdecec;
  --warning: #b45309;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 4px 12px rgba(16, 24, 40, 0.08);
  --focus: 0 0 0 3px rgba(37, 99, 235, 0.4);
}

[data-theme="dark"] {
  --bg: #0f1318;
  --bg-elevated: #171c23;
  --bg-sunken: #0b0e12;
  --fg: #e6e9ee;
  --fg-muted: #9aa4b0;
  --border: #2a313b;
  --border-strong: #3a434f;
  --accent: #4f8bff;
  --accent-fg: #0a0d11;
  --accent-weak: #16263f;
  --success: #4ade80;
  --success-weak: #11261a;
  --danger: #f87171;
  --danger-weak: #2a1414;
  --warning: #fbbf24;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 6px 18px rgba(0, 0, 0, 0.45);
  --focus: 0 0 0 3px rgba(79, 139, 255, 0.45);
}

/* ── Base ──────────────────────────────────────────────────────────────── */
* { box-sizing: border-box; }

html, body { height: 100%; }
/* Allow panning/scrolling but disable pinch-zoom and double-tap zoom on touch
   devices (the terminal owns its own layout). */
html { touch-action: pan-x pan-y; }

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--radius-sm); }

h1, h2, h3 { margin: 0 0 0.4em; line-height: 1.25; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
p { margin: 0 0 0.8em; }

code, kbd, .mono { font-family: var(--font-mono); font-size: 0.92em; }

/* ── Layout ────────────────────────────────────────────────────────────── */
#app { min-height: 100%; display: flex; flex-direction: column; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  gap: var(--space);
  padding: calc(10px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right))
           10px calc(20px + env(safe-area-inset-left));
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border);
}
.app-header .brand {
  font-weight: 700;
  letter-spacing: 0.2px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.app-header .brand .dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent);
}
.app-header .spacer { flex: 1; }
.app-header .meta { color: var(--fg-muted); font-size: 0.9rem; }

.app-main {
  flex: 1;
  width: 100%;
  max-width: var(--maxw);
  margin: 0 auto;
  padding: 24px calc(20px + env(safe-area-inset-right))
           calc(48px + env(safe-area-inset-bottom)) calc(20px + env(safe-area-inset-left));
}

.center-host {
  flex: 1;
  display: grid;
  place-items: center;
  padding: 24px;
}

/* ── Components ─────────────────────────────────────────────────────────── */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
}
.card.pad-lg { padding: 32px; }
.card.narrow { width: 100%; max-width: 420px; }

.stack { display: flex; flex-direction: column; gap: 14px; }
.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 0.85rem; color: var(--fg-muted); font-weight: 600; }
.field .hint { font-size: 0.8rem; color: var(--fg-muted); }

input[type="text"], input[type="password"], input[type="url"], input[type="number"], select {
  width: 100%;
  padding: 10px 12px;
  font: inherit;
  color: var(--fg);
  background: var(--bg);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
}
input:focus-visible { box-shadow: var(--focus); border-color: var(--accent); }

.check { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.check input { width: auto; }

/* Radio group (settings panel: dimension preset + text size). */
.radio-group { display: flex; flex-direction: column; gap: 8px; }
.radio-group.inline { flex-direction: row; flex-wrap: wrap; gap: 12px; }
.radio { display: flex; align-items: center; gap: 8px; font-size: 0.9rem; }
.radio input { width: auto; }
.settings-panel h3 { font-size: 1rem; margin: 0; }
/* In the flex column, hr's default margin-inline:auto collapses it to 0 width;
   reset it to a full-width divider. */
.settings-panel hr { width: 100%; margin: 0; border: 0; border-top: 1px solid var(--border); }
.settings-panel .custom-dims { gap: 12px; flex-wrap: wrap; }
.settings-panel .custom-dims .field { flex: 1; min-width: 90px; }
.settings-panel .custom-dims.disabled { opacity: 0.5; }

button {
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--fg);
  transition: background 0.12s ease, border-color 0.12s ease;
}
button:hover { background: var(--bg-sunken); }
button:disabled { opacity: 0.55; cursor: not-allowed; }
button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-fg);
}
button.primary:hover { filter: brightness(1.06); background: var(--accent); }
button.ghost { background: transparent; border-color: transparent; }
button.ghost:hover { background: var(--bg-sunken); }
button.icon { padding: 8px; line-height: 1; }
/* The settings gear reads a touch small at the base size; nudge the glyph up. */
button.settings-icon { font-size: 1.2rem; }
button.danger { color: var(--danger); border-color: var(--border-strong); }
button.danger:hover { background: var(--danger-weak); }
/* Compact button (e.g. the sessions toolbar's New Session / Refresh); the
   `button.` prefix keeps it winning over the larger mobile touch padding. */
button.btn-sm { padding: 6px 10px; font-size: 0.82rem; }

.badge {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.78rem; font-weight: 600;
  padding: 3px 9px; border-radius: 999px;
  background: var(--bg-sunken); color: var(--fg-muted);
  border: 1px solid var(--border);
}
.badge.online { background: var(--success-weak); color: var(--success); border-color: transparent; }
.badge.offline { background: var(--bg-sunken); color: var(--fg-muted); }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }

.banner {
  display: flex; gap: 10px; align-items: flex-start;
  padding: 12px 14px; border-radius: var(--radius-sm);
  border: 1px solid transparent;
}
.banner.error { background: var(--danger-weak); color: var(--danger); border-color: var(--danger); }
.banner.warning { background: var(--danger-weak); color: var(--warning); }
.banner .hint { color: var(--fg-muted); font-size: 0.85rem; margin-top: 2px; }

.muted { color: var(--fg-muted); }
.version-footer { text-align: center; margin: 4px 0 0; opacity: 0.8; }
.empty {
  text-align: center; color: var(--fg-muted);
  padding: 48px 16px;
}

.spinner {
  width: 18px; height: 18px;
  border: 2px solid var(--border-strong);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation-duration: 1.6s; }
  button, input { transition: none; }
}

.list { display: flex; flex-direction: column; gap: 10px; }
.list-item {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-align: left;
  width: 100%;
  cursor: pointer;
  color: inherit;
}
.list-item:hover { border-color: var(--border-strong); background: var(--bg-elevated); }
/* The last-interacted session in the list gets an accent ring so it's easy to
   spot after arriving from a node's session preview. */
.list-item.highlight {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.list-item .title { font-weight: 600; }
.list-item .sub { color: var(--fg-muted); font-size: 0.85rem; }

/* Session action buttons stay compact and on one line. */
.session-actions { flex-wrap: nowrap; gap: 6px; flex: 0 0 auto; }
.session-actions button { padding: 6px 10px; font-size: 0.82rem; }

/* The running-program badge sits beside the state badge, accented and
   truncated so a long command doesn't blow out the row. */
.badge.cmd {
  background: var(--success-weak);
  color: var(--success);
  border-color: transparent;
  max-width: 16ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: inline-block;
}

.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 18px; }
.kv dt { color: var(--fg-muted); }
/* Truncate long values (e.g. a UID) with an ellipsis so they don't widen the
   page on a phone. min-width:0 lets the grid cell shrink below its content. */
.kv dd {
  margin: 0;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.toolbar h1 { margin: 0; }
/* The sessions toolbar heading sits above the big node-id title, so keep it a
   touch smaller. */
.toolbar h1.sessions-title { font-size: 1.15rem; }
/* The node id title grows to push the action buttons right, truncating rather
   than overflowing the toolbar on narrow screens. */
.node-title {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(8, 11, 15, 0.55);
  display: grid; place-items: center; padding: 20px;
}
.modal {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%; max-width: 720px;
  max-height: 85vh; display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { margin: 0; flex: 1; font-size: 1.05rem; }
.modal-body { padding: 18px; overflow: auto; }
.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 18px; border-top: 1px solid var(--border);
}
.screen-capture {
  margin: 0; padding: 14px;
  background: var(--bg-sunken); color: var(--fg);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono); font-size: 0.85rem;
  white-space: pre-wrap; word-break: break-word;
  max-height: 60vh; overflow: auto;
}

/* Toast container */
#toasts {
  position: fixed;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  z-index: 100;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--bg-elevated); color: var(--fg);
  border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm); box-shadow: var(--shadow);
  padding: 10px 14px; max-width: 360px;
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }

@media (max-width: 640px) {
  .app-header {
    padding: calc(10px + env(safe-area-inset-top)) calc(14px + env(safe-area-inset-right))
             10px calc(14px + env(safe-area-inset-left));
  }
  .app-main {
    padding: 18px calc(14px + env(safe-area-inset-right))
             calc(40px + env(safe-area-inset-bottom)) calc(14px + env(safe-area-inset-left));
  }
  .app-header .meta.hide-sm { display: none; }
  /* Buttons get comfortable touch targets on small screens. */
  button { padding: 11px 16px; }
  .list-item { padding: 16px; }
  /* Sessions: stack the info over a full-width action row so the (smaller)
     buttons fit on a single line on a phone / vertical screen. */
  .session-item { flex-direction: column; align-items: stretch; gap: 10px; }
  .session-actions { justify-content: flex-start; }
  .session-actions button { flex: 1 1 auto; padding: 8px 6px; font-size: 0.82rem; }
  /* Login card uses more of the screen on phones: trim the outer gutter
     (respecting safe-area insets) and the card's inner padding so the form
     fields get extra width instead of being boxed in. The 420px cap still
     keeps it from sprawling on larger phones/tablets. */
  .center-host {
    padding: 16px calc(12px + env(safe-area-inset-right))
             16px calc(12px + env(safe-area-inset-left));
  }
  .card.pad-lg { padding: 24px; }
}
