:root {
  --ink: #1c2430;
  --muted: #5a6574;
  --panel: #fffdf8;
  --line: #d7d0c3;
  --accent: #0f6e56;
  --accent-soft: #d8efe6;
  --danger: #9b2c2c;
  --surface: #ffffff;
  --surface-muted: #faf8f3;
  --hover-bg: #f7f3ea;
  --tree-bg: #ffffff;
  --folder-count-bg: #f3efe6;
  --on-accent: #ffffff;
  --search-summary-bg: linear-gradient(135deg, #f8f4ea 0%, #eef7f3 100%);
  --search-card-bg: #ffffff;
  --search-snippet-bg: #fcfaf6;
  --search-snippet-border: #e7dfd0;
  --search-snippet-text: #3f3a32;
  --search-relevance-track: #efe8da;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Noto Sans Arabic", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 90% -10%, #e7f3ee 0%, transparent 55%),
    radial-gradient(900px 420px at 0% 0%, #f7e8d4 0%, transparent 50%),
    linear-gradient(180deg, #f7f3ea 0%, #efe9dc 100%);
  min-height: 100vh;
  direction: rtl;
  text-align: right;
}

h1, h2 {
  font-family: "Noto Serif Arabic", Georgia, serif;
  margin: 0 0 0.5rem 0;
}

.hidden { display: none !important; }

.view { padding: 1.25rem; max-width: 1200px; margin: 0 auto; }

.login-wrap {
  min-height: 80vh;
  display: grid;
  place-items: center;
}

.login-card {
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.5rem;
  box-shadow: 0 12px 40px rgba(28, 36, 48, 0.08);
}

.login-card h1 { text-align: center; font-size: 2rem; }

label {
  display: block;
  margin: 0.75rem 0 0.35rem;
  font-weight: 600;
}

input[type="text"],
input[type="password"],
input[type="search"],
input[type="file"],
select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font: inherit;
}

.btn {
  border: none;
  border-radius: 10px;
  padding: 0.7rem 1rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
}

.btn.primary {
  background: var(--accent);
  color: var(--on-accent);
  width: 100%;
  margin-top: 1rem;
}

.btn.ghost {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--ink);
}

.btn.small {
  width: auto;
  padding: 0.35rem 0.75rem;
  font-size: 0.85rem;
}

.btn.danger {
  background: var(--danger);
  color: #fff;
  width: auto;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: grid;
  place-items: center;
  padding: 1rem;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(28, 36, 48, 0.45);
}

.modal-card {
  position: relative;
  width: min(420px, 100%);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 1.25rem 1.5rem;
  box-shadow: 0 16px 48px rgba(28, 36, 48, 0.18);
}

.modal-card h2 {
  font-size: 1.25rem;
  margin-bottom: 0.35rem;
}

.modal-actions {
  display: flex;
  gap: 0.75rem;
  justify-content: flex-start;
  margin-top: 1.25rem;
}

.modal-actions .btn {
  margin-top: 0;
  width: auto;
  min-width: 7rem;
}

.muted { color: var(--muted); }
.hint { font-size: 0.85rem; color: var(--muted); text-align: center; margin-top: 1rem; }
.error { color: var(--danger); margin-top: 0.75rem; }

.hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  border-bottom: 1px solid var(--line);
  padding-bottom: 1rem;
  margin-bottom: 1rem;
}

.hero-brand {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
}

.hero-brand-mark {
  width: 3rem;
  height: 3rem;
  flex-shrink: 0;
  color: var(--accent);
}

.tagline { color: var(--muted); max-width: 40rem; margin: 0.35rem 0 0; }

.grid {
  display: grid;
  grid-template-columns: 1fr 1.15fr;
  gap: 1rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
}

.chips { display: flex; flex-wrap: wrap; gap: 0.4rem; margin: 0.75rem 0; }

.chip {
  background: var(--accent-soft);
  color: var(--accent);
  border-radius: 999px;
  padding: 0.2rem 0.65rem;
  font-size: 0.82rem;
  font-weight: 600;
}

.library { display: grid; gap: 0.75rem; }

.app-nav {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding: 0.35rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  width: fit-content;
}

.app-nav-btn {
  border: none;
  border-radius: 9px;
  padding: 0.55rem 0.9rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--muted);
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
}

.app-nav-btn:hover {
  background: #f3efe6;
  color: var(--ink);
}

.app-nav-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.trash-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.2rem;
  height: 1.2rem;
  padding: 0 0.3rem;
  border-radius: 999px;
  background: #c0392b;
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
}

.trash-page-panel {
  max-width: 900px;
}

.trash-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem 1rem;
  margin-bottom: 1rem;
}

.trash-toolbar .muted {
  margin: 0;
  flex: 1;
  min-width: 200px;
}

.search-results-shell {
  margin-top: 1rem;
  display: grid;
  gap: 1rem;
}

.search-results-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  padding: 0.75rem 1rem;
  border-radius: 12px;
  background: var(--search-summary-bg);
  border: 1px solid var(--line);
  color: var(--ink);
}

.search-summary-stat strong {
  color: var(--accent);
  font-size: 1.05rem;
}

.search-summary-dot {
  color: var(--muted);
}

.search-summary-query {
  margin-inline-start: auto;
  font-size: 0.9rem;
}

.search-active-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.search-option-chip {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 0.18rem 0.55rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border: 1px solid var(--line);
}

.search-results-grid {
  display: grid;
  gap: 0.85rem;
}

.search-result-card {
  position: relative;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 1rem;
  background: var(--search-card-bg);
  box-shadow: 0 8px 24px rgba(36, 28, 16, 0.04);
  overflow: hidden;
  color: var(--ink);
}

.search-result-card::before {
  content: "";
  position: absolute;
  inset-inline-start: 0;
  top: 0;
  bottom: 0;
  width: 4px;
  background: var(--accent);
}

.search-result-card.rank-gold::before { background: linear-gradient(180deg, #d4af37, #f0d78c); }
.search-result-card.rank-silver::before { background: linear-gradient(180deg, #9aa3ad, #d5dbe3); }
.search-result-card.rank-bronze::before { background: linear-gradient(180deg, #b87333, #e2a76f); }

.search-result-rank {
  position: absolute;
  top: 0.85rem;
  inset-inline-start: 1rem;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--muted);
  letter-spacing: 0.02em;
}

.search-result-card.rank-gold .search-result-rank {
  color: #9a7b1f;
}

.search-result-head {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding-top: 1.1rem;
}

.search-result-icon {
  width: 2.5rem;
  height: 2.5rem;
  border-radius: 12px;
  background: var(--accent-soft);
  display: grid;
  place-items: center;
  font-size: 1.2rem;
  flex-shrink: 0;
}

.search-result-meta {
  flex: 1;
  min-width: 0;
}

.search-result-title {
  margin: 0;
  font-size: 1rem;
  word-break: break-word;
}

.search-result-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.35rem;
  align-items: center;
}

.search-result-count {
  color: var(--muted);
  font-size: 0.82rem;
}

.search-result-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
  flex-shrink: 0;
}

.search-image-chip {
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
}

.search-result-card.has-image {
  display: grid;
  gap: 0.75rem;
}

.search-result-thumb,
.fb-card-thumb {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 10;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  overflow: hidden;
  background: var(--surface-muted);
  cursor: zoom-in;
}

.search-result-thumb {
  margin-top: 1.35rem;
}

.fb-card-thumb {
  aspect-ratio: 4 / 3;
}

.search-result-thumb img,
.fb-card-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s ease;
}

.search-result-thumb:hover img,
.search-result-thumb:focus-visible img,
.fb-card-thumb:hover img,
.fb-card-thumb:focus-visible img {
  transform: scale(1.03);
}

.search-result-thumb-placeholder,
.fb-card-thumb-placeholder {
  display: grid;
  place-items: center;
  width: 100%;
  height: 100%;
  font-size: 2rem;
  color: var(--muted);
}

.search-result-thumb.is-locked,
.fb-card-thumb.is-locked {
  cursor: not-allowed;
  opacity: 0.72;
}

.search-result-thumb.is-error,
.fb-card-thumb.is-error {
  border-style: dashed;
}

.search-relevance {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin: 0.85rem 0 0.65rem;
}

.search-relevance-track {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: var(--search-relevance-track);
  overflow: hidden;
}

.search-relevance-fill {
  height: 100%;
  width: var(--relevance, 0%);
  border-radius: inherit;
  background: linear-gradient(90deg, #6dbf9d, var(--accent));
  transition: width 0.35s ease;
}

.search-relevance-label {
  color: var(--accent);
  font-size: 0.82rem;
  font-weight: 700;
  white-space: nowrap;
}

.search-snippet-stack {
  display: grid;
  gap: 0.55rem;
}

.search-snippet {
  border: 1px dashed var(--search-snippet-border);
  border-radius: 10px;
  background: var(--search-snippet-bg);
  overflow: hidden;
}

.search-snippet-summary {
  list-style: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  font-weight: 600;
}

.search-snippet-summary::-webkit-details-marker { display: none; }

.search-snippet-pill {
  font-size: 0.82rem;
  color: var(--ink);
}

.search-snippet-score {
  font-size: 0.78rem;
  color: var(--accent);
}

.search-snippet-body {
  padding: 0 0.75rem 0.75rem;
}

.search-snippet-text {
  margin: 0;
  line-height: 1.7;
  color: var(--search-snippet-text);
}

.search-ellipsis {
  color: var(--muted);
  font-weight: 700;
}

.search-snippet-full {
  margin-top: 0.65rem;
  padding: 0.75rem;
  border-radius: 8px;
  background: var(--surface);
  border: 1px solid var(--line);
  line-height: 1.7;
  white-space: pre-wrap;
  color: var(--ink);
}

mark.query-hit {
  background: #ffe9a8;
  color: inherit;
  padding: 0 0.1em;
  border-radius: 3px;
}

.search-empty {
  margin-top: 1rem;
}

.folder-tree {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--tree-bg);
  padding: 0.5rem;
  overflow: hidden;
}

.tree-empty {
  padding: 1rem;
}

.tree-folder {
  border-radius: 8px;
}

.tree-folder-nested {
  margin: 0.15rem 0 0.15rem 0.75rem;
  border-right: 2px solid var(--accent-soft);
  padding-right: 0.5rem;
}

.tree-folder > summary.tree-folder-label {
  list-style: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.5rem 0.55rem;
  border-radius: 8px;
  font-weight: 600;
  user-select: none;
}

.tree-folder > summary.tree-folder-label::-webkit-details-marker {
  display: none;
}

.tree-folder > summary.tree-folder-label:hover {
  background: var(--hover-bg);
}

.tree-chevron {
  width: 0.45rem;
  height: 0.45rem;
  border-left: 2px solid var(--muted);
  border-bottom: 2px solid var(--muted);
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
  flex-shrink: 0;
}

.tree-folder:not([open]) > summary .tree-chevron {
  transform: rotate(135deg);
}

.tree-folder-icon {
  flex-shrink: 0;
}

.tree-folder-name {
  flex: 1;
  min-width: 0;
  word-break: break-word;
}

.tree-folder-count {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--muted);
  background: var(--folder-count-bg);
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
}

.tree-children {
  padding: 0.15rem 0 0.35rem 0.25rem;
}

.tree-files {
  list-style: none;
  margin: 0.2rem 0 0;
  padding: 0 0 0 1.25rem;
  border-right: 1px dashed var(--line);
}

.tree-file {
  margin: 0.1rem 0;
}

.tree-file-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
}

.tree-file-row:hover {
  background: var(--hover-bg);
}

.tree-file-icon {
  font-size: 1.1rem;
  flex-shrink: 0;
}

.tree-file-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}

.tree-file-name {
  font-weight: 600;
  word-break: break-word;
}

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

.tree-file-actions.explorer-actions {
  flex-direction: row;
  flex-wrap: wrap;
  gap: 0.25rem;
}

.tree-file.locked .tree-file-row {
  opacity: 0.85;
}

.explorer { display: grid; gap: 0.55rem; }

.explorer-folder {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  overflow: hidden;
}

.explorer-folder > summary {
  cursor: pointer;
  list-style: none;
  padding: 0.75rem 0.9rem;
  font-weight: 700;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
}

.explorer-folder > summary::-webkit-details-marker { display: none; }

.explorer-body { padding: 0.55rem 0.75rem 0.75rem; }

.explorer-group {
  margin: 0.45rem 0;
  padding-right: 0.65rem;
  border-right: 2px solid var(--accent-soft);
}

.explorer-group-title {
  font-weight: 600;
  margin-bottom: 0.35rem;
  color: var(--muted);
}

.explorer-file {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.75rem;
  margin: 0.25rem 0;
  border-radius: 12px;
  background: #fff;
  border: 1px solid #ece7dc;
}

.explorer-file-main {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  flex: 1;
  min-width: 0;
}

.explorer-file-main .file-icon-large {
  width: 3.5rem;
  height: 3.5rem;
  font-size: 1.75rem;
  flex-shrink: 0;
}

.explorer-file-title { font-weight: 700; word-break: break-word; }
.explorer-file-meta { color: var(--muted); font-size: 0.85rem; margin-top: 0.2rem; }
.explorer-file-preview { color: var(--muted); font-size: 0.85rem; margin-top: 0.35rem; }

.explorer-actions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex-shrink: 0;
}

.results { margin-top: 0.25rem; }

mark.query-hit, .query-hit {
  background: #ffe566;
  color: inherit;
  padding: 0 0.12rem;
  border-radius: 3px;
  font-weight: 600;
}

.doc-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0.85rem;
  background: #fff;
}

.doc-head {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  align-items: flex-start;
}

.doc-title { font-weight: 700; word-break: break-word; }

.doc-meta { color: var(--muted); font-size: 0.88rem; margin-top: 0.35rem; }

.status {
  margin-bottom: 1rem;
  padding: 0.75rem 1rem;
  border-radius: 10px;
  background: #eef7f3;
  border: 1px solid #b9dfd2;
}

.section-gap { margin-top: 1.5rem; }

.drop-zone {
  position: relative;
  border: 2px dashed var(--line);
  border-radius: 16px;
  background: linear-gradient(180deg, #fff 0%, #faf7f0 100%);
  padding: 1.5rem 1rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.15s;
  margin-bottom: 1rem;
}

.drop-zone:hover,
.drop-zone:focus-visible {
  border-color: var(--accent);
  background: #f3fbf8;
  outline: none;
}

.drop-zone.drag-over {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: scale(1.01);
}

.drop-zone-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
  width: 100%;
  height: 100%;
}

.drop-zone-icon {
  display: grid;
  place-items: center;
  margin-bottom: 0.5rem;
}

.cloud-transfer-icon--drop {
  width: 3rem;
  height: 3rem;
  color: var(--accent);
}

.drop-zone-title {
  font-weight: 700;
  font-size: 1.05rem;
  margin: 0 0 0.25rem;
}

.drop-zone-sub { margin: 0 0 0.85rem; }

.drop-zone-types {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  justify-content: center;
}

.type-pill {
  font-size: 0.78rem;
  font-weight: 700;
  padding: 0.2rem 0.55rem;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: #fff;
}

.type-pill.pdf { color: #b42318; border-color: #fecdca; background: #fef3f2; }
.type-pill.word { color: #175cd3; border-color: #b2ddff; background: #eff8ff; }
.type-pill.excel { color: #067647; border-color: #abefc6; background: #ecfdf3; }
.type-pill.powerpoint { color: #b93815; border-color: #f9dbaf; background: #fff6ed; }
.type-pill.text { color: #6941c6; border-color: #d9d6fe; background: #f4f3ff; }
.type-pill.image { color: #0e7090; border-color: #a5f0fc; background: #ecfeff; }

.drop-zone-ocr {
  margin-top: 0.65rem;
  font-size: 0.85rem;
}

.ocr-engine-panel {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 1rem;
}

.ocr-engine-hint {
  margin: 0;
  font-size: 0.84rem;
}

.pending-images-note {
  margin-top: 0.85rem;
  padding: 0.75rem 0.9rem;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: var(--surface-muted);
}

.ocr-dialog-card {
  max-width: 34rem;
}

.ocr-dialog-filename {
  margin: 0 0 0.35rem;
  word-break: break-word;
}

.ocr-dialog-status {
  margin: 0.75rem 0 0;
  min-height: 1.25rem;
}

.ocr-dialog-status.error {
  color: var(--danger);
}

.ocr-badge {
  display: inline-flex;
  align-items: center;
  padding: 0.12rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  color: #9a6700;
  background: #fff7d6;
  border: 1px solid #f5d565;
}

.storage-settings-panel {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.storage-mode-picker {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
}

.storage-mode-label {
  font-weight: 700;
  color: var(--ink);
}

.storage-mode-options {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.storage-mode-option {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--ink);
  cursor: pointer;
  font-weight: 600;
  font-size: 0.88rem;
}

.storage-mode-option:has(input:checked) {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
}

.storage-mode-option input {
  accent-color: var(--accent);
}

.storage-mode-status {
  margin: 0;
  font-size: 0.86rem;
}

.drive-connect-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.85rem;
  margin-bottom: 1rem;
  padding: 0.9rem 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-muted);
  color: var(--ink);
}

.drive-connect-panel strong {
  color: var(--ink);
}

.drive-connect-panel .btn.primary {
  background: var(--accent);
  color: var(--on-accent);
  border: 1px solid transparent;
}

.drive-connect-panel .btn.ghost {
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface);
}

.drive-connect-info {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  min-width: 0;
}

.drive-connect-icon {
  font-size: 1.5rem;
  line-height: 1;
}

.drive-connect-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
}

.puter-connect-panel {
  margin-top: 0.75rem;
}

.puter-login-note {
  margin: 0;
  font-size: 0.8rem;
  line-height: 1.5;
}

.puter-login-note a {
  color: var(--accent);
}

.mega-login-fields {
  display: grid;
  gap: 0.5rem;
  margin-top: 0.65rem;
}

.mega-login-input {
  width: min(100%, 280px);
  padding: 0.5rem 0.7rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
}

.mega-connect-panel {
  margin-bottom: 1rem;
}

.mega-connect-panel.is-recovery,
.puter-connect-panel.is-recovery {
  border-color: color-mix(in srgb, var(--danger, #c0392b) 45%, var(--line));
  background: color-mix(in srgb, var(--danger, #c0392b) 6%, var(--surface));
}

.auth-recovery-error {
  margin: 0.35rem 0 0;
  font-size: 0.85rem;
  line-height: 1.45;
  color: var(--danger, #c0392b);
}

.auth-recovery-error.hidden {
  display: none;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.drop-zone.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.drop-zone.is-disabled .drop-zone-input {
  pointer-events: none;
}

.search-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin-top: 0.35rem;
}

.search-actions .btn.primary {
  flex: 1;
  min-width: 7rem;
}

.pending-files-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.pending-files-grid.has-images {
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
}

.pending-file-card.is-image {
  align-items: stretch;
  text-align: start;
  gap: 0.65rem;
}

.pending-image-fields {
  display: grid;
  gap: 0.4rem;
  width: 100%;
}

.pending-image-fields.is-incomplete {
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  border: 1px dashed #f5d565;
  background: #fffdf5;
}

.pending-image-label {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink);
}

.pending-image-name-input,
.pending-image-folder-select,
.pending-image-folder-new {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
}

.pending-image-hint {
  margin: 0.15rem 0 0;
  font-size: 0.75rem;
  line-height: 1.4;
}

.pending-file-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  width: 100%;
  margin-top: 0.15rem;
}

.pending-file-footer .pending-file-size {
  margin: 0;
  text-align: start;
}

.pending-file-card.is-image .pending-file-remove {
  flex-shrink: 0;
}

.pending-file-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.45rem;
  padding: 0.85rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--surface);
  text-align: center;
}

.file-icon-large {
  width: 4.5rem;
  height: 4.5rem;
  border-radius: 14px;
  display: grid;
  place-items: center;
  font-size: 2.2rem;
  border: 1px solid transparent;
}

.file-icon-large.pdf { background: #fef3f2; border-color: #fecdca; }
.file-icon-large.word { background: #eff8ff; border-color: #b2ddff; }
.file-icon-large.excel { background: #ecfdf3; border-color: #abefc6; }
.file-icon-large.powerpoint { background: #fff6ed; border-color: #f9dbaf; }
.file-icon-large.text { background: #f4f3ff; border-color: #d9d6fe; }
.file-icon-large.other { background: #f2f4f7; border-color: #d0d5dd; }

.pending-file-name {
  font-size: 0.78rem;
  font-weight: 600;
  word-break: break-word;
  line-height: 1.3;
  max-width: 100%;
}

.pending-file-size {
  font-size: 0.72rem;
  color: var(--muted);
}

.pending-file-remove {
  border: none;
  background: transparent;
  color: var(--danger);
  font: inherit;
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0;
}

.pending-file-card.is-image {
  padding: 0.55rem;
}

.pending-file-thumb {
  width: 100%;
  aspect-ratio: 1;
  border: 1px solid #a5f0fc;
  border-radius: 12px;
  overflow: hidden;
  padding: 0;
  background: #ecfeff;
  cursor: zoom-in;
  display: block;
}

.pending-file-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  transition: transform 0.2s ease;
}

.pending-file-thumb:hover img,
.pending-file-thumb:focus-visible img {
  transform: scale(1.04);
}

.pending-file-thumb:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

body.image-preview-open {
  overflow: hidden;
}

.image-preview-modal {
  position: fixed;
  inset: 0;
  z-index: 1100;
  display: grid;
  place-items: center;
  padding: 0.75rem;
}

.image-preview-backdrop {
  position: absolute;
  inset: 0;
  background: color-mix(in srgb, var(--ink) 58%, transparent);
}

.image-preview-shell {
  position: relative;
  width: min(960px, 100%);
  max-height: calc(100vh - 1.5rem);
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: var(--panel);
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 24px 64px color-mix(in srgb, var(--ink) 22%, transparent);
}

.image-preview-toolbar {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.85rem;
  background: var(--surface-muted);
  border-bottom: 1px solid var(--line);
}

.image-preview-title {
  flex: 1;
  min-width: 0;
  margin: 0;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.image-preview-zoom-controls {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.image-preview-zoom-btn,
.image-preview-close {
  width: 2.1rem;
  height: 2.1rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

.image-preview-zoom-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.image-preview-fit-btn {
  min-width: auto;
  padding: 0.35rem 0.65rem;
  font-size: 0.78rem;
  color: var(--ink);
  border-color: var(--line);
  background: var(--surface);
}

.image-preview-zoom-level {
  min-width: 3.2rem;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--muted);
}

.image-preview-stage {
  position: relative;
  min-height: 280px;
  height: min(68vh, 640px);
  overflow: hidden;
  touch-action: none;
  background: var(--surface-muted);
  cursor: grab;
}

.image-preview-frame {
  position: absolute;
  left: 50%;
  top: 50%;
  transform-origin: center center;
  line-height: 0;
  will-change: transform;
}

.image-preview-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.image-preview-stage.is-zoomed {
  cursor: grab;
}

.image-preview-stage.is-dragging {
  cursor: grabbing;
}

.image-preview-comments {
  display: grid;
  gap: 0.45rem;
  padding: 0 0.85rem;
}

.image-preview-comments label {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 700;
}

.image-preview-comments textarea {
  width: 100%;
  min-height: 4.5rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  color: var(--ink);
  font: inherit;
  resize: vertical;
}

.image-preview-comment-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.65rem;
}

.image-preview-comment-status {
  margin: 0;
  font-size: 0.82rem;
}

.image-preview-comment-status.error {
  color: var(--danger);
}

.comment-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: color-mix(in srgb, var(--accent) 12%, transparent);
  color: var(--accent);
}

.image-preview-hint {
  margin: 0;
  padding: 0 0.85rem 0.75rem;
  font-size: 0.78rem;
  text-align: center;
  color: var(--muted);
}

@media (max-width: 640px) {
  .image-preview-toolbar {
    flex-wrap: wrap;
  }

  .image-preview-zoom-controls {
    order: 3;
    width: 100%;
    justify-content: center;
  }

  .image-preview-stage {
    height: min(58vh, 520px);
  }
}

.explorer-file.locked {
  border-color: #d9d6fe;
  background: #faf9ff;
}

.lock-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.78rem;
  font-weight: 700;
  color: #6941c6;
  background: #f4f3ff;
  border: 1px solid #d9d6fe;
  border-radius: 999px;
  padding: 0.1rem 0.45rem;
  margin-right: 0.35rem;
}

.locked-preview {
  color: #6941c6;
  font-style: italic;
  font-size: 0.85rem;
}

.trash-list {
  display: grid;
  gap: 0.55rem;
}

.trash-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.7rem 0.8rem;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: #fffaf5;
}

.trash-item-info { flex: 1; min-width: 0; }

.trash-item-title {
  font-weight: 700;
  word-break: break-word;
}

.trash-item-meta {
  color: var(--muted);
  font-size: 0.82rem;
  margin-top: 0.2rem;
}

.trash-actions {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  flex-shrink: 0;
}

.modal-card label {
  margin-top: 0.75rem;
}

.modal-card input[type="text"],
.modal-card input[type="password"] {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  font: inherit;
  color: var(--ink);
}

.password-field-wrap {
  position: relative;
}

.password-field-wrap.has-password-toggle input {
  padding-left: 2.5rem;
}

.password-field-wrap .password-toggle-btn {
  position: absolute;
  top: 50%;
  left: 0.55rem;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
  padding: 0.2rem 0.35rem;
}

.password-field-wrap .password-toggle-btn:hover {
  color: var(--accent, #0f6e56);
}

@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
  .hero { flex-direction: column; }
}

.explorer-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}

.explorer-title {
  margin-bottom: 0.2rem;
}

.explorer-storage-label {
  margin: 0;
  font-size: 0.86rem;
}

.advanced-search-panel {
  margin: 0.75rem 0 1rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-muted);
  padding: 0.65rem 0.85rem;
}

.advanced-search-panel summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--accent);
}

.advanced-search-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.55rem 0.85rem;
  margin-top: 0.75rem;
}

.advanced-search-hint {
  grid-column: 1 / -1;
  margin: 0;
  font-size: 0.82rem;
}

.search-option {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.9rem;
  font-weight: 500;
}

.search-option input {
  width: auto;
  margin: 0;
}

.tree-storage-root,
.tree-storage-children {
  display: grid;
  gap: 0.65rem;
}

.tree-storage-label {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--surface-muted);
  font-weight: 700;
  cursor: pointer;
  list-style: none;
}

.tree-storage-icon {
  font-size: 1.1rem;
}

.tree-storage-name {
  flex: 1;
}

.tree-file-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 0.65rem;
  align-items: center;
  color: var(--muted);
  font-size: 0.78rem;
  margin-top: 0.2rem;
}

.tree-file-path {
  word-break: break-word;
}

.tree-file-size::before {
  content: "·";
  margin-left: 0.35rem;
}

.storage-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.2rem;
  border-radius: 999px;
  padding: 0.08rem 0.45rem;
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid transparent;
}

.storage-badge.storage-github {
  color: #5b21b6;
  background: #f3e8ff;
  border-color: #d8b4fe;
}

.storage-badge.storage-drive {
  color: #0e7490;
  background: #ecfeff;
  border-color: #a5f0fc;
}

.storage-badge.storage-mega {
  color: #b91c1c;
  background: #fef2f2;
  border-color: #fecaca;
}

.storage-badge.storage-onedrive {
  color: #1d4ed8;
  background: #eff6ff;
  border-color: #bfdbfe;
}

.storage-badge.storage-local {
  color: #475467;
  background: #f2f4f7;
  border-color: #d0d5dd;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --ink: #e8edf5;
  --muted: #9aa8ba;
  --panel: #162033;
  --line: #2f3b50;
  --accent: #34d399;
  --accent-soft: #123b30;
  --danger: #ff9b9b;
  --surface: #101828;
  --surface-muted: #1a2438;
  --hover-bg: #243044;
  --tree-bg: #141d2e;
  --folder-count-bg: #243044;
  --on-accent: #052e1d;
  --search-summary-bg: linear-gradient(135deg, #1a2438 0%, #132a24 100%);
  --search-card-bg: #1a2438;
  --search-snippet-bg: #141d2e;
  --search-snippet-border: #334155;
  --search-snippet-text: #d7e0ea;
  --search-relevance-track: #243044;
}

html[data-theme="dark"] body {
  background:
    radial-gradient(1200px 500px at 90% -10%, rgba(61, 214, 160, 0.08) 0%, transparent 55%),
    radial-gradient(900px 420px at 0% 0%, rgba(120, 140, 255, 0.08) 0%, transparent 50%),
    linear-gradient(180deg, #0b1220 0%, #121b2d 100%);
}

html[data-theme="dark"] .search-results-summary,
html[data-theme="dark"] .search-result-card,
html[data-theme="dark"] .search-snippet,
html[data-theme="dark"] .search-snippet-full {
  background: var(--search-card-bg);
  color: var(--ink);
  border-color: var(--line);
}

html[data-theme="dark"] .search-snippet {
  background: var(--search-snippet-bg);
  border-color: var(--search-snippet-border);
}

html[data-theme="dark"] .search-snippet-text,
html[data-theme="dark"] .search-snippet-pill,
html[data-theme="dark"] .search-result-title {
  color: var(--search-snippet-text);
}

html[data-theme="dark"] .search-result-card.rank-gold .search-result-rank {
  color: #f0d78c;
}

html[data-theme="dark"] mark.query-hit {
  background: #7c5e10;
  color: #fff8e7;
}

html[data-theme="dark"] .drop-zone,
html[data-theme="dark"] .pending-file-card,
html[data-theme="dark"] .storage-mode-picker,
html[data-theme="dark"] .advanced-search-panel,
html[data-theme="dark"] .tree-storage-label,
html[data-theme="dark"] .tree-folder > summary.tree-folder-label,
html[data-theme="dark"] .tree-file-row,
html[data-theme="dark"] .trash-item {
  background: var(--surface-muted);
}

html[data-theme="dark"] .folder-tree {
  background: var(--tree-bg);
  border-color: var(--line);
}

html[data-theme="dark"] .tree-storage-label:hover,
html[data-theme="dark"] .tree-folder > summary.tree-folder-label:hover,
html[data-theme="dark"] .tree-file-row:hover {
  background: var(--hover-bg);
}

html[data-theme="dark"] .drive-connect-panel {
  background: var(--surface-muted);
  border-color: #3b5f82;
  color: var(--ink);
}

html[data-theme="dark"] .drive-connect-panel .btn.primary {
  background: var(--accent);
  color: var(--on-accent);
  font-weight: 700;
}

html[data-theme="dark"] .drive-connect-panel .btn.primary:hover {
  filter: brightness(1.08);
}

html[data-theme="dark"] .drive-connect-panel .btn.ghost {
  color: var(--ink);
  background: var(--surface);
  border-color: var(--line);
}

html[data-theme="dark"] .storage-mode-option {
  background: var(--surface);
  color: var(--ink);
}

html[data-theme="dark"] .storage-mode-option:has(input:checked) {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent);
}

html[data-theme="dark"] .storage-badge.storage-github {
  color: #d8b4fe;
  background: #2a1a45;
  border-color: #5b21b6;
}

html[data-theme="dark"] .storage-badge.storage-drive {
  color: #67e8f9;
  background: #10323a;
  border-color: #0e7490;
}

html[data-theme="dark"] .storage-badge.storage-mega {
  color: #fca5a5;
  background: #3a1515;
  border-color: #b91c1c;
}

html[data-theme="dark"] .storage-badge.storage-onedrive {
  color: #93c5fd;
  background: #14244a;
  border-color: #1d4ed8;
}

html[data-theme="dark"] .storage-badge.storage-local {
  color: #d0d5dd;
  background: #243041;
  border-color: #475467;
}

html[data-theme="dark"] .type-pill,
html[data-theme="dark"] .chip,
html[data-theme="dark"] .lock-badge {
  filter: brightness(0.92);
}

html[data-theme="dark"] .btn.ghost {
  color: var(--ink);
  border-color: var(--line);
}

html[data-theme="dark"] .status {
  background: #1a2a40;
  border-color: #2f4d67;
}

html[data-theme="dark"] .ocr-badge {
  color: #f5d565;
  background: #3a2f10;
  border-color: #7c5e10;
}

html[data-theme="dark"] .pending-images-note,
html[data-theme="dark"] .ocr-dialog-card .drive-connect-panel {
  background: var(--surface-muted);
}

html[data-theme="dark"] .pending-image-fields.is-incomplete {
  background: #2a2410;
  border-color: #7c5e10;
}

html[data-theme="dark"] .pending-image-fields.is-incomplete {
  background: #2a2410;
  border-color: #7c5e10;
}

/* ── PDF Studio (Sejda-like editor) ── */

body.pdf-studio-open {
  overflow: hidden;
}

.pdf-studio-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: flex;
  align-items: stretch;
  justify-content: center;
}

.pdf-studio-modal.hidden {
  display: none;
}

.pdf-studio-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 14, 22, 0.72);
}

.pdf-studio-shell {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  width: min(100%, 1440px);
  height: 100%;
  margin: 0 auto;
  background: var(--surface);
  border-inline: 1px solid var(--line);
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.35);
}

.pdf-studio-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--surface-muted);
}

.pdf-studio-header-main {
  flex: 1 1 180px;
  min-width: 0;
}

.pdf-studio-title {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pdf-studio-page-label {
  margin: 0.2rem 0 0;
  font-size: 0.85rem;
}

.pdf-studio-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  align-items: center;
  flex: 2 1 420px;
}

.pdf-studio-merge-btn {
  cursor: pointer;
}

.pdf-studio-merge-select {
  max-width: 200px;
  padding: 0.35rem 0.5rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  font-size: 0.82rem;
}

.pdf-studio-close {
  border: 0;
  background: transparent;
  color: var(--ink-muted);
  font-size: 1.25rem;
  cursor: pointer;
  padding: 0.25rem 0.45rem;
  border-radius: 8px;
}

.pdf-studio-close:hover {
  background: var(--surface);
  color: var(--ink);
}

.pdf-studio-body {
  display: grid;
  grid-template-columns: minmax(88px, 112px) minmax(108px, 132px) minmax(0, 1fr);
  flex: 1;
  min-height: 0;
}

.pdf-studio-sidebar {
  border-inline-end: 1px solid var(--line);
  background: var(--surface-muted);
  padding: 0.65rem 0.5rem;
  overflow: auto;
}

.pdf-studio-sidebar-title {
  margin: 0 0 0.5rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-muted);
  text-align: center;
}

.pdf-studio-thumbs {
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

.pdf-studio-thumb {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 72px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  padding: 0.35rem;
}

.pdf-studio-thumb.is-active {
  border-color: var(--accent);
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--accent) 35%, transparent);
}

.pdf-studio-thumb-num {
  font-size: 0.9rem;
  font-weight: 700;
}

.pdf-studio-thumb-rot,
.pdf-studio-thumb-ocr {
  position: absolute;
  font-size: 0.65rem;
  line-height: 1;
}

.pdf-studio-thumb-rot {
  top: 4px;
  inset-inline-start: 4px;
  color: var(--ink-muted);
}

.pdf-studio-thumb-ocr {
  bottom: 4px;
  inset-inline-end: 4px;
}

.pdf-studio-stage {
  overflow: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 0.75rem 1rem 1rem;
  background: color-mix(in srgb, var(--ink) 4%, var(--surface));
  min-width: 0;
}

.pdf-studio-zoom-bar {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.65rem;
  width: 100%;
  max-width: 920px;
}

.pdf-studio-zoom-label {
  min-width: 3.5rem;
  text-align: center;
  font-size: 0.85rem;
  color: var(--ink-muted);
}

.pdf-studio-page-wrap {
  position: relative;
  margin: 0 auto;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.18);
  background: #fff;
}

.pdf-studio-canvas {
  display: block;
  max-width: 100%;
  height: auto;
  background: #fff;
}

.pdf-studio-text-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  line-height: 1;
  z-index: 3;
  pointer-events: none;
}

.pdf-studio-text-layer.is-selectable {
  z-index: 6;
}

.pdf-studio-text-layer.is-selectable span {
  color: transparent !important;
  -webkit-text-fill-color: transparent;
  user-select: text;
  -webkit-user-select: text;
  cursor: text;
  pointer-events: auto;
}

.pdf-studio-text-layer.is-selectable ::selection {
  background: rgba(20, 184, 166, 0.35);
  color: transparent;
}

.pdf-studio-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  touch-action: none;
  pointer-events: none;
}

.pdf-studio-overlay.is-interactive {
  z-index: 4;
  pointer-events: auto;
  cursor: crosshair;
}

.pdf-studio-annotation-layer {
  position: absolute;
  inset: 0;
  z-index: 4;
  pointer-events: none;
}

.pdf-studio-annotation-layer:not(.hidden) {
  pointer-events: auto;
}

.pdf-ann-hit {
  position: absolute;
  border: 2px solid transparent;
  background: transparent;
  padding: 0;
  cursor: pointer;
}

.pdf-ann-hit.is-selected {
  border-color: var(--accent);
  background: rgba(20, 184, 166, 0.12);
}

.pdf-inline-text-editor {
  position: absolute;
  z-index: 6;
  min-width: 160px;
  min-height: 1.5em;
  max-width: min(320px, 90%);
  padding: 0.25rem 0.4rem;
  border: 2px solid var(--accent);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.97);
  color: var(--ink);
  font-family: "Noto Sans Arabic", sans-serif;
  font-size: 16px;
  line-height: 1.4;
  outline: none;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
}

.pdf-studio-submodal {
  z-index: 1300;
}

#pdf-text-dialog textarea {
  width: 100%;
  min-height: 5rem;
  margin-top: 0.5rem;
  padding: 0.6rem;
  border: 1px solid var(--line);
  border-radius: 8px;
  font-family: "Noto Sans Arabic", sans-serif;
  resize: vertical;
}

.pdf-studio-edit-tools {
  border-inline-end: 1px solid var(--line);
  background: var(--surface-muted);
  padding: 0.65rem 0.5rem;
  overflow: auto;
}

.pdf-studio-tool-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.35rem;
}

.pdf-studio-tool {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  color: var(--ink);
  min-height: 36px;
  font-size: 0.95rem;
  cursor: pointer;
}

.pdf-studio-tool.is-active {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
  color: var(--accent);
}

.pdf-studio-delete-ann {
  width: 100%;
  margin-top: 0.55rem;
}

.pdf-studio-prop {
  display: grid;
  gap: 0.25rem;
  margin-top: 0.55rem;
  font-size: 0.78rem;
  color: var(--ink-muted);
}

.pdf-studio-prop input[type="number"],
.pdf-studio-prop input[type="color"] {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  padding: 0.25rem;
}

.pdf-signature-pad {
  width: 100%;
  max-width: 420px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: #fff;
  touch-action: none;
  cursor: crosshair;
}

.pdf-studio-thumb-edit {
  position: absolute;
  top: 4px;
  inset-inline-end: 4px;
  font-size: 0.65rem;
}

.pdf-studio-footer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  align-items: center;
  justify-content: space-between;
  padding: 0.65rem 1rem;
  border-top: 1px solid var(--line);
  background: var(--surface-muted);
}

.pdf-studio-hint {
  margin: 0;
  font-size: 0.8rem;
}

.pdf-studio-status {
  margin: 0;
  font-size: 0.85rem;
}

.pdf-studio-status.is-error {
  color: var(--danger, #c0392b);
}

.pdf-studio-status.hidden {
  display: none;
}

.fb-card.is-pdf .fb-card-icon {
  cursor: pointer;
}

button.fb-card-icon {
  border: 0;
  background: transparent;
  padding: 0.35rem;
  width: 100%;
  display: grid;
  place-items: center;
  border-radius: 10px;
}

.fb-card.is-pdf .fb-card-icon:hover,
button.fb-card-icon:hover {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}

@media (max-width: 900px) {
  .pdf-studio-body {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto minmax(0, 1fr);
  }

  .pdf-studio-sidebar,
  .pdf-studio-edit-tools {
    border-inline-end: 0;
    border-bottom: 1px solid var(--line);
    max-height: 110px;
  }

  .pdf-studio-thumbs {
    flex-direction: row;
    overflow-x: auto;
  }

  .pdf-studio-tool-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .pdf-studio-thumb {
    min-width: 56px;
    min-height: 56px;
  }
}

html[data-theme="dark"] .pdf-studio-stage {
  background: #111827;
}

html[data-theme="dark"] .pdf-studio-canvas {
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.45);
}

/* ── File browser (Drive / Windows 11 style) ── */

.files-page-panel {
  padding: 0;
  overflow: hidden;
}

.file-browser-root {
  min-height: min(72vh, 720px);
}

.library-files-link {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.65rem;
  margin-top: 1.25rem;
  padding: 0.85rem 1rem;
  border: 1px dashed var(--line);
  border-radius: 12px;
  background: var(--surface-muted);
}

.files-count-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.35rem;
  height: 1.35rem;
  padding: 0 0.35rem;
  margin-inline-start: 0.35rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  background: var(--accent-soft);
  color: var(--accent);
}

.fb-shell {
  --fb-sidebar-width: 260px;
  display: flex;
  align-items: stretch;
  min-height: min(72vh, 720px);
}

.fb-sidebar {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  width: var(--fb-sidebar-width);
  min-width: var(--fb-sidebar-width);
  max-width: 55%;
  flex-shrink: 0;
  padding: 1rem 0.75rem;
  border-inline-end: 1px solid var(--line);
  background: var(--surface-muted);
  overflow: auto;
}

.fb-resize-handle {
  position: relative;
  flex-shrink: 0;
  width: 8px;
  margin: 0 -3px;
  cursor: col-resize;
  touch-action: none;
  z-index: 2;
}

.fb-resize-handle::after {
  content: "";
  position: absolute;
  inset: 0.75rem 3px;
  border-radius: 4px;
  background: var(--line);
  opacity: 0.35;
  transition: opacity 0.15s ease, background 0.15s ease;
}

.fb-resize-handle:hover::after,
.fb-resize-handle:focus-visible::after,
.fb-shell.is-resizing .fb-resize-handle::after {
  opacity: 1;
  background: var(--accent);
}

.fb-resize-handle:focus-visible {
  outline: none;
}

body.fb-resizing,
body.fb-resizing * {
  cursor: col-resize !important;
  user-select: none !important;
}

.fb-nav-section {
  margin: 0.85rem 0 0.35rem;
  padding: 0 0.55rem;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.fb-nav-section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  text-transform: none;
  letter-spacing: normal;
  font-size: 0.85rem;
}

.fb-create-folder-btn {
  padding: 0.2rem 0.55rem;
  min-height: auto;
}

.fb-nav-empty {
  margin: 0.25rem 0.75rem 0.5rem;
  font-size: 0.85rem;
}

.fb-folder-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.2rem;
  align-items: start;
  border-radius: 10px;
}

.fb-folder-row.active {
  background: var(--accent-soft);
}

.fb-folder-row.is-locked .fb-nav-item {
  opacity: 0.88;
}

.fb-folder-actions {
  display: inline-flex;
  gap: 0.15rem;
  padding-inline-end: 0.25rem;
}

.fb-folder-action-btn {
  border: none;
  background: transparent;
  cursor: pointer;
  padding: 0.2rem 0.35rem;
  border-radius: 8px;
  font-size: 0.82rem;
  line-height: 1;
}

.fb-folder-action-btn:hover {
  background: var(--hover-bg);
}

.fb-folder-action-btn.danger:hover {
  background: #fee4e2;
}

.pending-customize {
  width: 100%;
  text-align: start;
}

.pending-customize summary {
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: 0.35rem;
}

.pending-customize .pending-image-fields {
  margin-top: 0.35rem;
}

.pending-files-grid.has-mixed {
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

.fb-nav-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: start;
  gap: 0.55rem;
  width: 100%;
  padding: 0.55rem 0.65rem;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  text-align: start;
  cursor: pointer;
  transition: background 0.15s ease;
}

.fb-nav-item:hover {
  background: var(--hover-bg);
}

.fb-nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.fb-nav-icon {
  font-size: 1rem;
  line-height: 1;
  flex-shrink: 0;
}

.fb-nav-label {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
  line-height: 1.35;
}

.fb-nav-count {
  min-width: 1.4rem;
  padding: 0.1rem 0.35rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-align: center;
  background: var(--folder-count-bg, #eef2f6);
  color: var(--muted);
  flex-shrink: 0;
}

.fb-nav-item.active .fb-nav-count {
  background: rgba(255, 255, 255, 0.35);
  color: inherit;
}

.fb-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 1rem 1.1rem 1.25rem;
}

.fb-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  margin-bottom: 0.35rem;
}

.fb-breadcrumbs {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
}

.fb-crumb {
  border: none;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-size: 0.9rem;
  padding: 0.2rem 0.35rem;
  border-radius: 8px;
  cursor: pointer;
}

.fb-crumb:hover:not(.current) {
  background: var(--hover-bg);
  color: var(--ink);
}

.fb-crumb.current {
  color: var(--ink);
  font-weight: 700;
  cursor: default;
}

.fb-crumb-sep {
  color: var(--muted);
  opacity: 0.7;
  user-select: none;
}

.fb-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.fb-search-wrap {
  display: flex;
  min-width: min(100%, 220px);
}

.fb-search-input,
.fb-select {
  width: 100%;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
}

.fb-select-wrap {
  min-width: 7rem;
}

.fb-view-toggle {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
}

.fb-view-btn {
  border: none;
  background: var(--panel);
  color: var(--muted);
  padding: 0.45rem 0.65rem;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}

.fb-view-btn.active {
  background: var(--accent-soft);
  color: var(--accent);
}

.fb-summary {
  margin: 0 0 0.85rem;
  font-size: 0.88rem;
}

.fb-content {
  flex: 1;
  min-height: 0;
  overflow: auto;
}

.fb-source-split {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
  align-items: start;
}

.fb-source-section {
  border: 1px solid var(--line);
  border-radius: 16px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  overflow: hidden;
}

.fb-source-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--line);
  background: color-mix(in srgb, var(--accent) 6%, var(--panel));
}

.fb-source-header h3 {
  margin: 0;
  font-size: 1rem;
}

.fb-source-content {
  padding: 0.85rem;
}

.fb-source-empty {
  margin: 0;
  padding: 1.25rem 1rem 1.5rem;
}

@media (max-width: 960px) {
  .fb-source-split {
    grid-template-columns: 1fr;
  }
}

.fb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 0.85rem;
}

.fb-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.85rem;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, transform 0.15s ease;
}

.fb-card:hover {
  border-color: color-mix(in srgb, var(--accent) 45%, var(--line));
  box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
  transform: translateY(-1px);
}

.fb-card.is-selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 28%, transparent);
}

.fb-card-select {
  position: absolute;
  top: 0.55rem;
  inset-inline-start: 0.55rem;
  z-index: 3;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.35rem;
  height: 1.35rem;
  border-radius: 6px;
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  cursor: pointer;
}

.fb-card-select input {
  width: 1rem;
  height: 1rem;
  margin: 0;
  cursor: pointer;
  accent-color: var(--accent);
}

.fb-selection-bar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  padding: 0.35rem 0 0.15rem;
}

.fb-select-all {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.9rem;
  cursor: pointer;
  user-select: none;
}

.fb-select-all input {
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--accent);
}

.fb-selection-count {
  font-size: 0.88rem;
}

.fb-card.is-locked {
  border-style: dashed;
  opacity: 0.92;
}

.fb-card.is-image {
  gap: 0.65rem;
}

.fb-card-icon {
  font-size: 2rem;
  line-height: 1;
}

.fb-card-thumb:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.fb-card-title {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  line-height: 1.35;
  word-break: break-word;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.fb-card-meta {
  margin: 0;
  font-size: 0.82rem;
}

.fb-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.fb-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: auto;
  padding-top: 0.25rem;
}

.fb-list {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.fb-list-header,
.fb-list-row {
  display: grid;
  grid-template-columns: minmax(0, 2.2fr) minmax(90px, 1fr) minmax(110px, 1fr) 72px minmax(180px, auto);
  gap: 0.65rem;
  align-items: center;
}

.fb-list-header {
  padding: 0.35rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 700;
}

.fb-list-row {
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
}

.fb-list-row:hover {
  background: var(--hover-bg);
}

.fb-list-main {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  min-width: 0;
}

.fb-list-icon {
  font-size: 1.35rem;
  flex-shrink: 0;
}

.fb-list-info {
  min-width: 0;
}

.fb-list-title {
  font-weight: 700;
  word-break: break-word;
}

.fb-list-sub {
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.fb-list-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  justify-content: flex-end;
}

.fb-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.35rem;
  min-height: 280px;
  padding: 2rem 1rem;
}

.fb-empty-icon {
  font-size: 3rem;
  opacity: 0.85;
}

.fb-empty h3 {
  margin: 0.35rem 0 0;
}

@media (max-width: 900px) {
  .fb-shell {
    flex-direction: column;
  }

  .fb-resize-handle {
    display: none;
  }

  .fb-sidebar {
    width: 100%;
    min-width: 0;
    max-width: none;
    border-inline-end: none;
    border-bottom: 1px solid var(--line);
    max-height: 220px;
  }

  .fb-list-header {
    display: none;
  }

  .fb-list-row {
    grid-template-columns: 1fr;
    gap: 0.45rem;
  }

  .fb-list-category,
  .fb-list-storage,
  .fb-list-size {
    font-size: 0.82rem;
  }

  .fb-list-actions {
    justify-content: flex-start;
  }
}

html[data-theme="dark"] .fb-sidebar,
html[data-theme="dark"] .library-files-link {
  background: var(--surface-muted);
}

html[data-theme="dark"] .fb-card,
html[data-theme="dark"] .fb-list-row,
html[data-theme="dark"] .fb-search-input,
html[data-theme="dark"] .fb-select {
  background: var(--surface-muted);
}

html[data-theme="dark"] .fb-card:hover {
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}

.fb-draggable.is-dragging {
  opacity: 0.55;
  transform: scale(0.98);
}

.fb-drop-target,
.fb-folder-row.fb-drop-target,
.fb-content.fb-drop-target {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
  background: var(--accent-soft);
}

.fb-content {
  min-height: 200px;
}
