/* ===== RESET & BASE ===== */
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }

:root {
  --bg-primary: #f8f9fc;
  --bg-secondary: #ffffff;
  --bg-card: rgba(255, 255, 255, 0.85);
  --bg-card-hover: rgba(245, 247, 255, 0.95);
  --border: rgba(99, 102, 241, 0.15);
  --border-hover: rgba(99, 102, 241, 0.35);
  --text-primary: #1e293b;
  --text-secondary: #475569;
  --text-muted: #94a3b8;
  --accent: #6366f1;
  --accent-light: #818cf8;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --node1: #6366f1;
  --node2: #ec4899;
  --node3: #10b981;
  --sidebar-width: 260px;
  --radius: 12px;
  --radius-sm: 8px;
  --glass: rgba(99,102,241,0.04);
  --shadow: 0 4px 24px rgba(0,0,0,0.06);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.08);
}

html { font-size: 15px; }

body {
  font-family: 'Inter', -apple-system, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  overflow-x: hidden;
}

.hidden { display: none !important; }

/* ===== ANIMATED BACKGROUND ===== */
.bg-grid {
  position: fixed; inset: 0; z-index: 0;
  background-image:
    linear-gradient(rgba(99,102,241,0.04) 1px, transparent 1px),
    linear-gradient(90deg, rgba(99,102,241,0.04) 1px, transparent 1px);
  background-size: 60px 60px;
  pointer-events: none;
}

.bg-glow {
  position: fixed; border-radius: 50%; filter: blur(120px); opacity: 0.10;
  pointer-events: none; z-index: 0;
  animation: glowFloat 12s ease-in-out infinite alternate;
}
.bg-glow-1 { width: 500px; height: 500px; top: -100px; right: -100px; background: var(--accent); }
.bg-glow-2 { width: 400px; height: 400px; bottom: -100px; left: 10%; background: #ec4899; animation-delay: -6s; }

@keyframes glowFloat {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(30px, 20px) scale(1.1); }
}

/* ===== AUTH SCREEN ===== */
.auth-screen {
  min-height: 100vh;
  display: flex; align-items: center; justify-content: center;
  position: relative; z-index: 1;
  background: linear-gradient(135deg, #f0f4ff 0%, #fdf2f8 50%, #f0fdf4 100%);
}

.auth-container { width: 100%; max-width: 420px; padding: 20px; position: relative; z-index: 2; }

.auth-brand { text-align: center; margin-bottom: 32px; }
.auth-logo { font-size: 3.5rem; margin-bottom: 8px; }
.auth-brand h1 { font-size: 2rem; font-weight: 800; letter-spacing: -1px; color: #1e293b; }
.auth-brand p { color: var(--text-muted); font-size: 0.85rem; margin-top: 4px; text-transform: uppercase; letter-spacing: 2px; }

.auth-card {
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
  box-shadow: var(--shadow-lg);
}

.auth-title { font-size: 1.35rem; font-weight: 700; margin-bottom: 4px; color: #1e293b; }
.auth-subtitle { color: var(--text-muted); font-size: 0.85rem; margin-bottom: 24px; }

.form-group { margin-bottom: 18px; }
.form-group label {
  display: block; font-size: 0.78rem; font-weight: 600;
  color: var(--text-secondary); margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.form-group input, .form-group select {
  width: 100%; padding: 12px 16px;
  background: #f8f9fc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit; font-size: 0.92rem;
  outline: none; transition: border-color 0.2s;
}
.form-group input::placeholder { color: var(--text-muted); }
.form-group input:focus, .form-group select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(99,102,241,0.1); }
.form-group select { cursor: pointer; }
.form-group select option { background: #fff; }

.btn-primary {
  width: 100%; padding: 13px;
  background: linear-gradient(135deg, var(--accent), #818cf8);
  border: none; border-radius: var(--radius-sm);
  color: white; font-family: inherit;
  font-size: 0.95rem; font-weight: 600;
  cursor: pointer; transition: all 0.3s;
  margin-top: 8px;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 8px 24px rgba(99,102,241,0.3); }

.auth-switch {
  text-align: center; margin-top: 20px;
  font-size: 0.85rem; color: var(--text-muted);
}
.auth-switch a { color: var(--accent); text-decoration: none; font-weight: 600; }

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: var(--sidebar-width);
  background: #ffffff;
  border-right: 1px solid #e2e8f0;
  display: flex; flex-direction: column;
  z-index: 100;
  padding: 24px 16px;
}

.sidebar-brand {
  display: flex; align-items: center; gap: 12px;
  padding: 0 8px 24px;
  border-bottom: 1px solid #e2e8f0;
  margin-bottom: 24px;
}
.brand-icon { font-size: 2rem; }
.brand-title { font-size: 1.25rem; font-weight: 700; letter-spacing: -0.5px; color: #1e293b; }
.brand-sub { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 1px; }

.sidebar-nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }

.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-radius: var(--radius-sm);
  color: var(--text-secondary); text-decoration: none;
  font-weight: 500; font-size: 0.93rem;
  transition: all 0.2s;
}
.nav-item:hover { background: #f1f5f9; color: var(--text-primary); }
.nav-item.active {
  background: rgba(99,102,241,0.08);
  color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
  font-weight: 600;
}
.nav-icon { font-size: 1.15rem; }

.sidebar-footer { padding-top: 16px; border-top: 1px solid #e2e8f0; }

.user-info { display: flex; align-items: center; gap: 10px; padding: 8px; }
.user-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #818cf8);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.85rem; flex-shrink: 0; color: #fff;
}
.user-details { flex: 1; min-width: 0; }
.user-name { display: block; font-size: 0.85rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #1e293b; }
.user-role { display: block; font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.logout-btn {
  background: none; border: 1px solid #e2e8f0;
  color: var(--text-muted); width: 32px; height: 32px;
  border-radius: var(--radius-sm); cursor: pointer;
  font-size: 1rem; transition: all 0.2s; flex-shrink: 0;
}
.logout-btn:hover { border-color: var(--danger); color: var(--danger); background: #fef2f2; }

/* ===== MAIN CONTENT ===== */
.app-wrapper { display: flex; min-height: 100vh; position: relative; }
.main-content {
  margin-left: var(--sidebar-width);
  padding: 32px 40px;
  position: relative; z-index: 1;
  min-height: 100vh; flex: 1;
  background: var(--bg-primary);
}

/* ===== PAGES ===== */
.page { display: none; animation: fadeIn 0.35s ease; }
.page.active { display: block; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: none; } }

.page-header { margin-bottom: 32px; }
.page-title { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.5px; color: #1e293b; }
.page-subtitle { color: var(--text-muted); font-size: 0.9rem; margin-top: 4px; display: block; }

/* ===== STAT CARDS ===== */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 20px; margin-bottom: 32px; }

.stat-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius);
  padding: 24px;
  display: flex; align-items: center; gap: 20px;
  transition: all 0.3s;
}
.stat-card:hover { border-color: var(--border-hover); transform: translateY(-2px); box-shadow: var(--shadow-lg); }

.stat-icon {
  width: 52px; height: 52px; border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem; flex-shrink: 0;
}
.stat-value { font-size: 1.65rem; font-weight: 700; display: block; color: #1e293b; }
.stat-label { font-size: 0.8rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }

/* ===== CARDS ===== */
.card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 24px;
  transition: all 0.3s;
}
.card:hover { box-shadow: var(--shadow); }
.card-title { font-size: 1.05rem; font-weight: 600; margin-bottom: 20px; color: #1e293b; }

.dashboard-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }

/* ===== NODE BARS ===== */
.node-bar-item { margin-bottom: 20px; }
.node-bar-label { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 6px; color: var(--text-secondary); }
.node-bar-track { height: 10px; background: #f1f5f9; border-radius: 5px; overflow: hidden; }
.node-bar-fill { height: 100%; border-radius: 5px; transition: width 0.8s ease; }
.node-bar-fill.n1 { background: linear-gradient(90deg, var(--node1), #818cf8); }
.node-bar-fill.n2 { background: linear-gradient(90deg, var(--node2), #f9a8d4); }
.node-bar-fill.n3 { background: linear-gradient(90deg, var(--node3), #6ee7b7); }

/* ===== RECENT LIST ===== */
.recent-list .recent-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid #f1f5f9;
  font-size: 0.88rem;
}
.recent-item:last-child { border-bottom: none; }
.recent-item-name { font-weight: 500; color: #1e293b; }
.recent-item-meta { color: var(--text-muted); font-size: 0.78rem; }
.empty-state { color: var(--text-muted); text-align: center; padding: 32px; font-size: 0.9rem; }

/* ===== UPLOAD ZONE ===== */
.upload-card { margin-bottom: 24px; }
.upload-zone {
  border: 2px dashed #cbd5e1;
  border-radius: var(--radius);
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: all 0.3s;
  background: #fafbff;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--accent);
  background: rgba(99,102,241,0.04);
}
.upload-icon { font-size: 3rem; margin-bottom: 12px; }
.upload-text { font-size: 1rem; color: var(--text-secondary); }
.upload-link { color: var(--accent); cursor: pointer; text-decoration: underline; font-weight: 600; }
.upload-hint { font-size: 0.78rem; color: var(--text-muted); margin-top: 8px; }
.hidden-input { display: none; }

.upload-progress { padding: 16px 0; }
.progress-info { display: flex; justify-content: space-between; font-size: 0.85rem; margin-bottom: 8px; color: var(--text-secondary); }
.progress-bar { height: 8px; background: #f1f5f9; border-radius: 4px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: linear-gradient(90deg, var(--accent), var(--accent-light)); border-radius: 4px; transition: width 0.3s; }

/* ===== FILE TABLE ===== */
.table-wrapper { overflow-x: auto; }
.file-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.file-table th {
  text-align: left; padding: 12px 16px;
  color: var(--text-muted); font-weight: 600;
  text-transform: uppercase; font-size: 0.72rem;
  letter-spacing: 0.5px;
  border-bottom: 2px solid #f1f5f9;
}
.file-table td {
  padding: 14px 16px;
  border-bottom: 1px solid #f1f5f9;
  vertical-align: middle;
  color: var(--text-secondary);
}
.file-table tbody tr { transition: background 0.2s; }
.file-table tbody tr:hover { background: #f8f9fc; }
.empty-row td { color: var(--text-muted); text-align: center; padding: 32px; }

.encryption-badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(99,102,241,0.08); color: var(--accent);
  padding: 4px 10px; border-radius: 20px; font-size: 0.75rem; font-weight: 600;
}

.action-btn {
  background: none; border: 1px solid #e2e8f0;
  color: var(--text-secondary); padding: 6px 12px;
  border-radius: var(--radius-sm); cursor: pointer;
  font-size: 0.78rem; font-family: inherit;
  transition: all 0.2s; margin-right: 6px;
}
.action-btn:hover { border-color: var(--accent); color: var(--accent); background: rgba(99,102,241,0.04); }
.action-btn.danger:hover { border-color: var(--danger); color: var(--danger); background: #fef2f2; }

.star-btn {
  background: none; border: none; cursor: pointer;
  font-size: 1.2rem; transition: transform 0.2s; padding: 4px;
}
.star-btn:hover { transform: scale(1.3); }
.star-btn.starred { animation: starPop 0.3s ease; }
@keyframes starPop { 0% { transform: scale(1); } 50% { transform: scale(1.5); } 100% { transform: scale(1); } }

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.3);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; backdrop-filter: blur(4px);
}
.modal-overlay.hidden { display: none; }
.modal {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius);
  width: 90%; max-width: 700px; max-height: 80vh;
  overflow-y: auto;
  box-shadow: 0 24px 64px rgba(0,0,0,0.12);
}
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 20px 24px; border-bottom: 1px solid #f1f5f9;
}
.modal-header h3 { font-size: 1.1rem; color: #1e293b; }
.modal-close {
  background: none; border: none; color: var(--text-muted);
  font-size: 1.2rem; cursor: pointer;
}
.modal-body { padding: 24px; }

.block-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 12px; }
.block-item {
  background: #f8f9fc;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 14px; text-align: center;
}
.block-item .block-idx { font-weight: 700; font-size: 1.1rem; color: #1e293b; }
.block-item .block-node { font-size: 0.78rem; color: var(--text-muted); margin-top: 4px; }
.block-item .block-size { font-size: 0.72rem; color: var(--text-muted); }
.block-item.node1 { border-left: 3px solid var(--node1); }
.block-item.node2 { border-left: 3px solid var(--node2); }
.block-item.node3 { border-left: 3px solid var(--node3); }

/* ===== NODES GRID ===== */
.nodes-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px; }

.node-card {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius);
  padding: 28px;
  text-align: center;
  transition: all 0.3s;
}
.node-card:hover { transform: translateY(-4px); box-shadow: var(--shadow-lg); border-color: var(--border-hover); }

.node-card-icon {
  width: 64px; height: 64px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.8rem; margin: 0 auto 16px;
}
.node-card.n1 .node-card-icon { background: rgba(99,102,241,0.1); }
.node-card.n2 .node-card-icon { background: rgba(236,72,153,0.1); }
.node-card.n3 .node-card-icon { background: rgba(16,185,129,0.1); }

.node-card-name { font-weight: 700; font-size: 1.1rem; margin-bottom: 4px; color: #1e293b; }
.node-card-status { font-size: 0.78rem; color: var(--success); display: flex; align-items: center; justify-content: center; gap: 6px; margin-bottom: 20px; }

.node-stat { display: flex; justify-content: space-between; padding: 10px 0; border-top: 1px solid #f1f5f9; font-size: 0.85rem; }
.node-stat-label { color: var(--text-muted); }
.node-stat-value { font-weight: 600; color: #1e293b; }

.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--success);
  box-shadow: 0 0 8px rgba(16,185,129,0.4);
  animation: pulse 2s infinite;
}
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }

.capacity-bar { margin-top: 16px; }
.capacity-label { display: flex; justify-content: space-between; font-size: 0.78rem; color: var(--text-muted); margin-bottom: 6px; }
.capacity-track { height: 8px; background: #f1f5f9; border-radius: 4px; overflow: hidden; }
.capacity-fill { height: 100%; border-radius: 4px; transition: width 0.8s; }
.n1 .capacity-fill { background: var(--node1); }
.n2 .capacity-fill { background: var(--node2); }
.n3 .capacity-fill { background: var(--node3); }

/* ===== ADMIN PANEL ===== */
.admin-grid { display: grid; gap: 24px; }
.config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0; }
.config-item {
  display: flex; justify-content: space-between; padding: 14px 16px;
  border-bottom: 1px solid #f1f5f9; font-size: 0.88rem;
}
.config-label { color: var(--text-muted); }
.config-value { font-weight: 600; color: var(--accent); }

/* ===== TOAST ===== */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 2000; display: flex; flex-direction: column; gap: 10px; }
.toast {
  background: #ffffff;
  border: 1px solid #e2e8f0;
  border-radius: var(--radius-sm);
  padding: 14px 20px;
  font-size: 0.88rem;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.35s ease;
  min-width: 280px;
  color: var(--text-secondary);
}
.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }
.toast.info { border-left: 3px solid var(--accent); }

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

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(99,102,241,0.2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(99,102,241,0.4); }

/* ===== RESPONSIVE ===== */
@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .dashboard-grid { grid-template-columns: 1fr; }
  .nodes-grid { grid-template-columns: 1fr 1fr; }
  .admin-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  html { font-size: 14px; }

  /* Mobile hamburger toggle */
  .mobile-toggle {
    display: flex !important;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 1000;
    width: 44px;
    height: 44px;
    align-items: center;
    justify-content: center;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    cursor: pointer;
    font-size: 1.4rem;
    box-shadow: var(--shadow);
    -webkit-tap-highlight-color: transparent;
  }

  /* Sidebar as overlay on mobile */
  .sidebar {
    position: fixed;
    top: 0;
    left: -280px;
    width: 260px;
    height: 100vh;
    z-index: 999;
    transition: left 0.3s ease;
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open {
    left: 0;
  }

  /* Overlay backdrop */
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 998;
  }
  .sidebar-overlay.active {
    display: block;
  }

  .main-content {
    margin-left: 0 !important;
    padding: 68px 16px 24px !important;
    width: 100%;
  }

  .stats-grid { grid-template-columns: 1fr 1fr; gap: 12px; }
  .stat-card { padding: 16px; }
  .stat-value { font-size: 1.5rem; }

  .nodes-grid { grid-template-columns: 1fr; }

  .page-header { margin-bottom: 20px; }
  .page-title { font-size: 1.5rem; }

  .table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .file-table { min-width: 600px; }

  .upload-zone { padding: 24px 16px; }
  .upload-icon { font-size: 2rem; }

  .card { padding: 20px; }

  .config-grid { grid-template-columns: 1fr 1fr; }

  .auth-container { padding: 16px; }
  .auth-brand h1 { font-size: 1.75rem; }
  .auth-logo { font-size: 2.5rem; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .config-grid { grid-template-columns: 1fr; }
  .stat-card { flex-direction: column; text-align: center; }
  .stat-icon { width: 48px; height: 48px; font-size: 1.3rem; margin-bottom: 8px; }
}

/* Mobile toggle hidden by default on desktop */
.mobile-toggle { display: none; }
.sidebar-overlay { display: none; }

