:root {
  --bg-primary: #f8fafc;
  --bg-surface: #ffffff;
  --bg-subtle: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --text-subtle: #94a3b8;
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-subtle: #eff6ff;
  --accent-success: #10b981;
  --accent-warning: #f59e0b;
  --accent-danger: #ef4444;
  --border-color: #e2e8f0;
  --border-focus: #3b82f6;
  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.08), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.04);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  color: var(--text-main);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

/* Utilities */
.hidden { display: none !important; }

/* ================= AUTH LOCK SCREEN ================= */
.auth-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: radial-gradient(circle at 50% 20%, #e2e8f0 0%, #f8fafc 100%);
}

.auth-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 40px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.auth-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--primary-subtle);
  color: var(--primary);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 4px 12px;
  border-radius: 9999px;
  margin-bottom: 20px;
}

.auth-title {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-main);
  margin-bottom: 8px;
}

.auth-subtitle {
  font-size: 0.92rem;
  color: var(--text-muted);
  margin-bottom: 28px;
}

.pin-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.pin-input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.pin-input-group input {
  width: 100%;
  padding: 14px 44px 14px 18px;
  font-size: 1.25rem;
  letter-spacing: 0.15em;
  text-align: center;
  border: 2px solid var(--border-color);
  border-radius: var(--radius-md);
  outline: none;
  background: var(--bg-surface);
  color: var(--text-main);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.pin-input-group input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.btn-toggle-vis {
  position: absolute;
  right: 12px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  opacity: 0.6;
}
.btn-toggle-vis:hover { opacity: 1; }

.auth-error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #b91c1c;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  text-align: left;
}

.auth-footer {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--border-color);
  font-size: 0.8rem;
  color: var(--text-muted);
  line-height: 1.4;
}

/* Buttons */
.btn-primary {
  background-color: var(--primary);
  color: #ffffff;
  border: none;
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background-color 0.15s ease, transform 0.05s ease;
  text-decoration: none;
}
.btn-primary:hover { background-color: var(--primary-hover); }
.btn-primary:active { transform: scale(0.99); }

.btn-block { width: 100%; }

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-main);
  border: 1px solid var(--border-color);
  padding: 8px 16px;
  font-size: 0.88rem;
  font-weight: 500;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}
.btn-secondary:hover {
  background: var(--bg-subtle);
  border-color: #cbd5e1;
}

.btn-panic {
  background: #fee2e2;
  color: #991b1b;
  border: 1px solid #fecaca;
  padding: 8px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s ease;
}
.btn-panic:hover {
  background: #fca5a5;
  color: #7f1d1d;
}

.btn-danger {
  background: #ef4444;
  color: #ffffff;
  border: none;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
}
.btn-danger:hover { background: #dc2626; }

.btn-sm { font-size: 0.8rem; padding: 6px 12px; }

.btn-icon {
  background: none;
  border: none;
  font-size: 1.1rem;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
}
.btn-icon:hover { color: var(--text-main); background: var(--bg-subtle); }

/* ================= MAIN APPLICATION LAYOUT ================= */
.app-layout {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Header */
.app-header {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-color);
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-sm);
}

.header-left {
  display: flex;
  align-items: center;
  gap: 16px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
}
.brand-icon { font-size: 1.4rem; }
.brand-name {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.session-pill {
  font-size: 0.75rem;
  font-weight: 600;
  background: #ecfdf5;
  color: #065f46;
  border: 1px solid #a7f3d0;
  padding: 2px 8px;
  border-radius: 9999px;
}

.nav-tabs {
  display: flex;
  gap: 6px;
  background: var(--bg-subtle);
  padding: 4px;
  border-radius: var(--radius-md);
}

.nav-tab {
  background: transparent;
  border: none;
  padding: 8px 16px;
  font-size: 0.88rem;
  font-weight: 500;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s ease;
}

.nav-tab:hover {
  color: var(--text-main);
}

.nav-tab.active {
  background: var(--bg-surface);
  color: var(--text-main);
  font-weight: 600;
  box-shadow: var(--shadow-sm);
}

.counter-badge {
  background: var(--primary);
  color: white;
  font-size: 0.75rem;
  padding: 2px 7px;
  border-radius: 9999px;
  font-weight: 600;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-muted);
  background: var(--bg-subtle);
  padding: 4px 10px;
  border-radius: 9999px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
}
.status-dot.connected { background: var(--accent-success); box-shadow: 0 0 6px rgba(16, 185, 129, 0.6); }
.status-dot.connecting { background: var(--accent-warning); }
.status-dot.disconnected { background: var(--accent-danger); }

/* Main Content Area */
.app-content {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  padding: 28px 24px 60px;
}

.tab-panel {
  display: none;
}
.tab-panel.active {
  display: block;
  animation: fadeIn 0.15s ease-in-out;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
}

.panel-title {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text-main);
}

.panel-subtitle {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-top: 4px;
}

/* Toolbar */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 14px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 260px;
  max-width: 440px;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 0.9rem;
  opacity: 0.5;
}

.search-box input {
  width: 100%;
  padding: 9px 14px 9px 36px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  outline: none;
  background: var(--bg-surface);
}
.search-box input:focus {
  border-color: var(--border-focus);
}

.filter-chips {
  display: flex;
  gap: 8px;
}

.chip {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  color: var(--text-muted);
  padding: 6px 14px;
  font-size: 0.82rem;
  font-weight: 500;
  border-radius: 9999px;
  cursor: pointer;
  transition: all 0.15s ease;
}
.chip:hover {
  background: var(--bg-subtle);
  color: var(--text-main);
}
.chip.active {
  background: var(--text-main);
  border-color: var(--text-main);
  color: #ffffff;
}

/* File Grid */
.file-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 16px;
}

.file-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
}

.file-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: #cbd5e1;
}

.file-card-top {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin-bottom: 12px;
}

.file-type-icon {
  font-size: 2rem;
  line-height: 1;
}

.file-main-info {
  flex: 1;
  min-width: 0;
}

.file-title {
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.file-meta-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.78rem;
  color: var(--text-muted);
}

.file-caption-box {
  background: var(--bg-subtle);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.85rem;
  color: var(--text-main);
  margin-bottom: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 120px;
  overflow-y: auto;
}

.file-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: auto;
  padding-top: 10px;
  border-top: 1px solid var(--border-color);
}

.file-actions .btn-download {
  flex: 1;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 60px 20px;
  background: var(--bg-surface);
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  margin-top: 20px;
}
.empty-icon { font-size: 3rem; margin-bottom: 14px; }
.empty-state h3 { font-size: 1.15rem; font-weight: 600; margin-bottom: 6px; }
.empty-state p { font-size: 0.9rem; color: var(--text-muted); max-width: 480px; margin: 0 auto; }

/* ================= TAB 2: UPLOAD STYLES ================= */
.upload-container {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 24px;
}

@media (max-width: 860px) {
  .upload-container { grid-template-columns: 1fr; }
}

.upload-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 28px;
  box-shadow: var(--shadow-sm);
}

.drop-zone {
  border: 2px dashed #93c5fd;
  background: #f8fafc;
  border-radius: var(--radius-md);
  padding: 36px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  margin-bottom: 20px;
}

.drop-zone.drag-over {
  background: #eff6ff;
  border-color: var(--primary);
  transform: scale(1.01);
}

.file-input {
  display: none;
}

.drop-icon { font-size: 2.8rem; margin-bottom: 10px; }
.drop-zone h3 { font-size: 1.05rem; font-weight: 600; margin-bottom: 4px; }
.drop-zone p { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 14px; }

.selected-file-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  border-radius: var(--radius-sm);
  padding: 10px 14px;
}

.file-preview-mini {
  display: flex;
  align-items: center;
  gap: 10px;
}
.file-mini-icon { font-size: 1.4rem; }
.file-mini-meta { text-align: left; }
.file-mini-name { font-weight: 600; font-size: 0.9rem; display: block; color: var(--text-main); }
.file-mini-size { font-size: 0.78rem; color: var(--text-muted); }

.form-group {
  margin-bottom: 18px;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
  margin-bottom: 6px;
}

.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  resize: vertical;
}
.form-group textarea:focus {
  border-color: var(--border-focus);
}

.recipient-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-subtle);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 20px;
  font-size: 0.85rem;
}
.recipient-label { color: var(--text-muted); }
.recipient-badge { font-weight: 600; color: #047857; }

.btn-large {
  width: 100%;
  padding: 14px;
  font-size: 1rem;
}

.progress-bar-container {
  margin-top: 16px;
}
.progress-bar {
  height: 6px;
  background: var(--bg-subtle);
  border-radius: 9999px;
  overflow: hidden;
}
.progress-bar-fill {
  height: 100%;
  width: 0%;
  background: var(--primary);
  transition: width 0.2s ease;
}
.progress-text {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 6px;
  display: block;
  text-align: center;
}

.upload-alert {
  margin-top: 16px;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}
.upload-alert.success {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #065f46;
}
.upload-alert.error {
  background: #fef2f2;
  border: 1px solid #fecaca;
  color: #991b1b;
}

.tips-card {
  background: #f0fdf4;
  border: 1px solid #bbf7d0;
  border-radius: var(--radius-lg);
  padding: 24px;
  height: fit-content;
}
.tips-card h4 {
  font-size: 0.95rem;
  font-weight: 700;
  color: #166534;
  margin-bottom: 12px;
}
.tips-card ul {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.tips-card li {
  font-size: 0.85rem;
  color: #14532d;
  line-height: 1.4;
}

/* ================= TAB 3: SETTINGS STYLES ================= */
.settings-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
}
@media (max-width: 768px) {
  .settings-grid { grid-template-columns: 1fr; }
}

.settings-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 22px;
}
.settings-card h3 {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 16px;
}

.status-detail-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--bg-subtle);
  padding: 14px;
  border-radius: var(--radius-sm);
}
.status-row {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
}
.status-row span { color: var(--text-muted); }

.pairing-box {
  margin-top: 18px;
  padding-top: 16px;
  border-top: 1px solid var(--border-color);
}
.pairing-box h4 { font-size: 0.95rem; margin-bottom: 6px; }
.pairing-box p { font-size: 0.82rem; color: var(--text-muted); margin-bottom: 12px; }

.pairing-form {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
}
.pairing-form input {
  flex: 1;
  padding: 8px 12px;
  font-size: 0.88rem;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
}

.code-display {
  background: #fef3c7;
  border: 1px solid #fde68a;
  padding: 12px;
  border-radius: var(--radius-sm);
  text-align: center;
  margin-top: 10px;
}
.code-display span { font-size: 0.8rem; color: #92400e; display: block; margin-bottom: 6px; }
.code-box {
  font-size: 1.5rem;
  font-weight: 800;
  letter-spacing: 0.2em;
  color: #78350f;
  font-family: monospace;
}

.qr-container {
  margin-top: 14px;
  text-align: center;
}
.qr-container img {
  max-width: 220px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 8px;
  background: white;
  margin-top: 6px;
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}
.modal-card {
  background: white;
  border-radius: var(--radius-lg);
  max-width: 720px;
  width: 100%;
  max-height: 85vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.modal-header h3 { font-size: 1.05rem; font-weight: 600; }
.modal-body {
  padding: 20px;
  overflow-y: auto;
  flex: 1;
}
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
}

/* Alert Banner */
.alert-banner {
  padding: 12px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  font-size: 0.9rem;
}
.alert-banner.warning {
  background: #fffbeb;
  border-bottom: 1px solid #fde68a;
  color: #92400e;
}
.banner-content {
  display: flex;
  align-items: center;
  gap: 8px;
}

.code-steps {
  text-align: left;
  font-size: 0.82rem;
  color: #78350f;
  margin-bottom: 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
