:root {
  /* Color Palette - Light Mode */
  --primary-hue: 250;
  --primary: hsl(var(--primary-hue), 70%, 60%);
  --primary-hover: hsl(var(--primary-hue), 70%, 50%);
  --primary-light: hsl(var(--primary-hue), 70%, 96%);

  --bg-body: #f8fafc;
  --bg-surface: #ffffff;
  --bg-surface-glass: rgba(255, 255, 255, 0.85);
  
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;

  --danger: #ef4444;
  --success: #22c55e;
  
  --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
  --shadow-lg: 0 10px 15px -3px rgb(0 0 0 / 0.1), 0 4px 6px -4px rgb(0 0 0 / 0.1);

  --radius-md: 0.5rem;
  --radius-lg: 0.75rem;
  
  --font-sans: 'Inter', system-ui, -apple-system, sans-serif;
}

[data-theme="dark"] {
  --bg-body: #0f172a;
  --bg-surface: #1e293b;
  --bg-surface-glass: rgba(30, 41, 59, 0.85);
  
  --text-main: #f8fafc;
  --text-muted: #94a3b8;
  --border-color: #334155;

  --primary-light: hsl(var(--primary-hue), 30%, 15%);
}

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

body {
  font-family: var(--font-sans);
  background-color: var(--bg-body);
  color: var(--text-main);
  line-height: 1.5;
  transition: background-color 0.3s ease, color 0.3s ease;
  overflow-x: hidden;
}

/* Utilities */
.hidden { display: none !important; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 0.5rem; }
.gap-4 { gap: 1rem; }
.w-full { width: 100%; }

/* Layout */
#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
}

/* Login Screen */
#login-screen {
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top right, var(--primary-light), transparent 40%),
              radial-gradient(circle at bottom left, var(--primary-light), transparent 40%);
}

.login-card {
  background: var(--bg-surface-glass);
  backdrop-filter: blur(12px);
  padding: 2.5rem;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 400px;
  border: 1px solid var(--border-color);
  animation: fadeUp 0.5s ease-out;
}

.login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-icon {
  width: 3rem;
  height: 3rem;
  color: var(--primary);
  margin-bottom: 1rem;
}

/* Main Layout: Sidebar + Content */
.app-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 260px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  padding: 1rem;
  transition: transform 0.3s ease;
  z-index: 20;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 0.5rem;
  margin-bottom: 2rem;
  font-weight: 700;
  font-size: 1.25rem;
  color: var(--primary);
}

.sidebar-nav {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.2s;
  font-weight: 500;
}

.nav-item:hover, .nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
}

.nav-item svg { width: 1.25rem; height: 1.25rem; }

.user-profile {
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1rem 0.5rem;
}

.avatar {
  width: 2.5rem;
  height: 2.5rem;
  background: var(--primary);
  color: white;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 1rem;
}

.user-info small {
  display: block;
  font-size: 0.75rem;
  color: var(--text-muted);
}

.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-body);
  position: relative;
  overflow: hidden;
}

/* Header / Toolbar */
.top-bar {
  padding: 1rem 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: var(--bg-surface-glass);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border-color);
  z-index: 10;
}

.search-bar {
  position: relative;
  width: 300px;
}

.search-bar input {
  width: 100%;
  padding: 0.6rem 1rem 0.6rem 2.5rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
  color: var(--text-main);
  transition: border-color 0.2s;
}

.search-bar input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.search-icon {
  position: absolute;
  left: 0.8rem;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  width: 1rem;
  height: 1rem;
}

/* Breadcrumbs */
.breadcrumb-container {
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.9rem;
  overflow-x: auto;
}

.breadcrumb-item {
  cursor: pointer;
  transition: color 0.2s;
}

.breadcrumb-item:hover { color: var(--primary); }
.breadcrumb-item.active { 
  color: var(--text-main); 
  font-weight: 600;
  cursor: default;
}
.breadcrumb-separator { color: var(--text-muted); opacity: 0.5; }

/* File Grid */
.file-area {
  flex: 1;
  overflow-y: auto;
  padding: 0 2rem 2rem;
  position: relative;
}

/* Catching Design / Drop Overlay */
.drop-overlay {
  position: absolute;
  top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg-surface-glass);
  backdrop-filter: blur(4px);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  z-index: 50;
  border: 4px dashed var(--primary);
  border-radius: var(--radius-lg);
  margin: 1rem;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.file-area.drag-over .drop-overlay {
  opacity: 1;
}

.files-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 1.5rem;
  padding-bottom: 2rem;
  margin-top: 10px;
}

.files-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.file-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 1rem;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  position: relative;
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  -moz-user-select: none;
  -ms-user-select: none;
}

.files-list .file-card {
  flex-direction: row;
  padding: 0.75rem 1rem;
  gap: 1rem;
  text-align: left;
}

/* Hover Effects V2 */
.file-card::after {
    content: '';
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--primary);
    opacity: 0;
    transition: opacity 0.2s;
    pointer-events: none;
    z-index: 0;
}

.file-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-lg);
  border-color: var(--primary);
}

.file-card:hover::after {
    opacity: 0.03;
}

.file-icon-wrapper {
  width: 3.5rem;
  height: 3.5rem;
  margin-bottom: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
  z-index: 1;
}

.file-thumbnail {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: var(--radius-md);
}

.files-list .file-icon-wrapper {
  width: 2.5rem;
  height: 2.5rem;
  margin-bottom: 0;
}

.file-icon { width: 100%; height: 100%; }

.file-icon.folder { color: #fbbf24; }
.file-icon.image { color: #8b5cf6; }
.file-icon.video { color: #ec4899; }
.file-icon.pdf { color: #ef4444; }
.file-icon.code { color: #10b981; }

.file-info {
  width: 100%;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.file-name {
  font-weight: 500;
  font-size: 0.9rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-bottom: 0.25rem;
  direction: auto; /* Arabic support */
}

/* Drag move target style */
.file-card.drag-target-folder {
    border: 2px dashed var(--primary);
    background: var(--primary-light);
}

.breadcrumb-item.drag-target-folder {
    background: var(--primary-light);
    color: var(--primary);
    border-radius: var(--radius-md);
    outline: 2px dashed var(--primary);
}

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

/* Modals */
.modal-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.active {
  opacity: 1;
  pointer-events: auto;
  display: flex;
}

.modal-content {
  background: var(--bg-surface);
  padding: 2rem;
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 500px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border-color);
  transform: scale(0.95);
  transition: transform 0.2s;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-overlay.active .modal-content {
  transform: scale(1);
}

/* Forms */
.form-group { margin-bottom: 1.25rem; }
.form-group label {
  display: block;
  margin-bottom: 0.5rem;
  font-weight: 500;
  font-size: 0.9rem;
}

input[type="text"], input[type="password"], select {
  width: 100%;
  padding: 0.75rem;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: var(--bg-body);
  color: var(--text-main);
  transition: border-color 0.2s;
}

input:focus, select:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-md);
  font-weight: 500;
  cursor: pointer;
  transition: all 0.2s;
  border: none;
  gap: 0.5rem;
  font-size: 0.9rem;
}

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

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

.btn-danger {
  background: #fee2e2;
  color: var(--danger);
}
.btn-danger:hover { background: #fecaca; }

.btn-block { width: 100%; }

/* Context Menu */
.context-menu {
  position: absolute;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: 0.5rem;
  z-index: 50;
  min-width: 160px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.1s;
}

.context-menu.active {
  opacity: 1;
  pointer-events: auto;
}

.menu-item {
  padding: 0.5rem 1rem;
  border-radius: var(--radius-md);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.9rem;
  color: var(--text-main);
}

.menu-item:hover {
  background: var(--primary-light);
  color: var(--primary);
}

.menu-item.danger:hover {
  background: #fee2e2;
  color: var(--danger);
}

/* Toast */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 200;
}

.toast {
  background: var(--bg-surface);
  color: var(--text-main);
  padding: 1rem 1.5rem;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  border-left: 4px solid var(--primary);
  animation: slideIn 0.3s ease-out;
  display: flex;
  flex-direction: column; /* Allow multi-line/progress */
  gap: 0.5rem;
  min-width: 300px;
}

.toast-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--success); }

/* Progress Bar in Toast */
.upload-progress {
    width: 100%;
    height: 4px;
    background: var(--bg-body);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 0.5rem;
}

.progress-bar {
    height: 100%;
    background: var(--success);
    width: 0%;
    transition: width 0.2s linear;
}

.toast-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    display: flex;
    justify-content: space-between;
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

@keyframes slideIn {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}

/* Responsive */
@media (max-width: 768px) {
  .app-layout { flex-direction: column; }
  .sidebar { 
    width: 100%; 
    height: auto; 
    padding: 0.5rem; 
    flex-direction: row; 
    border-right: none;
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    align-items: center;
  }
  .sidebar-header { margin-bottom: 0; font-size: 1rem; }
  .user-profile { 
    display: none; /* Simplify mobile view */ 
  }
  .sidebar-nav { flex-direction: row; }
  .nav-item span { display: none; }
  .top-bar { padding: 0.75rem 1rem; }
  .search-bar { width: 100%; }
}

/* Info Modal Grid */
.info-grid {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 1rem 2rem;
    font-size: 0.95rem;
    align-items: start;
}
.info-label {
    font-weight: 500;
    color: var(--text-muted);
    min-width: 100px;
}
.info-value {
    color: var(--text-main);
    word-break: break-all;
}

/* Drag Ghost */
.drag-ghost {
  position: absolute;
  top: -1000px;
  left: -1000px;
  z-index: -1; /* Keep it out of view but renderable for setDragImage */
  background: var(--bg-surface);
  border: 1px solid var(--primary);
  border-radius: 999px; /* Pill shape */
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  box-shadow: var(--shadow-lg);
  width: auto;
  max-width: 250px;
  pointer-events: none;
  opacity: 0.9;
}

.drag-ghost .file-icon, .drag-ghost img {
    width: 1.5rem;
    height: 1.5rem;
    object-fit: contain;
}

.drag-ghost .file-name {
    font-size: 0.85rem;
    color: var(--text-main);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin: 0;
    font-weight: 500;
}
