/* Black Box DRAFT styles */
:root {
  --bg: #020202;
  --bg-soft: #070707;
  --line: #161616;
  --line-strong: #242424;
  --text: #e6e6e6;
  --muted: #666;
  --keyboard-inset: 0px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  overscroll-behavior: none;
}

.app {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(circle at 15% 20%, rgba(255, 255, 255, 0.02), transparent 25%),
    linear-gradient(var(--bg), var(--bg));
}

.canvas {
  flex: 1;
  position: relative;
  padding: 1rem 1rem calc(6.2rem + var(--keyboard-inset));
}

.keyboard-scroll-buffer {
  height: 0;
  pointer-events: none;
}

body.kb-open .keyboard-scroll-buffer {
  height: 28vh;
}

.mirror-live {
  position: relative;
  z-index: 1;
  border: 1px solid #242424;
  background: rgba(20, 32, 48, 0.22);
  box-shadow: inset 0 0 0 1px rgba(36, 36, 36, 0.35);
  margin-bottom: 0.6rem;
  min-height: 280px;
  height: clamp(320px, 58vh, 620px);
  max-height: 68vh;
  display: flex;
  flex-direction: column;
}

.mirror-live-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 22px;
  min-height: 22px;
  border-bottom: 1px solid #1d1d1d;
  color: #8b8b8b;
  font-size: 11px;
  letter-spacing: 0.06em;
  padding: 4px 8px;
}

.mirror-live-content {
  margin: 0;
  padding: 0;
  color: #bdbdbd;
  font: 12px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  -webkit-overflow-scrolling: touch;
}

.mirror-live-meta {
  color: #9f9f9f;
  margin: 0;
  padding: 6px 8px 8px;
  border-top: 1px solid #141414;
  font-size: 11px;
}

.mirror-live-img {
  display: block;
  max-width: 100%;
  max-height: 160px;
  object-fit: contain;
  border: 1px solid #1f1f1f;
  background: #050505;
}

.mirror-live-frame {
  width: 100%;
  min-height: 140px;
  height: 160px;
  border: 1px solid #1f1f1f;
  background: #050505;
}

.mirror-live-window {
  border: 1px solid #1f1f1f;
  background: #070707;
  padding: 0;
  width: 100%;
  height: 100%;
  max-width: 100%;
  max-height: 100%;
  overflow: hidden;
  position: relative;
}

.mirror-fit {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.mirror-live-window,
.mirror-live-window * {
  max-width: 100%;
  max-height: 100%;
  box-sizing: border-box;
}

.mirror-live-window .preview-fill {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.mirror-window-shell {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  border: 1px solid #2a2a2a;
  background: #090909;
}

.mirror-window-titlebar {
  height: 18px;
  min-height: 18px;
  display: flex;
  align-items: center;
  padding: 0 6px;
  border-bottom: 1px solid #1d1d1d;
  background: #0b0b0b;
}

.mirror-window-title {
  font-size: 11px;
  color: #7f7f7f;
  letter-spacing: 0.03em;
}

.mirror-window-body {
  flex: 1;
  min-height: 0;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
}

.mirror-window-body > * {
  max-width: 100%;
  max-height: 100%;
}

.mirror-live-window img,
.mirror-live-window video,
.mirror-live-window canvas,
.mirror-live-window iframe,
.mirror-live-window svg {
  width: 100% !important;
  height: 100% !important;
  object-fit: contain !important;
}

.mirror-url-frame {
  display: block;
  border: 0;
  background: #000;
  contain: layout paint size;
  transform: translateZ(0);
  backface-visibility: hidden;
  will-change: transform;
}

.window-layer {
  position: absolute;
  left: 1rem;
  right: 1rem;
  top: 1rem;
  bottom: calc(6.2rem + var(--keyboard-inset));
  z-index: 2;
  border: 1px solid #101010;
  background: rgba(4, 4, 4, 0.12);
  padding: 0.6rem;
  overflow: hidden;
  pointer-events: none;
}

.window-layer .window {
  pointer-events: auto;
}


.window {
  position: absolute;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--line-strong);
  background: var(--bg-soft);
  box-shadow: 0 10px 28px rgba(0,0,0,0.45);
  min-width: 240px;
  min-height: 180px;
  overflow: hidden;
}

.window.is-active {
  border-color: #333;
}

.window.is-expanded {
  border-color: #3d3d3d;
  box-shadow: 0 0 0 1px rgba(255,255,255,0.04), 0 18px 38px rgba(0,0,0,0.55);
}

.window.is-snapped {
  min-width: 1px;
  min-height: 1px;
}

.window.is-expanded .resize-handle {
  display: none;
}

.window-titlebar {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 18px;
  min-height: 18px;
  padding: 0 2px;
  border-bottom: 1px solid var(--line);
  background: #0a0a0a;
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  overflow: visible;
}

.window-title {
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  color: #4f4f4f;
  user-select: none;
  opacity: 0.35;
}

.window-actions {
  display: flex;
  align-items: center;
  gap: 2px;
  height: 20px;
}

.win-btn {
  border: 1px solid transparent;
  background: transparent;
  color: #434343;
  cursor: pointer;
  width: 20px;
  height: 20px;
  padding: 5px; /* 20px visual + 10px total = ~30px touch target */
  box-sizing: content-box;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 0.25rem;
  font-size: 12px;
  line-height: 1;
  opacity: 0.16;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  transition: opacity 120ms ease, color 120ms ease, border-color 120ms ease, background 120ms ease;
}

.window:hover .win-btn,
.window.is-active .win-btn,
.win-btn:focus-visible {
  opacity: 0.72;
  color: #8e8e8e;
}

.window:hover .window-title,
.window.is-active .window-title {
  opacity: 0.62;
}

.win-btn:hover {
  border-color: #262626;
  background: rgba(255,255,255,0.02);
  color: #b3b3b3;
}

.placement-menu {
  position: absolute;
  top: 22px;
  right: 2px;
  width: max-content;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 2px;
  padding: 4px;
  background: rgba(8, 8, 8, 0.97);
  border: 1px solid #1f1f1f;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
  z-index: 999;
}

.placement-item {
  border: 1px solid transparent;
  background: transparent;
  color: #8e8e8e;
  width: 32px;
  height: 30px;
  padding: 0;
  border-radius: 4px;
  touch-action: manipulation;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.placement-item:hover,
.placement-item:focus-visible {
  color: #c1c1c1;
  border-color: #2b2b2b;
  background: rgba(255,255,255,0.03);
}

.layout-icon {
  position: relative;
  width: 10px;
  height: 16px;
  border: 1px solid #5f5f5f;
  border-radius: 2px;
}

.layout-icon::after {
  content: "";
  position: absolute;
  background: #969696;
}

.layout-left::after {
  left: 0;
  top: 0;
  width: 50%;
  height: 100%;
}

.layout-right::after {
  right: 0;
  top: 0;
  width: 50%;
  height: 100%;
}

.layout-top::after {
  left: 0;
  top: 0;
  width: 100%;
  height: 50%;
}

.layout-bottom::after {
  left: 0;
  bottom: 0;
  width: 100%;
  height: 50%;
}

.layout-full::after {
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
}

.layout-restore::after {
  left: 2px;
  top: 2px;
  width: calc(100% - 4px);
  height: calc(100% - 4px);
  background: transparent;
  border: 1px solid #8b8b8b;
  border-radius: 1px;
}

.window-body {
  flex: 1;
  min-height: 0;
  padding: 0.85rem;
  color: #bfbfbf;
  font-size: 0.88rem;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
}

.window-body p { margin: 0 0 0.55rem; }
.window-body p:last-child { margin-bottom: 0; color: #888; }

.window-body > .preview-fill {
  width: 100%;
  height: 100%;
  margin: 0;
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #050505;
}

.window-body > .preview-fill img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  object-position: center;
  display: block;
}

.chat-thread {
  width: 100%;
  height: 100%;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-empty {
  color: #767676;
  font-size: 12px;
}

.chat-msg {
  display: flex;
  align-items: flex-start;
  gap: 6px;
}

.chat-copy-btn,
.chat-copy-code {
  border: 1px solid #2a2a2a;
  background: #111;
  color: #aaa;
  font-size: 10px;
  line-height: 1;
  width: 20px;
  height: 20px;
  padding: 0;
  border-radius: 5px;
  cursor: pointer;
}

.chat-rich-stack {
  display: flex;
  flex-direction: column;
  gap: 6px;
  width: 100%;
}

.chat-code-wrap {
  position: relative;
  margin-top: 4px;
}

.chat-code-wrap pre {
  margin: 0;
  padding: 8px;
  background: #0b0b0b;
  border: 1px solid #242424;
  overflow: auto;
}

.chat-tree-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  border: 1px solid #242424;
  background: #0b0b0b;
}

.chat-tree {
  margin: 0;
  padding: 8px;
  font: 11px/1.3 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre;
  min-width: max-content;
}

.chat-code-wrap .chat-copy-code {
  position: absolute;
  top: 6px;
  right: 6px;
}

.chat-msg p {
  margin: 0;
  font-size: 12px;
  line-height: 1.35;
  padding: 8px 10px;
  border: 1px solid #262626;
  background: #0a0a0a;
  max-width: 90%;
  white-space: pre-wrap;
  word-break: break-word;
}

.chat-msg.user {
  justify-content: flex-end;
}

.chat-msg.user p {
  border-color: #313131;
  background: #0d0d0d;
}

.chat-msg.assistant {
  justify-content: flex-start;
}

.chat-msg.pending p {
  margin: 0;
}

.chat-pending-card {
  width: min(100%, 320px);
  border: 1px solid #262626;
  background:
    linear-gradient(180deg, rgba(20, 20, 20, 0.96), rgba(10, 10, 10, 0.98));
  border-left: 3px solid #4f4f4f;
  border-radius: 14px;
  padding: 10px 12px;
  display: grid;
  gap: 8px;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
}

.chat-pending-card.tone-receiving {
  border-left-color: #8a8a8a;
}

.chat-pending-card.tone-thinking {
  border-left-color: #7ca8d9;
}

.chat-pending-card.tone-working {
  border-left-color: #d5b36a;
}

.chat-pending-card.tone-deep {
  border-left-color: #d97c7c;
}

.chat-pending-card.tone-error {
  border-left-color: #d95858;
}

.chat-pending-card.tone-complete {
  border-left-color: #5ea96d;
}

.chat-pending-head {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-pending-pulse {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 30px;
}

.chat-pending-meta {
  display: grid;
  gap: 2px;
}

.chat-pending-meta strong {
  font-size: 12px;
  line-height: 1.1;
  color: #f2f2f2;
  letter-spacing: 0.02em;
}

.chat-pending-meta span {
  font-size: 11px;
  line-height: 1;
  color: #8c8c8c;
}

.chat-pending-detail {
  font-size: 12px;
  line-height: 1.35;
  color: #b0b0b0;
}

.chat-pending-actions {
  display: flex;
  gap: 8px;
}

.chat-request-btn {
  appearance: none;
  border: 1px solid #3a3a3a;
  background: #151515;
  color: #f2f2f2;
  border-radius: 10px;
  padding: 7px 12px;
  font: 600 12px/1 system-ui, sans-serif;
  cursor: pointer;
}

.chat-request-btn.is-accept {
  border-color: #6a8f5a;
  background: #1d2418;
}

.chat-request-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #8a8a8a;
  display: inline-block;
  opacity: 0.35;
  animation: bbTyping 1s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.16s; }
.typing-dot:nth-child(3) { animation-delay: 0.32s; }

.typing-label {
  margin-left: 6px;
  font-size: 12px;
  color: #9a9a9a;
}

@keyframes bbTyping {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.3; }
  40% { transform: translateY(-2px); opacity: 1; }
}

.resize-handle {
  position: absolute;
  width: 30px;
  height: 30px;
  border: 0;
  background: transparent;
  opacity: 0.2;
  touch-action: none;
}

.resize-br {
  right: 0;
  bottom: 0;
  cursor: nwse-resize;
}

.resize-bl {
  left: 0;
  bottom: 0;
  cursor: nesw-resize;
}

.window:hover .resize-handle,
.window.is-active .resize-handle,
.resize-handle:focus-visible {
  opacity: 0.65;
}

.chat-dock {
  position: fixed;
  left: 0;
  right: 0;
  bottom: calc(var(--keyboard-inset) + env(safe-area-inset-bottom, 0px));
  border-top: 1px solid #161616;
  background: rgba(8, 8, 8, 0.96);
  padding: 0.75rem;
  backdrop-filter: blur(3px);
  z-index: 9999;
}

.chat-form {
  max-width: 1100px;
  margin: 0 auto;
}

.upload-status {
  margin-top: 6px;
  font-size: 12px;
  color: #8f8f8f;
  min-height: 16px;
}

.input-shell {
  position: relative;
}

#chat-input {
  width: 100%;
  border: 1px solid #242424;
  background: #0a0a0a;
  color: var(--text);
  padding: 0.68rem 8rem 0.68rem 0.75rem;
  font-size: 16px; /* iOS Safari: prevent focus-zoom on inputs */
}

#chat-input::placeholder { color: transparent; }
#chat-input:focus { outline: none; border-color: #343434; }

.attach-btn,
.send-btn,
.session-btn {
  position: absolute;
  top: 50%;
  height: 1.55rem;
  border: 1px solid transparent;
  background: transparent;
  color: #575757;
  border-radius: 0.25rem;
  cursor: pointer;
  line-height: 1;
  font-size: 0.95rem;
  opacity: 0.55;
}

.attach-btn,
.send-btn {
  width: 1.55rem;
}

.send-btn {
  right: 0.38rem;
  transform: translateY(-50%) scaleY(-1);
}

.attach-btn {
  right: 2.25rem;
  transform: translateY(-50%);
}

.session-btn {
  right: 4.2rem;
  min-width: 2.75rem;
  padding: 0 0.48rem;
  transform: translateY(-50%);
  font-size: 0.66rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.attach-btn:hover,
.attach-btn:focus-visible,
.session-btn:hover,
.session-btn:focus-visible,
.send-btn:hover,
.send-btn:focus-visible {
  color: #9a9a9a;
  border-color: #2a2a2a;
  opacity: 1;
}

@media (max-width: 640px) {
  .canvas { padding: 0.75rem 0.75rem calc(6.5rem + var(--keyboard-inset)); }

  .resize-handle {
    width: 36px;
    height: 36px;
  }
}

.lead-list { display:flex; flex-direction:column; gap:6px; max-height:100%; overflow:auto; -webkit-overflow-scrolling: touch; }
.lead-row { display:grid; gap:8px; padding:7px 8px; border:1px solid #242424; background:#0a0a0a; font-size:12px; }
.lead-row-4 { grid-template-columns: 1.2fr .9fr .8fr 1.6fr; }
.lead-row-5 { grid-template-columns: 1.1fr .8fr 1.2fr .8fr 1.6fr; }
.lead-row-6 { grid-template-columns: 1fr .75fr 1.05fr 1.05fr .75fr 1.5fr; }
.lead-row-7 { grid-template-columns: 1fr .5fr .75fr 1.05fr 1.05fr .75fr 1.4fr; }
.lead-row span { color:#9a9a9a; }
.lead-row a { color:#9fc2ff; text-decoration:none; }
.lead-row a:hover { text-decoration:underline; }
.lead-dispo { display:flex; gap:8px; align-items:center; flex-wrap:wrap; font-size:11px; color:#bdbdbd; }
.lead-dispo label { display:inline-flex; align-items:center; gap:4px; white-space:nowrap; }
.lead-dispo input { accent-color:#7aa2ff; }
.dup-badge { margin-left:6px; font-size:10px; color:#ffcf8a; border:1px solid #6a4d1e; padding:1px 4px; border-radius:10px; }
.lead-row-dup { background:#11100b; border-color:#3c2d12; }
.lead-head { position: sticky; top: 0; z-index: 2; background:#101010; border-color:#323232; }
.download-btn { border:1px solid #2b2b2b; color:#dcdcdc; text-decoration:none; padding:6px 8px; border-radius:6px; font-size:12px; background:#121212; }

@media (orientation: landscape) {
  .layout-icon {
    width: 16px;
    height: 10px;
  }
}
