/* مستودع الإبداع — واجهة الموقع بنفس تصميم التطبيق (RTL، تدرّج الهوية، بطاقات، ألواح سفلية) */

:root {
  --brand-start: #6a5bff;
  --brand-mid: #4f8bff;
  --brand-end: #22d3ee;
  --primary: #4f6bff;
  --navy: #0e1430;

  --bg: #f6f7fb;
  --surface: #ffffff;
  --border: #e6e8f0;
  --text: #0e1430;
  --muted: rgba(14, 20, 48, 0.58);
  --chip: #eef0fa;
  --scrim: rgba(8, 12, 29, 0.55);

  --success: #10b981;
  --warning: #f59e0b;
  --danger: #f43f5e;

  --kind-folder: #4f6bff;
  --kind-video: #f43f5e;
  --kind-image: #8b5cf6;

  --radius: 18px;
  --nav-h: 68px;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);

  color-scheme: light;
}

:root[data-theme='dark'] {
  --bg: #0b1020;
  --surface: #151b33;
  --border: #232b4d;
  --text: #eef1ff;
  --muted: rgba(238, 241, 255, 0.6);
  --chip: #1d2542;
  --scrim: rgba(0, 0, 0, 0.65);
  color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Cairo', system-ui, -apple-system, 'Segoe UI', Tahoma, sans-serif;
  line-height: 1.5;
  min-height: 100vh;
  min-height: 100dvh;
}

a { color: inherit; text-decoration: none; }
button { font: inherit; color: inherit; cursor: pointer; }
img, video { max-width: 100%; }
[hidden] { display: none !important; }

/* ------------------------------------------------------------- الهيكل */
.app {
  max-width: 720px;
  margin: 0 auto;
  padding: calc(10px + var(--safe-top)) 16px calc(var(--nav-h) + 120px + var(--safe-bottom));
}

.header { display: flex; align-items: center; gap: 12px; padding: 6px 0 12px; }
.logo {
  width: 44px; height: 44px; border-radius: 13px; flex: none;
  background: linear-gradient(135deg, var(--brand-start), var(--brand-mid), var(--brand-end));
  display: grid; place-items: center;
  box-shadow: 0 8px 20px rgba(79, 107, 255, 0.32);
}
.logo svg { width: 26px; height: 26px; }
.header-text { flex: 1; min-width: 0; }
.header-text h1 { margin: 0; font-size: 18px; font-weight: 800; line-height: 1.2; }
.header-text p { margin: 2px 0 0; font-size: 11.5px; color: var(--muted); }

.icon-btn {
  width: 42px; height: 42px; border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); display: grid; place-items: center; flex: none;
}
.icon-btn svg { width: 20px; height: 20px; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; border: 0; flex: none;
  background: linear-gradient(135deg, var(--brand-start), var(--brand-end));
  color: #fff; font-weight: 800; font-size: 16px; display: grid; place-items: center;
}

/* ---------------------------------------------------------------- بحث */
.search {
  display: flex; align-items: center; gap: 10px; height: 50px; padding: 0 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 26px; margin-bottom: 14px;
}
.search svg { width: 20px; height: 20px; color: var(--muted); flex: none; }
.search input {
  flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; font-size: 14px;
}

/* --------------------------------------------------------- بطاقة المساحة */
.storage {
  position: relative; overflow: hidden; color: #fff; padding: 18px 20px; margin-bottom: 18px;
  border-radius: 24px;
  background: linear-gradient(135deg, #3f3a9e 0%, #2a4fb8 55%, #0e8fa6 100%);
  box-shadow: 0 14px 30px rgba(42, 79, 184, 0.28);
}
.storage::after {
  content: ''; position: absolute; width: 160px; height: 160px; border-radius: 50%;
  background: rgba(255, 255, 255, 0.08); inset-inline-start: -50px; top: -60px;
}
.storage-top { display: flex; align-items: center; justify-content: space-between; position: relative; z-index: 1; }
.storage-top span { font-size: 14px; font-weight: 700; opacity: 0.92; }
.storage-pill { background: rgba(255, 255, 255, 0.18); padding: 2px 10px; border-radius: 12px; font-size: 11px; font-weight: 800; }
.storage-used { margin: 8px 0 2px; font-size: 28px; font-weight: 800; position: relative; z-index: 1; }
.storage-of { font-size: 12px; opacity: 0.78; position: relative; z-index: 1; }
.bar { height: 8px; border-radius: 6px; background: rgba(255, 255, 255, 0.2); margin-top: 12px; overflow: hidden; position: relative; z-index: 1; }
.bar > i { display: block; height: 100%; border-radius: 6px; background: #fff; transition: width 0.4s ease; min-width: 2px; }

/* ----------------------------------------------------------- فتات الخبز */
.crumbs { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-bottom: 14px; font-size: 13px; }
.crumb {
  padding: 5px 12px; border-radius: 16px; background: var(--chip); font-weight: 700; color: var(--primary);
}
.crumb.current { background: transparent; color: var(--text); padding-inline: 4px; }
.crumb-sep { color: var(--muted); }

.section-title { display: flex; align-items: baseline; justify-content: space-between; margin: 18px 0 10px; }
.section-title h2 { margin: 0; font-size: 15px; font-weight: 800; }
.section-title small { color: var(--muted); font-size: 12px; }

/* ----------------------------------------------------------------- الشبكة */
.grid { display: grid; gap: 12px; grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 640px) { .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); } }

.folder {
  position: relative; display: flex; align-items: center; gap: 10px; padding: 12px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.folder-ico {
  width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; flex: none;
  background: color-mix(in srgb, var(--kind-folder) 14%, transparent); color: var(--kind-folder);
}
.folder-ico svg { width: 22px; height: 22px; }
.folder-body { flex: 1; min-width: 0; }
.folder-name {
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
  font-size: 13px; font-weight: 700; line-height: 1.35; word-break: break-word;
}
.folder-meta { font-size: 11px; color: var(--muted); }

.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
  display: flex; flex-direction: column;
}
.thumb {
  position: relative; display: block; width: 100%; aspect-ratio: 4 / 3; border: 0; padding: 0; overflow: hidden;
  background: linear-gradient(135deg, color-mix(in srgb, var(--k) 22%, transparent), color-mix(in srgb, var(--k) 8%, transparent));
  color: var(--k);
}
.thumb > svg.kind { position: absolute; inset: 0; margin: auto; width: 38px; height: 38px; opacity: 0.9; }
.thumb img, .thumb video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.badge {
  position: absolute; bottom: 8px; inset-inline-start: 8px; padding: 1px 8px; border-radius: 8px; font-size: 10px; font-weight: 800;
  background: color-mix(in srgb, var(--surface) 88%, transparent); color: var(--k);
}
.play {
  position: absolute; inset: 0; margin: auto; width: 42px; height: 42px; border-radius: 50%;
  background: rgba(0, 0, 0, 0.5); color: #fff; display: grid; place-items: center;
}
.play svg { width: 20px; height: 20px; }
.card-foot { display: flex; align-items: flex-start; gap: 4px; padding: 10px 6px 10px 12px; }
.card-info { flex: 1; min-width: 0; }
.card-name {
  font-size: 12.5px; font-weight: 700; line-height: 1.35; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden; word-break: break-word;
}
.card-meta { font-size: 10.5px; color: var(--muted); margin-top: 3px; }

.more {
  width: 30px; height: 30px; border-radius: 50%; border: 0; background: transparent; display: grid; place-items: center; flex: none;
}
.more svg { width: 18px; height: 18px; }

.empty { text-align: center; padding: 50px 20px; color: var(--muted); }
.empty .empty-ico {
  width: 76px; height: 76px; margin: 0 auto 14px; border-radius: 24px; display: grid; place-items: center; color: #fff;
  background: linear-gradient(135deg, var(--brand-start), var(--brand-end)); opacity: 0.92;
}
.empty .empty-ico svg { width: 38px; height: 38px; }
.empty h3 { margin: 0 0 4px; color: var(--text); font-size: 16px; }
.empty p { margin: 0; font-size: 13px; }

/* ---------------------------------------------------- شريط تقدّم الرفع */
.upload-banner {
  position: fixed; z-index: 30; inset-inline: 12px; bottom: calc(var(--nav-h) + 88px + var(--safe-bottom));
  max-width: 696px; margin-inline: auto; background: var(--surface); border: 1px solid var(--border);
  border-radius: 16px; padding: 10px 14px 12px; box-shadow: 0 10px 28px rgba(0, 0, 0, 0.18);
}
.ub-row { display: flex; align-items: center; gap: 10px; }
.ub-row svg { width: 20px; height: 20px; color: var(--primary); flex: none; }
.ub-title { flex: 1; min-width: 0; font-size: 12.5px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ub-pct { font-size: 12px; font-weight: 800; color: var(--primary); }
.ub-bar { height: 6px; border-radius: 6px; background: var(--border); margin-top: 8px; overflow: hidden; }
.ub-bar > i { display: block; height: 100%; width: 0; border-radius: 6px; background: var(--primary); transition: width 0.15s ease; }
.ub-bar.busy > i { width: 40% !important; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { 0% { margin-inline-start: -40%; } 100% { margin-inline-start: 100%; } }
.ub-detail { font-size: 10.5px; color: var(--muted); margin-top: 6px; }
.upload-banner.error .ub-row svg, .upload-banner.error .ub-pct { color: var(--danger); }
.upload-banner.error .ub-bar > i { background: var(--danger); }

/* -------------------------------------------------- التنقّل السفلي + الزر */
.nav {
  position: fixed; z-index: 20; inset-inline: 0; bottom: 0; height: calc(var(--nav-h) + var(--safe-bottom));
  padding-bottom: var(--safe-bottom); background: var(--surface); border-top: 1px solid var(--border);
}
.nav-inner { max-width: 720px; margin: 0 auto; height: var(--nav-h); display: flex; align-items: stretch; }
.nav a, .nav button {
  flex: 1; border: 0; background: transparent; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; font-size: 11px; font-weight: 700; color: var(--muted);
}
.nav svg { width: 24px; height: 24px; }
.nav .active { color: var(--primary); }
.nav .spacer { flex: 1.1; pointer-events: none; }

.fab {
  position: fixed; z-index: 25; left: max(16px, calc(50% - 344px)); bottom: calc(var(--nav-h) + 14px + var(--safe-bottom));
  height: 56px; padding: 0 24px; border: 0; border-radius: 28px; color: #fff; font-weight: 800; font-size: 15px;
  display: flex; align-items: center; gap: 8px;
  background: linear-gradient(135deg, var(--brand-start), var(--brand-mid) 60%, #1aa8c4);
  box-shadow: 0 12px 26px rgba(79, 107, 255, 0.45);
}
.fab svg { width: 22px; height: 22px; }

/* ----------------------------------------------------------- ألواح سفلية */
.scrim { position: fixed; inset: 0; z-index: 40; background: var(--scrim); opacity: 0; pointer-events: none; transition: opacity 0.2s; }
.scrim.on { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; z-index: 41; inset-inline: 0; bottom: 0; max-width: 600px; margin: 0 auto;
  background: var(--surface); border-radius: 26px 26px 0 0; padding: 8px 20px calc(20px + var(--safe-bottom));
  transform: translateY(105%); transition: transform 0.25s ease; max-height: 88vh; overflow-y: auto;
}
.sheet.on { transform: translateY(0); }
.grabber { width: 42px; height: 4px; border-radius: 4px; background: var(--border); margin: 6px auto 12px; }
.sheet h3 { margin: 0 0 12px; font-size: 15px; font-weight: 800; }
.sheet-item {
  width: 100%; display: flex; align-items: center; gap: 14px; padding: 10px 0; border: 0; background: transparent; text-align: start;
}
.sheet-ico { width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; flex: none; background: color-mix(in srgb, var(--c) 14%, transparent); color: var(--c); }
.sheet-ico svg { width: 22px; height: 22px; }
.sheet-item b { display: block; font-size: 14px; }
.sheet-item small { color: var(--muted); font-size: 11.5px; }
.field {
  width: 100%; height: 50px; padding: 0 16px; border-radius: 16px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font: inherit; font-size: 15px; outline: 0;
}
.field:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 20%, transparent); }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; height: 50px; padding: 0 22px;
  border-radius: 16px; border: 0; font-weight: 800; font-size: 15px; color: #fff; background: var(--primary);
}
.btn.block { width: 100%; }
.btn.grad { background: linear-gradient(135deg, var(--brand-start), var(--brand-mid) 60%, #1aa8c4); }
.btn.danger { background: var(--danger); }
.btn.ghost { background: var(--chip); color: var(--text); }
.btn-row { display: flex; gap: 10px; margin-top: 14px; }
.btn-row .btn { flex: 1; }
.hint { font-size: 12px; color: var(--muted); margin: 8px 2px 0; }
.error-text { color: var(--danger); font-size: 12.5px; margin: 8px 2px 0; }

.profile { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.profile .avatar { width: 52px; height: 52px; font-size: 20px; }
.profile b { display: block; }
.profile small { color: var(--muted); }

/* ---------------------------------------------------------------- معاين */
.viewer { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, 0.92); display: none; flex-direction: column; }
.viewer.on { display: flex; }
.viewer-bar { display: flex; align-items: center; gap: 10px; padding: calc(12px + var(--safe-top)) 14px 10px; color: #fff; }
.viewer-bar span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 700; font-size: 14px; }
.viewer-bar .icon-btn { background: rgba(255, 255, 255, 0.14); border: 0; color: #fff; }
.viewer-body { flex: 1; min-height: 0; display: grid; place-items: center; padding: 0 12px calc(16px + var(--safe-bottom)); }
.viewer-body img, .viewer-body video { max-width: 100%; max-height: 100%; border-radius: 12px; }

/* ------------------------------------------------------------------ إشعار */
.toast {
  position: fixed; z-index: 70; inset-inline: 16px; bottom: calc(var(--nav-h) + 96px + var(--safe-bottom)); max-width: 480px; margin-inline: auto;
  padding: 12px 16px; border-radius: 16px; background: var(--surface); border: 1px solid var(--border);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.2); display: flex; align-items: center; gap: 10px; font-size: 13.5px; font-weight: 700;
  animation: toast-in 0.25s ease, toast-out 0.3s ease 3.4s forwards;
}
.toast svg { width: 20px; height: 20px; color: var(--success); flex: none; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } }
@keyframes toast-out { to { opacity: 0; transform: translateY(12px); visibility: hidden; } }

/* ------------------------------------------------------------ تسجيل الدخول */
.auth {
  min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 20px calc(24px + var(--safe-bottom));
  background: linear-gradient(180deg, #141c42, #0e1430 55%, #080c1d); color: #fff;
}
.auth-box { width: 100%; max-width: 400px; }
.auth .logo { width: 84px; height: 84px; border-radius: 26px; margin: 0 auto 18px; }
.auth .logo svg { width: 48px; height: 48px; }
.auth h1 { margin: 0; text-align: center; font-size: 26px; font-weight: 800; }
.auth .sub { margin: 4px 0 26px; text-align: center; font-size: 13px; opacity: 0.7; }
.auth .field { margin-bottom: 12px; background: rgba(255, 255, 255, 0.08); border-color: rgba(255, 255, 255, 0.14); color: #fff; }
.auth .field::placeholder { color: rgba(255, 255, 255, 0.5); }
.auth .remember { display: flex; align-items: center; gap: 8px; font-size: 13px; opacity: 0.85; margin: 4px 2px 16px; }
.auth .error-text { color: #ff8da3; margin-bottom: 10px; }
.auth .foot { margin-top: 22px; text-align: center; font-size: 11.5px; opacity: 0.45; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

.folder-link { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.stack-hint { margin-top: 10px; }

/* ------------------------------------------------ ترتيب + شرائح التصنيف */
.search-filter {
  width: 34px; height: 34px; margin-inline-end: -6px; border: 0; border-radius: 50%; background: transparent;
  display: grid; place-items: center; flex: none; color: var(--muted);
}
.search-filter svg { width: 20px; height: 20px; }

.chips { display: flex; gap: 8px; overflow-x: auto; margin: 0 -16px 14px; padding: 0 16px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; padding: 7px 18px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface);
  font-size: 13px; font-weight: 700; color: var(--text);
}
.chip.on { background: var(--primary); border-color: var(--primary); color: #fff; }

.storage-title { display: inline-flex; align-items: center; gap: 8px; }
.storage-title svg { width: 22px; height: 22px; }

.sort-opt.on { background: var(--chip); border-radius: 14px; padding-inline: 10px; margin-inline: -10px; width: calc(100% + 20px); }
