:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-hover: #242836;
  --border: #2e3345;
  --text: #e8eaed;
  --text-muted: #9aa0b0;
  --primary: #5b8def;
  --primary-hover: #4a7de0;
  --danger: #ef5b5b;
  --success: #3ecf8e;
  --radius: 12px;
  --shadow: 0 8px 32px rgba(0,0,0,.4);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

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

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
}

.hidden { display: none !important; }

/* ========== AUTH ========== */
#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at top, #1a2035 0%, var(--bg) 70%);
  padding: 20px;
}

.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow);
}

.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--primary);
  margin-bottom: 8px;
}
.logo h1 { font-size: 1.75rem; font-weight: 700; color: var(--text); }
.subtitle { color: var(--text-muted); margin-bottom: 28px; font-size: 0.95rem; }

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 24px;
}
.tab {
  flex: 1;
  padding: 10px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
}
.tab.active { background: var(--bg-card); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.3); }

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 6px; font-weight: 500; }
.field input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  transition: border .2s;
}
.field input:focus { outline: none; border-color: var(--primary); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  border: none;
  border-radius: 10px;
  font-weight: 600;
  font-size: 0.95rem;
  cursor: pointer;
  transition: all .2s;
  font-family: inherit;
}
.btn.primary { background: var(--primary); color: #fff; width: 100%; }
.btn.primary:hover { background: var(--primary-hover); }
.btn.ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--bg-hover); color: var(--text); }
.btn.small { padding: 8px 14px; font-size: 0.85rem; width: auto; }
.btn.danger { background: var(--danger); color: #fff; }
.btn.icon {
  width: 36px; height: 36px; padding: 0;
  background: var(--bg-hover); color: var(--text-muted); border-radius: 8px;
}
.btn.icon:hover { color: var(--text); background: var(--border); }
.btn.icon.danger:hover { color: var(--danger); }

.form-error { color: var(--danger); font-size: 0.85rem; margin-top: 12px; min-height: 1.2em; }

/* ========== APP LAYOUT ========== */
#app-screen {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 240px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 12px;
  flex-shrink: 0;
}
.logo-sm {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  margin-bottom: 24px;
  color: var(--primary);
  font-weight: 700;
  font-size: 1.15rem;
}
.logo-sm span { color: var(--text); }

nav { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: 10px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 500;
  transition: all .15s;
  text-align: left;
}
.nav-item:hover { background: var(--bg-hover); color: var(--text); }
.nav-item.active { background: rgba(91,141,239,.15); color: var(--primary); }

.sidebar-footer {
  border-top: 1px solid var(--border);
  padding-top: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.user-info { display: flex; align-items: center; gap: 12px; padding: 0 8px; }
.avatar {
  width: 40px; height: 40px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--primary), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1rem;
}
.username { font-weight: 600; font-size: 0.9rem; }
.stats { font-size: 0.75rem; color: var(--text-muted); }

.main { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 28px;
  border-bottom: 1px solid var(--border);
}
.topbar h2 { font-size: 1.35rem; font-weight: 600; }

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px;
  width: 280px;
}
.search-box input {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 0.9rem;
  width: 100%;
  font-family: inherit;
}
.search-box input:focus { outline: none; }
.search-box svg { color: var(--text-muted); flex-shrink: 0; }

.view { flex: 1; overflow-y: auto; padding: 24px 28px; }

/* ========== FILES ========== */
.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}
.storage-bar {
  flex: 1;
  height: 6px;
  background: var(--bg-card);
  border-radius: 3px;
  overflow: hidden;
  max-width: 200px;
}
.storage-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #8b5cf6);
  border-radius: 3px;
  width: 0%;
  transition: width .4s;
}
.storage-text { font-size: 0.8rem; color: var(--text-muted); }

.files-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 16px;
}

.file-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  transition: all .2s;
  position: relative;
}
.file-card:hover { border-color: var(--primary); transform: translateY(-2px); box-shadow: 0 4px 20px rgba(0,0,0,.3); }

.file-icon {
  width: 48px; height: 48px;
  border-radius: 10px;
  background: var(--bg-hover);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 12px;
  font-size: 1.4rem;
}
.file-name {
  font-weight: 600;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 4px;
}
.file-meta { font-size: 0.75rem; color: var(--text-muted); margin-bottom: 12px; }

.file-actions {
  display: flex;
  gap: 6px;
  opacity: 0;
  transition: opacity .15s;
}
.file-card:hover .file-actions { opacity: 1; }

.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}
.empty-state svg { margin-bottom: 16px; opacity: .5; }
.empty-state p { margin-bottom: 20px; font-size: 1.05rem; }

/* ========== UPLOAD ========== */
.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 16px;
  padding: 60px 20px;
  text-align: center;
  transition: all .2s;
  background: var(--bg-card);
}
.upload-zone.dragover {
  border-color: var(--primary);
  background: rgba(91,141,239,.08);
}
.upload-zone svg { color: var(--text-muted); margin-bottom: 16px; }
.upload-zone p { color: var(--text-muted); margin-bottom: 16px; }
.upload-zone .hint { font-size: 0.8rem; margin-top: 16px; margin-bottom: 0; }

.upload-queue { margin-top: 24px; display: flex; flex-direction: column; gap: 10px; }
.upload-item {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 14px;
}
.upload-item .name { flex: 1; font-weight: 500; font-size: 0.9rem; }
.upload-item .progress {
  width: 120px; height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
}
.upload-item .progress-bar {
  height: 100%;
  background: var(--primary);
  width: 0%;
  transition: width .3s;
}
.upload-item.done .progress-bar { background: var(--success); }
.upload-item.error .progress-bar { background: var(--danger); }
.upload-item .status { font-size: 0.8rem; color: var(--text-muted); width: 80px; text-align: right; }

/* ========== TOAST & MODAL ========== */
.toast {
  position: fixed;
  bottom: 28px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  padding: 12px 24px;
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 1000;
  font-weight: 500;
  animation: slideUp .3s ease;
}
.toast.success { border-color: var(--success); color: var(--success); }
.toast.error { border-color: var(--danger); color: var(--danger); }

@keyframes slideUp {
  from { opacity: 0; transform: translateX(-50%) translateY(20px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.modal-content {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px;
  width: 90%;
  max-width: 400px;
}
.modal-content h3 { margin-bottom: 16px; }
.modal-content input {
  width: 100%;
  padding: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 1rem;
  font-family: inherit;
  margin-bottom: 20px;
}
.modal-content input:focus { outline: none; border-color: var(--primary); }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }
.modal-actions .btn { width: auto; }

/* Responsive */
@media (max-width: 768px) {
  #app-screen { flex-direction: column; }
  .sidebar {
    width: 100%;
    flex-direction: row;
    align-items: center;
    padding: 12px;
    gap: 8px;
    overflow-x: auto;
  }
  .logo-sm { margin-bottom: 0; }
  nav { flex-direction: row; flex: 1; }
  .sidebar-footer { border: none; padding: 0; flex-direction: row; align-items: center; }
  .user-info .stats { display: none; }
  .search-box { width: 160px; }
  .files-grid { grid-template-columns: 1fr 1fr; }
}
