/* ---------- Tokens (Apple semantic colors) ---------- */
:root {
  --bg: #f5f5f7;
  --window: #ffffff;
  --toolbar: rgba(246, 246, 248, 0.86);
  --label: #1d1d1f;
  --label-secondary: rgba(60, 60, 67, 0.72);
  --label-tertiary: rgba(60, 60, 67, 0.45);
  --separator: rgba(60, 60, 67, 0.14);
  --fill: rgba(118, 118, 128, 0.12);
  --fill-hover: rgba(118, 118, 128, 0.08);
  --tint: #007aff;
  --window-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.04), 0 24px 60px rgba(0, 0, 0, 0.12);
  --ease: cubic-bezier(0.32, 0.72, 0, 1);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --window: #1c1c1e;
    --toolbar: rgba(40, 40, 42, 0.86);
    --label: #f5f5f7;
    --label-secondary: rgba(235, 235, 245, 0.68);
    --label-tertiary: rgba(235, 235, 245, 0.4);
    --separator: rgba(84, 84, 88, 0.6);
    --fill: rgba(118, 118, 128, 0.24);
    --fill-hover: rgba(118, 118, 128, 0.16);
    --tint: #0a84ff;
    --window-shadow: 0 0 0 0.5px rgba(255, 255, 255, 0.14), 0 24px 60px rgba(0, 0, 0, 0.7);
  }
}

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--label);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  letter-spacing: -0.01em;
  -webkit-font-smoothing: antialiased;
}

button { font: inherit; color: inherit; }

:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--tint) 55%, transparent);
  outline-offset: 2px;
}

/* ---------- Layout: sidebar + preview, fills the viewport ---------- */
.app {
  height: 100dvh;
  display: grid;
  grid-template-columns: 300px 1fr;
  gap: 40px;
  padding: 48px 48px 48px 40px;
  max-width: 1600px;
  margin: 0 auto;
}

/* ---------- Sidebar ---------- */
.sidebar {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.eyebrow {
  margin: 0 0 4px 12px;
  font-size: 13px;
  font-weight: 600;
  color: var(--label-tertiary);
}

.sidebar h1 {
  margin: 0 0 28px 12px;
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "Inter", system-ui, sans-serif;
  font-size: 34px; /* HIG Large Title */
  font-weight: 700;
  letter-spacing: -0.025em;
  line-height: 1.1;
}

.list {
  list-style: none;
  margin: 0;
  padding: 0;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.row {
  width: 100%;
  min-height: 52px; /* > 44pt target */
  display: grid;
  grid-template-columns: 22px 32px 1fr;
  align-items: center;
  gap: 12px;
  padding: 8px 12px;
  border: 0;
  border-radius: 12px;
  background: transparent;
  text-align: left;
  cursor: pointer;
  transition: background 0.2s, transform 0.2s var(--ease);
}
.row:hover { background: var(--fill-hover); }
.row:active { transform: scale(0.985); }
.row[aria-selected="true"] {
  background: color-mix(in srgb, var(--c2) 16%, transparent);
  box-shadow: inset 0 0 0 0.5px color-mix(in srgb, var(--c2) 30%, transparent);
}

.row .num {
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--label-tertiary);
  text-align: right;
}
.row .name { font-size: 15px; font-weight: 600; }
.row .host {
  display: block;
  font-size: 12px;
  color: var(--label-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.row[aria-selected="true"] .num { color: color-mix(in srgb, var(--c2) 80%, var(--label)); }

.hint {
  margin: auto 0 0 12px;
  padding-top: 20px;
  font-size: 12px;
  color: var(--label-tertiary);
}
kbd {
  font: inherit;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--fill);
}

/* ---------- Icon (squircle) ---------- */
.icon {
  width: 32px;
  height: 32px;
  border-radius: 22.37%;
  display: grid;
  place-items: center;
  color: #fff;
  background: linear-gradient(135deg, var(--c1), var(--c2));
  box-shadow: inset 0 0 0 0.5px rgba(255, 255, 255, 0.25), 0 1px 3px rgba(0, 0, 0, 0.12);
  position: relative;
  overflow: hidden;
}
.icon::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent 55%);
}
.icon svg { width: 17px; height: 17px; position: relative; z-index: 1; }

/* ---------- Preview window (Safari-style) ---------- */
.window {
  min-height: 0;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  overflow: hidden;
  background: var(--window);
  box-shadow: var(--window-shadow);
}

.toolbar {
  position: relative;
  height: 52px;
  flex: none;
  display: grid;
  grid-template-columns: 1fr minmax(0, 520px) 1fr;
  align-items: center;
  gap: 12px;
  padding: 0 12px 0 18px;
  background: var(--toolbar);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--separator);
}

.lights { display: flex; gap: 8px; }
.lights span { width: 12px; height: 12px; border-radius: 50%; box-shadow: inset 0 0 0 0.5px rgba(0, 0, 0, 0.12); }
.lights span:nth-child(1) { background: #ff5f57; }
.lights span:nth-child(2) { background: #febc2e; }
.lights span:nth-child(3) { background: #28c840; }

.address {
  height: 34px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 0 12px;
  border-radius: 10px;
  background: var(--fill);
  color: var(--label);
  font-size: 14px;
  text-decoration: none;
  min-width: 0;
  transition: background 0.2s;
}
.address:hover { background: var(--fill-hover); }
.address svg { flex: none; color: var(--label-secondary); }
.address .url { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.address .url .path { color: var(--label-tertiary); }

.actions { display: flex; justify-content: flex-end; align-items: center; gap: 4px; }

.tool {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--label-secondary);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.2s, color 0.2s;
}
.tool:hover { background: var(--fill); color: var(--label); }
.tool[aria-pressed="true"] { background: var(--fill); color: var(--tint); }

/* Progress bar under the toolbar, like Safari's */
.progress {
  position: absolute;
  left: 0;
  bottom: -0.5px;
  height: 2px;
  width: 0;
  background: var(--tint);
  opacity: 0;
}
.loading .progress { opacity: 1; animation: progress 2.4s var(--ease) forwards; }
.loaded .progress { width: 100%; opacity: 0; transition: width 0.2s, opacity 0.4s 0.2s; }
@keyframes progress { from { width: 0; } to { width: 85%; } }

/* ---------- Viewport ---------- */
.viewport {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  background: var(--bg);
}
.frame {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
  transition: width 0.5s var(--ease), height 0.5s var(--ease), border-radius 0.5s var(--ease), opacity 0.3s;
}
.loading .frame { opacity: 0.35; }

/* Phone-width preview mode */
.window.phone .frame {
  width: 390px;
  height: min(844px, calc(100% - 48px));
  border-radius: 40px;
  box-shadow: 0 0 0 10px #1d1d1f, 0 0 0 11px #3a3a3c, 0 30px 60px rgba(0, 0, 0, 0.25);
}

/* Fallback card for sites that can't be embedded */
.blocked {
  display: none;
  text-align: center;
  padding: 32px;
  max-width: 360px;
}
.window.no-embed .frame { display: none; }
.window.no-embed .blocked { display: block; animation: rise 0.5s var(--ease); }
.blocked .icon { width: 88px; height: 88px; margin: 0 auto 18px; box-shadow: 0 12px 30px rgba(0, 0, 0, 0.18); }
.blocked .icon svg { width: 42px; height: 42px; }
.blocked h2 { margin: 0; font-size: 22px; letter-spacing: -0.02em; }
.blocked p { margin: 6px 0 22px; color: var(--label-secondary); }
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  padding: 0 22px;
  border-radius: 999px;
  background: var(--tint);
  color: #fff;
  font-weight: 600;
  text-decoration: none;
  transition: filter 0.2s, transform 0.2s var(--ease);
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(0.97); }

@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* ---------- Small screens: stack list above preview ---------- */
@media (max-width: 820px) {
  .app {
    height: auto;
    grid-template-columns: 1fr;
    gap: 20px;
    padding: 28px 16px 32px;
  }
  .sidebar h1 { margin-bottom: 16px; }
  .hint, .lights, #device { display: none; }
  .window { height: 72dvh; }
  .window.phone .frame { width: 100%; height: 100%; border-radius: 0; box-shadow: none; } /* already phone-sized */
  .toolbar { grid-template-columns: minmax(0, 1fr) auto; padding: 0 8px 0 10px; }
}

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