:root {
  --bg: #f4f6fa;
  --card: #ffffff;
  --ink: #16202e;
  --muted: #6b7686;
  --line: #e3e8ef;
  --accent: #1a66d6;
  --accent-soft: #e8f0fc;
  --danger: #d33a3a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .05), 0 2px 8px rgba(16, 24, 40, .04);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "IBM Plex Sans Arabic", system-ui, -apple-system, "Segoe UI", Tahoma, sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.6;
}
button, input, textarea { font: inherit; color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

/* الشريط العلوي */
.topbar { position: sticky; top: 0; z-index: 10; background: rgba(255,255,255,.9); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.topbar-inner { max-width: 1200px; margin: 0 auto; padding: 12px 20px; display: flex; align-items: center; gap: 16px; }
.brand { font-size: 20px; margin: 0; font-weight: 700; white-space: nowrap; }
.search { flex: 1; max-width: 420px; display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 6px 14px; color: var(--muted); }
.search input { border: 0; outline: 0; background: transparent; width: 100%; color: var(--ink); }
.user-chip { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; border: 1px solid var(--line); background: var(--card); border-radius: 999px; padding: 4px 6px 4px 14px; cursor: pointer; }
.user-chip:hover { border-color: var(--accent); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 13px; }

/* المساحة */
.usage { margin-inline-start: auto; display: flex; align-items: center; gap: 8px; font-size: 12.5px; color: var(--muted); white-space: nowrap; }
.usage-bar { width: 90px; height: 6px; background: var(--line); border-radius: 99px; overflow: hidden; }
.usage-bar i { display: block; height: 100%; width: 0; background: #2f9e62; transition: width .3s; }
.usage.warn .usage-bar i { background: #e09a1f; }
.usage.full .usage-bar i { background: var(--danger); }
.usage.full { color: var(--danger); }
.usage + .user-chip { margin-inline-start: 0; }

/* المحتوى */
.container { max-width: 1200px; margin: 0 auto; padding: 20px; }
.toolbar { display: flex; justify-content: flex-start; margin-bottom: 16px; }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 7px 14px; cursor: pointer; text-decoration: none; font-weight: 500; white-space: nowrap; }
.btn:hover { border-color: #c5cfdc; background: #fafbfd; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #1558bb; }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); background: #fdf3f3; }
.btn:disabled { opacity: .6; cursor: default; }
.icon-btn { border: 0; background: transparent; width: 34px; height: 34px; border-radius: 9px; display: grid; place-items: center; cursor: pointer; color: var(--muted); }
.icon-btn:hover { background: var(--bg); color: var(--ink); }

/* الأقسام */
.sections { display: flex; flex-direction: column; gap: 14px; }
.section { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); transition: border-color .15s, box-shadow .15s; }
.section.drag { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.section-head { display: flex; align-items: center; gap: 10px; padding: 14px 16px; cursor: pointer; user-select: none; }
.section-head .chev { color: var(--muted); transition: transform .2s; }
.section.open .chev { transform: rotate(-90deg); }
.section-title { font-size: 17px; font-weight: 600; margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.section-count { color: var(--muted); font-size: 13px; background: var(--bg); border-radius: 999px; padding: 1px 10px; white-space: nowrap; }
.section-actions { margin-inline-start: auto; display: flex; align-items: center; gap: 4px; }
.add-btn { width: 36px; height: 36px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); display: grid; place-items: center; cursor: pointer; color: var(--accent); }
.add-btn:hover { background: var(--accent-soft); border-color: var(--accent); }
.add-btn svg { width: 20px; height: 20px; }
.section-body { padding: 0 16px 16px; display: none; }
.section.open .section-body { display: block; }

.menu { position: relative; }
.menu-list { position: absolute; top: 100%; inset-inline-end: 0; margin-top: 4px; background: var(--card); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 8px 24px rgba(16,24,40,.12); padding: 4px; min-width: 150px; z-index: 5; }
.menu-list button { display: block; width: 100%; text-align: start; border: 0; background: none; padding: 8px 12px; border-radius: 7px; cursor: pointer; }
.menu-list button:hover { background: var(--bg); }
.menu-list button.danger { color: var(--danger); }

/* الملفات */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.file-card { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; background: var(--card); cursor: pointer; display: flex; flex-direction: column; transition: transform .12s, box-shadow .12s, border-color .12s; text-align: start; padding: 0; }
.file-card:hover { transform: translateY(-2px); box-shadow: 0 6px 18px rgba(16,24,40,.08); border-color: #c5cfdc; }
.thumb { aspect-ratio: 4 / 3; background: #eef2f7; display: grid; place-items: center; position: relative; overflow: hidden; }
.thumb img, .thumb video { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .play { position: absolute; width: 38px; height: 38px; border-radius: 50%; background: rgba(0,0,0,.55); color: #fff; display: grid; place-items: center; }
.thumb .play svg { fill: #fff; stroke: none; width: 16px; height: 16px; margin-inline-start: -2px; }
.ext { font-weight: 700; font-size: 15px; letter-spacing: .5px; color: #fff; padding: 10px 12px; border-radius: 10px; min-width: 56px; text-align: center; direction: ltr; }
.file-info { padding: 9px 11px 10px; }
.file-name { font-weight: 600; font-size: 14px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; word-break: break-word; }
.file-meta { font-size: 12px; color: var(--muted); margin-top: 3px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.badge { display: inline-flex; align-items: center; gap: 3px; background: var(--accent-soft); color: var(--accent); border-radius: 999px; padding: 0 8px; font-size: 11.5px; font-weight: 600; }
.badge svg { width: 12px; height: 12px; }

.drop-hint { border: 2px dashed var(--line); border-radius: 12px; padding: 26px; text-align: center; color: var(--muted); cursor: pointer; }
.drop-hint:hover { border-color: var(--accent); color: var(--accent); }

/* الرفع */
.uploads { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; }
.upload-row { background: var(--bg); border-radius: 10px; padding: 8px 12px; font-size: 13px; }
.upload-row .top { display: flex; justify-content: space-between; gap: 10px; }
.upload-row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 5px; background: var(--line); border-radius: 99px; margin-top: 6px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.upload-row.err .bar > i { background: var(--danger); }

/* الفراغ والتحميل */
.empty { text-align: center; padding: 60px 20px; }
.empty-icon { font-size: 44px; }
.empty p { margin: 4px 0; }
.loading { display: grid; place-items: center; padding: 60px; }
.spinner { width: 28px; height: 28px; border: 3px solid var(--line); border-top-color: var(--accent); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* النوافذ */
.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 20px; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(15, 22, 35, .55); }
.modal-card { position: relative; background: var(--card); border-radius: 16px; box-shadow: 0 20px 60px rgba(0,0,0,.25); max-height: calc(100vh - 40px); }
.ask { width: min(420px, 100%); padding: 22px; }
.ask h2 { margin: 0 0 4px; font-size: 18px; }
.ask p { margin: 0 0 14px; }
.ask input { width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: 0; }
.ask input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.ask-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

.file-view { width: min(1100px, 100%); height: min(720px, calc(100vh - 40px)); display: grid; grid-template-columns: 1fr 340px; overflow: hidden; }
.file-view .close { position: absolute; top: 10px; inset-inline-start: 10px; z-index: 2; background: rgba(255,255,255,.9); }
.preview { background: #0f1623; display: grid; place-items: center; overflow: hidden; min-height: 0; }
.preview img, .preview video { max-width: 100%; max-height: 100%; object-fit: contain; }
.preview iframe { width: 100%; height: 100%; border: 0; background: #fff; }
.preview audio { width: 80%; }
.preview .noprev { color: #c9d2df; text-align: center; }
.preview .noprev .ext { font-size: 22px; padding: 18px 22px; margin-bottom: 12px; display: inline-block; }
.fv-side { border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; padding: 18px; }
.fv-name { font-size: 17px; margin: 0 0 4px; padding-inline-start: 34px; word-break: break-word; }
.fv-meta { font-size: 13px; color: var(--muted); }
.fv-meta div { margin: 2px 0; }
.fv-meta b { color: var(--ink); font-weight: 600; }
.fv-actions { display: flex; gap: 6px; flex-wrap: wrap; margin: 12px 0 4px; }
.fv-actions .btn { padding: 6px 11px; font-size: 13.5px; }
.notes-title { font-size: 15px; margin: 14px 0 8px; padding-top: 12px; border-top: 1px solid var(--line); }
.comments { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; min-height: 60px; }
.comment { background: var(--bg); border-radius: 12px; padding: 9px 12px; }
.comment-head { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.comment-head b { font-weight: 600; }
.comment-head .t { color: var(--muted); font-size: 12px; }
.comment-head .del { margin-inline-start: auto; border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 12px; padding: 0; }
.comment-head .del:hover { color: var(--danger); }
.comment-body { white-space: pre-wrap; word-break: break-word; margin-top: 2px; }
.comments .none { color: var(--muted); font-size: 13px; text-align: center; padding: 14px 0; }
.comment-form { display: flex; gap: 8px; align-items: flex-end; margin-top: 10px; }
.comment-form textarea { flex: 1; resize: none; border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; outline: 0; max-height: 140px; }
.comment-form textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

/* التنبيهات */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; align-items: center; }
.toast { background: #16202e; color: #fff; border-radius: 10px; padding: 9px 16px; font-size: 14px; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: up .2s ease; }
.toast.err { background: var(--danger); }
@keyframes up { from { transform: translateY(10px); opacity: 0; } }

/* الجوال */
@media (max-width: 760px) {
  .topbar-inner { flex-wrap: wrap; gap: 10px; padding: 10px 14px; }
  .search { order: 3; max-width: none; flex-basis: 100%; }
  .usage-bar { width: 50px; }
  .container { padding: 14px; }
  .grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .modal { padding: 0; }
  .file-view { grid-template-columns: 1fr; grid-template-rows: 42vh 1fr; height: 100vh; max-height: 100vh; border-radius: 0; }
  .fv-side { border-inline-end: 0; }
  .fv-name { padding-inline-start: 0; }
  .file-view .close { top: 8px; }
}

/* الدخول */
.login { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px; background: linear-gradient(160deg, #eaf1fc, #f4f6fa 60%); }
.login-card { width: min(380px, 100%); background: var(--card); border: 1px solid var(--line); border-radius: 18px; box-shadow: 0 12px 40px rgba(16,24,40,.08); padding: 28px; display: flex; flex-direction: column; gap: 14px; }
.login-logo { font-size: 40px; text-align: center; }
.login-card h1 { margin: 0 0 4px; text-align: center; font-size: 22px; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-weight: 500; font-size: 14px; }
.login-card input { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; outline: 0; font-weight: 400; }
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card .btn { justify-content: center; padding: 10px; margin-top: 4px; }
.login-err { margin: 0; color: var(--danger); font-size: 14px; text-align: center; }
