/* ==========================================================================
   Zola Editor — Deep ocean theme (v3.3)
   ========================================================================== */

/* ---------- Tokens: dark (default) ---------- */

[data-theme="dark"] {
  --abyss: #061a35;
  --deep-ocean: #082b52;
  --ocean: #0b4275;
  --blue-current: #105d9a;
  --ocean-light: #167fc0;
  --bioluminescent: #40a9df;
  --sea-mist: #b8dff5;
  --marine-green: #24b99a;

  --bg: var(--abyss);
  --surface: var(--deep-ocean);
  --surface-raised: var(--ocean);
  --surface-hover: var(--blue-current);

  --border: #16446c;
  --border-strong: #1f5a8c;

  --text: #eaf5ff;
  --text-secondary: #9dbdda;
  --text-muted: #7a9ab8;

  --primary: var(--ocean-light);
  --primary-hover: var(--blue-current);
  --primary-text: #ffffff;
  --primary-subtle: #0a2d50;

  --danger: #dc2626;
  --danger-hover: #b91c1c;
  --danger-text: #ffffff;

  --success: var(--marine-green);
  --warn: #f59e0b;
  --code-bg: #0a2d50;

  --dot-md: #40a9df;
  --dot-section: #167fc0;
  --dot-config: #f59e0b;
  --dot-style: #24b99a;
  --dot-script: #eab308;
  --dot-markup: #f87171;
  --dot-image: #a78bfa;
  --dot-font: #f472b6;
  --dot-pdf: #fb7185;
  --dot-other: #7a9ab8;

  --font-sans: "Vazirmatn", Tahoma, "Iranian Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Monaco, Consolas, "Courier New",
    monospace;
}

/* ---------- Tokens: light ---------- */

:root:not([data-theme="dark"]),
[data-theme="light"] {
  color-scheme: light;
  --font-sans: "Vazirmatn", Tahoma, "Iranian Sans", "Segoe UI", system-ui, sans-serif;
  --font-mono: ui-monospace, "SF Mono", SFMono-Regular, Menlo, Monaco, Consolas, "Courier New",
    monospace;
  --abyss: #172923;
  --deep-ocean: #ffffff;
  --ocean: #e8f1ec;
  --blue-current: #dcebe4;
  --ocean-light: #197568;
  --bioluminescent: #1b8c7c;
  --sea-mist: #d8eee8;
  --marine-green: #17836f;

  --bg: #f3f5f1;
  --surface: #ffffff;
  --surface-raised: #edf3ee;
  --surface-hover: #e4eee8;
  --border: #dce6df;
  --border-strong: #b8cdc0;
  --text: #1b2b25;
  --text-secondary: #52665c;
  --text-muted: #77877e;
  --primary: #197568;
  --primary-hover: #125f55;
  --primary-text: #ffffff;
  --primary-subtle: #e1f1ec;
  --danger: #c24646;
  --danger-hover: #a93636;
  --danger-text: #ffffff;
  --success: #17836f;
  --warn: #b7791f;
  --code-bg: #eaf0eb;

  --dot-md: #197568;
  --dot-section: #4776b8;
  --dot-config: #bd7d1e;
  --dot-style: #17836f;
  --dot-script: #bd7d1e;
  --dot-markup: #c24646;
  --dot-image: #8062bf;
  --dot-font: #c15f8e;
  --dot-pdf: #c24646;
  --dot-other: #77877e;
}

/* ---------- Reset ---------- */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body { height: 100%; }

body {
  font-family: var(--font-sans);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  direction: rtl;
  text-align: right;
}

.admin-body { overflow: hidden; }

code, pre,
textarea.code-area,
textarea.file-textarea,
#f-body { font-family: var(--font-mono); }

.hidden { display: none !important; }
.small { font-size: 12px; }
.muted { color: var(--text-muted); }

/* ---------- Auth pages ---------- */

.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg);
  padding: 20px;
}

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 36px 32px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.auth-card h1 {
  font-size: 20px;
  font-weight: 600;
  margin-bottom: 6px;
  color: var(--text);
}

.auth-card .muted { margin-bottom: 24px; font-size: 13.5px; }

.auth-card form {
  display: flex;
  flex-direction: column;
  gap: 10px;
  text-align: left;
}

.auth-card input[type="password"] {
  width: 100%;
  height: 40px;
  padding: 0 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
}

.auth-card input:focus { outline: none; border-color: var(--primary); }

.auth-cta { height: 40px; gap: 8px; }
.auth-hint { margin-top: 18px; font-size: 12px; }

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  margin: 0 auto 16px;
  border-radius: 10px;
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 700;
  font-size: 20px;
}

.auth-error {
  background: var(--bg);
  color: var(--danger);
  border: 1px solid var(--danger);
  padding: 10px 12px;
  border-radius: 6px;
  font-size: 13px;
  margin-bottom: 16px;
  text-align: left;
}

/* ---------- Topbar ---------- */

.topbar {
  height: 38px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  gap: 16px;
  flex-shrink: 0;
  font-size: 12.5px;
  user-select: none;
}

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

.brand-dot {
  width: 8px;
  height: 8px;
  background: var(--bioluminescent);
  border-radius: 2px;
  flex-shrink: 0;
}

.topbar-title {
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
}

.topbar-branch {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-secondary);
  background: var(--bg);
  border: 1px solid var(--border);
  padding: 1px 7px;
  border-radius: 4px;
  white-space: nowrap;
}

.clock {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  flex-shrink: 0;
}

.clock-item {
  display: inline-flex;
  gap: 5px;
  align-items: baseline;
  white-space: nowrap;
}

.clock-label { color: var(--text-muted); font-size: 11px; }
.clock-value { font-family: var(--font-mono); font-size: 12px; color: var(--text); }
.clock-sep { color: var(--border-strong); padding: 0 2px; }

/* ---------- App shell ---------- */

.app {
  display: grid;
  grid-template-columns: 300px minmax(0, 1fr);
  height: calc(100vh - 38px);
  overflow: hidden;
}

/* ---------- Sidebar ---------- */

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.workspace-switcher {
  padding: 18px 12px 12px;
  border-bottom: 1px solid var(--border);
}

.workspace-label {
  display: block;
  padding: 0 7px 8px;
  color: var(--text-muted);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.workspace-nav {
  display: grid;
  gap: 3px;
}

.workspace-nav a {
  display: flex;
  align-items: center;
  min-height: 35px;
  padding: 0 9px;
  border-radius: 2px;
  color: var(--text-secondary);
  font-size: 13px;
  text-decoration: none;
  transition: background 120ms ease, color 120ms ease;
}

.workspace-nav a:hover {
  background: var(--surface-hover);
  color: var(--text);
}

.workspace-nav a[aria-current="page"] {
  background: var(--primary-subtle);
  color: var(--primary);
  font-weight: 600;
}

body[data-workspace="writing"] .file-actions,
body[data-workspace="writing"] .assets-only,
body[data-workspace="files"] .writing-only,
body[data-workspace="files"] .assets-only,
body[data-workspace="assets"] .writing-only {
  display: none;
}

.sidebar-actions {
  display: flex;
  gap: 6px;
  padding: 10px 10px 0;
  flex-shrink: 0;
}

.sidebar-actions + .sidebar-actions {
  padding-top: 6px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
}

.sidebar-actions .btn-primary { flex: 1; min-width: 0; }
.sidebar-actions .btn-outline { flex: 1; min-width: 0; }
.sidebar-actions .icon-btn { flex: 0 0 auto; width: 34px; }

.search-wrap {
  padding: 10px 10px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}

.search-wrap input {
  width: 100%;
  height: 32px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 13px;
  font-family: var(--font-sans);
  background: var(--bg);
  color: var(--text);
}

.search-wrap input::placeholder { color: var(--text-muted); }
.search-wrap input:focus { outline: none; border-color: var(--primary); }

.tree-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  min-height: 0;
}

.tree, .tree ul { list-style: none; padding: 0; margin: 0; }
.tree ul { padding-left: 12px; }

.tree-item {
  display: flex;
  align-items: center;
  gap: 7px;
  padding: 5px 8px;
  border-radius: 2px;
  cursor: pointer;
  font-size: 13px;
  color: var(--text);
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  line-height: 1.4;
}

.tree-item:hover { background: var(--surface-hover); }
.tree-item.active {
  background: var(--primary-subtle);
  color: var(--primary);
  font-weight: 500;
}

.tree-item .twisty {
  width: 12px;
  height: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 10px;
  color: var(--text-muted);
  line-height: 1;
}

.tree-item .twisty-placeholder { width: 12px; flex-shrink: 0; }

.tree-item .ti-dot {
  width: 8px;
  height: 8px;
  border-radius: 2px;
  flex-shrink: 0;
  display: inline-block;
}

.ti-dot-md { background: var(--dot-md); }
.ti-dot-section { background: var(--dot-section); }
.ti-dot-config { background: var(--dot-config); }
.ti-dot-style { background: var(--dot-style); }
.ti-dot-script { background: var(--dot-script); }
.ti-dot-markup { background: var(--dot-markup); }
.ti-dot-image { background: var(--dot-image); }
.ti-dot-font { background: var(--dot-font); }
.ti-dot-pdf { background: var(--dot-pdf); }
.ti-dot-other { background: var(--dot-other); }

.tree-item .label {
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.tree-item.has-draft .label::after {
  content: "●";
  color: var(--warn);
  font-size: 9px;
  margin-left: 5px;
  vertical-align: middle;
}

.tree-empty {
  padding: 16px 10px;
  text-align: center;
  color: var(--text-muted);
  font-size: 12px;
}

.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  flex-shrink: 0;
}

.sidebar-footer #repo-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
  font-family: var(--font-mono);
  font-size: 11px;
}

.footer-actions {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-shrink: 0;
}

.icon-btn {
  display: inline-flex !important;
  align-items: center;
  justify-content: center;
}

[data-theme="dark"] .icon-sun { display: none; }
[data-theme="dark"] .icon-moon { display: inline-block; }
[data-theme="light"] .icon-sun { display: inline-block; }
[data-theme="light"] .icon-moon { display: none; }

/* ---------- Main ---------- */

.main {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-height: 0;
  background: var(--bg);
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  text-align: center;
  color: var(--text-muted);
  padding: 40px;
}

.empty-icon { font-size: 44px; margin-bottom: 14px; opacity: 0.35; }

.empty-state h2 {
  font-size: 18px;
  color: var(--text);
  font-weight: 600;
  margin-bottom: 6px;
}

.empty-actions { display: flex; gap: 8px; margin-top: 22px; }

/* ---------- Editors ---------- */

.editor, .file-editor, .file-info, .settings {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
  min-height: 0;
}

.editor-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  background: var(--bg);
  min-height: 52px;
}

.editor-title-group {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.editor-kind {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: var(--text-muted);
  border: 1px solid var(--border);
  padding: 2px 7px;
  border-radius: 4px;
  flex-shrink: 0;
}

.editor-header h1 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.editor-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.dirty {
  font-size: 12px;
  color: var(--warn);
  font-weight: 500;
}

.editor-body {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  padding: 14px 20px 18px;
  gap: 12px;
  min-height: 0;
}

.file-editor-body { padding: 14px 20px 18px; }

/* ---------- Fields ---------- */

.fields {
  display: flex;
  flex-direction: column;
  gap: 10px;
  flex-shrink: 0;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 5px;
  flex: 1;
  min-width: 0;
}

.field label { font-size: 11px; font-weight: 500; color: var(--text-muted); }
.field-optional { color: var(--text-muted); font-weight: 400; }

.field input, .field select {
  width: 100%;
  height: 34px;
  padding: 0 10px;
  border: 1px solid var(--border);
  border-radius: 2px;
  font-size: 13px;
  font-family: var(--font-sans);
  background: var(--surface);
  color: var(--text);
}

.field input::placeholder { color: var(--text-muted); }
.field input:hover, .field select:hover { border-color: var(--border-strong); }
.field input:focus, .field select:focus { outline: none; border-color: var(--primary); }

.field input[readonly] {
  background: var(--surface-raised);
  color: var(--text-secondary);
  cursor: default;
}

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

.post-fields { gap: 12px; }
.post-heading-fields { grid-template-columns: minmax(0, 1fr) minmax(190px, 0.62fr); }
.post-title-field input {
  height: 42px;
  font-size: 17px;
  font-weight: 500;
}
.post-path-field input {
  height: 42px;
  font-size: 12px;
  font-family: var(--font-mono);
}

.post-options {
  border-top: 1px solid var(--border);
  padding-top: 8px;
}

.post-options summary {
  width: fit-content;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  user-select: none;
}

.post-options summary:hover { color: var(--primary); }
.post-options-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 12px;
}

.field-row.checkboxes {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  padding: 2px 0;
}

.field-row.checkboxes label,
.checkbox-line {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  color: var(--text);
  cursor: pointer;
  font-weight: 400;
}

.date-row { display: flex; align-items: center; gap: 8px; }

.date-badge {
  font-size: 11px;
  font-family: var(--font-mono);
  color: var(--primary);
  background: var(--primary-subtle);
  border: 1px solid var(--border);
  padding: 3px 8px;
  border-radius: 4px;
  white-space: nowrap;
  flex-shrink: 0;
}

/* ---------- Content pane ---------- */

.content-pane {
  flex: 1;
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  border-radius: 2px;
  overflow: hidden;
  min-height: 0;
  background: var(--bg);
}

.md-toolbar {
  display: flex;
  align-items: center;
  gap: 1px;
  padding: 4px 6px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
  flex-shrink: 0;
}

.md-toolbar button {
  padding: 0;
  border: none;
  background: transparent;
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-family: var(--font-sans);
  color: var(--text-secondary);
  min-width: 28px;
  height: 26px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.md-toolbar button:hover { background: var(--surface-hover); color: var(--text); }
.md-toolbar button:active { background: var(--surface-raised); }
.md-toolbar button b { font-weight: 700; }
.md-toolbar button i { font-style: italic; }
.md-toolbar-sep { width: 1px; height: 16px; background: var(--border); margin: 0 4px; }

.tabs {
  display: flex;
  align-items: center;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  padding: 0 6px;
}

.tab {
  padding: 7px 14px;
  border: none;
  background: transparent;
  cursor: pointer;
  font-size: 12.5px;
  font-family: var(--font-sans);
  color: var(--text-muted);
  font-weight: 500;
}

.tab:hover { color: var(--text); }
.tab.active {
  color: var(--primary);
  background: var(--bg);
  border-bottom: 2px solid var(--primary);
  margin-bottom: -1px;
}

.spacer { flex: 1; }
.word-count {
  font-size: 11px;
  color: var(--text-muted);
  padding-right: 10px;
  font-variant-numeric: tabular-nums;
}

#f-body, .file-textarea {
  flex: 1;
  width: 100%;
  border: none;
  padding: 14px 16px;
  font-size: 13.5px;
  line-height: 1.65;
  resize: none;
  outline: none;
  background: var(--bg);
  color: var(--text);
  min-height: 0;
}

.file-textarea {
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface);
}

.file-textarea:focus { border-color: var(--primary); }

.preview {
  flex: 1;
  padding: 18px 22px;
  overflow-y: auto;
  font-size: 14.5px;
  line-height: 1.7;
  min-height: 0;
  color: var(--text);
}

.preview h1, .preview h2, .preview h3, .preview h4 {
  margin: 16px 0 8px;
  line-height: 1.3;
  color: var(--text);
}
.preview h1 { font-size: 1.55em; }
.preview h2 { font-size: 1.3em; }
.preview h3 { font-size: 1.12em; }
.preview p { margin: 9px 0; }
.preview ul, .preview ol { margin: 9px 0; padding-left: 22px; }
.preview code {
  background: var(--code-bg);
  padding: 2px 5px;
  border-radius: 3px;
  font-family: var(--font-mono);
  font-size: 0.9em;
}
.preview pre {
  background: var(--surface);
  padding: 11px 13px;
  border-radius: 4px;
  overflow-x: auto;
  margin: 11px 0;
  border: 1px solid var(--border);
}
.preview pre code { background: none; padding: 0; }
.preview blockquote {
  border-left: 3px solid var(--border-strong);
  padding-left: 13px;
  color: var(--text-secondary);
  margin: 11px 0;
}
.preview img { max-width: 100%; height: auto; border-radius: 4px; }
.preview a { color: var(--primary); text-decoration: none; }
.preview a:hover { text-decoration: underline; }
.preview table { border-collapse: collapse; margin: 11px 0; }
.preview th, .preview td { border: 1px solid var(--border); padding: 5px 9px; }
.preview hr { border: none; border-top: 1px solid var(--border); margin: 18px 0; }

/* ---------- File info ---------- */

.info-body {
  flex: 1;
  padding: 20px 24px;
  overflow-y: auto;
  min-height: 0;
}

.info-image-wrap {
  margin-bottom: 20px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  background: var(--surface);
  text-align: center;
}

.info-image-wrap img {
  max-width: 100%;
  max-height: 420px;
  height: auto;
  border-radius: 4px;
}

.info-row {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.info-label { color: var(--text-muted); min-width: 50px; font-weight: 500; }

.info-value {
  font-family: var(--font-mono);
  color: var(--text);
  word-break: break-all;
  font-size: 12px;
}

.info-hint { margin-top: 16px; }

/* ---------- Settings ---------- */

.settings-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}

.settings-nav {
  width: 170px;
  border-right: 1px solid var(--border);
  background: var(--surface);
  padding: 10px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
  overflow-y: auto;
}

.settings-nav-item {
  text-align: left;
  padding: 8px 12px;
  border: none;
  background: transparent;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  font-family: var(--font-sans);
  color: var(--text-secondary);
  font-weight: 500;
}

.settings-nav-item:hover { background: var(--surface-hover); color: var(--text); }
.settings-nav-item.active {
  background: var(--primary-subtle);
  color: var(--primary);
  font-weight: 600;
}

.settings-panels {
  flex: 1;
  overflow-y: auto;
  padding: 20px 24px;
  min-height: 0;
}

.settings-panel { display: none; flex-direction: column; gap: 12px; }
.settings-panel.active { display: flex; }

.hint { font-size: 12px; color: var(--text-muted); line-height: 1.55; }

.hint code {
  background: var(--code-bg);
  padding: 1px 5px;
  border-radius: 3px;
  color: var(--text-secondary);
  font-family: var(--font-mono);
  font-size: 11.5px;
}

.code-area {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.6;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--surface);
  color: var(--text);
  resize: vertical;
  outline: none;
}

.code-area:focus { border-color: var(--primary); background: var(--bg); }

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 34px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 2px;
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-sans);
  line-height: 1;
  color: var(--text);
  background: var(--surface-raised);
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
  transition: background-color 100ms ease, border-color 100ms ease, color 100ms ease;
}

.btn:focus-visible { outline: 2px solid var(--bioluminescent); outline-offset: 2px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

.btn-primary {
  background: var(--primary);
  color: var(--primary-text);
  border-color: var(--primary);
}
.btn-primary:hover:not(:disabled) {
  background: var(--primary-hover);
  border-color: var(--primary-hover);
}
.btn-primary:active:not(:disabled) {
  background: var(--ocean);
  border-color: var(--ocean);
}

.btn-outline {
  background: var(--surface-raised);
  color: var(--text);
  border-color: var(--border);
}
.btn-outline:hover:not(:disabled) {
  background: var(--surface-hover);
  border-color: var(--border-strong);
}

.btn-danger {
  background: var(--danger);
  color: var(--danger-text);
  border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 5px; }
.icon-btn { width: 34px; padding: 0; flex-shrink: 0; }
.btn-sm.icon-btn { width: 28px; }
.btn-block { width: 100%; }

/* ---------- Modal ---------- */

.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--abyss);
}

.modal-panel {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 2px;
  padding: 24px;
  width: 100%;
  max-width: 420px;
  animation: modal-in 140ms ease;
}

.modal-panel h3 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
  color: var(--text);
}

.modal-panel p {
  font-size: 13.5px;
  color: var(--text-secondary);
  line-height: 1.55;
  margin-bottom: 20px;
  word-break: break-word;
}

.modal-panel input[type="text"] {
  width: 100%;
  height: 36px;
  padding: 0 11px;
  border: 1px solid var(--border);
  border-radius: 2px;
  font-size: 13.5px;
  font-family: var(--font-mono);
  background: var(--bg);
  color: var(--text);
  margin-bottom: 16px;
  outline: none;
}

.modal-panel input[type="text"]:focus { border-color: var(--primary); }

.modal-actions { display: flex; gap: 8px; justify-content: flex-end; }

@keyframes modal-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------- Toasts ---------- */

.toast-stack {
  position: fixed;
  top: 50px;
  right: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 3000;
  pointer-events: none;
  max-width: min(400px, calc(100vw - 32px));
}

.toast {
  pointer-events: auto;
  padding: 10px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-left: 3px solid var(--primary);
  word-break: break-word;
  animation: toast-in 160ms ease;
  font-family: var(--font-sans);
}

.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.info { border-left-color: var(--primary); }

.toast.removing { animation: toast-out 180ms ease forwards; }

@keyframes toast-in { from { opacity: 0; transform: translateX(16px); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(16px); } }

/* ---------- Responsive ---------- */

.mobile-only { display: none; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--border);
  }

  .app.editing .sidebar { display: none; }
  .app:not(.editing) .main { display: none; }
  .mobile-only { display: inline-flex; }
  .field-row { grid-template-columns: 1fr; }
  .settings-body { flex-direction: column; }
  .settings-nav {
    width: auto;
    flex-direction: row;
    overflow-x: auto;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .settings-nav-item { white-space: nowrap; }
  .topbar { padding: 0 12px; }
  .topbar-branch { display: none; }
}

@media (max-width: 560px) {
  .topbar-title { display: none; }
  .clock-label { display: none; }
  .clock-sep { padding: 0; }
  .md-toolbar button { min-width: 24px; height: 24px; }
}

/* ---------- Persian RTL editorial workspace ---------- */

:root:not([data-theme="dark"]),
[data-theme="light"] { color-scheme: light; }

[data-theme="dark"] { color-scheme: dark; }

input, select, button, textarea { font: inherit; }
input, select, textarea { text-align: right; }
input[dir="ltr"], textarea[dir="ltr"], .topbar-branch, .sidebar-footer #repo-label,
.tree-item .label, .info-value, code, pre, .code-area, .file-textarea,
#f-path, #f-weight { direction: ltr; text-align: left; }

.topbar {
  height: 54px;
  padding-inline: 24px;
  background: var(--surface);
  border-bottom-color: var(--border);
  box-shadow: 0 2px 12px rgb(22 53 39 / 5%);
}

.brand-dot { width: 10px; height: 10px; border-radius: 50%; }
.topbar-title { font-size: 14px; }
.topbar-branch { border-radius: 999px; padding: 3px 10px; }
.clock-value { font-family: var(--font-sans); direction: ltr; unicode-bidi: isolate; }

.app { height: calc(100vh - 54px); grid-template-columns: 310px minmax(0, 1fr); }
.sidebar { border-right: 0; border-left: 1px solid var(--border); }
.workspace-switcher { padding: 20px 16px 14px; }
.workspace-label { letter-spacing: 0; font-size: 11px; }
.workspace-nav { gap: 5px; }
.workspace-nav a { min-height: 42px; padding-inline: 12px; border-radius: 10px; }
.workspace-nav a[aria-current="page"] { box-shadow: inset -3px 0 var(--primary); }
.sidebar-actions { padding: 12px 14px 0; gap: 8px; }
.sidebar-actions + .sidebar-actions { padding-top: 8px; padding-bottom: 12px; }
.search-wrap { padding: 12px 14px; }
.search-wrap input { height: 40px; border-radius: 10px; }
.tree-scroll { padding: 8px; }
.tree ul { padding-inline-start: 14px; }
.tree-item { min-height: 34px; border-radius: 8px; }
.tree-item.active { box-shadow: inset -3px 0 var(--primary); }
.sidebar-footer { padding: 12px 14px; }

.main { background: var(--bg); }
.empty-state { color: var(--text-secondary); }
.empty-icon {
  display: grid;
  place-items: center;
  width: 78px;
  height: 78px;
  margin-bottom: 20px;
  border-radius: 24px;
  background: var(--primary-subtle);
  color: var(--primary);
  font-size: 34px;
  opacity: 1;
}
.empty-state h2 { font-size: 23px; margin-bottom: 10px; }
.empty-state p { max-width: 420px; line-height: 1.9; }

.editor-header {
  min-height: 68px;
  padding: 12px 26px;
  background: var(--surface);
  border-bottom-color: var(--border);
}
.editor-header h1 { font-size: 15px; }
.editor-kind { letter-spacing: 0; border-radius: 999px; padding: 4px 10px; }
.editor-actions { gap: 9px; }
.editor-body {
  display: block;
  overflow: auto;
  padding: 22px clamp(18px, 3vw, 44px) 36px;
}

.post-fields {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 18px;
  max-width: 1220px;
  margin: 0 auto;
}
.post-heading-fields { grid-template-columns: minmax(0, 1.5fr) minmax(260px, .7fr); gap: 14px; }
.post-title-field input { height: 58px; font-size: 23px; font-weight: 600; }
.post-path-field input { height: 58px; border-radius: 12px; }
.field { gap: 8px; }
.field label { font-size: 12px; color: var(--text-secondary); font-weight: 600; }
.field input, .field select {
  height: 44px;
  padding-inline: 13px;
  border-radius: 11px;
  background: var(--surface);
  transition: border-color .16s ease, box-shadow .16s ease, background .16s ease;
}
.field input:focus, .field select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 14%, transparent);
  background: var(--surface);
}
.post-meta-grid {
  display: grid;
  grid-template-columns: minmax(0, .95fr) minmax(0, 1.05fr);
  gap: 16px;
  padding: 18px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 8px 26px rgb(22 53 39 / 4%);
}
.post-date-weight { grid-template-columns: minmax(0, 1.3fr) minmax(95px, .7fr); gap: 14px; }
.date-row { gap: 8px; }
.date-row input { flex: 1; min-width: 130px; }
#f-date { direction: ltr; text-align: center; font-variant-numeric: tabular-nums; }
.tag-editor {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 44px;
  padding: 6px 9px;
  border: 1px solid var(--border);
  border-radius: 11px;
  background: var(--surface);
}
.tag-editor:focus-within {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 14%, transparent);
}
.tag-list { display: contents; }
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 4px 9px;
  border-radius: 999px;
  color: var(--primary);
  background: var(--primary-subtle);
  font-size: 12px;
}
.tag-chip button {
  width: 17px;
  height: 17px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  color: inherit;
  background: transparent;
  cursor: pointer;
  line-height: 1;
}
.tag-chip button:hover { color: var(--danger); background: var(--surface); }
#f-tag-input {
  flex: 1 1 170px;
  width: 100px;
  min-width: 100px;
  height: 30px;
  padding: 0 4px;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}
.post-toggles {
  align-items: center;
  gap: 10px;
  padding: 0;
}
.post-toggles label {
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
}
.post-cover-fields { gap: 14px; }
.content-pane {
  min-height: 56vh;
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 8px 28px rgb(22 53 39 / 5%);
}
.md-toolbar { padding: 8px 12px; gap: 4px; background: var(--surface); }
.md-toolbar button {
  min-width: 34px;
  height: 34px;
  padding-inline: 8px;
  border-radius: 8px;
}
.md-toolbar-sep { margin-inline: 6px; }
.tabs { padding-inline: 10px; background: var(--surface); }
.tab { padding: 10px 16px; }
#f-body { padding: 24px clamp(18px, 4vw, 56px); font-family: var(--font-sans); font-size: 16px; line-height: 2; }
.preview { padding: 26px clamp(18px, 4vw, 56px); line-height: 2; }
.preview blockquote { border-left: 0; border-right: 3px solid var(--primary); padding-left: 0; padding-right: 14px; }
.word-count { padding-inline: 10px; }

.btn {
  height: 40px;
  padding-inline: 16px;
  border-radius: 10px;
  font-weight: 600;
  transition: transform .16s ease, background .16s ease, box-shadow .16s ease;
}
.btn:hover:not(:disabled) { transform: translateY(-1px); }
.btn-primary { box-shadow: 0 4px 12px color-mix(in srgb, var(--primary) 20%, transparent); }
.btn-sm { height: 34px; padding-inline: 12px; border-radius: 9px; }
.icon-btn { width: 40px; }
.btn-sm.icon-btn { width: 34px; }
.btn-danger { box-shadow: 0 4px 12px color-mix(in srgb, var(--danger) 14%, transparent); }
.settings-nav { border-right: 0; border-left: 1px solid var(--border); }
.settings-nav-item { text-align: right; border-radius: 9px; }
.settings-nav-item.active { box-shadow: inset -3px 0 var(--primary); }
.settings-panels { padding: 24px clamp(18px, 3vw, 40px); }
.code-area { direction: ltr; text-align: left; border-radius: 12px; }
.modal-panel { border-radius: 18px; box-shadow: 0 24px 80px rgb(0 0 0 / 22%); }
.modal-actions { justify-content: flex-start; }
.toast-stack { right: auto; left: 16px; }
.toast { border-left: 1px solid var(--border); border-right: 4px solid var(--primary); border-radius: 12px; }
.toast.success { border-right-color: var(--success); }
.toast.error { border-right-color: var(--danger); }
.toast.info { border-right-color: var(--primary); }
.auth-card { border-radius: 22px; box-shadow: 0 18px 70px rgb(25 54 40 / 10%); }
.auth-card form { text-align: right; }
.auth-error { text-align: right; border-radius: 10px; }

@media (max-width: 1120px) {
  .post-meta-grid { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 860px) {
  .sidebar { border-left: 0; }
  .settings-nav { border-left: 0; border-bottom: 1px solid var(--border); }
  .editor-body { padding: 14px; }
  .post-heading-fields { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 560px) {
  .topbar { height: 48px; }
  .app { height: calc(100vh - 48px); }
  .topbar-title { display: inline; }
  .clock { gap: 5px; }
  .clock-value { font-size: 10px; }
  .post-meta-grid { padding: 13px; border-radius: 13px; }
  .post-date-weight { grid-template-columns: minmax(0, 1fr); }
  .post-cover-fields { grid-template-columns: minmax(0, 1fr); }
  .editor-header { padding: 10px 12px; flex-wrap: wrap; }
  .editor-actions { gap: 5px; }
  .editor-actions .btn { padding-inline: 9px; }
  .editor-actions .dirty { display: none; }
  .content-pane { min-height: 60vh; }
  .md-toolbar { gap: 2px; }
  .md-toolbar button { min-width: 30px; height: 30px; }
}

/* Keep the existing layout while using a flat, crisp visual treatment. */
.topbar { box-shadow: none; }
.workspace-nav a[aria-current="page"],
.tree-item.active,
.settings-nav-item.active { box-shadow: none; }
.post-meta-grid,
.content-pane,
.auth-card,
.modal-panel,
.btn-primary,
.btn-danger,
.field input:focus,
.field select:focus,
.tag-editor:focus-within { box-shadow: none; }
.post-meta-grid,
.content-pane,
.auth-card,
.modal-panel { border-radius: 8px; }
.field input,
.field select,
.tag-editor { border-radius: 6px; }
.workspace-nav a,
.tree-item,
.settings-nav-item,
.post-toggles label,
.md-toolbar button,
.btn,
.btn-sm { border-radius: 6px; }
.btn:hover:not(:disabled) { transform: none; }
.btn:active:not(:disabled) { transform: none; }
.field input:focus,
.field select:focus,
.tag-editor:focus-within { outline: 2px solid color-mix(in srgb, var(--primary) 28%, transparent); outline-offset: 1px; }
.btn-primary:hover:not(:disabled) { filter: brightness(.96); }
.btn-primary:active:not(:disabled) { filter: brightness(.9); }
.bi {
  display: inline-block;
  font-size: 1.05em;
  line-height: 1;
  vertical-align: -0.08em;
}
.icon-btn .bi { font-size: 16px; }
.auth-cta .bi { font-size: 17px; }
