:root {
  --bg-app: #090d16;
  --bg-gradient: radial-gradient(circle at 30% 0%, rgba(59, 130, 246, 0.15) 0%, rgba(15, 23, 42, 0) 70%),
                     radial-gradient(circle at 100% 40%, rgba(99, 102, 241, 0.12) 0%, transparent 60%);
  --surface-main: #111827;
  --surface-card: #162032;
  --surface-card-hover: #1c2a42;
  --surface-input: #0e1524;
  --border-subtle: rgba(255, 255, 255, 0.08);
  --border-highlight: rgba(99, 102, 241, 0.4);
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --primary-gradient: linear-gradient(135deg, #3b82f6 0%, #6366f1 100%);
  --accent-red: #ef4444;
  --accent-green: #10b981;
  --shadow-card: 0 8px 24px -6px rgba(0, 0, 0, 0.45);
  --shadow-floating: 0 16px 40px -10px rgba(0, 0, 0, 0.6), 0 0 20px rgba(59, 130, 246, 0.2);
  --radius-lg: 16px;
  --radius-md: 10px;
  --radius-sm: 6px;
  --transition: all 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-app);
  background-image: var(--bg-gradient);
  background-attachment: fixed;
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Fluid Container for Wide Screens */
.container-fluid {
  max-width: 1560px;
  margin: 0 auto;
  padding: 0 1.5rem;
  width: 100%;
}

/* Header */
.app-header {
  border-bottom: 1px solid var(--border-subtle);
  background: rgba(9, 13, 22, 0.85);
  backdrop-filter: blur(16px);
  position: sticky;
  top: 0;
  z-index: 40;
}

.header-content {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 68px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: inherit;
}

.brand-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-md);
  background: var(--primary-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.4);
}

.brand-icon svg {
  width: 20px;
  height: 20px;
}

.brand-text h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-badge {
  font-size: 0.68rem;
  padding: 2px 7px;
  border-radius: 20px;
  background: rgba(59, 130, 246, 0.2);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.4);
  text-transform: uppercase;
  font-weight: 600;
}

.brand-tagline {
  font-size: 0.72rem;
  color: var(--text-muted);
}

.network-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid rgba(16, 185, 129, 0.3);
  color: #34d399;
  font-size: 0.8rem;
  padding: 6px 14px;
  border-radius: 30px;
  cursor: pointer;
  transition: var(--transition);
}

.network-badge:hover {
  background: rgba(16, 185, 129, 0.2);
  border-color: rgba(16, 185, 129, 0.5);
}

.network-badge.badge-public-active {
  background: rgba(14, 165, 233, 0.15);
  border-color: rgba(56, 189, 248, 0.5);
  color: #38bdf8;
  box-shadow: 0 0 15px rgba(56, 189, 248, 0.2);
}

.network-badge.badge-public-active .pulse-dot {
  background: #38bdf8;
  box-shadow: 0 0 10px #38bdf8;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #10b981;
  box-shadow: 0 0 10px #10b981;
  animation: pulse 2s infinite;
  display: inline-block;
}

@keyframes pulse {
  0% { transform: scale(0.95); opacity: 0.8; }
  50% { transform: scale(1.2); opacity: 1; }
  100% { transform: scale(0.95); opacity: 0.8; }
}

/* Main Workspace Grid (Side-by-Side) */
.main-wrapper {
  flex: 1;
  padding: 1.5rem 0 6rem;
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(420px, 490px) 1fr;
  gap: 1.75rem;
  align-items: start;
}

@media (max-width: 1100px) {
  .workspace-grid {
    grid-template-columns: 1fr;
  }
}

/* Left Column */
.workspace-left {
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

.hero-mini h2 {
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
  color: #fff;
}

.hero-mini p {
  color: var(--text-secondary);
  font-size: 0.88rem;
  line-height: 1.45;
}

/* Upload Dropzone */
.dropzone-container {
  margin-bottom: 0;
}

.dropzone {
  border: 2px dashed rgba(255, 255, 255, 0.16);
  background: rgba(19, 27, 46, 0.6);
  backdrop-filter: blur(12px);
  border-radius: var(--radius-lg);
  padding: 2.25rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}

.dropzone:hover,
.dropzone.drag-over {
  border-color: var(--primary);
  background: rgba(59, 130, 246, 0.08);
  box-shadow: 0 0 25px rgba(59, 130, 246, 0.18);
  transform: translateY(-2px);
}

.dropzone-icon {
  width: 54px;
  height: 54px;
  margin: 0 auto 1rem;
  border-radius: 50%;
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
}

.dropzone:hover .dropzone-icon {
  transform: scale(1.08);
  background: var(--primary-gradient);
  color: #fff;
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.5);
}

.dropzone-icon svg {
  width: 26px;
  height: 26px;
}

.dropzone-title {
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 0.35rem;
}

.dropzone-subtitle {
  color: var(--text-muted);
  font-size: 0.82rem;
  margin-bottom: 1.25rem;
}

.btn-browse {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  background: var(--primary-gradient);
  color: #fff;
  font-weight: 600;
  font-size: 0.9rem;
  padding: 9px 20px;
  border-radius: 30px;
  border: none;
  cursor: pointer;
  transition: var(--transition);
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.35);
}

.btn-browse:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(59, 130, 246, 0.5);
}

/* Files Section */
.files-section {
  display: none;
}

.files-section.active {
  display: block;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  gap: 10px;
}

.section-title {
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.files-count-badge {
  background: rgba(59, 130, 246, 0.15);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.3);
  font-size: 0.75rem;
  padding: 2px 9px;
  border-radius: 20px;
  font-weight: 600;
}

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

.btn-sm {
  padding: 6px 12px;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-weight: 500;
  transition: var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.05);
  color: var(--text-primary);
}

.btn-sm:hover {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.2);
}

.btn-danger {
  color: #f87171;
  background: rgba(239, 68, 68, 0.1);
  border-color: rgba(239, 68, 68, 0.25);
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
  border-color: rgba(239, 68, 68, 0.5);
}

/* Cards Grid */
.cards-grid {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-bottom: 1.25rem;
  max-height: 380px;
  overflow-y: auto;
  padding-right: 4px;
}

.cards-grid::-webkit-scrollbar {
  width: 6px;
}
.cards-grid::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.15);
  border-radius: 4px;
}

/* File Card */
.file-card {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.85rem 1rem;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: var(--shadow-card);
  transition: transform 0.18s ease, box-shadow 0.18s ease, border-color 0.18s ease;
  user-select: none;
}

.file-card:hover {
  background: var(--surface-card-hover);
  border-color: rgba(255, 255, 255, 0.16);
}

.file-card.dragging {
  opacity: 0.4;
  transform: scale(0.98);
  border: 2px dashed var(--primary);
}

.file-card.drag-over-top {
  border-top: 3px solid #60a5fa;
  transform: translateY(-2px);
}

.file-card.drag-over-bottom {
  border-bottom: 3px solid #60a5fa;
  transform: translateY(2px);
}

/* Order Badge */
.order-badge {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  background: var(--primary-gradient);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1rem;
  box-shadow: 0 4px 10px rgba(59, 130, 246, 0.35);
  flex-shrink: 0;
}

/* Drag Handle */
.drag-handle {
  cursor: grab;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 4px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}

.drag-handle:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

.drag-handle:active {
  cursor: grabbing;
}

.drag-handle svg {
  width: 18px;
  height: 18px;
}

/* Card Info */
.card-info {
  flex: 1;
  min-width: 0;
}

.card-title {
  font-size: 0.92rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 2px;
}

.card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.card-meta span {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* Card Actions */
.card-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-subtle);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}

.icon-btn:hover:not(:disabled) {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
}

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

.icon-btn.btn-remove:hover {
  color: #f87171;
  background: rgba(239, 68, 68, 0.15);
  border-color: rgba(239, 68, 68, 0.3);
}

/* Config Panel */
.config-panel {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 1.15rem;
  display: grid;
  grid-template-columns: 1fr;
  gap: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.form-control {
  width: 100%;
  background: var(--surface-input);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
  font-size: 0.85rem;
  transition: var(--transition);
}

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

/* Right Column: Live Preview Panel */
.workspace-right {
  position: sticky;
  top: 84px;
}

.live-preview-panel {
  background: var(--surface-card);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  height: calc(100vh - 108px);
  min-height: 600px;
}

.live-preview-header {
  padding: 0.85rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: rgba(17, 24, 39, 0.8);
  backdrop-filter: blur(10px);
}

.live-status-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.live-title {
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.preview-badge-sync {
  font-size: 0.72rem;
  padding: 2px 8px;
  border-radius: 12px;
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
  font-weight: 600;
}

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

.btn-preview-tool {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: var(--transition);
}

.btn-preview-tool:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
}

.btn-merge-quick {
  background: var(--primary-gradient);
  border: none;
  color: #fff;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 14px rgba(59, 130, 246, 0.4);
  transition: var(--transition);
}

.btn-merge-quick:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(59, 130, 246, 0.55);
}

.live-preview-body {
  flex: 1;
  background: #ffffff;
  position: relative;
  overflow: hidden;
}

.live-preview-body iframe {
  width: 100%;
  height: 100%;
  border: none;
  display: block;
}

/* Empty State in Preview */
.preview-empty {
  height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2.5rem;
  text-align: center;
  background: #0d1322;
}

.empty-icon {
  width: 68px;
  height: 68px;
  margin-bottom: 1.25rem;
  color: #3b82f6;
  opacity: 0.45;
}

.empty-icon svg {
  width: 100%;
  height: 100%;
}

.preview-empty h4 {
  font-size: 1.15rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
}

.preview-empty p {
  font-size: 0.85rem;
  color: var(--text-muted);
  max-width: 360px;
  line-height: 1.5;
}

/* Sticky Bottom Action Bar (Mobile only or extra convenience) */
.bottom-bar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(17, 24, 39, 0.9);
  backdrop-filter: blur(16px);
  border-top: 1px solid var(--border-subtle);
  padding: 0.75rem 0;
  z-index: 50;
  box-shadow: 0 -8px 24px rgba(0, 0, 0, 0.5);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.bottom-bar.visible {
  transform: translateY(0);
}

.bottom-bar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}

.bar-summary {
  display: flex;
  align-items: center;
  gap: 10px;
}

.bar-summary-text {
  font-size: 0.9rem;
  font-weight: 600;
}

.bar-summary-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.bar-buttons {
  display: flex;
  align-items: center;
  gap: 10px;
}

.btn-merge {
  background: var(--primary-gradient);
  border: none;
  color: #fff;
  padding: 8px 24px;
  border-radius: 30px;
  font-size: 0.9rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  box-shadow: 0 4px 16px rgba(59, 130, 246, 0.45);
  transition: var(--transition);
}

.btn-merge:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(59, 130, 246, 0.6);
}

/* Network Info Modal */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(8px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.modal-backdrop.active {
  opacity: 1;
  pointer-events: auto;
}

.modal-container {
  background: var(--surface-main);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 520px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  box-shadow: var(--shadow-floating);
  transform: scale(0.96);
  transition: transform 0.2s ease;
}

.modal-backdrop.active .modal-container {
  transform: scale(1);
}

.modal-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}

.network-modal-body {
  padding: 1.25rem;
  font-size: 0.88rem;
  color: var(--text-secondary);
}

.network-links-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 1rem;
}

.network-link-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface-input);
  border: 1px solid var(--border-subtle);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-family: monospace;
  color: #60a5fa;
  font-size: 0.88rem;
}

.btn-copy {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--border-subtle);
  color: var(--text-primary);
  padding: 4px 10px;
  border-radius: 4px;
  font-size: 0.75rem;
  cursor: pointer;
  transition: var(--transition);
}

.btn-copy:hover {
  background: var(--primary);
  border-color: var(--primary);
}

.network-public-card {
  background: linear-gradient(135deg, rgba(14, 165, 233, 0.12), rgba(16, 185, 129, 0.12));
  border: 1px solid rgba(56, 189, 248, 0.4);
  border-radius: var(--radius-md);
  padding: 14px;
  margin-bottom: 16px;
}

.network-public-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 6px;
  font-weight: 700;
  color: #38bdf8;
  font-size: 0.85rem;
  letter-spacing: 0.02em;
}

.badge-online {
  background: rgba(16, 185, 129, 0.2);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
  font-size: 0.7rem;
  padding: 2px 8px;
  border-radius: 12px;
  font-weight: 600;
}

.network-public-url-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.35);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid rgba(56, 189, 248, 0.25);
  margin-top: 8px;
}

.network-public-url {
  color: #7dd3fc;
  font-family: monospace;
  font-size: 0.85rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  text-decoration: none;
}

.network-public-url:hover {
  text-decoration: underline;
}

.btn-copy-public {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  font-weight: 600;
}

.btn-copy-public:hover {
  background: var(--primary-hover);
}

.network-lan-title {
  font-weight: 600;
  font-size: 0.82rem;
  color: var(--text-secondary);
  margin: 12px 0 6px 0;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 80px;
  right: 24px;
  z-index: 120;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: rgba(19, 27, 46, 0.95);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-subtle);
  padding: 10px 16px;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-floating);
  color: #fff;
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: toastIn 0.3s ease;
}

.toast.toast-success {
  border-left: 4px solid #10b981;
}

.toast.toast-info {
  border-left: 4px solid #3b82f6;
}

.toast.toast-error {
  border-left: 4px solid #ef4444;
}

@keyframes toastIn {
  from { transform: translateX(50px); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
