/* Layout: app bar on top, the drawing on a work surface, page tabs at the bottom (like Visio). */
:root {
  --bar: #ffffff; --bar-line: #dfe4ea; --fg: #1d2733; --muted: #5d6b7a; --faint: #8a97a5;
  --surface: #e8ecf0; --hover: #eef2f6; --press: #e1e7ee; --field: #f3f5f8;
  --accent: #1f6fb2; --accent-hover: #195d96; --accent-fg: #ffffff; --accent-soft: #e2eefa;
  --menu: #ffffff; --shadow: 0 8px 28px rgba(20, 35, 55, .16), 0 1px 3px rgba(20, 35, 55, .12);
  --paper-shadow: 0 1px 2px rgba(20, 35, 55, .18), 0 6px 24px rgba(20, 35, 55, .10);
  --mark: rgba(255, 196, 0, .32); --mark-line: rgba(214, 150, 0, .55); --mark-current: #e8590c;
  --danger: #b42318;
  --ui: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bar: #1b2129; --bar-line: #2c3540; --fg: #e4e9ef; --muted: #a3afbc; --faint: #7d8a98;
    --surface: #11161c; --hover: #262e38; --press: #2e3844; --field: #232b35;
    --accent: #4a9ae0; --accent-hover: #64aae6; --accent-fg: #0b1724; --accent-soft: #1d3247;
    --menu: #1f262f; --shadow: 0 10px 30px rgba(0, 0, 0, .5), 0 1px 3px rgba(0, 0, 0, .4);
    --paper-shadow: 0 1px 3px rgba(0, 0, 0, .5), 0 8px 30px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font: 14px/1.4 var(--ui); color: var(--fg); background: var(--surface);
  display: grid; grid-template-rows: auto 1fr auto; overflow: hidden;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.ico { width: 18px; height: 18px; flex: none; }
[hidden] { display: none !important; }
html:not(.web) .web-only { display: none !important; }

/* ---- app bar ---- */
.bar {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; min-height: 52px;
  background: var(--bar); border-bottom: 1px solid var(--bar-line); position: relative; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 600; white-space: nowrap; }
.logo { width: 26px; height: 26px; }
.file {
  min-width: 0; max-width: 34vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: var(--muted); padding-left: 10px; margin-left: 2px; border-left: 1px solid var(--bar-line);
}
.file:empty { display: none; }
.grow { flex: 1; }
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 34px; padding: 0 12px;
  border: 1px solid var(--bar-line); border-radius: 8px; background: var(--bar); white-space: nowrap;
}
.btn:hover { background: var(--hover); }
.btn:active { background: var(--press); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.large { height: 42px; padding: 0 18px; font-size: 15px; }
.btn .caret { width: 14px; height: 14px; margin-right: -4px; opacity: .7; }
.icon-btn {
  display: inline-grid; place-items: center; width: 30px; height: 30px; border: 0; border-radius: 6px;
  background: transparent; color: var(--muted);
}
.icon-btn:hover { background: var(--hover); color: var(--fg); }
.icon-btn:disabled { opacity: .35; pointer-events: none; }

.search {
  display: flex; align-items: center; gap: 2px; height: 34px; padding: 0 2px 0 10px;
  background: var(--field); border: 1px solid transparent; border-radius: 8px; color: var(--muted);
}
.search:focus-within { border-color: var(--accent); background: var(--bar); }
.search input { width: 150px; border: 0; background: transparent; outline: none; padding: 0 6px; color: var(--fg); }
.search input::-webkit-search-cancel-button { display: none; }
.search .count { min-width: 44px; text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; color: var(--faint); }
.search .count.none { color: var(--danger); }

.zoom { display: flex; align-items: center; gap: 2px; padding: 2px; border-radius: 8px; background: var(--field); }
.zoom-value {
  min-width: 54px; height: 30px; border: 0; border-radius: 6px; background: transparent;
  font-variant-numeric: tabular-nums; color: var(--fg);
}
.zoom-value:hover { background: var(--hover); }

.menu { position: relative; }
.menu-list {
  position: absolute; right: 0; top: calc(100% + 6px); width: 300px; padding: 6px;
  background: var(--menu); border: 1px solid var(--bar-line); border-radius: 10px; box-shadow: var(--shadow);
  display: grid; gap: 2px;
}
.menu-list button, .menu-list a {
  display: grid; gap: 1px; text-align: left; padding: 8px 10px; border: 0; border-radius: 7px;
  background: transparent; color: var(--fg); text-decoration: none;
}
.menu-list button:hover, .menu-list a:hover, .menu-list :focus-visible { background: var(--hover); outline: none; }
.menu-list b { font-weight: 600; }
.menu-list small { color: var(--muted); font-size: 12px; }
.menu-list hr { border: 0; border-top: 1px solid var(--bar-line); margin: 4px 2px; }
.menu-list .promo b { color: var(--accent); }

/* ---- drawing ---- */
#stage { position: relative; overflow: hidden; cursor: grab; touch-action: none; outline: none; }
#stage.panning { cursor: grabbing; }
#paper {
  position: absolute; left: 0; top: 0; transform-origin: 0 0; background: #fff;
  box-shadow: var(--paper-shadow); border-radius: 2px;
}
#graph { position: relative; overflow: hidden; }
#graph svg { display: block; }
#marks { position: absolute; inset: 0; pointer-events: none; }
.mark { position: absolute; background: var(--mark); outline: 1px solid var(--mark-line); border-radius: 3px; }
.mark.current { background: transparent; outline: 3px solid var(--mark-current); outline-offset: 2px; }

/* ---- page tabs ---- */
.tabs {
  display: flex; align-items: stretch; gap: 2px; padding: 0 8px; min-height: 36px; overflow-x: auto;
  background: var(--bar); border-top: 1px solid var(--bar-line); scrollbar-width: thin;
}
.tab {
  position: relative; display: inline-flex; align-items: center; gap: 6px; max-width: 260px; padding: 0 14px;
  border: 0; background: transparent; color: var(--muted); white-space: nowrap; flex: none;
}
.tab .name { overflow: hidden; text-overflow: ellipsis; }
.tab:hover { background: var(--hover); color: var(--fg); }
.tab[aria-selected="true"] { color: var(--fg); font-weight: 600; }
.tab[aria-selected="true"]::before { content: ""; position: absolute; left: 8px; right: 8px; top: -1px; height: 3px; background: var(--accent); border-radius: 0 0 3px 3px; }
.tab .hits { flex: none; min-width: 18px; text-align: center; font-size: 11px; font-weight: 600; padding: 0 6px; border-radius: 9px; background: var(--mark); color: var(--fg); }

/* ---- start screen ---- */
#start { display: none; }
body.is-empty #start { display: grid; place-items: center; grid-row: 2 / 4; padding: 24px; overflow: auto; }
body.is-empty #stage, body.is-empty .doc-only { display: none; }
.drop {
  width: min(560px, 100%); padding: 40px 36px 28px; text-align: center; display: grid; justify-items: center; gap: 12px;
  background: var(--bar); border: 2px dashed var(--bar-line); border-radius: 16px;
}
.drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop h1 { margin: 6px 0 0; font-size: 24px; font-weight: 650; text-wrap: balance; }
.drop p { margin: 0; color: var(--muted); }
.logo.big { width: 52px; height: 52px; }
.start-actions { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.url-form { width: 100%; display: grid; gap: 6px; margin-top: 14px; padding-top: 18px; border-top: 1px solid var(--bar-line); text-align: left; }
.url-form label { font-size: 13px; color: var(--muted); }
.url-row { display: flex; gap: 8px; }
.url-row input { flex: 1; min-width: 0; height: 34px; padding: 0 10px; border: 1px solid var(--bar-line); border-radius: 8px; background: var(--field); }
.url-row input:focus { outline: none; border-color: var(--accent); background: var(--bar); }
.privacy { display: inline-flex; align-items: center; gap: 6px; margin-top: 10px !important; font-size: 13px; }
.privacy .ico { width: 16px; height: 16px; color: var(--accent); }
.formats { font-size: 12px; color: var(--faint) !important; }

/* ---- overlays ---- */
#busy, #notice, #dragCover { position: fixed; inset: 0; z-index: 20; display: grid; place-items: center; }
#busy { background: color-mix(in srgb, var(--surface) 70%, transparent); align-content: center; gap: 14px; }
#busy p { margin: 0; color: var(--muted); }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--bar-line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
#notice { background: rgba(10, 18, 28, .35); }
.notice-card { width: min(460px, calc(100% - 32px)); padding: 22px 24px; background: var(--menu); border-radius: 14px; box-shadow: var(--shadow); display: grid; gap: 10px; }
.notice-card h2 { margin: 0; font-size: 18px; }
.notice-card p { margin: 0; color: var(--muted); overflow-wrap: anywhere; }
.notice-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }
#dragCover { background: color-mix(in srgb, var(--accent) 14%, transparent); border: 3px dashed var(--accent); pointer-events: none; }
#dragCover p { padding: 10px 18px; border-radius: 10px; background: var(--accent); color: var(--accent-fg); font-weight: 600; }
#toast {
  position: fixed; left: 50%; bottom: 56px; transform: translateX(-50%); z-index: 30; max-width: min(560px, calc(100% - 32px));
  padding: 10px 16px; border-radius: 10px; background: var(--fg); color: var(--bar); box-shadow: var(--shadow);
}
#rate {
  position: fixed; right: 16px; bottom: 52px; z-index: 25; display: flex; align-items: center; gap: 10px; max-width: calc(100% - 32px);
  padding: 10px 12px 10px 16px; background: var(--menu); border: 1px solid var(--bar-line); border-radius: 12px; box-shadow: var(--shadow);
}
#rate span { color: var(--muted); }
#rate a { text-decoration: none; }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }

/* narrow windows: keep the essentials */
@media (max-width: 1100px) { .brand span { display: none; } .search input { width: 110px; } }
@media (max-width: 860px) { .file, .btn span:not(.keep) { display: none; } .search .count { display: none; } }
@media (max-width: 640px) {
  .bar { gap: 4px; padding: 8px; }
  .search, .zoom-value, .btn .caret { display: none; }
  .btn { padding: 0 9px; }
  .menu-list { position: fixed; left: 8px; right: 8px; top: 56px; width: auto; }
  .drop { padding: 28px 18px 20px; }
}

/* ---- print: only the pages ---- */
#print { display: none; }
@media print {
  @page { margin: 10mm; }
  @page landscape { size: landscape; }
  @page portrait { size: portrait; }
  body { display: block; background: #fff; height: auto; overflow: visible; }
  body > :not(#print) { display: none !important; }
  #print { display: block; }
  .print-page { break-after: page; display: grid; place-items: center; height: 100vh; }
  .print-page:last-child { break-after: auto; }
  .print-page.landscape { page: landscape; }
  .print-page.portrait { page: portrait; }
  .print-page img { max-width: 100%; max-height: 100%; }
}
