/* ── Reset & base ─────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --blue:        #2563EB;
  --blue-dark:   #1D4ED8;
  --blue-light:  #DBEAFE;
  --green:       #10B981;
  --red:         #EF4444;
  --bg:          #F1F5F9;
  --surface:     #FFFFFF;
  --border:      #E2E8F0;
  --text:        #0F172A;
  --text-soft:   #64748B;
  --radius:      14px;
  --shadow:      0 2px 12px rgba(0,0,0,.08);
  --font:        -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

html { -webkit-tap-highlight-color: transparent; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
}

/* ── Layout ───────────────────────────────────────── */
#app {
  max-width: 520px;
  margin: 0 auto;
  padding: 0 16px 48px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 0 16px;
}

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

main { display: flex; flex-direction: column; gap: 16px; }

/* ── Screens ──────────────────────────────────────── */
.screen { display: none; flex-direction: column; gap: 16px; }
.screen--active { display: flex; }

/* ── Panels / cards ───────────────────────────────── */
.panel {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.panel h2 {
  font-size: .95rem;
  font-weight: 600;
  color: var(--text);
}

.sub {
  font-size: .82rem;
  color: var(--text-soft);
  line-height: 1.4;
}

/* ── Status badge ─────────────────────────────────── */
.badge {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: .78rem;
  font-weight: 500;
  padding: 4px 10px;
  border-radius: 999px;
}

.badge__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
}

.badge--connecting { background: #FEF3C7; color: #92400E; }
.badge--connecting .badge__dot { background: #F59E0B; animation: pulse 1.2s ease-in-out infinite; }

.badge--ready { background: #DBEAFE; color: #1D4ED8; }
.badge--ready .badge__dot { background: #2563EB; }

.badge--connected { background: #D1FAE5; color: #065F46; }
.badge--connected .badge__dot { background: #10B981; }

.badge--error { background: #FEE2E2; color: #991B1B; }
.badge--error .badge__dot { background: #EF4444; }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%       { opacity: .3; }
}

/* ── Init screen ──────────────────────────────────── */
#screen-init {
  align-items: center;
  justify-content: center;
  padding: 80px 0;
  gap: 20px;
}

.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── QR code ──────────────────────────────────────── */
#qr-container {
  display: flex;
  justify-content: center;
  padding: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

#qr-container canvas,
#qr-container img {
  display: block;
  max-width: 100%;
  height: auto;
}

/* ── ID row ───────────────────────────────────────── */
.id-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border-radius: 8px;
  padding: 10px 12px;
}

.id-text {
  flex: 1;
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: .9rem;
  font-weight: 600;
  letter-spacing: .08em;
  word-break: break-all;
  color: var(--blue-dark);
  user-select: all;
  -webkit-user-select: all;
}

/* ── Divider ──────────────────────────────────────── */
.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-soft);
  font-size: .8rem;
}
.divider::before, .divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ── Buttons ──────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  font-family: var(--font);
  font-size: .9rem;
  font-weight: 600;
  border: none;
  cursor: pointer;
  border-radius: 9px;
  padding: 11px 20px;
  transition: background .15s, opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
  white-space: nowrap;
}
.btn:active { transform: scale(.97); }

.btn--primary { background: var(--blue); color: #fff; }
.btn--primary:hover { background: var(--blue-dark); }

.btn--ghost {
  background: transparent;
  color: var(--text-soft);
  border: 1px solid var(--border);
}
.btn--ghost:hover { background: var(--bg); }

.btn--sm { font-size: .8rem; padding: 7px 12px; border-radius: 7px; }
.btn--danger { color: var(--red); border-color: #FECACA; }
.btn--danger:hover { background: #FEF2F2; }

/* ── Input row ────────────────────────────────────── */
.input-row {
  display: flex;
  gap: 8px;
}

input[type="text"] {
  flex: 1;
  padding: 11px 14px;
  border: 1.5px solid var(--border);
  border-radius: 9px;
  font-family: var(--font);
  font-size: .9rem;
  color: var(--text);
  background: var(--bg);
  outline: none;
  transition: border-color .15s;
  min-width: 0;
}
input[type="text"]:focus { border-color: var(--blue); background: #fff; }
input[type="text"]::placeholder { color: #94A3B8; }

.error-msg {
  font-size: .82rem;
  color: var(--red);
  background: #FEF2F2;
  padding: 8px 12px;
  border-radius: 7px;
}

/* ── Connected bar ────────────────────────────────── */
.connected-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: #D1FAE5;
  border-radius: var(--radius);
  padding: 12px 16px;
  font-size: .9rem;
  font-weight: 600;
  color: #065F46;
}
.connected-bar .btn { margin-left: auto; }

/* ── Drop zone ────────────────────────────────────── */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 32px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  text-align: center;
  position: relative;
  user-select: none;
  -webkit-user-select: none;
}
.drop-zone:hover,
.drop-zone:focus,
.drop-zone--over {
  border-color: var(--blue);
  background: var(--blue-light);
}
.drop-zone p { font-size: .9rem; font-weight: 500; color: var(--text-soft); }
.drop-zone .hint { font-size: .8rem; }

#file-input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

/* ── File lists ───────────────────────────────────── */
.file-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.file-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg);
  border-radius: 9px;
  font-size: .85rem;
}

.file-icon {
  flex-shrink: 0;
  width: 34px;
  height: 34px;
  background: var(--blue-light);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--blue);
  font-size: .7rem;
  font-weight: 700;
  text-transform: uppercase;
}

.file-info { flex: 1; min-width: 0; }
.file-name {
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.file-size { font-size: .75rem; color: var(--text-soft); margin-top: 2px; }

.file-action { flex-shrink: 0; }

/* Progress bar inside file item */
.file-progress {
  width: 100%;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin-top: 6px;
  overflow: hidden;
}
.file-progress__fill {
  height: 100%;
  background: var(--blue);
  border-radius: 2px;
  transition: width .1s linear;
}
.file-progress__fill--done { background: var(--green); }

.file-status {
  font-size: .75rem;
  color: var(--text-soft);
  margin-top: 3px;
}

/* Download button */
.btn--download {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: .8rem;
  font-weight: 600;
  padding: 6px 12px;
  background: var(--green);
  color: #fff;
  border-radius: 7px;
  border: none;
  cursor: pointer;
  text-decoration: none;
  transition: opacity .15s;
}
.btn--download:hover { opacity: .85; }

/* ── Toast ────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: #1E293B;
  color: #fff;
  font-size: .85rem;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: 999px;
  box-shadow: 0 4px 20px rgba(0,0,0,.25);
  opacity: 0;
  transition: opacity .2s, transform .2s;
  pointer-events: none;
  white-space: nowrap;
  z-index: 100;
}
.toast--show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ── Utility ──────────────────────────────────────── */
.hidden { display: none !important; }
.hint { font-size: .82rem; color: var(--text-soft); }

/* ── Responsive tweaks ────────────────────────────── */
@media (max-width: 400px) {
  .input-row { flex-direction: column; }
  .btn--primary { width: 100%; }
}

/* iOS Safari safe area */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
  body { padding-bottom: env(safe-area-inset-bottom); }
}
