/* =========================================================
   LocalBeam — Tactile Precision UI (Light & Dark Themes)
   ========================================================= */

:root {
  --bg: #F6F5F1;
  --surface: #FFFFFF;
  --surface-alt: #EFEDE7;
  --surface-hover: #E7E4DC;
  --border: #E0DDD4;
  --border-strong: #C9C5B9;

  --text: #141413;
  --text-muted: #5F5E58;
  --text-subtle: #8A8880;

  --accent: #D94E28;
  --accent-hover: #C0401E;
  --accent-soft: rgba(217, 78, 40, 0.10);

  --success: #16794F;
  --success-soft: rgba(22, 121, 79, 0.11);
  --warn: #B26B00;
  --warn-soft: rgba(178, 107, 0, 0.12);

  --shadow-sm: 0 1px 2px rgba(20, 20, 19, 0.04);
  --shadow-md: 0 8px 24px rgba(20, 20, 19, 0.07), 0 1px 3px rgba(20, 20, 19, 0.04);
  --shadow-lg: 0 24px 56px rgba(20, 20, 19, 0.16);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;

  --ease-spring: cubic-bezier(0.22, 1, 0.36, 1);
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

[data-theme="dark"] {
  --bg: #111110;
  --surface: #1A1A18;
  --surface-alt: #232320;
  --surface-hover: #2C2C28;
  --border: #2D2D29;
  --border-strong: #3E3E39;

  --text: #F2F1EC;
  --text-muted: #A6A49B;
  --text-subtle: #73716A;

  --accent: #E8623D;
  --accent-hover: #F07350;
  --accent-soft: rgba(232, 98, 61, 0.14);

  --success: #34B37E;
  --success-soft: rgba(52, 179, 126, 0.14);
  --warn: #E5A033;
  --warn-soft: rgba(229, 160, 51, 0.14);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.25);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.36);
  --shadow-lg: 0 28px 64px rgba(0, 0, 0, 0.6);
}

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

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  transition: background-color 0.25s ease, color 0.25s ease;
}

button,
input {
  font: inherit;
  color: inherit;
}

.hidden {
  display: none !important;
}

.truncate {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Shell & Topbar */
.app-shell {
  max-width: 1160px;
  margin: 0 auto;
  padding: 18px 20px 40px;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.brand-text {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.brand-name {
  font-weight: 700;
  font-size: 15px;
  letter-spacing: -0.02em;
  line-height: 1.2;
}

.brand-sub {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* Status Pill */
.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: var(--radius-pill);
  font-size: 12.5px;
  font-weight: 600;
  background: var(--surface-alt);
  color: var(--text-muted);
  border: 1px solid var(--border);
  transition: all 0.25s var(--ease-spring);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-subtle);
  transition: background-color 0.25s ease;
}

.status-pill[data-state="waiting"] {
  background: var(--warn-soft);
  color: var(--warn);
  border-color: transparent;
}
.status-pill[data-state="waiting"] .status-dot {
  background: var(--warn);
  animation: pulseDot 1.6s ease-in-out infinite;
}

.status-pill[data-state="connected"] {
  background: var(--success-soft);
  color: var(--success);
  border-color: transparent;
}
.status-pill[data-state="connected"] .status-dot {
  background: var(--success);
  animation: pulseDot 2.4s ease-in-out infinite;
}

@keyframes pulseDot {
  0%, 100% { transform: scale(1); opacity: 1; }
  50% { transform: scale(1.35); opacity: 0.55; }
}

/* Theme Icon */
.icon-moon { display: none; }
[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: block; }

/* Workspace Grid */
.workspace {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  align-items: start;
  flex: 1;
}

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}

.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}

.panel-title {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.panel-desc {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--text-muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 15px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s var(--ease-spring), background-color 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

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

.btn-primary {
  background: var(--accent);
  color: #FFFFFF;
}
.btn-primary:hover {
  background: var(--accent-hover);
}

.btn-secondary {
  background: var(--surface-alt);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
}
.btn-ghost:hover {
  background: var(--surface-alt);
  color: var(--text);
}

.btn-sm {
  min-height: 32px;
  padding: 0 11px;
  font-size: 12.5px;
}

.btn-full {
  width: 100%;
}

.btn-flex {
  flex: 1;
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-alt);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: transform 0.15s var(--ease-spring), background-color 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.icon-btn:hover {
  background: var(--surface-hover);
}

.icon-btn:active {
  transform: scale(0.94);
}

/* Segmented Control */
.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  background: var(--surface-alt);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  margin-bottom: 18px;
}

.seg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease, color 0.2s ease, box-shadow 0.2s ease;
  -webkit-tap-highlight-color: transparent;
}

.seg-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

/* Inputs */
.input {
  width: 100%;
  min-height: 40px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 13.5px;
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.input::placeholder {
  color: var(--text-subtle);
}

/* Pairing Stages */
.pair-view {
  animation: fadeSlideUp 0.28s var(--ease-spring);
}

.hint-text {
  margin: 0 0 14px;
  font-size: 13px;
  color: var(--text-muted);
}

.hint-text.compact {
  margin-bottom: 10px;
  font-size: 12.5px;
}

.qr-stage {
  display: flex;
  flex-direction: column;
  gap: 12px;
  animation: fadeSlideUp 0.3s var(--ease-spring);
}

.step-badge {
  align-self: flex-start;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: 0.01em;
}

.qr-frame {
  background: #FFFFFF;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 14px;
  display: grid;
  place-items: center;
  min-height: 210px;
  box-shadow: inset 0 0 0 1px rgba(0,0,0,0.03);
}

.qr-frame img,
.qr-frame svg,
.qr-frame canvas {
  display: block;
  width: 100%;
  max-width: 210px;
  height: auto;
  image-rendering: pixelated;
}

.action-row {
  display: flex;
  gap: 8px;
}

.paste-row {
  display: flex;
  gap: 8px;
  margin-top: 2px;
}

.paste-row .input {
  font-family: var(--font-mono);
  font-size: 12px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 6px 0 2px;
  color: var(--text-subtle);
  font-size: 11.5px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Connected Card */
.connected-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px;
  border-radius: var(--radius-md);
  background: var(--success-soft);
  border: 1px solid rgba(22, 121, 79, 0.22);
  animation: fadeSlideUp 0.3s var(--ease-spring);
}

.connected-icon {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--success);
  color: #FFFFFF;
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.connected-title {
  font-weight: 700;
  font-size: 14px;
  color: var(--success);
}

.connected-meta {
  font-size: 12.5px;
  color: var(--text-muted);
}

/* Transfer Panel & Dropzone */
.transfer-panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.composer {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.dropzone {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--bg);
  padding: 22px 18px;
  cursor: pointer;
  transition: border-color 0.2s ease, background-color 0.2s ease, transform 0.22s var(--ease-spring);
  -webkit-tap-highlight-color: transparent;
}

.dropzone:hover,
.dropzone:focus-visible {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

.dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: scale(1.01);
}

.dropzone-inner {
  display: flex;
  align-items: center;
  gap: 14px;
}

.drop-icon {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--accent);
  display: grid;
  place-items: center;
  flex-shrink: 0;
  transition: transform 0.25s var(--ease-spring);
}

.dropzone:hover .drop-icon,
.dropzone.dragover .drop-icon {
  transform: translateY(-2px);
}

.drop-copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.drop-copy strong {
  font-size: 14px;
  font-weight: 700;
}

.drop-copy span {
  font-size: 12.5px;
  color: var(--text-muted);
}

/* Link Composer */
.link-composer {
  display: flex;
  gap: 8px;
}

.link-input-wrap {
  position: relative;
  flex: 1;
}

.link-input-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-subtle);
  pointer-events: none;
}

.link-input {
  padding-left: 36px;
}

/* Feed */
.feed-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-top: 4px;
  border-top: 1px solid var(--border);
}

.feed-title-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.feed-title {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.count-badge {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: var(--radius-pill);
  background: var(--surface-alt);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 700;
  font-family: var(--font-mono);
  display: inline-grid;
  place-items: center;
  color: var(--text-muted);
}

.feed-empty {
  padding: 36px 16px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}

.feed-empty-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--surface-alt);
  color: var(--text-subtle);
  display: grid;
  place-items: center;
  margin-bottom: 4px;
}

.feed-empty-title {
  margin: 0;
  font-weight: 600;
  font-size: 14.5px;
}

.feed-empty-sub {
  margin: 0;
  max-width: 360px;
  font-size: 13px;
  color: var(--text-muted);
}

.feed-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* Feed Item Card */
.item-card {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg);
  padding: 13px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  animation: cardEnter 0.32s var(--ease-spring);
  transition: border-color 0.2s ease, transform 0.2s var(--ease-spring);
}

.item-card:hover {
  border-color: var(--border-strong);
}

@keyframes cardEnter {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes fadeSlideUp {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.item-top {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.item-thumb {
  width: 46px;
  height: 46px;
  border-radius: 9px;
  background: var(--surface);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  color: var(--text-muted);
  overflow: hidden;
  flex-shrink: 0;
}

.item-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.item-thumb.is-link {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: transparent;
}

.item-info {
  flex: 1;
  min-width: 0;
}

.item-name {
  font-weight: 600;
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.item-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.dir-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.dir-tag.sent {
  background: var(--surface-alt);
  color: var(--text-muted);
}

.dir-tag.received {
  background: var(--success-soft);
  color: var(--success);
}

.platform-tag {
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: var(--radius-pill);
  background: var(--accent-soft);
  color: var(--accent);
}

.item-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-shrink: 0;
}

.link-url-box {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  word-break: break-all;
}

.note-box {
  font-size: 13.5px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 11px;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Progress Bar */
.progress-wrap {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.progress-track {
  width: 100%;
  height: 6px;
  border-radius: var(--radius-pill);
  background: var(--surface-alt);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  border-radius: var(--radius-pill);
  transition: width 0.14s linear;
}

.progress-stats {
  display: flex;
  justify-content: space-between;
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  background: rgba(15, 15, 14, 0.64);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 16px;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  animation: modalPop 0.26s var(--ease-spring);
}

@keyframes modalPop {
  from { opacity: 0; transform: scale(0.95) translateY(10px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.scanner-card {
  max-width: 440px;
}

.preview-card {
  max-width: 820px;
  max-height: 90dvh;
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
}

.modal-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
}

.preview-meta {
  min-width: 0;
  flex: 1;
}

.preview-sub {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
}

.preview-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.scanner-viewport {
  position: relative;
  background: #000000;
  aspect-ratio: 4 / 3;
  overflow: hidden;
}

.scanner-viewport video {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.scanner-reticle {
  position: absolute;
  inset: 18%;
  border: 2px solid rgba(255, 255, 255, 0.85);
  border-radius: 14px;
  box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.scanner-reticle::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--accent);
  box-shadow: 0 0 10px var(--accent);
  animation: scanSweep 2.1s ease-in-out infinite;
}

@keyframes scanSweep {
  0%, 100% { top: 8%; }
  50% { top: 90%; }
}

.scanner-hint {
  margin: 0;
  padding: 12px 16px;
  font-size: 13px;
  color: var(--text-muted);
  text-align: center;
}

.preview-body {
  padding: 16px;
  overflow: auto;
  display: grid;
  place-items: center;
  background: var(--bg);
  flex: 1;
  min-height: 240px;
}

.preview-body img,
.preview-body video {
  max-width: 100%;
  max-height: 70dvh;
  border-radius: var(--radius-sm);
  display: block;
}

.preview-body audio {
  width: 100%;
  max-width: 480px;
}

.preview-body iframe {
  width: 100%;
  height: 70dvh;
  border: none;
  border-radius: var(--radius-sm);
  background: #FFFFFF;
}

.preview-body pre {
  width: 100%;
  margin: 0;
  padding: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-family: var(--font-mono);
  font-size: 12.5px;
  overflow: auto;
  max-height: 65dvh;
  white-space: pre-wrap;
  word-break: break-word;
}

/* Toasts */
.toast-stack {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--text);
  color: var(--bg);
  padding: 10px 15px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  animation: toastIn 0.25s var(--ease-spring);
}

@keyframes toastIn {
  from { opacity: 0; transform: translateY(10px) scale(0.96); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Mobile Responsive */
@media (max-width: 860px) {
  .app-shell {
    padding: 12px 12px calc(24px + env(safe-area-inset-bottom));
    gap: 14px;
  }

  .workspace {
    grid-template-columns: 1fr;
    gap: 14px;
  }

  .panel {
    padding: 16px;
  }

  .topbar {
    padding: 10px 12px;
  }

  .brand-sub {
    display: none;
  }

  .item-top {
    flex-wrap: wrap;
  }

  .item-actions {
    width: 100%;
    justify-content: flex-end;
    padding-top: 4px;
  }

  .toast-stack {
    left: 12px;
    right: 12px;
    bottom: 14px;
    align-items: center;
  }

  .modal-card.preview-card {
    max-height: 92dvh;
  }
}

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