/**
 * DECT Mesh Visualizer — iOS / Apple Human Interface–inspired UI
 */

:root {
  --bg: #f2f2f7;
  --bg-elevated: #ffffff;
  --text: #1c1c1e;
  --text-secondary: #636366;
  --text-tertiary: #8e8e93;
  --separator: rgba(60, 60, 67, 0.12);
  --separator-strong: rgba(60, 60, 67, 0.18);
  --fill: rgba(120, 120, 128, 0.12);
  --accent: #007aff;
  --accent-pressed: #0062cc;
  --accent-tint: rgba(0, 122, 255, 0.12);
  --green: #34c759;
  --red: #ff3b30;
  --indigo: #5856d6;
  --radius-lg: 14px;
  --radius-md: 10px;
  --radius-sm: 8px;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 2px 8px rgba(0, 0, 0, 0.06);
  --shadow-float: 0 4px 24px rgba(0, 0, 0, 0.08), 0 1px 3px rgba(0, 0, 0, 0.04);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --ease: cubic-bezier(0.25, 0.1, 0.25, 1);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  height: 100%;
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.47;
  letter-spacing: -0.01em;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.app {
  display: flex;
  height: 100vh;
  height: 100dvh;
  min-height: 480px;
}

/* ——— Sidebar ——— */

.sidebar {
  width: 360px;
  min-width: 300px;
  max-width: 100%;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.72);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-right: 0.5px solid var(--separator-strong);
  box-shadow: 1px 0 0 rgba(255, 255, 255, 0.8) inset;
}

.sidebar-header {
  padding: calc(20px + var(--safe-top)) 22px 18px;
  border-bottom: 0.5px solid var(--separator);
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}

.brand-icon {
  flex-shrink: 0;
  filter: drop-shadow(0 2px 8px rgba(0, 122, 255, 0.25));
}

.brand-copy h1 {
  margin: 0;
  font-size: 1.375rem;
  font-weight: 700;
  letter-spacing: -0.03em;
  line-height: 1.15;
  color: var(--text);
}

.brand-tagline {
  margin: 2px 0 0;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-tertiary);
  letter-spacing: 0.02em;
}

.sidebar-lead {
  margin: 0;
  font-size: 0.8125rem;
  line-height: 1.5;
  color: var(--text-secondary);
  max-width: 32em;
}

.sidebar-scroll {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 18px 20px;
  scrollbar-width: thin;
  scrollbar-color: var(--separator-strong) transparent;
}

.sidebar-scroll::-webkit-scrollbar {
  width: 6px;
}

.sidebar-scroll::-webkit-scrollbar-thumb {
  background: var(--separator-strong);
  border-radius: 100px;
}

.panel {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  padding: 16px 16px 18px;
  margin-bottom: 12px;
  border: 0.5px solid var(--separator);
  box-shadow: var(--shadow-sm);
}

.panel--last {
  margin-bottom: 0;
}

.section-title {
  margin: 0 0 12px;
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-tertiary);
}

/* ——— Inputs ——— */

textarea.input-json {
  width: 100%;
  min-height: 148px;
  padding: 12px 14px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  line-height: 1.5;
  color: var(--text);
  border: none;
  border-radius: var(--radius-md);
  resize: vertical;
  background: #f2f2f7;
  transition: box-shadow 0.2s var(--ease), background 0.2s var(--ease);
}

textarea.input-json::placeholder {
  color: var(--text-tertiary);
}

textarea.input-json:hover {
  background: #ebedf0;
}

textarea.input-json:focus {
  outline: none;
  background: var(--bg-elevated);
  box-shadow: 0 0 0 3px var(--accent-tint), 0 0 0 1px var(--accent);
}

/* ——— Buttons ——— */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 8px 16px;
  font-size: 0.875rem;
  font-weight: 600;
  letter-spacing: -0.01em;
  border: none;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.12s var(--ease), background 0.15s var(--ease), opacity 0.15s;
}

.btn:active:not(:disabled) {
  transform: scale(0.97);
}

.btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.2) inset;
}

.btn-primary:hover {
  background: #0077ed;
}

.btn-primary:active {
  background: var(--accent-pressed);
}

.btn-secondary {
  background: var(--fill);
  color: var(--accent);
}

.btn-secondary:hover {
  background: rgba(120, 120, 128, 0.16);
}

.btn-secondary:active {
  background: rgba(120, 120, 128, 0.22);
}

.btn-block {
  flex: 1;
  min-width: 0;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 12px;
}

.btn-row--equal {
  gap: 8px;
}

.file-row {
  display: flex;
  align-items: center;
  gap: 0;
  margin-top: 12px;
}

.file-input {
  position: absolute;
  width: 0.1px;
  height: 0.1px;
  opacity: 0;
  overflow: hidden;
  z-index: -1;
}

.btn-file {
  width: 100%;
  background: var(--bg-elevated);
  color: var(--accent);
  border: 1px solid var(--separator-strong);
  font-weight: 600;
}

.btn-file:hover {
  background: #f9f9fb;
}

/* ——— iOS-style switches ——— */

.toggle-stack {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.ios-switch {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 10px 0;
  cursor: pointer;
  user-select: none;
  border-bottom: 0.5px solid var(--separator);
}

.ios-switch:last-of-type {
  border-bottom: none;
  padding-bottom: 2px;
}

.ios-switch-input {
  position: absolute;
  opacity: 0;
  width: 1px;
  height: 1px;
  margin: 0;
}

.ios-switch-track {
  position: relative;
  flex-shrink: 0;
  width: 51px;
  height: 31px;
  border-radius: 100px;
  background: #e9e9eb;
  transition: background 0.25s var(--ease);
  margin-top: 1px;
}

.ios-switch-thumb {
  position: absolute;
  top: 2px;
  left: 2px;
  width: 27px;
  height: 27px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 1px 1px rgba(0, 0, 0, 0.06);
  transition: transform 0.25s var(--ease);
}

.ios-switch-input:checked + .ios-switch-track {
  background: var(--green);
}

.ios-switch-input:checked + .ios-switch-track .ios-switch-thumb {
  transform: translateX(20px);
}

.ios-switch-input:focus-visible + .ios-switch-track {
  box-shadow: 0 0 0 3px var(--accent-tint);
}

.ios-switch-label {
  flex: 1;
  font-size: 0.875rem;
  line-height: 1.4;
  color: var(--text);
  padding-top: 2px;
}

/* ——— Stats ——— */

.stats {
  font-size: 0.875rem;
  line-height: 1.55;
  color: var(--text-secondary);
}

.stats-body strong {
  color: var(--text);
  font-weight: 600;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  margin-top: 10px;
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text-tertiary);
  background: #f2f2f7;
  border-radius: 100px;
  min-height: 1.5em;
}

.warnings {
  margin-top: 10px;
}

.warning-item {
  font-size: 0.8125rem;
  line-height: 1.45;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  margin-bottom: 8px;
  background: rgba(255, 149, 0, 0.1);
  border: 0.5px solid rgba(255, 149, 0, 0.35);
  color: #8e4b10;
}

.warning-item.severe {
  background: rgba(255, 59, 48, 0.08);
  border-color: rgba(255, 59, 48, 0.35);
  color: #c41e16;
}

.sidebar-footer {
  padding: 12px 22px calc(14px + var(--safe-bottom));
  border-top: 0.5px solid var(--separator);
  background: rgba(250, 250, 252, 0.8);
}

.sidebar-footer-text {
  font-size: 0.6875rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-tertiary);
}

/* ——— Main graph area ——— */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  position: relative;
  padding: 14px 14px 14px 10px;
  background: linear-gradient(165deg, #e8eaf0 0%, #f2f2f7 45%, #ebebf0 100%);
}

.graph-chrome {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-radius: 20px;
  overflow: hidden;
  box-shadow: var(--shadow-float), 0 0 0 0.5px rgba(0, 0, 0, 0.04);
}

.graph-stage {
  flex: 1;
  min-height: 200px;
  background: radial-gradient(ellipse 120% 80% at 50% 20%, #fafbfd 0%, #f5f6fa 50%, #eef0f5 100%);
  position: relative;
}

#network {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

/* Legend — floating glass card */

.legend {
  position: absolute;
  bottom: 16px;
  left: 16px;
  z-index: 5;
  max-width: min(280px, calc(100% - 32px));
  padding: 12px 14px 14px;
  font-size: 0.8125rem;
  line-height: 1.4;
  color: var(--text-secondary);
  background: rgba(255, 255, 255, 0.76);
  backdrop-filter: saturate(180%) blur(16px);
  -webkit-backdrop-filter: saturate(180%) blur(16px);
  border-radius: var(--radius-lg);
  border: 0.5px solid rgba(255, 255, 255, 0.9);
  box-shadow: var(--shadow-sm);
}

.legend-title {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-tertiary);
  margin-bottom: 10px;
}

.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0;
}

.legend-row--text {
  font-size: 0.8125rem;
}

.legend-line {
  width: 32px;
  height: 0;
  flex-shrink: 0;
  border-top: 3px solid var(--green);
  border-radius: 2px;
}

.legend-line.weak {
  border-top-style: dashed;
  border-top-color: var(--red);
}

.legend-divider {
  height: 0.5px;
  background: var(--separator);
  margin: 10px 0 6px;
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-dot--master {
  background: var(--accent);
  box-shadow: 0 0 0 2px rgba(0, 122, 255, 0.25);
}

.legend-dot--sync {
  background: var(--accent);
  opacity: 0.9;
}

/* Hover tooltip */

.tooltip-panel {
  position: absolute;
  top: 16px;
  left: 16px;
  z-index: 6;
  max-width: min(340px, calc(100% - 32px));
  padding: 14px 16px 16px;
  background: rgba(255, 255, 255, 0.82);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border: 0.5px solid rgba(255, 255, 255, 0.95);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-float);
  pointer-events: none;
  opacity: 0;
  transform: translateY(-4px);
  transition: opacity 0.22s var(--ease), transform 0.22s var(--ease);
}

.tooltip-panel.visible {
  opacity: 1;
  transform: translateY(0);
}

.tooltip-title {
  margin: 0 0 10px;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: -0.02em;
  color: var(--text);
}

.tooltip-list {
  margin: 0;
  padding-left: 18px;
}

.tooltip-list li {
  margin: 5px 0;
}

.tooltip-list li.strong {
  color: #1a6b2c;
}

.tooltip-list li.weak {
  color: #c41e16;
}

/* ——— Responsive ——— */

@media (max-width: 960px) {
  .app {
    flex-direction: column;
    height: auto;
    min-height: 100dvh;
  }

  .sidebar {
    width: 100%;
    min-width: 0;
    border-right: none;
    border-bottom: 0.5px solid var(--separator-strong);
    max-height: none;
  }

  .main {
    padding: 10px;
    min-height: 55vh;
  }

  .graph-chrome {
    min-height: 420px;
    border-radius: 16px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
  }

  .btn:active:not(:disabled) {
    transform: none;
  }
}
