:root {
  --bg-primary: #0a0e17;
  --bg-secondary: #111827;
  --bg-card: #162032;
  --bg-card-hover: #1c2940;
  --border-color: #24324a;
  --border-highlight: #3b82f6;
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --text-dim: #64748b;
  
  --primary: #0284c7;
  --primary-hover: #0369a1;
  --primary-glow: rgba(2, 132, 199, 0.25);
  
  --success: #10b981;
  --success-glow: rgba(16, 185, 129, 0.25);
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-glow: rgba(239, 68, 68, 0.25);
  
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 9999px;
  
  --font-family: 'Cairo', system-ui, -apple-system, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

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

html {
  height: 100%;
  overflow-y: auto;
  scroll-behavior: smooth;
}

body {
  background-color: var(--bg-primary);
  color: var(--text-main);
  font-family: var(--font-family);
  direction: rtl;
  min-height: 100%;
  height: auto;
  overflow-y: visible;
  display: flex;
  flex-direction: column;
  -webkit-font-smoothing: antialiased;
}

/* Header */
.app-header {
  background: rgba(17, 24, 39, 0.85);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-color);
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0.9rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1.5rem;
  flex-wrap: wrap;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.brand-logo {
  background: linear-gradient(135deg, #0284c7, #4f46e5);
  padding: 8px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 12px var(--primary-glow);
}

.brand-text h1 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #fff;
  letter-spacing: -0.3px;
}

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

/* Node Info Card */
.node-info-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-full);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  font-size: 0.8rem;
}

.status-indicator {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-weight: 600;
}

.pulse-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--warning);
  display: inline-block;
  box-shadow: 0 0 6px var(--warning);
  transition: all 0.3s;
}

.pulse-dot.online {
  background: var(--success);
  box-shadow: 0 0 8px var(--success);
  animation: pulse-ring 2s infinite;
}

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

.node-details {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  border-right: 1px solid var(--border-color);
  padding-right: 0.5rem;
}

.dns-name {
  font-family: var(--font-mono);
  color: #38bdf8;
  font-weight: 600;
  font-size: 0.78rem;
}

.node-ip {
  background: #1e293b;
  color: var(--text-dim);
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

/* Main Container */
.main-container {
  max-width: 1200px;
  width: 100%;
  margin: 1.2rem auto;
  padding: 0 1.2rem 5rem;
  flex: 1;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 0.9rem;
  margin-bottom: 1.5rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  padding: 0.85rem 1.1rem;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  gap: 0.9rem;
  transition: transform 0.2s, border-color 0.2s;
}

.stat-card:hover {
  transform: translateY(-2px);
  border-color: var(--border-highlight);
}

.stat-icon {
  font-size: 1.3rem;
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-blue { background: rgba(56, 189, 248, 0.12); color: #38bdf8; }
.icon-green { background: rgba(16, 185, 129, 0.12); color: #10b981; }
.icon-purple { background: rgba(129, 140, 248, 0.12); color: #818cf8; }

.stat-info {
  display: flex;
  flex-direction: column;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: #fff;
  font-family: var(--font-mono);
}

/* Section Header */
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.1rem;
  flex-wrap: wrap;
  gap: 0.8rem;
}

.section-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.section-desc {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.15rem;
}

/* Buttons */
.btn {
  font-family: var(--font-family);
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.45rem 0.95rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  transition: all 0.2s;
  text-decoration: none;
}

.btn-primary {
  background: linear-gradient(135deg, #0284c7, #2563eb);
  color: #fff;
  box-shadow: 0 4px 14px var(--primary-glow);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #0369a1, #1d4ed8);
  box-shadow: 0 6px 18px var(--primary-glow);
  transform: translateY(-1px);
}

.btn-success {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #fff;
  box-shadow: 0 4px 14px var(--success-glow);
}

.btn-success:hover {
  background: linear-gradient(135deg, #059669, #047857);
}

.btn-danger {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  color: #fff;
  box-shadow: 0 4px 14px var(--danger-glow);
}

.btn-outline {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  color: var(--text-main);
}

.btn-outline:hover {
  border-color: #475569;
  background: #1e293b;
}

.btn-danger-outline {
  background: transparent;
  border: 1px solid rgba(239, 68, 68, 0.4);
  color: #f87171;
}

.btn-danger-outline:hover {
  background: rgba(239, 68, 68, 0.15);
  border-color: #ef4444;
}

.btn-secondary {
  background: #334155;
  color: #f8fafc;
}

.btn-secondary:hover {
  background: #475569;
}

/* Apps Grid */
.apps-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1rem;
}

/* App Card */
.app-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1.1rem;
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  position: relative;
  transition: border-color 0.25s, box-shadow 0.25s;
}

.app-card.active {
  border-color: rgba(16, 185, 129, 0.5);
  box-shadow: 0 8px 20px rgba(16, 185, 129, 0.1);
}

.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.7rem;
}

.app-title-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.app-title {
  font-size: 0.98rem;
  font-weight: 700;
  color: #fff;
}

.card-badges {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
}

.badge {
  font-size: 0.74rem;
  font-weight: 700;
  padding: 0.22rem 0.65rem;
  border-radius: var(--radius-full);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.badge-mode-funnel {
  background: rgba(2, 132, 199, 0.18);
  color: #38bdf8;
  border: 1px solid rgba(2, 132, 199, 0.3);
}

.badge-mode-serve {
  background: rgba(129, 140, 248, 0.18);
  color: #818cf8;
  border: 1px solid rgba(129, 140, 248, 0.3);
}

.badge-local-port {
  background: #1e293b;
  color: #94a3b8;
  font-family: var(--font-mono);
  border: 1px solid #334155;
}

.badge-ts-port {
  background: #0f172a;
  color: #e2e8f0;
  font-family: var(--font-mono);
  border: 1px solid #38bdf8;
}

.card-status-pill {
  font-size: 0.76rem;
  font-weight: 700;
  padding: 0.25rem 0.75rem;
  border-radius: var(--radius-full);
}

.status-active {
  background: rgba(16, 185, 129, 0.18);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.4);
}

.status-inactive {
  background: rgba(100, 116, 139, 0.18);
  color: #94a3b8;
  border: 1px solid rgba(100, 116, 139, 0.3);
}

/* Health Bar */
.health-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  padding: 0.65rem 0.9rem;
  border-radius: var(--radius-md);
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}

.health-status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.health-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.health-dot.running {
  background: #10b981;
  box-shadow: 0 0 6px #10b981;
}

.health-dot.offline {
  background: #f59e0b;
}

.btn-test-server {
  background: transparent;
  border: 1px dashed #475569;
  color: #38bdf8;
  font-size: 0.72rem;
  font-family: var(--font-family);
  padding: 0.2rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
}

.btn-test-server:hover {
  background: rgba(56, 189, 248, 0.1);
  border-color: #38bdf8;
}

/* Public URL Box */
.url-box {
  background: #0b1120;
  border: 1px solid #1e293b;
  border-radius: var(--radius-md);
  padding: 0.65rem 0.9rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
}

.url-text {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: #38bdf8;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  direction: ltr;
  text-align: left;
}

.url-actions {
  display: flex;
  gap: 0.35rem;
}

.btn-icon-sm {
  background: #1e293b;
  border: 1px solid #334155;
  color: #cbd5e1;
  width: 32px;
  height: 32px;
  border-radius: var(--radius-sm);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-icon-sm:hover {
  background: #334155;
  color: #fff;
  border-color: #64748b;
}

/* Card Actions */
.card-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: auto;
}

.btn-toggle-publish {
  flex: 1;
  justify-content: center;
}

/* Empty State / Loading */
.loading-state, .empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 4rem 1.5rem;
  background: var(--bg-card);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-lg);
  color: var(--text-muted);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(56, 189, 248, 0.2);
  border-top-color: #38bdf8;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 1.2rem;
}

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

/* Modal Dialog */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  backdrop-filter: blur(5px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0.75rem;
}

.modal-dialog {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  max-width: 440px;
  width: 100%;
  max-height: 86vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 20px 40px -10px rgba(0, 0, 0, 0.6);
  animation: modal-enter 0.2s ease-out;
  overflow: hidden;
}

@keyframes modal-enter {
  from { opacity: 0; transform: scale(0.97); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.8rem 1.1rem;
  border-bottom: 1px solid var(--border-color);
  background: #0f172a;
}

.modal-header h3 {
  font-size: 0.98rem;
  font-weight: 700;
  color: #fff;
}

.btn-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
}

.btn-close:hover {
  color: #fff;
}

.modal-form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.modal-body-scroll {
  padding: 0.9rem 1.1rem;
  overflow-y: auto;
  flex: 1;
  scrollbar-width: thin;
  scrollbar-color: #334155 transparent;
}

.modal-body-scroll::-webkit-scrollbar {
  width: 5px;
}

.modal-body-scroll::-webkit-scrollbar-thumb {
  background: #334155;
  border-radius: 4px;
}

/* Form Styles */
.form-group {
  margin-bottom: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

label {
  font-size: 0.8rem;
  font-weight: 700;
  color: #cbd5e1;
}

input[type="text"], input[type="number"] {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  color: #fff;
  font-family: var(--font-family);
  font-size: 0.85rem;
  padding: 0.45rem 0.7rem;
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

input[type="text"]:focus, input[type="number"]:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px var(--primary-glow);
}

.input-hint {
  font-size: 0.68rem;
  color: var(--text-dim);
}

/* Quick Ports */
.quick-ports {
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  gap: 0.35rem;
  flex-wrap: wrap;
}

.quick-label {
  font-size: 0.72rem;
  color: var(--text-muted);
  width: 100%;
}

.btn-tag {
  background: #1e293b;
  border: 1px solid #334155;
  color: #cbd5e1;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  padding: 0.2rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

.btn-tag:hover {
  border-color: var(--primary);
  color: #38bdf8;
}

.btn-tag.active {
  background: rgba(2, 132, 199, 0.25);
  border-color: var(--primary);
  color: #38bdf8;
  font-weight: 700;
}

/* Mode Selector */
.mode-selector {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.mode-option {
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  cursor: pointer;
  transition: all 0.2s;
}

.mode-option.active {
  border-color: var(--primary);
  background: rgba(2, 132, 199, 0.08);
}

.mode-option input {
  margin-top: 0.2rem;
  accent-color: var(--primary);
}

.mode-title {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  color: #fff;
}

.mode-desc {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.1rem;
}

/* Preview Box */
.preview-box {
  background: #0f172a;
  border: 1px solid #1e293b;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-sm);
  margin-top: 0.2rem;
  margin-bottom: 0.2rem;
}

.preview-label {
  display: block;
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
}

.preview-box code {
  font-family: var(--font-mono);
  color: #38bdf8;
  font-size: 0.78rem;
  direction: ltr;
  display: block;
  text-align: left;
}

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.6rem;
  padding: 0.75rem 1.1rem;
  border-top: 1px solid var(--border-color);
  background: #0f172a;
}

/* Navigation Tabs */
.nav-tabs-bar {
  display: flex;
  gap: 0.6rem;
  margin-bottom: 1.4rem;
  border-bottom: 1px solid var(--border-color);
  padding-bottom: 0.5rem;
}

.nav-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text-muted);
  font-family: var(--font-family);
  font-size: 0.85rem;
  font-weight: 700;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  transition: all 0.2s;
}

.nav-tab:hover {
  color: #fff;
  background: #1e293b;
}

.nav-tab.active {
  background: #1e293b;
  color: #38bdf8;
  border-color: #0284c7;
}

.tab-badge {
  background: #0284c7;
  color: #fff;
  font-size: 0.68rem;
  padding: 1px 6px;
  border-radius: 9999px;
  font-family: var(--font-mono);
}

.tab-content {
  animation: tab-fade-in 0.2s ease-out;
}

@keyframes tab-fade-in {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Terminal Card (Dedicated Logs View) */
.terminal-card {
  background: #070b12;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  overflow: hidden;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
}

.terminal-header {
  background: #0f172a;
  padding: 0.65rem 1rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 1px solid #1e293b;
}

.terminal-title {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.82rem;
  color: #cbd5e1;
}

.terminal-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
}

.terminal-dot.red { background: #ef4444; }
.terminal-dot.yellow { background: #f59e0b; }
.terminal-dot.green { background: #10b981; }

.terminal-actions {
  display: flex;
  gap: 0.5rem;
}

.btn-sm {
  font-size: 0.74rem;
  padding: 0.25rem 0.6rem;
}

.terminal-body {
  padding: 1rem 1.2rem;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: #cbd5e1;
  direction: ltr;
  text-align: left;
  min-height: 420px;
  max-height: 65vh;
  overflow-y: auto;
  line-height: 1.6;
}

.log-entry {
  color: #cbd5e1;
  margin-bottom: 0.25rem;
}

.log-entry.system { color: #38bdf8; }
.log-entry.error { color: #f87171; }
.log-entry.success { color: #34d399; }

/* QR Code in App Cards */
.card-qr-section {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  background: #0a0e17;
  border: 1px solid #1e293b;
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.75rem;
}

.card-qr-box {
  background: #fff;
  padding: 4px;
  border-radius: 6px;
  width: 64px;
  height: 64px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
  flex-shrink: 0;
}

.card-qr-box:hover {
  transform: scale(1.06);
  box-shadow: 0 0 10px rgba(56, 189, 248, 0.4);
}

.card-qr-box canvas, .card-qr-box img {
  width: 100% !important;
  height: 100% !important;
  display: block;
}

.card-qr-details {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  flex: 1;
}

.qr-title {
  font-size: 0.78rem;
  font-weight: 700;
  color: #fff;
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.qr-desc {
  font-size: 0.7rem;
  color: var(--text-muted);
  line-height: 1.3;
}

.btn-qr-zoom {
  background: transparent;
  border: none;
  color: #38bdf8;
  font-size: 0.7rem;
  font-family: var(--font-family);
  cursor: pointer;
  padding: 0;
  text-align: right;
  text-decoration: underline;
  width: fit-content;
}

.btn-qr-zoom:hover {
  color: #7dd3fc;
}

.qr-canvas-wrapper {
  background: #fff;
  padding: 12px;
  border-radius: 10px;
  display: inline-block;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}

.qr-canvas-wrapper canvas, .qr-canvas-wrapper img {
  display: block;
}

.modal-dialog-sm {
  max-width: 350px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 1.5rem;
  left: 1.5rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.toast {
  background: #1e293b;
  border: 1px solid #334155;
  color: #fff;
  padding: 0.75rem 1.2rem;
  border-radius: var(--radius-md);
  font-size: 0.88rem;
  box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  animation: toast-in 0.25s ease-out;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(-10px); }
  to { opacity: 1; transform: translateY(0); }
}

.toast.success { border-color: #10b981; }
.toast.error { border-color: #ef4444; }

@media (max-width: 768px) {
  .header-container { flex-direction: column; align-items: stretch; }
  .node-info-card { justify-content: space-between; }
  .form-row { grid-template-columns: 1fr; }
}
