/* ============================================================
   Layout — app shell, panels, statusbar
   ============================================================ */

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

/*
 * The [hidden] attribute must always win — without this, our flex/grid
 * containers (.sidebar, .welcome, .editor-scroll) override the UA
 * stylesheet's [hidden] { display: none } because class selectors and
 * attribute selectors share the same specificity, and the author rule
 * defined later in the cascade wins.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--c-bg);
  color: var(--c-ink);
  font-family: var(--f-ui);
  font-size: var(--fs-base);
  line-height: var(--lh-ui);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow: hidden;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

::selection {
  background: var(--c-selection);
  color: var(--c-ink);
}

/* ---------- App shell ---------- */
.app {
  display: grid;
  grid-template-rows:
    var(--h-titlebar)
    var(--h-menubar)
    var(--h-toolbar)
    var(--h-eltbar)
    1fr
    var(--h-statusbar);
  height: 100vh;
  width: 100vw;
}

/* ---------- Title bar (subtle, brand only) ---------- */
.titlebar {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-line);
  font-size: var(--fs-xs);
  color: var(--c-muted);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  user-select: none;
  position: relative;
}

.titlebar .brand {
  font-weight: var(--fw-semi);
  color: var(--c-ink);
  letter-spacing: 0.16em;
}

.titlebar .doc-title {
  margin-left: var(--s-3);
  text-transform: none;
  letter-spacing: 0;
  color: var(--c-ink-soft);
  font-weight: var(--fw-regular);
  padding: 2px 6px;
  border-radius: var(--r-sm);
  cursor: text;
  outline: none;
  min-width: 60px;
  max-width: 60ch;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background-color var(--t-fast) var(--ease);
}

.titlebar .doc-title:hover {
  background: var(--c-hover);
}

.titlebar .doc-title:focus {
  background: var(--c-surface);
  box-shadow: 0 0 0 2px var(--c-accent);
  color: var(--c-ink);
  white-space: normal;
  overflow: visible;
}

.titlebar .doc-title.dirty::after {
  content: ' •';
  color: var(--c-accent);
}

/* ---------- Workspace (editor + sidebars) ---------- */
.workspace {
  display: grid;
  grid-template-columns: 1fr;
  overflow: hidden;
  background: var(--c-bg);
  position: relative;
}

.workspace.with-sidebar-right {
  grid-template-columns: 1fr 320px;
}

.workspace.split-vertical {
  grid-template-columns: 1fr 1fr;
}

.workspace.split-horizontal {
  grid-template-columns: 1fr;
  grid-template-rows: 1fr 1fr;
}

.editor-pane {
  position: relative;
  overflow: auto;
  scroll-behavior: smooth;
  background: var(--c-bg);
}

.editor-pane:focus { outline: none; }

.sidebar {
  background: var(--c-surface);
  border-left: 1px solid var(--c-line);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.sidebar-header {
  height: var(--h-eltbar);
  padding: 0 var(--s-3);
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--c-line);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--c-muted);
  font-weight: var(--fw-semi);
}

.sidebar-body {
  flex: 1;
  overflow: auto;
  padding: var(--s-3);
}

/* ---------- Status bar ---------- */
.statusbar {
  display: flex;
  align-items: center;
  background: var(--c-surface);
  border-top: 1px solid var(--c-line);
  padding: 0 var(--s-3);
  font-size: var(--fs-xs);
  color: var(--c-ink-soft);
  user-select: none;
  gap: var(--s-2);
}

.statusbar .seg {
  display: inline-flex;
  align-items: center;
  gap: var(--s-1);
  padding: 0 var(--s-2);
  height: 18px;
  border-radius: var(--r-sm);
  cursor: default;
}

.statusbar .seg.btn {
  cursor: pointer;
  transition: background var(--t-fast) var(--ease);
}

.statusbar .seg.btn:hover { background: var(--c-hover); }
.statusbar .seg.active   { background: var(--c-accent-soft); color: var(--c-accent-ink); }

.statusbar .spacer { flex: 1; }

.statusbar .seg-label {
  color: var(--c-muted);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  font-size: 10px;
}

.statusbar .seg-value { font-variant-numeric: tabular-nums; }

/* ---------- Welcome screen ---------- */
.welcome {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: var(--s-9);
  background: var(--c-bg);
}

.welcome-mark {
  font-family: var(--f-mono);
  font-size: 56px;
  font-weight: var(--fw-regular);
  letter-spacing: 0.18em;
  color: var(--c-ink);
  margin: 0 0 var(--s-2) 0;
}

.welcome-mark .dot { color: var(--c-accent); }

.welcome-tagline {
  font-size: var(--fs-lg);
  color: var(--c-muted);
  letter-spacing: var(--tracking-caps);
  text-transform: uppercase;
  margin: 0 0 var(--s-8) 0;
}

.welcome-actions {
  display: flex;
  gap: var(--s-3);
  margin-bottom: var(--s-7);
}

.welcome-recents {
  width: 100%;
  max-width: 520px;
  text-align: left;
}

.welcome-recents-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin: 0 0 var(--s-3) 0;
}

.welcome-recents h3 {
  font-size: var(--fs-xs);
  font-weight: var(--fw-semi);
  text-transform: uppercase;
  letter-spacing: var(--tracking-caps);
  color: var(--c-muted);
  margin: 0;
}

.recent-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border-top: 1px solid var(--c-line);
}

.recent-list li,
.recent-item-row {
  border-bottom: 1px solid var(--c-line);
  display: flex;
  align-items: stretch;
}

.recent-list .recent-open {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: none;
  border: 0;
  padding: var(--s-3) var(--s-2);
  cursor: pointer;
  text-align: left;
  transition: background var(--t-fast) var(--ease);
  color: var(--c-ink);
  font-family: inherit;
}

.recent-list .recent-open:hover { background: var(--c-hover); }

.recent-list .recent-delete {
  flex: 0 0 auto;
  width: 32px;
  background: none;
  border: 0;
  color: var(--c-faint);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  border-radius: var(--r-sm);
  margin: var(--s-1);
  padding: 0;
  opacity: 0;
  transition: opacity var(--t-fast) var(--ease), background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}

.recent-item-row:hover .recent-delete,
.recent-list .recent-delete:focus-visible {
  opacity: 1;
}

.recent-list .recent-delete:hover {
  background: var(--c-error, #dc2626);
  color: #fff;
  opacity: 1;
}

.recent-list .recent-name {
  font-weight: var(--fw-medium);
  color: var(--c-ink);
}

.recent-list .recent-meta {
  font-size: var(--fs-xs);
  color: var(--c-muted);
  font-variant-numeric: tabular-nums;
}

.welcome-empty {
  font-size: var(--fs-sm);
  color: var(--c-faint);
  font-style: italic;
}
