/**
 * Layout: top-level grid, header, sidebar shell, and editor panes.
 * Pure structure — visual button/menu styles live in components.css.
 */
.app-shell {
  min-height: 100vh;
  background: var(--bg);
}
.app-shell[data-current-page="home"] .home-page {
  display: block;
}
.app-shell[data-current-page="home"] .editor-page {
  display: none;
}
.app-shell[data-current-page="editor"] .home-page {
  display: none;
}

.app-shell[data-current-page="editor"] .editor-page {
  display: grid;
}

.home-page {
  display: block;
  min-height: 100vh;
}

.home-header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--bg);
  border-bottom: 1px solid var(--line);
  padding: 1rem 2rem;
}

.home-header-content {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.home-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.home-icon {
  font-size: 2rem;
  color: var(--accent);
}

.home-brand h1 {
  margin: 0;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text);
}

.home-content {
  max-width: 1200px;
  margin: 0 auto;
  padding: 3rem 2rem;
}

.home-actions {
  text-align: center;
  margin-bottom: 4rem;
}

.home-actions h2 {
  font-size: 2rem;
  margin: 0 0 0.75rem;
  color: var(--text);
}

.home-actions p {
  font-size: 1.125rem;
  color: var(--muted);
  margin: 0 0 2rem;
}

.home-buttons {
  display: flex;
  gap: 1rem;
  justify-content: center;
  flex-wrap: wrap;
}

.home-files {
  background: var(--panel);
  border-radius: 16px;
  padding: 2rem;
  box-shadow: var(--shadow);
}

.home-files-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.home-files-header h3 {
  margin: 0;
  font-size: 1.25rem;
  color: var(--text);
}

.search-box.small {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--subtle);
  border-radius: 12px;
  padding: 0.5rem 1rem;
}

.search-box.small .material-symbols-outlined {
  font-size: 1.25rem;
  color: var(--muted);
}

.search-box.small input {
  border: 0;
  background: transparent;
  padding: 0;
  min-height: auto;
  width: 12rem;
}

.search-box.small input:focus {
  box-shadow: none;
}

.doc-list-home {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1rem;
}

.doc-list-home .doc-item {
  padding: 1.25rem;
  border: 1px solid var(--line);
  border-radius: 12px;
  transition: all 200ms ease;
}

.doc-list-home .doc-item:hover,
.doc-list-home .doc-item[aria-current="true"] {
  border-color: var(--accent);
  background: var(--accent-soft);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.editor-page {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto minmax(0, 1fr);
  min-height: 100vh;
}

.app-shell[data-sidebar-open="true"] .sidebar {
  display: block;
}

@media (min-width: 1024px) {
  .editor-page {
    grid-template-columns: minmax(0, 1fr);
  }

  .topbar {
    grid-column: 1 / -1;
  }
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: auto minmax(12rem, 1fr) auto;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
}

.topbar-title-input {
  min-width: 0;
  min-height: 3rem;
  text-align: start;
}

.icon-button {
  display: inline-grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  flex: 0 0 auto;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: all 150ms ease;
}

.icon-button:hover,
.icon-button:focus-visible {
  border-color: var(--line);
  background: var(--subtle);
  outline: none;
}

.icon-button:active {
  transform: translateY(1px);
}

.editor-menu-wrapper {
  position: relative;
  display: inline-flex;
}

.file-actions-menu {
  position: absolute;
  top: calc(100% + 0.4rem);
  left: 0;
  z-index: 60;
  display: grid;
  min-width: 13.5rem;
  max-width: min(18rem, calc(100vw - 1rem));
  padding: 0.35rem;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--panel-strong);
  box-shadow: var(--shadow);
  direction: rtl;
}

.file-actions-menu[hidden] {
  display: none;
}

.file-actions-menu button {
  display: grid;
  grid-template-columns: 1.35rem minmax(0, 1fr);
  align-items: center;
  gap: 0.55rem;
  width: 100%;
  min-height: 2.3rem;
  padding: 0.35rem 0.65rem;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  text-align: start;
  cursor: pointer;
  transition: all 150ms ease;
}

.file-actions-menu button:hover,
.file-actions-menu button:focus-visible {
  background: var(--accent-soft);
  outline: none;
}

.file-actions-menu button[data-action="delete-doc"] {
  color: var(--danger);
}

.file-actions-menu .material-symbols-outlined,
.icon-button .material-symbols-outlined {
  font-size: 1.35rem;
  line-height: 1;
}

.save-status-text {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.sidebar {
  display: none;
  min-height: 0;
  border-inline-end: 1px solid var(--line);
  background: var(--panel);
  padding: 1rem;
  overflow: auto;
}

.sidebar-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
  margin-bottom: 0.9rem;
}

.primary-button,
.ghost-button,
.segmented-control button,
.context-menu button {
  border: 1px solid var(--line);
  border-radius: 10px;
  cursor: pointer;
  transition: all 150ms ease;
}

.primary-button,
.ghost-button {
  min-height: 2.5rem;
  padding: 0.5rem 1rem;
}

.primary-button {
  border-color: var(--accent);
  background: var(--accent);
  color: white;
}

.primary-button:hover {
  background: var(--accent-strong);
}

.ghost-button {
  background: var(--panel);
  color: var(--text);
}

.ghost-button:hover {
  background: var(--subtle);
}

.primary-button.large,
.ghost-button.large {
  min-height: 3rem;
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.search-box {
  display: grid;
  gap: 0.35rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.search-box input,
.title-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  color: var(--text);
  outline: none;
  transition: all 150ms ease;
}

.search-box input {
  min-height: 2.5rem;
  padding: 0.5rem 0.75rem;
}

.search-box input:focus,
.title-input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.doc-list {
  display: grid;
  gap: 0.5rem;
  margin-block: 1rem;
}

.doc-item {
  display: grid;
  gap: 0.25rem;
  width: 100%;
  padding: 0.75rem;
  border: 1px solid transparent;
  border-radius: 10px;
  background: transparent;
  text-align: start;
  cursor: pointer;
  transition: all 150ms ease;
}

.doc-item:hover,
.doc-item[aria-current="true"] {
  border-color: var(--line);
  background: var(--subtle);
}

.doc-item strong {
  overflow: hidden;
  font-size: 0.95rem;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
}

.doc-item span {
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.4;
}

.storage-hint {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.workspace {
  display: grid;
  grid-template-rows: minmax(0, 1fr);
  min-width: 0;
  min-height: 0;
}

.title-input {
  min-width: 0;
  min-height: 2.75rem;
  padding: 0.5rem 0.875rem;
  font-weight: 700;
  font-size: 1.125rem;
}

.panes {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  min-height: 0;
}

.editor-pane,
.preview-pane,
.flow-pane {
  min-width: 0;
  min-height: 0;
}

.editor-pane {
  border-inline-end: 1px solid var(--line);
  background: var(--panel);
}

#editor {
  display: block;
  width: 100%;
  height: 100%;
  min-height: calc(100vh - 4.5rem);
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  padding: clamp(1.25rem, 2.5vw, 2.5rem);
  font-family: var(--ui-font);
  font-size: clamp(1rem, 0.96rem + 0.2vw, 1.08rem);
  line-height: 1.85;
  text-align: start;
  tab-size: 2;
  unicode-bidi: normal;
}

#editor[dir="ltr"] {
  font-family: var(--latin-font);
}

.preview-pane {
  overflow: auto;
  background: var(--panel);
}

.flow-pane {
  display: none;
  overflow: auto;
  background: var(--panel);
}
