* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  background: #1e1e1e;
  color: #dcddde;
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
  display: flex;
  flex-direction: column;
  height: 100%;
}

/* Obsidian-mobile style top bar: flat, icon-only ghost buttons */
#toolbar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 10px 12px;
  background: #1e1e1e;
  direction: rtl;
  flex: 0 0 auto;
}
#toolbar .spacer { flex: 1; }
#fileName {
  direction: ltr;
  unicode-bidi: isolate;
  font-size: 16px;
  font-weight: 600;
  color: #dcddde;
  max-width: 44vw;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-inline-start: 6px;
}
.iconbtn {
  background: none;
  border: none;
  border-radius: 8px;
  padding: 8px;
  color: #a3a3a3;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.iconbtn svg { width: 22px; height: 22px; }
.iconbtn:active { background: #2d2d2d; color: #dcddde; }
body.nofile .fileonly { display: none; }

/* group picker dropdown */
#groupPicker, #sharePicker {
  display: none;
  position: absolute;
  top: 52px;
  inset-inline-end: 10px;
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 10px;
  padding: 6px;
  z-index: 30;
  min-width: 190px;
  direction: rtl;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
}
#groupPicker.open, #sharePicker.open { display: block; }
#groupPicker .gp-item, #sharePicker .gp-item {
  padding: 10px 12px;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
}
#groupPicker .gp-item:active, #sharePicker .gp-item:active { background: #3a3a3a; }
#groupPicker .gp-empty { color: #8a8a8a; font-size: 13px; padding: 8px 12px; }

/* reader */
#view {
  flex: 1;
  overflow-y: auto;
  padding: 8px 20px 80px;
  font-size: 16px;
  line-height: 1.7;
  word-wrap: break-word;
}
#editor {
  flex: 1;
  background: #1e1e1e;
  color: #dcddde;
  border: none;
  outline: none;
  resize: none;
  padding: 8px 20px 80px;
  font-family: system-ui, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.7;
}
#editor { display: none; }
body.editing #view { display: none; }
body.editing #editor { display: block; }
body.nofile #view, body.nofile #editor { display: none !important; }
body:not(.nofile) #home { display: none; }

/* home / library */
#home {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px 60px;
  direction: rtl;
}
.home-head { text-align: center; margin: 8px 0 18px; }
.home-logo {
  direction: ltr;
  unicode-bidi: isolate;
  width: 72px; height: 72px;
  margin: 0 auto 10px;
  border-radius: 20px;
  background: linear-gradient(135deg, #8b5cf6, #6d28d9);
  color: #fff;
  font-weight: 800;
  font-size: 24px;
  display: flex; align-items: center; justify-content: center;
  letter-spacing: -0.5px;
}
.home-head h1 { margin: 0 0 4px; font-size: 24px; color: #e8e8e8; }
.home-head p { margin: 0; color: #8a8a8a; font-size: 14px; }

.home-actions { display: flex; gap: 10px; margin-bottom: 18px; }
.cardbtn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: #262626;
  border: 1px solid #333;
  border-radius: 14px;
  padding: 16px 8px;
  color: #dcddde;
  font-size: 14px;
  font-family: inherit;
}
.cardbtn svg { width: 26px; height: 26px; color: #8b5cf6; }
.cardbtn:active { background: #2d2d2d; }

.section { margin-bottom: 18px; }
.section-title {
  font-size: 13px;
  font-weight: 700;
  color: #8a8a8a;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.listrow {
  display: flex;
  align-items: center;
  gap: 10px;
  background: #262626;
  border: 1px solid #2f2f2f;
  border-radius: 12px;
  padding: 12px 14px;
  margin-bottom: 8px;
  font-size: 15px;
}
.listrow .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; direction: ltr; unicode-bidi: isolate; text-align: end; }
.listrow svg { width: 20px; height: 20px; color: #8b5cf6; flex: 0 0 auto; }
.listrow .sub { font-size: 12px; color: #8a8a8a; }
.listrow .del {
  border: none; background: none; color: #666; font-size: 18px; padding: 2px 6px;
}
.listrow .share {
  border: none; background: none; font-size: 16px; padding: 2px 6px;
}
.listrow .del:active { color: #ff5252; }
.listrow:active { background: #2d2d2d; }

.addrow { display: flex; gap: 8px; margin-top: 4px; }
.addrow input {
  flex: 1;
  background: #262626;
  border: 1px solid #333;
  border-radius: 10px;
  padding: 10px 12px;
  color: #dcddde;
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
.smallbtn {
  background: #8b5cf6;
  border: none;
  border-radius: 10px;
  color: #fff;
  padding: 10px 16px;
  font-size: 14px;
  font-family: inherit;
}
.linkbtn { background: none; border: none; color: #8b5cf6; font-size: 13px; font-family: inherit; }

.syncnote p { font-size: 13px; color: #8a8a8a; line-height: 1.7; margin: 0; background: #242424; border-radius: 10px; padding: 12px 14px; }

/* mixed Arabic/English blocks pick their own direction */
#view p, #view li, #view h1, #view h2, #view h3,
#view h4, #view h5, #view h6, #view blockquote, #view td, #view th {
  unicode-bidi: plaintext;
}

#view h1, #view h2, #view h3 { color: #e8e8e8; line-height: 1.35; }
#view h1 { font-size: 1.7em; }
#view a { color: #7f6df2; text-decoration: none; }
#view code {
  background: #2d2d2d;
  border-radius: 4px;
  padding: 1px 5px;
  font-size: 0.9em;
  direction: ltr;
  unicode-bidi: embed;
}
#view pre {
  background: #2d2d2d;
  border-radius: 8px;
  padding: 12px;
  overflow-x: auto;
  direction: ltr;
  text-align: left;
}
#view pre code { background: none; padding: 0; }
#view img { max-width: 100%; }
#view table { border-collapse: collapse; margin: 12px 0; }
#view th, #view td { border: 1px solid #3a3a3a; padding: 6px 12px; }
#view th { background: #242424; }
#view hr { border: none; border-top: 1px solid #3a3a3a; margin: 24px 0; }
#view mark { background: rgba(255, 213, 0, 0.25); color: #ffe9a8; border-radius: 3px; padding: 0 2px; }
#view input[type=checkbox] { width: 16px; height: 16px; vertical-align: -2px; accent-color: #7f6df2; }

/* KaTeX math direction */
.katex { direction: ltr; unicode-bidi: embed; font-size: 1.05em; }
.katex-display { direction: ltr; text-align: center; margin: 12px 0; overflow-x: auto; }

/* blockquote without callout marker */
#view blockquote {
  margin: 10px 0;
  padding: 4px 14px;
  border-inline-start: 2px solid #4a4a4a;
  color: #b8b8b8;
  font-style: italic;
}

/* Obsidian-style callouts */
.callout {
  margin: 12px 0;
  border-radius: 8px;
  padding: 6px 16px 10px;
  background: color-mix(in srgb, var(--c) 12%, #1e1e1e);
}
.callout-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  color: var(--c);
  padding: 6px 0 2px;
  unicode-bidi: plaintext;
}
.callout-title .fold { margin-inline-start: auto; cursor: pointer; user-select: none; opacity: 0.7; font-size: 13px; }
.callout-content > :first-child { margin-top: 2px; }
.callout-content > :last-child { margin-bottom: 4px; }
.callout.collapsed .callout-content { display: none; }

.callout-note, .callout-info, .callout-todo { --c: #4a9eff; }
.callout-tip, .callout-hint, .callout-important { --c: #00c97a; }
.callout-success, .callout-check, .callout-done { --c: #27c93f; }
.callout-question, .callout-help, .callout-faq { --c: #e0b13e; }
.callout-warning, .callout-caution, .callout-attention { --c: #ff9f2e; }
.callout-failure, .callout-fail, .callout-missing { --c: #ff5252; }
.callout-danger, .callout-error, .callout-bug { --c: #ff1744; }
.callout-example { --c: #b17cff; }
.callout-quote, .callout-cite { --c: #9e9e9e; }
.callout-abstract, .callout-summary, .callout-tldr { --c: #26c6da; }

.wikilink { color: #7f6df2; cursor: default; }

/* clean PDF export: white page, black text, toolbar hidden, colors preserved */
@media print {
  body { background: #fff; color: #000; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  #toolbar, #groupPicker, #sharePicker, #home, #editor { display: none !important; }
  #view { display: block !important; overflow: visible; padding: 0; color: #000; }
  #view h1, #view h2, #view h3 { color: #000; }
  #view a, .wikilink { color: #5b21b6; }
  #view code { background: #f2f2f2; color: #111; }
  #view pre { background: #f2f2f2; }
  #view th, #view td { border-color: #ccc; }
  #view th { background: #f5f5f5; }
  #view blockquote { color: #444; border-inline-start-color: #bbb; }
  #view mark { background: rgba(255, 213, 0, 0.4); color: #5c4d00; }
  .callout { background: color-mix(in srgb, var(--c) 10%, #ffffff); border: 1px solid color-mix(in srgb, var(--c) 35%, #ffffff); }
  .katex-display { overflow: visible; }
}
