/* ============================================================================
 * BreathShare -- Zero-Knowledge E2EE File Transfer Stylesheet (styles.css)
 * ============================================================================
 * FINAL PRODUCTION -- Mobile-first, zero-dependency, Cloudflare Pages CSS.
 * Matched 1:1 with index.html and app.js dynamic classes.
 *
 * IMPORTANT: Save this file as exact lowercase "styles.css" (plural, with "s")
 *            to match <link rel="stylesheet" href="./styles.css" /> in index.html.
 * ============================================================================ */

/* ---------------------------------------------------------------------------
 * 1. DESIGN TOKENS (Dark Default + Automatic Light Mode)
 * --------------------------------------------------------------------------- */
:root {
  --bg: #0b1120;
  --bg-accent: radial-gradient(circle at 50% -10%, rgba(56, 189, 248, 0.14), transparent 58%);
  --surface: #111827;
  --surface-elevated: #172033;
  --surface-hover: #1e293b;
  --border: rgba(148, 163, 184, 0.16);
  --border-strong: rgba(148, 163, 184, 0.28);

  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --text-subtle: #64748b;

  --primary: #38bdf8;
  --primary-strong: #0ea5e9;
  --primary-gradient: linear-gradient(135deg, #38bdf8 0%, #6366f1 100%);
  --primary-text: #ffffff;
  --primary-soft: rgba(56, 189, 248, 0.12);

  --success: #34d399;
  --success-bg: rgba(16, 185, 129, 0.14);
  --success-border: rgba(52, 211, 153, 0.32);

  --warn: #fbbf24;
  --warn-bg: rgba(245, 158, 11, 0.14);
  --warn-border: rgba(251, 191, 36, 0.34);

  --danger: #f87171;
  --danger-solid: #ef4444;
  --danger-bg: rgba(239, 68, 68, 0.14);
  --danger-border: rgba(248, 113, 113, 0.34);

  --info: #60a5fa;
  --info-bg: rgba(59, 130, 246, 0.14);
  --info-border: rgba(96, 165, 250, 0.34);

  --shadow-card: 0 12px 32px rgba(2, 6, 23, 0.45);
  --shadow-toast: 0 10px 26px rgba(2, 6, 23, 0.55);

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

  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f8fafc;
    --bg-accent: radial-gradient(circle at 50% -10%, rgba(14, 165, 233, 0.12), transparent 58%);
    --surface: #ffffff;
    --surface-elevated: #f1f5f9;
    --surface-hover: #e2e8f0;
    --border: rgba(15, 23, 42, 0.1);
    --border-strong: rgba(15, 23, 42, 0.2);

    --text: #0f172a;
    --text-muted: #475569;
    --text-subtle: #64748b;

    --primary: #0284c7;
    --primary-strong: #0369a1;
    --primary-gradient: linear-gradient(135deg, #0284c7 0%, #4f46e5 100%);
    --primary-text: #ffffff;
    --primary-soft: rgba(2, 132, 199, 0.09);

    --success: #047857;
    --success-bg: rgba(16, 185, 129, 0.12);
    --success-border: rgba(5, 150, 105, 0.28);

    --warn: #b45309;
    --warn-bg: rgba(245, 158, 11, 0.12);
    --warn-border: rgba(217, 119, 6, 0.3);

    --danger: #dc2626;
    --danger-solid: #dc2626;
    --danger-bg: rgba(239, 68, 68, 0.1);
    --danger-border: rgba(220, 38, 38, 0.28);

    --info: #1d4ed8;
    --info-bg: rgba(59, 130, 246, 0.1);
    --info-border: rgba(37, 99, 235, 0.26);

    --shadow-card: 0 10px 28px rgba(15, 23, 42, 0.08);
    --shadow-toast: 0 10px 24px rgba(15, 23, 42, 0.18);
  }
}

/* ---------------------------------------------------------------------------
 * 2. RESET & CRITICAL [hidden] GUARD
 * --------------------------------------------------------------------------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

/* Critical: prevents display:flex/grid classes from overriding HTML hidden attribute */
[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  overflow-x: hidden;
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text);
  background-color: var(--bg);
  background-image: var(--bg-accent);
  background-repeat: no-repeat;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

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

/* Prevent duplicate browser-native password eye icons overlapping Show/Hide button */
input[type="password"]::-ms-reveal,
input[type="password"]::-ms-clear {
  display: none;
}

/* ---------------------------------------------------------------------------
 * 3. APP SHELL, HEADER & FOOTER
 * --------------------------------------------------------------------------- */
.app-shell {
  width: 100%;
  max-width: 540px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  padding:
    max(16px, env(safe-area-inset-top))
    max(16px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom))
    max(16px, env(safe-area-inset-left));
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 4px 2px;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 11px;
  text-decoration: none;
  color: var(--text);
  border-radius: var(--radius-md);
}

.brand:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 4px;
}

.brand-icon {
  width: 40px;
  height: 40px;
  border-radius: 12px;
  background: var(--primary-gradient);
  color: var(--primary-text);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 6px 16px rgba(56, 189, 248, 0.24);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.15;
}

.brand-name {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.brand-tag {
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--primary);
  letter-spacing: 0.02em;
  text-transform: uppercase;
  margin-top: 2px;
}

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

.view-section {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.app-footer {
  margin-top: auto;
  padding-top: 12px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-subtle);
  text-align: center;
}

/* ---------------------------------------------------------------------------
 * 4. BANNERS (Global Alerts & In-App WebView Warning)
 * --------------------------------------------------------------------------- */
.banner {
  padding: 12px 14px;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  line-height: 1.45;
  border: 1px solid var(--border);
  background: var(--surface-elevated);
  word-break: break-word;
}

.banner-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.banner-row span {
  flex: 1 1 200px;
}

.banner-row .btn {
  flex-shrink: 0;
}

.banner-warn {
  background: var(--warn-bg);
  border-color: var(--warn-border);
  color: var(--warn);
}

.banner-error {
  background: var(--danger-bg);
  border-color: var(--danger-border);
  color: var(--danger);
}

.banner-info {
  background: var(--info-bg);
  border-color: var(--info-border);
  color: var(--info);
}

.banner-success {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success);
}

/* ---------------------------------------------------------------------------
 * 5. CARDS & HEADINGS
 * --------------------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.loading-card {
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 36px 20px;
  gap: 14px;
}

.card-head {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.card-title {
  margin: 0;
  font-size: 1.28rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.25;
}

.archive-title {
  word-break: break-word;
  overflow-wrap: anywhere;
}

.card-subtitle,
.meta-text {
  margin: 0;
  font-size: 0.88rem;
  color: var(--text-muted);
  line-height: 1.45;
  word-break: break-word;
}

.section-subtitle {
  margin: 0;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--text);
}

.success-badge,
.rx-badge {
  align-self: flex-start;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 0.76rem;
  font-weight: 600;
}

.success-badge {
  background: var(--success-bg);
  border: 1px solid var(--success-border);
  color: var(--success);
}

.rx-badge {
  background: var(--primary-soft);
  border: 1px solid rgba(56, 189, 248, 0.28);
  color: var(--primary);
}

.status-pill {
  padding: 10px 13px;
  border-radius: var(--radius-md);
  font-size: 0.84rem;
  font-weight: 500;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  color: var(--text);
  word-break: break-word;
}

.status-pill.status-done {
  background: var(--success-bg);
  border-color: var(--success-border);
  color: var(--success);
}

.privacy-note {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.45;
}

.privacy-note code {
  font-family: var(--font-mono);
  font-size: 0.85em;
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--surface-elevated);
  border: 1px solid var(--border);
  color: var(--primary);
}

.text-danger {
  color: var(--danger) !important;
  font-weight: 600;
}

/* ---------------------------------------------------------------------------
 * 6. DROP ZONE & FILE LIST
 * --------------------------------------------------------------------------- */
.drop-zone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--surface-elevated);
  padding: 26px 16px;
  text-align: center;
  cursor: pointer;
  user-select: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  transition: border-color 0.16s ease, background-color 0.16s ease, transform 0.12s ease;
}

.drop-zone:hover,
.drop-zone:focus-visible {
  border-color: var(--primary);
  background: var(--primary-soft);
  outline: none;
}

.drop-zone:active {
  transform: scale(0.99);
}

.drop-zone.drag-over {
  border-color: var(--primary);
  background: var(--primary-soft);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

.drop-zone-icon {
  width: 52px;
  height: 52px;
  border-radius: 14px;
  background: var(--primary-soft);
  color: var(--primary);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 4px;
}

.drop-zone-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.drop-zone-hint {
  font-size: 0.82rem;
  color: var(--text-muted);
}

.file-summary {
  margin: -4px 0 0;
  font-size: 0.8rem;
  color: var(--text-muted);
  text-align: center;
}

.file-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 240px;
  overflow-y: auto;
  overscroll-behavior: contain;
  scrollbar-width: thin;
}

.file-list:empty {
  display: none;
}

.file-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-md);
  background: var(--surface-elevated);
  border: 1px solid var(--border);
}

.file-item-info {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.file-item-name {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-item-sub {
  font-size: 0.76rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------------------------------------------------------------------------
 * 7. FORM CONTROLS (16px floor prevents mobile auto-zoom on focus)
 * --------------------------------------------------------------------------- */
.options-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

@media (min-width: 440px) {
  .options-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
}

.form-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--text);
}

.label-muted {
  font-weight: 400;
  color: var(--text-muted);
}

.form-control {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  font-size: 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-strong);
  background: var(--surface-elevated);
  color: var(--text);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Dark/Light safe native dropdown options on Android & Windows Chrome */
select.form-control {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 36px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px 16px;
}

select.form-control option {
  background-color: var(--surface);
  color: var(--text);
}

.form-control::placeholder {
  color: var(--text-subtle);
  font-size: 0.9rem;
}

.form-control:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.2);
}

.link-input {
  font-family: var(--font-mono);
  font-size: 0.84rem;
  color: var(--primary);
  text-overflow: ellipsis;
}

.input-with-btn {
  position: relative;
  display: flex;
  align-items: center;
}

.input-with-btn .form-control {
  padding-right: 68px;
}

.btn-toggle-pwd {
  position: absolute;
  right: 6px;
  min-height: 36px;
  padding: 0 11px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-toggle-pwd:hover,
.btn-toggle-pwd:focus-visible {
  background: var(--primary-soft);
  outline: none;
}

.turnstile-box {
  display: flex;
  justify-content: center;
  min-height: 65px;
  overflow-x: auto;
}

/* ---------------------------------------------------------------------------
 * 8. PROGRESS BAR & SPINNER
 * --------------------------------------------------------------------------- */
.progress-box {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
  border-radius: var(--radius-md);
  background: var(--surface-elevated);
  border: 1px solid var(--border);
}

.progress-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text);
}

.progress-meta span:first-child {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.progress-meta span:last-child {
  flex-shrink: 0;
  font-variant-numeric: tabular-nums;
}

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

.progress-fill {
  height: 100%;
  width: 0%;
  border-radius: var(--radius-pill);
  background: var(--primary-gradient);
  will-change: width;
  transition: width 0.2s ease-out;
}

.spinner {
  width: 34px;
  height: 34px;
  border: 3px solid var(--border-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: bs-spin 0.8s linear infinite;
}

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

/* ---------------------------------------------------------------------------
 * 9. BUTTONS & ACTION LAYOUTS (Android 48px Touch Targets)
 * --------------------------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  touch-action: manipulation;
  transition: opacity 0.15s ease, transform 0.1s ease, background-color 0.15s ease, border-color 0.15s ease;
}

.btn:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

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

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-full {
  width: 100%;
}

.btn-sm {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 0.82rem;
  border-radius: var(--radius-sm);
}

.btn-primary {
  background: var(--primary-gradient);
  color: var(--primary-text);
  box-shadow: 0 6px 18px rgba(56, 189, 248, 0.22);
}

.btn-primary:hover:not(:disabled) {
  opacity: 0.94;
}

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

.btn-secondary:hover:not(:disabled) {
  background: var(--surface-hover);
}

.btn-danger {
  background: var(--danger-solid);
  color: #ffffff;
}

.btn-danger:hover:not(:disabled) {
  opacity: 0.92;
}

.btn-danger-outline {
  background: transparent;
  border-color: var(--danger-border);
  color: var(--danger);
}

.btn-danger-outline:hover:not(:disabled) {
  background: var(--danger-bg);
}

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

.btn-ghost:hover:not(:disabled) {
  color: var(--text);
  background: var(--surface-elevated);
}

.btn-icon {
  width: 34px;
  height: 34px;
  flex-shrink: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  touch-action: manipulation;
}

.btn-icon:hover,
.btn-icon:focus-visible {
  background: var(--danger-bg);
  color: var(--danger);
  outline: none;
}

.actions-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.actions-row {
  display: flex;
  gap: 10px;
}

.actions-row > .btn {
  flex: 1;
}

.actions-footer {
  padding-top: 8px;
  border-top: 1px solid var(--border);
}

.actions-footer-single {
  margin-top: 2px;
}

.extracted-section {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}

/* ---------------------------------------------------------------------------
 * 10. TOAST NOTIFICATION (Safe-Area Aware, Non-Blocking)
 * --------------------------------------------------------------------------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translate(-50%, 16px);
  max-width: calc(100vw - 32px);
  padding: 11px 16px;
  border-radius: var(--radius-pill);
  background: var(--surface-elevated);
  border: 1px solid var(--border-strong);
  color: var(--text);
  font-size: 0.86rem;
  font-weight: 500;
  text-align: center;
  box-shadow: var(--shadow-toast);
  opacity: 0;
  pointer-events: none;
  z-index: 1000;
  transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------------------------------------------------------------------------
 * 11. SMALL PHONE & REDUCED MOTION POLISH
 * --------------------------------------------------------------------------- */
@media (max-width: 380px) {
  .card {
    padding: 16px;
  }

  .actions-row {
    flex-direction: column;
  }
}

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