:root {
  --bg: #F4F5F7;
  --surface: #FFFFFF;
  --surface-2: #F8F9FB;
  --surface-3: #EEF1F5;
  --border: #E3E6EB;
  --border-strong: #D5DAE1;
  --text: #1A2233;
  --text-2: #3A4456;
  --muted: #5B6577;
  --accent: #1E5BD8;
  --accent-hover: #1747A8;
  --accent-soft: #EAF2FF;
  --accent-text: #1747A8;
  --row-hover: #F5F8FD;
  --row-selected: #E6EFFF;
  --danger: #B42318;
  --danger-soft: #FDECEA;
  --warn-soft: #FDF0E7;
  --warn-text: #A63F0A;
  --ok: #1E8A55;
  --side-bg: #0F1B2D;
  --side-text: #C9D2E1;
  --side-muted: #93A0B5;
  --side-active: #1F2E47;
  --side-card: #16243A;
  --folder-fill: #F4C25B;
  --folder-stroke: #D99E2B;
  --shadow: 0 6px 20px rgba(15, 27, 45, 0.10);
  --shadow-lg: 0 24px 60px rgba(15, 27, 45, 0.30);
  --radius: 8px;
  color-scheme: light;
}

:root[data-theme="dark"] {
  --bg: #0E1420;
  --surface: #161E2C;
  --surface-2: #1B2433;
  --surface-3: #222C3D;
  --border: #2A3547;
  --border-strong: #354257;
  --text: #E7ECF4;
  --text-2: #C3CCDA;
  --muted: #98A3B6;
  --accent: #4C8DFF;
  --accent-hover: #6EA2FF;
  --accent-soft: #1B2B4A;
  --accent-text: #9CC0FF;
  --row-hover: #1D2738;
  --row-selected: #213558;
  --danger: #FF8A80;
  --danger-soft: #3A1F22;
  --warn-soft: #3A2A1C;
  --warn-text: #FDBA8C;
  --ok: #4ADE80;
  --side-bg: #0A101A;
  --side-active: #1A2638;
  --side-card: #121B29;
  --shadow: 0 6px 20px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.55);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body, #root { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", "Segoe UI Variable Text", Tahoma, "Noto Sans Arabic", system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.icon { flex-shrink: 0; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 14px; border-radius: var(--radius);
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  cursor: pointer; white-space: nowrap; text-decoration: none;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 500; }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.small { height: 32px; padding: 0 10px; font-size: 13px; }
.icon-btn {
  width: 38px; height: 38px; display: inline-flex; align-items: center; justify-content: center;
  border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface); color: var(--text-2); cursor: pointer; position: relative;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn.ghost { border-color: transparent; background: transparent; }
.icon-btn.spin .icon { animation: spin .8s linear; }
@keyframes spin { to { transform: rotate(360deg); } }
.link { background: none; border: none; color: var(--accent); cursor: pointer; padding: 0; font-weight: 500; }
.input, .select {
  width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--border-strong);
  border-radius: var(--radius); background: var(--surface); color: var(--text);
}
.input:focus, .select:focus { outline: 2px solid var(--accent); outline-offset: -1px; border-color: var(--accent); }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-weight: 500; font-size: 13px; }
.form-error { color: var(--danger); font-size: 13px; min-height: 18px; }
.code-input { letter-spacing: .4em; font-size: 22px; text-align: center; height: 52px; }

/* ---------- sign-in screens ---------- */
.auth-screen { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--side-bg); }
.auth-card { width: 100%; max-width: 420px; background: var(--surface); border-radius: 14px; padding: 32px; display: flex; flex-direction: column; gap: 16px; box-shadow: var(--shadow-lg); }
.auth-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.brand-mark { width: 36px; height: 36px; border-radius: 9px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; }
.auth-card h1 { font-size: 22px; }
.auth-foot { display: flex; justify-content: space-between; align-items: center; font-size: 13px; }
.qr { align-self: center; width: 200px; height: 200px; border-radius: 8px; border: 1px solid var(--border); background: #fff; }
.secret-key { font-family: Consolas, monospace; font-size: 15px; letter-spacing: .08em; padding: 10px 12px; background: var(--surface-3); border-radius: 8px; text-align: center; user-select: all; word-break: break-all; }

/* ---------- app shell ---------- */
.shell { display: flex; height: 100%; }
.sidebar { width: 236px; flex-shrink: 0; background: var(--side-bg); color: var(--side-text); padding: 18px 12px; display: flex; flex-direction: column; gap: 22px; overflow-y: auto; }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 2px 8px; }
.side-brand strong { color: #fff; font-size: 15px; display: block; }
.side-brand span { font-size: 12px; color: var(--side-muted); }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav-title { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--side-muted); padding: 0 10px 6px; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--side-text); background: none; border: none; cursor: pointer; text-align: start; width: 100%; }
.nav-item:hover { background: var(--side-active); color: #fff; }
.nav-item[aria-current="page"] { background: var(--side-active); color: #fff; font-weight: 500; }
.side-status { margin-top: auto; padding: 12px; border-radius: 10px; background: var(--side-card); display: flex; flex-direction: column; gap: 8px; font-size: 12px; }
.meter { height: 6px; border-radius: 3px; background: #2A3B57; overflow: hidden; }
.meter > div { height: 100%; background: var(--accent); border-radius: 3px; }
.dot { width: 8px; height: 8px; border-radius: 4px; display: inline-block; flex-shrink: 0; }
.dot.live { background: #34C47C; }
.dot.wait { background: #F5B942; }
.dot.off { background: #EF6B5E; }
.status-line { display: flex; align-items: center; gap: 6px; color: var(--side-muted); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; align-items: center; gap: 10px; padding: 12px 24px; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.search { flex: 1 1 260px; display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: var(--radius); background: var(--surface-2); color: var(--muted); }
.search input { flex: 1; min-width: 0; border: none; background: transparent; outline: none; color: var(--text); }
.user-chip { display: flex; align-items: center; gap: 10px; padding: 4px 8px 4px 4px; border-radius: 999px; background: none; border: none; cursor: pointer; text-align: start; }
.user-chip:hover { background: var(--surface-2); }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--accent-soft); color: var(--accent-text); display: flex; align-items: center; justify-content: center; font-weight: 600; font-size: 12px; flex-shrink: 0; }
.user-chip .who { display: flex; flex-direction: column; line-height: 1.2; }
.user-chip .who span { font-size: 12px; color: var(--muted); }

.content { flex: 1; overflow: auto; padding: 22px 24px 40px; position: relative; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head h1 { font-size: 22px; }
.title-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; min-width: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.crumbs { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; color: var(--muted); font-size: 13px; margin-bottom: 8px; }
.crumbs button { background: none; border: none; color: var(--muted); cursor: pointer; padding: 2px 4px; border-radius: 4px; }
.crumbs button:hover { color: var(--text); background: var(--surface-3); }
.crumbs .here { color: var(--text); font-weight: 500; padding: 2px 4px; }
[dir="rtl"] .crumbs .sep, [dir="rtl"] .chev { transform: scaleX(-1); }
.pill { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; background: var(--surface-3); color: var(--text-2); font-size: 12px; white-space: nowrap; }
.pill.warn { background: var(--warn-soft); color: var(--warn-text); }
.pill.danger { background: var(--danger-soft); color: var(--danger); }
.pill.accent { background: var(--accent-soft); color: var(--accent-text); }
.pill.ok { background: rgba(30, 138, 85, .12); color: var(--ok); }

.banner { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-radius: 8px; background: var(--accent-soft); color: var(--accent-text); font-size: 13px; margin-bottom: 14px; }

/* ---------- tables ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; }
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; min-width: 640px; }
table.list th { text-align: start; font-weight: 500; font-size: 12px; color: var(--muted); padding: 11px 16px; border-bottom: 1px solid var(--border); white-space: nowrap; user-select: none; }
table.list th.sortable { cursor: pointer; }
table.list th.sortable:hover { color: var(--text); }
table.list td { padding: 9px 16px; border-bottom: 1px solid var(--border); color: var(--text-2); vertical-align: middle; }
table.list tr:last-child td { border-bottom: none; }
table.list tbody tr { cursor: default; }
table.list tbody tr:hover { background: var(--row-hover); }
table.list tbody tr.selected { background: var(--row-selected); }
table.list tbody tr.fresh { animation: fresh 2.4s ease-out; }
@keyframes fresh { from { background: var(--accent-soft); } to { background: transparent; } }
.num { text-align: end !important; white-space: nowrap; }
.name-cell { display: flex; align-items: center; gap: 12px; min-width: 0; }
.name-cell .names { display: flex; flex-direction: column; min-width: 0; line-height: 1.3; }
.name-cell .primary-name { font-weight: 500; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name-cell .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folder-icon path { fill: var(--folder-fill); stroke: var(--folder-stroke); stroke-width: 1.2; }
.file-badge { width: 24px; height: 28px; border-radius: 4px; color: #fff; font-size: 7.5px; font-weight: 700; display: inline-flex; align-items: flex-end; justify-content: center; padding-bottom: 3px; flex-shrink: 0; letter-spacing: .02em; }
.row-more { opacity: 0; }
tr:hover .row-more, tr.selected .row-more, .row-more:focus { opacity: 1; }

.empty { padding: 56px 24px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 8px; color: var(--muted); }
.empty h3 { color: var(--text); font-size: 16px; }
.empty .big-icon { color: var(--border-strong); margin-bottom: 6px; }
.loading { padding: 40px; text-align: center; color: var(--muted); }
.skeleton { height: 14px; border-radius: 4px; background: linear-gradient(90deg, var(--surface-3), var(--surface-2), var(--surface-3)); background-size: 200% 100%; animation: shimmer 1.2s infinite; }
@keyframes shimmer { to { background-position: -200% 0; } }

.drop-overlay { position: absolute; inset: 12px; border: 2px dashed var(--accent); border-radius: 14px; background: color-mix(in srgb, var(--accent-soft) 85%, transparent); display: none; align-items: center; justify-content: center; font-size: 16px; font-weight: 600; color: var(--accent-text); z-index: 5; pointer-events: none; }
.content.dragging .drop-overlay { display: flex; }

/* ---------- dashboard ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { padding: 16px; display: flex; flex-direction: column; gap: 4px; }
.stat .value { font-size: 26px; font-weight: 600; color: var(--text); }
.stat .label { color: var(--muted); font-size: 13px; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: 16px; }
.card h3 { font-size: 15px; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.feed { list-style: none; margin: 0; padding: 4px 0; }
.feed li { display: flex; gap: 10px; padding: 10px 16px; align-items: flex-start; }
.feed li + li { border-top: 1px solid var(--border); }
.feed .when { margin-inline-start: auto; color: var(--muted); font-size: 12px; white-space: nowrap; }

/* ---------- dialogs ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(15, 22, 35, .55); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px; z-index: 50; overflow-y: auto; }
.dialog { width: 100%; background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg); outline: none; }
.dialog-body { padding: 22px 24px; display: flex; flex-direction: column; gap: 14px; }
.dialog-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }
.dialog-head h2 { font-size: 19px; }
.dialog-head p { margin-top: 3px; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.dialog-actions.split { justify-content: space-between; align-items: center; }
.confirm-text { font-size: 15px; }
.choice { display: flex; gap: 12px; align-items: flex-start; padding: 11px 14px; border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.choice:hover { border-color: var(--border-strong); }
.choice.on { border-color: var(--accent); background: var(--accent-soft); }
.choice input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--accent); flex-shrink: 0; }
.choice .txt { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.choice .txt span { font-size: 13px; color: var(--muted); }
.choices { display: flex; flex-direction: column; gap: 8px; }
.seg { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.seg button { height: 34px; padding: 0 12px; border-radius: 999px; border: 1px solid var(--border-strong); background: var(--surface); cursor: pointer; font-size: 13px; }
.seg button[aria-pressed="true"] { background: var(--accent); border-color: var(--accent); color: #fff; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 12px 14px; border-radius: 10px; background: var(--surface-3); }
.switch { appearance: none; width: 42px; height: 24px; border-radius: 12px; background: var(--border-strong); position: relative; cursor: pointer; transition: background .15s; flex-shrink: 0; }
.switch::after { content: ""; position: absolute; top: 3px; inset-inline-start: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: inset-inline-start .15s; }
.switch:checked { background: var(--accent); }
.switch:checked::after { inset-inline-start: 21px; }
.perm-table { width: 100%; border-collapse: collapse; min-width: 640px; }
.perm-table th { font-size: 12px; font-weight: 500; color: var(--muted); padding: 8px 6px; border-bottom: 1px solid var(--border); text-align: center; }
.perm-table th:first-child, .perm-table td:first-child { text-align: start; }
.perm-table td { padding: 9px 6px; border-bottom: 1px solid var(--border); text-align: center; }
.perm-table input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); cursor: pointer; }
.perm-table input:disabled { cursor: default; }
.who-cell { display: flex; align-items: center; gap: 10px; }
.who-cell .names { display: flex; flex-direction: column; line-height: 1.3; }
.picker { position: relative; flex: 1 1 240px; }
.picker-list { position: absolute; inset-inline: 0; top: 44px; background: var(--surface); border: 1px solid var(--border-strong); border-radius: 10px; box-shadow: var(--shadow); max-height: 260px; overflow: auto; z-index: 10; }
.picker-list button { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 12px; border: none; background: none; cursor: pointer; text-align: start; }
.picker-list button:hover, .picker-list button:focus { background: var(--row-hover); }
.tree { max-height: 340px; overflow: auto; border: 1px solid var(--border); border-radius: 10px; padding: 6px; }
.tree button { display: flex; align-items: center; gap: 8px; width: 100%; padding: 7px 8px; border: none; background: none; border-radius: 6px; cursor: pointer; text-align: start; }
.tree button:hover { background: var(--row-hover); }
.tree button.on { background: var(--row-selected); }

/* ---------- menus, toasts, uploads ---------- */
.menu { position: fixed; min-width: 200px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow); padding: 5px; z-index: 60; }
.menu-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: none; background: none; border-radius: 6px; cursor: pointer; text-align: start; }
.menu-item:hover, .menu-item:focus { background: var(--row-hover); outline: none; }
.menu-item.danger { color: var(--danger); }
.menu-item:disabled { opacity: .45; cursor: default; }
.menu-sep { height: 1px; background: var(--border); margin: 4px 6px; }
.toasts { position: fixed; bottom: 20px; inset-inline-start: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 70; align-items: center; }
[dir="rtl"] .toasts { transform: translateX(50%); }
.toast { background: #1A2233; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow); display: flex; gap: 14px; align-items: center; opacity: 0; transform: translateY(8px); transition: all .2s; max-width: 560px; }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #8A1C14; }
.toast.success { background: #155E3B; }
.toast .link { color: #9CC0FF; }
.uploads { position: fixed; bottom: 20px; inset-inline-end: 20px; width: 360px; max-width: calc(100vw - 40px); background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow); z-index: 40; overflow: hidden; }
.uploads-head { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; font-weight: 500; border-bottom: 1px solid var(--border); }
.uploads-list { max-height: 240px; overflow: auto; }
.up-item { padding: 10px 14px; display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.up-item + .up-item { border-top: 1px solid var(--border); }
.up-row { display: flex; justify-content: space-between; gap: 10px; }
.up-row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar { height: 5px; border-radius: 3px; background: var(--surface-3); overflow: hidden; }
.bar > div { height: 100%; background: var(--accent); transition: width .2s; }
.bar.err > div { background: var(--danger); }
.bar.ok > div { background: var(--ok); }

@media (max-width: 860px) {
  .sidebar { width: 72px; padding: 14px 8px; }
  .sidebar .label, .side-brand div, .nav-title, .side-status { display: none; }
  .nav-item { justify-content: center; }
  .user-chip .who { display: none; }
}

/* ---------- update banner ---------- */
.update-banner { display: flex; align-items: center; gap: 12px; padding: 10px 24px; background: var(--accent); color: #fff; }
.update-banner > div { flex: 1; min-width: 0; }
.update-banner .small { opacity: .9; }
.update-banner .btn.primary { background: #fff; color: var(--accent-text); border-color: #fff; }
.update-banner .btn.primary:hover { background: #EAF2FF; }

/* Search inside documents: the matching text */
.snippet { display: block; font-size: 12px; color: var(--muted); margin: 2px 0 1px; max-width: 640px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; white-space: normal; }
.snippet mark { background: var(--accent-soft); color: var(--accent-text); border-radius: 3px; padding: 0 2px; font-weight: 600; }
