:root {
  color-scheme: light;
  --bg: #ffffff;
  --bg-soft: #f7f7f7;
  --text: #111111;
  --muted: #526581;
  --line: #1a1a1a;
  --hairline: rgba(82, 101, 129, 0.2);
  --accent: #526581;
  --ui: #526581;
  --title-font: system-ui, -apple-system, "Segoe UI", sans-serif;
  --body-font: "Iowan Old Style", "Palatino Linotype", "Book Antiqua", Palatino, serif;
  --mono-font: "SF Mono", "Cascadia Mono", "Courier Prime", "Source Code Pro", monospace;
}

body.theme-dark {
  color-scheme: dark;
  --bg: #101215;
  --bg-soft: #15181d;
  --text: #f3f5f7;
  --muted: #9aa6b5;
  --line: #f3f5f7;
  --hairline: rgba(154, 166, 181, 0.22);
  --accent: #8aa1c2;
  --ui: #8aa1c2;
}

* {
  box-sizing: border-box;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  border: 0;
  opacity: 0;
  pointer-events: none;
}

body {
  margin: 0;
  min-height: 100vh;
  background: linear-gradient(180deg, #ffffff 0%, #f9f9f9 100%);
  color: var(--ui);
  font-family: var(--body-font);
}

body.theme-dark {
  background: linear-gradient(180deg, #0d0f12 0%, #11141a 100%);
}

.pipdown-app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.pipdown-topbar {
  position: sticky;
  top: 0;
  z-index: 12;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  padding: 8px 16px 6px;
  background: var(--bg);
  border-bottom: 1px solid var(--hairline);
  font-family: var(--title-font);
}

.topbar-left {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  flex: 1 1 auto;
  min-width: 0;
}

.back-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  width: auto;
  padding: 0 6px 0 2px;
  color: var(--ui);
  font-size: 0.95rem;
  letter-spacing: 0.02em;
}

.topbar-left {
  display: flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
}

.topbar-title {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin-left: 10px;
  color: var(--ui);
  font-family: var(--title-font);
  font-size: 0.85rem;
  letter-spacing: 0.06em;
}

.topbar-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.topbar-logo {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.topbar-text {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 24vw;
  font-weight: 700;
  color: var(--ui);
}

.start-brand {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-top: 8vh;
}

.start-logo {
  width: 48px;
  height: 48px;
}

.start-title {
  font-family: var(--title-font);
  font-size: 1.1rem;
  letter-spacing: 0.12em;
  color: #FA8334;
  font-weight: 700;
  text-transform: uppercase;
}

.back-icon {
  width: 22px;
  height: 22px;
}


.icon-btn {
  border: none;
  background: transparent;
  color: var(--ui);
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
  font-family: var(--title-font);
  font-size: 0.75rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.icon-btn.is-hidden {
  opacity: 0;
  pointer-events: none;
}

.icon-btn.is-disabled {
  opacity: 0.35;
  pointer-events: none;
}

.topbar-actions {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  justify-content: flex-end;
  justify-self: end;
  flex: 0 0 auto;
}

.topbar-actions .undo-right {
  margin-left: auto;
}

.topbar-actions .always-right {
  margin-left: auto;
}

.topbar-menu {
  display: inline-flex;
  justify-content: flex-end;
  align-items: center;
}

.select-btn {
  width: 34px;
  padding: 0;
  border: none;
  border-radius: 10px;
  height: 34px;
  background: transparent;
  color: var(--ui);
}

.select-btn .select-text {
  font-size: 0.7rem;
}

.select-action {
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: var(--ui);
}

.select-action svg {
  width: 18px;
  height: 18px;
  color: #ffffff;
}

.action-icon {
  width: 20px;
  height: 20px;
}

.icon-btn.is-disabled {
  opacity: 0.35;
  pointer-events: none;
}

.action-icon-flip {
  transform: scaleX(-1);
}

.menu-icon {
  display: inline-flex;
  flex-direction: column;
  gap: 4px;
}

.menu-icon span {
  width: 18px;
  height: 2px;
  background: var(--ui);
  border-radius: 999px;
}

.menu-panel {
  position: fixed;
  top: 56px;
  right: 12px;
  z-index: 20;
  display: none;
}

.menu-panel.is-open {
  display: block;
}

.menu-card {
  min-width: 200px;
  background: var(--bg);
  border: 1px solid var(--hairline);
  border-radius: 14px;
  padding: 8px;
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.12);
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-family: var(--title-font);
}

.menu-item {
  border: none;
  background: transparent;
  padding: 10px 12px;
  text-align: left;
  font-size: 0.8rem;
  letter-spacing: 0.08em;
  cursor: pointer;
  border-radius: 10px;
  color: var(--ui);
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
}

.menu-toggle {
  font-size: 0.75rem;
  letter-spacing: 0.04em;
}

.menu-toggle input {
  accent-color: var(--ui);
}

.menu-item:hover {
  background: var(--bg-soft);
}

.status-text {
  font-size: 0.7rem;
  color: var(--ui);
  font-family: var(--title-font);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  min-height: 18px;
}

.status-text.is-hidden {
  opacity: 0;
}

.sheet {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
}

.sheet.is-open {
  opacity: 1;
  pointer-events: auto;
}

.sheet-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(10, 18, 28, 0.35);
}

.sheet-card {
  position: relative;
  width: min(92vw, 420px);
  background: var(--bg);
  border: 1px solid var(--hairline);
  border-radius: 18px;
  padding: 16px;
  margin-bottom: 25vh;
  box-shadow: 0 28px 60px rgba(0, 0, 0, 0.2);
  display: grid;
  gap: 12px;
  z-index: 1;
  transform: translateY(120%);
  opacity: 0;
  transition: transform 0.35s cubic-bezier(0.22, 1, 0.36, 1), opacity 0.35s ease;
  will-change: transform, opacity;
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
}

.sheet.is-open .sheet-card {
  transform: translateY(0);
  opacity: 1;
}

.sheet-message {
  font-size: 0.95rem;
  color: var(--text);
  line-height: 1.5;
}

.sheet-btn {
  border: 1px solid var(--ui);
  background: var(--ui);
  color: var(--bg);
  border-radius: 999px;
  padding: 10px 16px;
  font-family: var(--title-font);
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
}

.sheet-actions {
  display: grid;
  gap: 8px;
}

.sheet-btn-outline {
  background: transparent;
  color: var(--ui);
}

.sheet-btn.is-loading {
  color: transparent;
  pointer-events: none;
  position: relative;
}

.sheet-btn.is-loading::after {
  content: "";
  position: absolute;
  inset: 0;
  margin: auto;
  width: 18px;
  height: 18px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffffff;
  animation: sheet-spin 0.7s linear infinite;
}

@keyframes sheet-spin {
  to {
    transform: rotate(360deg);
  }
}

.pipdown-content {
  flex: 1;
  display: flex;
  flex-direction: column;
}


.status-footer {
  border-top: 1px solid var(--hairline);
  padding: 6px 16px 8px;
  min-height: 28px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.status-footer.is-hidden {
  display: none;
}

.pipdown-view {
  display: none;
  flex: 1;
  padding: 10px 16px 24px;
}

.pipdown-view.is-active {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.file-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.file-item {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 8px;
  border-bottom: 1px solid var(--hairline);
  font-family: var(--title-font);
  letter-spacing: 0.02em;
  cursor: pointer;
}

.file-item.is-opening {
  background: rgba(82, 101, 129, 0.08);
}

.file-item.is-deleted {
  opacity: 0.45;
}

.file-item.is-missing {
  opacity: 0.5;
}

.file-item .pin-action {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.file-item .pin-action img {
  width: 16px;
  height: 16px;
}

.image-missing {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px dashed var(--hairline);
  padding: 10px 12px;
  color: #9aa5b5;
  font-family: var(--title-font);
  font-size: 0.85rem;
  border-radius: 10px;
}

.empty-message {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px dashed var(--hairline);
  padding: 10px 12px;
  color: #9aa5b5;
  font-family: var(--title-font);
  font-size: 0.85rem;
  border-radius: 10px;
}

.image-missing-icon {
  width: 18px;
  height: 18px;
}

.file-item:last-child {
  border-bottom: none;
}

.file-item .label {
  font-size: 0.98rem;
  color: var(--text);
}

.file-item[data-type="folder"] .label {
  font-weight: 600;
}

.file-item .check {
  width: 18px;
  height: 18px;
  border: 1px solid var(--ui);
  border-radius: 999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
}

.file-item .check svg {
  width: 12px;
  height: 12px;
}

.file-item.is-selected .check {
  opacity: 1;
  background: var(--ui);
  color: #ffffff;
}

.file-list.selection-mode .file-item[data-type="file"] .check {
  opacity: 1;
  pointer-events: auto;
}

.file-list.selection-mode .file-item[data-type="folder"] .check {
  opacity: 0;
}

.file-item .meta {
  font-size: 0.7rem;
  color: var(--ui);
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.file-item .icon {
  width: 18px;
  height: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.file-item .icon-img {
  width: 18px;
  height: 18px;
}
.file-item[data-type="folder"] .icon {
  width: 18px;
  height: 18px;
}

.primary-btn {
  align-self: center;
  border: 1px solid var(--ui);
  background: var(--ui);
  color: var(--bg);
  padding: 12px 18px;
  border-radius: 999px;
  font-family: var(--title-font);
  font-size: 0.8rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  cursor: pointer;
  margin-top: 6vh;
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.primary-btn .connect-icon {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.primary-btn.is-hidden {
  display: none;
}

.start-brand.is-hidden {
  display: none;
}


.pipdown-view#editorView {
  padding: 0 16px 32px;
}

.editor {
  width: 100%;
  border: none;
  outline: none;
  background: transparent;
  color: var(--text);
  line-height: 1.7;
  font-size: 1.15rem;
  min-height: calc(100vh - 140px);
}


.editor.wysiwyg {
  font-family: var(--body-font);
  display: none;
}

.editor.wysiwyg .md-token {
  color: #b4b4b4;
  font-family: var(--mono-font);
}

.editor.wysiwyg code {
  font-family: var(--mono-font);
  font-size: 0.95rem;
  background: #f0f0f0;
  padding: 0 4px;
  border-radius: 4px;
}

.editor.wysiwyg ul {
  padding-left: 22px;
}

.editor.wysiwyg li .md-token {
  margin-right: 6px;
}
.editor.code {
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  display: block;
  resize: none;
}

.editor.preview {
  font-family: var(--body-font);
  display: none;
  color: var(--text);
  white-space: normal;
}

.editor.preview p,
.editor.preview li {
  font-size: 1.15rem;
}

.menu-item span {
  flex: 1;
  font-weight: 700;
}

.menu-link {
  text-decoration: none;
}

.menu-icon-img {
  width: 20px;
  height: 20px;
}

.menu-item.is-disabled {
  opacity: 0.4;
  pointer-events: none;
}


.editor.preview h1,
.editor.preview h2,
.editor.preview h3,
.editor.preview h4,
.editor.preview h5,
.editor.preview h6 {
  font-family: var(--title-font);
  color: var(--text);
}

.editor.preview table {
  border-collapse: collapse;
  width: 100%;
}

.editor.preview th,
.editor.preview td {
  border: 1px solid var(--hairline);
  padding: 6px 8px;
}

.editor.preview blockquote {
  border-left: 2px solid var(--ui);
  margin: 16px 0;
  padding-left: 12px;
  color: var(--ui);
}

.editor.preview code {
  font-family: var(--mono-font);
  background: #f0f0f0;
  padding: 0 4px;
  border-radius: 4px;
}

.editor.wysiwyg h1 {
  font-size: 2rem;
  letter-spacing: -0.01em;
}

.editor.wysiwyg h2 {
  font-size: 1.5rem;
  letter-spacing: -0.01em;
}

.editor.wysiwyg h3 {
  font-size: 1.2rem;
}

.editor.wysiwyg hr {
  border: none;
  border-top: 1px solid var(--hairline);
  margin: 24px 0;
}

.editor.wysiwyg blockquote {
  border-left: 2px solid var(--text);
  margin: 16px 0;
  padding-left: 12px;
  color: var(--muted);
}

@media (min-width: 900px) {
  .pipdown-app {
    max-width: 900px;
    margin: 0 auto;
  }

  .pipdown-topbar {
    padding: 10px 10px 8px;
  }

  .pipdown-view#editorView {
    padding: 0 10px 48px;
  }

  .status-text {
    min-height: 18px;
    padding: 6px 10px 0;
  }
}
.footer-file {
  font-size: 0.7rem;
  color: #9aa5b5;
  font-family: var(--title-font);
  letter-spacing: 0.06em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 60%;
  direction: rtl;
  text-align: left;
  font-weight: 600;
}

#wordCount {
  min-width: 80px;
  text-align: right;
  color: #9aa5b5;
}
