/* ==========================================================================
   PocketOffice — shared theme & shell styles

   Requires a CSS custom-property–capable browser (Chrome 49+, Edge 15+,
   Firefox 31+, Safari 9.1+). IE 11 is not supported. Fallback values are
   provided on the most critical properties so the app is at least legible
   if a very old WebView strips custom properties.
   ========================================================================== */

:root {
  /* light theme (default) */
  --bg:          #f4f5f7;
  --surface:     #ffffff;
  --surface-2:   #f0f1f4;
  --surface-3:   #e7e9ee;
  --border:      #d7dae0;
  --border-soft: #e4e6ec;
  --text:        #1c1e22;
  --text-dim:    #5a606b;
  --text-faint:  #8a909c;
  --accent:      #1668e6;
  --accent-hov:  #0d57c4;
  --accent-soft: #e1ecff;
  --danger:      #d83a3a;
  --warn:        #c97700;
  --ok:          #1a8a4c;
  --shadow:      0 1px 3px rgba(20,25,40,.08), 0 4px 14px rgba(20,25,40,.06);
  --radius:      8px;
  --radius-sm:   5px;
  --tb-h:        44px;   /* toolbar height */
  --tab-h:       42px;   /* app-tab strip height */
  --status-h:    26px;
  --font-ui:     -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono:   "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --font-doc:    "Calibri", "Segoe UI", Tahoma, sans-serif;
}

body.theme-dark {
  --bg:          #1a1b1f;
  --surface:     #232429;
  --surface-2:   #2a2c32;
  --surface-3:   #34363d;
  --border:      #3c3f47;
  --border-soft: #32343b;
  --text:        #e6e7ea;
  --text-dim:    #a3a8b3;
  --text-faint:  #6f7480;
  --accent:      #5b94fc;
  --accent-hov:  #7aaaff;
  --accent-soft: #2a3a52;
  --shadow:      0 1px 3px rgba(0,0,0,.4), 0 4px 14px rgba(0,0,0,.3);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-family: var(--font-ui);
  font-size: 14px;
  color: #1c1e22;
  color: var(--text);
  background: #f4f5f7;
  background: var(--bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}
button { font-family: inherit; font-size: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: inherit; color: #1c1e22; color: var(--text); }

/* ---------- App shell ---------- */
#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* Tab strip (the 5 apps) */
.app-tabs {
  display: flex;
  align-items: center;
  height: var(--tab-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 8px;
  gap: 2px;
  flex-shrink: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 14px 0 6px;
  margin-right: 6px;
  border-right: 1px solid var(--border-soft);
  height: 100%;
}
.brand-logo {
  width: 24px; height: 24px;
  border-radius: 6px;
  background: linear-gradient(135deg, var(--accent), #8a5cf6);
  display: grid; place-items: center;
  color: #fff; font-weight: 700; font-size: 13px;
}
.brand-name { font-weight: 600; letter-spacing: .2px; }
.app-tab {
  display: flex; align-items: center; gap: 7px;
  height: 32px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text-dim);
  font-weight: 500;
  transition: background .12s, color .12s;
}
.app-tab:hover { background: #f0f1f4; background: var(--surface-2); color: #1c1e22; color: var(--text); }
.app-tab.active {
  background: #e1ecff;
  background: var(--accent-soft);
  color: #1668e6;
  color: var(--accent);
  border-color: color-mix(in srgb, var(--accent) 25%, transparent);
}
.app-tab .ico { font-size: 15px; line-height: 1; }

.tab-spacer { flex: 1; }
.icon-btn {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  color: var(--text-dim);
  font-size: 16px;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* App container: each tool panel */
.workspace { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.tool-panel { display: none; flex: 1; flex-direction: column; min-height: 0; }
.tool-panel.active { display: flex; }

/* Toolbars (shared look, used by all apps) */
.toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  flex-wrap: wrap;
  min-height: 44px;
  min-height: var(--tb-h);
  padding: 5px 10px;
  background: #ffffff;
  background: var(--surface);
  border-bottom: 1px solid #d7dae0;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.tb-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 30px;
  padding: 0 10px;
  border: 1px solid transparent;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
}
.tb-btn:hover { background: #f0f1f4; background: var(--surface-2); }
.tb-btn:active { background: #e7e9ee; background: var(--surface-3); }
.tb-btn.primary { background: #1668e6; background: var(--accent); color: #fff; }
.tb-btn.primary:hover { background: #0d57c4; background: var(--accent-hov); }
.tb-btn.ghost { color: var(--text-dim); }
.tb-btn.icon-only { width: 32px; padding: 0; justify-content: center; }
.tb-btn.active { background: var(--accent-soft); color: var(--accent); }
.tb-sep {
  width: 1px; height: 22px; background: var(--border-soft);
  margin: 0 5px;
}
.tb-select {
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  padding: 0 8px;
}
.tb-input {
  height: 30px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
  padding: 0 8px;
}
.tb-label { font-size: 12px; color: var(--text-dim); margin: 0 4px 0 6px; }

/* Status bar */
.statusbar {
  display: flex;
  align-items: center;
  gap: 18px;
  height: var(--status-h);
  padding: 0 12px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 12px;
  color: var(--text-dim);
  flex-shrink: 0;
}
.statusbar .spacer { flex: 1; }

/* ---------- Generic content panels ---------- */
.content {
  flex: 1;
  overflow: auto;
  background: var(--bg);
  position: relative;
}
.center-panel {
  display: grid;
  place-items: center;
  height: 100%;
  padding: 30px;
  text-align: center;
}
.empty-state {
  max-width: 520px;
  color: var(--text-dim);
}
.empty-state h2 { color: var(--text); margin: 0 0 8px; font-size: 19px; }
.empty-state p { margin: 0 0 18px; line-height: 1.55; }
.empty-state .big-btns { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; }

/* ---------- Dialogs ---------- */
.dialog-backdrop {
  position: fixed; inset: 0;
  background: rgba(15,18,25,.45);
  display: grid; place-items: center;
  z-index: 1000;
  animation: fade .12s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.dialog {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  min-width: 380px;
  max-width: 92vw;
  max-height: 88vh;
  overflow: auto;
  padding: 18px 20px;
}
.dialog h3 { margin: 0 0 12px; font-size: 16px; }
.dialog .row { display: flex; gap: 10px; align-items: center; margin: 10px 0; }
.dialog .row label { min-width: 90px; color: var(--text-dim); font-size: 13px; }
.dialog .actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }
.dialog input[type=text], .dialog input[type=number], .dialog select {
  flex: 1; height: 32px; padding: 0 10px;
  border: 1px solid var(--border); border-radius: 6px; background: var(--surface);
}

/* Toasts */
#toasts {
  position: fixed; bottom: 36px; right: 16px; z-index: 2000;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  font-size: 13px;
  max-width: 340px;
  animation: slideIn .18s ease;
}
.toast.ok    { border-left-color: var(--ok); }
.toast.err   { border-left-color: var(--danger); }
.toast.warn  { border-left-color: var(--warn); }
@keyframes slideIn { from { transform: translateX(20px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- Text editor ---------- */
.te-wrap { display: flex; flex: 1; min-height: 0; flex-direction: column; }
.te-tabs {
  display: flex; align-items: center;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  padding: 4px 6px 0;
  gap: 3px;
  overflow-x: auto;
  flex-shrink: 0;
}
.te-tab {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 6px 6px 0 0;
  background: transparent;
  color: var(--text-dim);
  font-size: 13px;
  max-width: 200px;
  cursor: pointer;
}
.te-tab .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 140px; }
.te-tab .close { opacity: .5; font-size: 14px; line-height: 1; padding: 0 2px; }
.te-tab .close:hover { opacity: 1; color: var(--danger); }
.te-tab.active {
  background: var(--bg);
  color: var(--text);
  border-color: var(--border);
}
.te-tab.dirty::after { content: "●"; color: var(--accent); margin-left: -4px; }
.te-new {
  margin-left: auto;
  padding: 4px 10px;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--text-dim);
  margin-bottom: 4px;
}
.te-new:hover { color: var(--text); border-color: var(--accent); }
.te-editor {
  display: flex;
  flex: 1;
  min-height: 0;
  background: var(--surface);
  font-family: var(--font-mono);
}
.te-gutter {
  flex-shrink: 0;
  padding: 10px 8px 10px 12px;
  text-align: right;
  color: var(--text-faint);
  background: var(--surface-2);
  border-right: 1px solid var(--border-soft);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  user-select: none;
  overflow: hidden;
  white-space: pre;
}
.te-textarea {
  flex: 1;
  border: none;
  outline: none;
  resize: none;
  padding: 10px 14px;
  background: transparent;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  line-height: 1.5;
  white-space: pre;
  overflow: auto;
  tab-size: 4;
}
.te-find {
  display: none;
  align-items: center;
  gap: 6px;
  padding: 6px 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.te-find.open { display: flex; }
.te-find input { height: 28px; padding: 0 8px; border: 1px solid var(--border); border-radius: 5px; background: var(--surface); }

/* ---------- PDF viewer ---------- */
.pdf-wrap { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.pdf-canvas-area {
  flex: 1;
  overflow: auto;
  background: #525659;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 20px;
  gap: 12px;
}
.pdf-canvas-area canvas {
  background: #fff;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
  max-width: 100%;
}
.pdf-pagewrap {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  background: transparent;
}
.pdf-pagewrap canvas {
  display: block;
  border-radius: 2px 2px 0 0;
}
.pdf-pagebar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 6px 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-top: none;
  border-radius: 0 0 4px 4px;
  box-shadow: 0 4px 12px rgba(0,0,0,.25);
}
.pdf-pagewrap .pdf-pagelabel {
  font-size: 12px; color: var(--text-dim); font-weight: 500;
}
.pdf-pagebar .tb-btn.icon-only { width: 28px; height: 28px; font-size: 13px; }

/* ---------- Calc preview (stub) ---------- */
.placeholder-grid {
  margin: 30px auto;
  max-width: 900px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}
.feature-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
  margin-top: 18px;
}
.feature-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  text-align: left;
}
.feature-card .ico { font-size: 22px; }
.feature-card h4 { margin: 8px 0 4px; font-size: 14px; }
.feature-card p { margin: 0; font-size: 12px; color: var(--text-dim); line-height: 1.45; }

.coming-soon {
  display: grid; place-items: center; height: 100%; text-align: center; color: var(--text-dim); padding: 30px;
}
.coming-soon .pill {
  display: inline-block; padding: 3px 10px; border-radius: 20px;
  background: var(--surface-2); border: 1px solid var(--border);
  font-size: 12px; color: var(--accent); margin-bottom: 10px;
}

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

/* ==========================================================================
   Writer (moved here from js/word.js in v2.0.0)
   ========================================================================== */
.writer-surface {
  flex: 1; overflow: auto;
  background: var(--bg);
  padding: 0;
}
.writer-doc {
  background: var(--surface);
  max-width: 8.5in;
  min-height: 11in;
  margin: 24px auto;
  padding: 1in 1in;
  box-shadow: var(--shadow);
  border-radius: 2px;
  font-family: var(--font-doc);
  font-size: 16px;
  line-height: 1.5;
  color: #1a1a1a;
  outline: none;
}
.writer-doc:focus { outline: none; }
.writer-doc p { margin: 0 0 12px; }
.writer-doc h1 { font-size: 2em; margin: .67em 0; }
.writer-doc h2 { font-size: 1.5em; margin: .75em 0; }
.writer-doc h3 { font-size: 1.17em; margin: .83em 0; }
.writer-doc h4 { font-size: 1em; margin: 1.12em 0; }
.writer-doc ul, .writer-doc ol { margin: 0 0 12px; padding-left: 32px; }
.writer-doc blockquote {
  border-left: 3px solid #ccc; padding-left: 12px; color: #555; margin: 0 0 12px;
}
.writer-doc pre {
  background: #f4f4f4; padding: 10px; border-radius: 4px;
  font-family: var(--font-mono); font-size: 13px; white-space: pre-wrap;
}
.writer-doc a { color: var(--accent); }
.writer-doc img { max-width: 100%; }
body.theme-dark .writer-doc { color: #222; background: #fdfdfd; }

/* ==========================================================================
   Calc (moved here from js/calc.js in v2.0.0)
   ========================================================================== */
.calc-wrap { display: flex; flex-direction: column; flex: 1; min-height: 0; position: relative; }
.calc-content {
  flex: 1; min-height: 0; overflow: auto;
  position: relative;
  background: var(--surface);
  font-family: var(--font-ui);
  font-size: 13px;
}
.calc-corner {
  position: sticky; top: 0; left: 0; z-index: 5;
  width: 44px; height: 26px;
  background: var(--surface-2); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  display: grid; place-items: center; color: var(--text-faint);
}
.calc-colheader {
  position: sticky; top: 0; z-index: 4;
  display: flex; align-items: center;
  height: 26px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.calc-colheader .calc-spacer { width: 44px; flex-shrink: 0; border-right: 1px solid var(--border); height: 100%; }
.calc-colhead {
  width: 92px; flex-shrink: 0;
  text-align: center; line-height: 26px;
  color: var(--text-dim); font-weight: 500;
  border-right: 1px solid var(--border-soft);
}
.calc-body { display: grid; grid-template-columns: 44px repeat(var(--calc-cols, 100), 92px); align-content: start; }
.calc-rowhead {
  position: sticky; left: 0; z-index: 3;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border-soft);
  text-align: center; line-height: 26px;
  color: var(--text-dim); font-size: 12px;
  height: 26px;
}
.calc-cell {
  height: 26px; padding: 0 6px;
  border-right: 1px solid var(--border-soft);
  border-bottom: 1px solid var(--border-soft);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  line-height: 26px;
  outline: none;
  cursor: cell;
  user-select: none;
}
.calc-cell.calc-num { text-align: right; color: #111; }
body.theme-dark .calc-cell.calc-num { color: var(--text); }
.calc-cell.calc-bool { text-align: center; color: var(--text-dim); font-style: italic; }
.calc-cell.calc-err { color: var(--danger); text-align: center; font-weight: 600; }
.calc-cell.calc-str { color: var(--text); }
.calc-cell.active { outline: 2px solid var(--accent); outline-offset: -2px; }
.calc-cell.editing { padding: 0; }
.calc-edit {
  width: 100%; height: 26px;
  border: 0; outline: 2px solid var(--accent); outline-offset: -2px;
  padding: 0 6px;
  background: var(--surface); color: var(--text);
  font: inherit;
}
/* Charts — floating overlay panels */
.calc-chart-layer {
  position: absolute; inset: 0;
  pointer-events: none;   /* let clicks pass to grid except on panels themselves */
  z-index: 6;
}
.calc-chart-panel {
  position: absolute;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: flex; flex-direction: column;
  pointer-events: auto;
  overflow: hidden;
  min-width: 160px; min-height: 100px;
}
.calc-chart-head {
  display: flex; align-items: center; gap: 2px;
  padding: 4px 6px 4px 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border-soft);
  cursor: move;
  font-size: 12px; font-weight: 600; color: var(--text-dim);
}
.calc-chart-head .tb-btn.icon-only { width: 24px; height: 24px; font-size: 12px; }
.calc-chart-panel canvas { flex: 1; min-height: 0; padding: 6px; box-sizing: border-box; }
.calc-chart-resize {
  position: absolute; right: 0; bottom: 0;
  width: 14px; height: 14px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, var(--border) 50%);
}

/* ==========================================================================
   Impress (moved here from js/impress.js in v2.0.0)
   ========================================================================== */
.impress-wrap { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.impress-row { display: flex; flex: 1; min-height: 0; }
.impress-sidebar {
  width: 180px; flex-shrink: 0;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  overflow: hidden;
}
.impress-sidehead {
  display: flex; align-items: center; justify-content: space-between;
  padding: 6px 10px;
  font-size: 12px; font-weight: 600; color: var(--text-dim);
  border-bottom: 1px solid var(--border);
  text-transform: uppercase; letter-spacing: .5px;
}
.impress-slidelist { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 8px; }
.impress-slideitem {
  background: var(--surface); border: 1px solid var(--border); border-radius: 6px;
  padding: 4px; cursor: pointer; transition: border-color .12s;
}
.impress-slideitem:hover { border-color: var(--accent); }
.impress-slideitem.active { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.impress-thumb {
  width: 100%; aspect-ratio: 16/9;
  background: #fff; border: 1px solid var(--border-soft); border-radius: 3px;
  position: relative; overflow: hidden;
}
.impress-slidemeta {
  display: flex; align-items: center; gap: 2px; margin-top: 4px; font-size: 11px;
}
.impress-slidemeta .num { font-weight: 600; color: var(--text-dim); padding: 0 4px; }
.impress-slidemeta button {
  background: transparent; border: 0; color: var(--text-faint); cursor: pointer;
  font-size: 11px; padding: 2px 3px; border-radius: 3px;
}
.impress-slidemeta button:hover { background: var(--surface-3); color: var(--text); }
.impress-slidemeta .del:hover { color: var(--danger); }

.impress-stage {
  flex: 1; min-width: 0; padding: 24px;
  display: grid; place-items: center;
  background: var(--bg);
  overflow: auto;
}
.impress-canvas {
  width: min(960px, 100%); aspect-ratio: 16/9;
  background: #fff; box-shadow: var(--shadow);
  border-radius: 3px; position: relative;
  outline: none;
}
.imp-el {
  position: absolute; cursor: move; user-select: none;
  box-sizing: border-box;
}
.imp-el.selected { outline: 2px solid var(--accent); outline-offset: 1px; }
.imp-text { padding: 4px 6px; }
.imp-shape { border: 1px solid rgba(0,0,0,.06); }
.imp-resize {
  position: absolute; right: -6px; bottom: -6px;
  width: 12px; height: 12px;
  background: var(--accent); border: 2px solid #fff; border-radius: 50%;
  cursor: nwse-resize;
}

.impress-inspector {
  width: 220px; flex-shrink: 0;
  background: var(--surface);
  border-left: 1px solid var(--border);
  padding: 12px; overflow-y: auto;
}
.imp-noinspect { color: var(--text-dim); font-size: 13px; line-height: 1.5; padding: 20px 4px; }
.imp-inspecthead {
  font-size: 11px; font-weight: 600; letter-spacing: .5px;
  color: var(--text-dim); text-transform: uppercase; margin-bottom: 10px;
  padding-bottom: 6px; border-bottom: 1px solid var(--border-soft);
}
.imp-field { margin-bottom: 8px; }
.imp-field label { display: block; font-size: 11px; color: var(--text-dim); margin-bottom: 3px; }
.imp-field input, .imp-field select {
  width: 100%; height: 28px; padding: 0 6px;
  border: 1px solid var(--border); border-radius: 5px; background: var(--surface); color: var(--text);
  font-size: 12px;
}
.imp-field input[type=color] { padding: 0; height: 30px; }
.imp-check { font-size: 12px; color: var(--text-dim); margin-right: 10px; cursor: pointer; }
.imp-check input { margin-right: 4px; }

#impPresent {
  position: fixed; inset: 0; z-index: 5000;
  background: #000; display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.imp-pres-slide {
  position: relative;
  width: min(100vw, calc(100vh * 16/9));
  height: min(100vh, calc(100vw * 9/16));
  background: #fff; overflow: hidden;
}
.imp-pres-controls {
  position: absolute; bottom: 16px; left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  background: rgba(0,0,0,.6); color: #fff;
  padding: 8px 16px; border-radius: 24px; font-size: 14px;
}
.imp-pres-controls button {
  background: rgba(255,255,255,.15); border: 0; color: #fff;
  width: 32px; height: 32px; border-radius: 50%; cursor: pointer; font-size: 14px;
}
.imp-pres-controls button:hover { background: rgba(255,255,255,.3); }

/* ==========================================================================
   Markdown (moved here from js/markdown.js in v2.0.0)
   ========================================================================== */
.md-wrap { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.md-toolbar { display: flex; align-items: center; gap: 2px; flex-wrap: wrap;
  min-height: var(--tb-h); padding: 5px 10px; background: var(--surface);
  border-bottom: 1px solid var(--border); flex-shrink: 0; }
.md-split { display: flex; flex: 1; min-height: 0; }
.md-editor-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.md-divider { width: 1px; background: var(--border); flex-shrink: 0; }
.md-preview-pane { flex: 1; min-width: 0; overflow: auto; background: var(--bg); }
.md-editor {
  flex: 1; width: 100%; border: 0; outline: none; resize: none; padding: 18px 24px;
  background: var(--surface); color: var(--text);
  font-family: var(--font-mono); font-size: 14px; line-height: 1.6; tab-size: 2;
}
.md-readmode .md-preview-pane { flex: 1; }

/* Rendered markdown preview */
.md-preview {
  max-width: 760px; margin: 24px auto; padding: 8px 24px;
  font-family: var(--font-doc); font-size: 16px; line-height: 1.6; color: var(--text);
  word-wrap: break-word;
}
.md-preview h1 { font-size: 2em; border-bottom: 1px solid var(--border-soft); padding-bottom: .3em; margin: .8em 0 .5em; }
.md-preview h2 { font-size: 1.5em; border-bottom: 1px solid var(--border-soft); padding-bottom: .3em; margin: 1em 0 .5em; }
.md-preview h3 { font-size: 1.25em; margin: 1em 0 .4em; }
.md-preview h4 { font-size: 1em; margin: 1em 0 .3em; }
.md-preview h5, .md-preview h6 { color: var(--text-dim); margin: 1em 0 .3em; }
.md-preview p { margin: 0 0 12px; }
.md-preview a { color: var(--accent); }
.md-preview ul, .md-preview ol { margin: 0 0 12px; padding-left: 28px; }
.md-preview li { margin: 3px 0; }
.md-preview code {
  font-family: var(--font-mono); font-size: .9em;
  background: var(--surface-3); padding: 2px 5px; border-radius: 4px;
}
.md-preview pre { background: var(--surface-3); padding: 14px; border-radius: 6px; overflow: auto; margin: 0 0 12px; }
.md-preview pre code { background: none; padding: 0; font-size: 13px; }
.md-preview blockquote {
  border-left: 4px solid var(--border); margin: 0 0 12px; padding: 4px 16px;
  color: var(--text-dim);
}
.md-preview table { border-collapse: collapse; margin: 0 0 12px; }
.md-preview th, .md-preview td { border: 1px solid var(--border); padding: 6px 12px; text-align: left; }
.md-preview th { background: var(--surface-2); }
.md-preview img { max-width: 100%; }
.md-preview hr { border: 0; border-top: 2px solid var(--border-soft); margin: 20px 0; }
.md-preview input[type=checkbox] { margin-right: 6px; }

/* ==========================================================================
   Print — hide the app chrome, show only the active document.
   ========================================================================== */
@media print {
  /* Hide all UI chrome */
  .app-tabs, .toolbar, .statusbar,
  .impress-sidebar, .impress-inspector, .impress-sidehead,
  .calc-colheader, .calc-rowhead, .calc-corner,
  .pdf-pagebar, .calc-chart-head, .calc-chart-resize,
  .md-toolbar, .md-editor-pane, .md-divider,
  #toasts, #dialogRoot, .te-find, .te-tabs { display: none !important; }

  /* Reset the flex layout so the document can flow naturally onto pages */
  html, body { height: auto !important; overflow: visible !important; background: #fff !important; }
  #app, .workspace { display: block !important; height: auto !important; overflow: visible !important; }
  .tool-panel { display: none !important; }
  .tool-panel.active { display: block !important; }

  /* Writer: clean white page, no shadow */
  .writer-surface { overflow: visible !important; background: #fff !important; padding: 0 !important; }
  .writer-doc {
    box-shadow: none !important; margin: 0 auto !important; max-width: none !important;
    min-height: 0 !important; padding: 0.5in !important; color: #000 !important; background: #fff !important;
  }

  /* Calc: show the grid as a plain table, hide empty area beyond data */
  .calc-wrap, .calc-content { overflow: visible !important; height: auto !important; display: block !important; }
  .calc-content { position: static !important; background: #fff !important; }
  .calc-body { position: static !important; display: table !important; width: auto !important; grid-template-columns: none !important; }
  .calc-rowhead { display: none !important; }
  .calc-cell { display: table-cell !important; height: auto !important; min-height: 20px; padding: 3px 6px !important;
    border: 1px solid #999 !important; color: #000 !important; overflow: visible !important; }
  .calc-cell:empty { display: none !important; }
  .calc-chart-panel { page-break-inside: avoid; box-shadow: none !important; border: 1px solid #999 !important; }

  /* Impress: print all slides, one per page. The print container (#impPrint) is
     built on demand; each .imp-print-slide breaks to a new page. */
  .impress-wrap, .impress-stage, .impress-canvas { display: none !important; }
  #impPrint { display: block !important; }
  .imp-print-slide {
    width: 10in; height: 5.625in; page-break-after: always; position: relative;
    background: #fff; overflow: hidden; box-shadow: none !important; border: 0 !important;
  }
  .imp-print-slide * { color: #000 !important; }

  /* Markdown: print only the rendered preview, as a clean document. */
  .md-wrap, .md-split, .md-preview-pane { display: block !important; overflow: visible !important; height: auto !important; background: #fff !important; }
  .md-preview {
    max-width: none !important; margin: 0 !important; padding: 0.5in !important;
    color: #000 !important; background: #fff !important; box-shadow: none !important;
  }
  .md-preview pre, .md-preview code { color: #000 !important; }
}

/* Tab drag-to-reorder states (shared Tabs strip) */
.te-tab.dragging { opacity: .45; }
.te-tab.drag-over { border-color: var(--accent); box-shadow: inset 0 2px 0 var(--accent); }
