:root {
  --bg: #f6f7f9; --panel: #ffffff; --fg: #1d2230; --muted: #6b7280;
  --line: #d9dde5; --accent: #2f6fd6; --accent-fg: #ffffff;
  --sel: rgba(47, 111, 214, 0.22); --hover: #eef2fb; --danger: #c0392b; --ok: #2e7d32;
  --mono: "DejaVu Sans Mono", "Menlo", "Consolas", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", "Ubuntu", "DejaVu Sans", sans-serif;
  --map-w: 36%; --side-w: 380px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #15171c; --panel: #1d2027; --fg: #e6e8ee; --muted: #9aa1ad;
    --line: #333844; --accent: #5b8ef0; --hover: #262b36; --sel: rgba(91, 142, 240, 0.30);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #15171c; --panel: #1d2027; --fg: #e6e8ee; --muted: #9aa1ad;
  --line: #333844; --accent: #5b8ef0; --hover: #262b36; --sel: rgba(91, 142, 240, 0.30);
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { height: 100%; margin: 0; }
body { background: var(--bg); color: var(--fg); font: 14px/1.4 var(--sans);
       display: flex; flex-direction: column; overflow: hidden; }
button, .button, select, input, textarea { font: inherit; color: inherit; }
button, .button { background: var(--panel); border: 1px solid var(--line); border-radius: 6px;
       padding: 4px 10px; cursor: pointer; white-space: nowrap; display: inline-block; }
button:hover, .button:hover { background: var(--hover); }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); }
button:disabled { opacity: .45; cursor: default; }
input[type=text], input[type=number], input[type=search], select, textarea {
  background: var(--panel); border: 1px solid var(--line); border-radius: 5px; padding: 3px 6px; }
textarea { font-family: var(--mono); width: 100%; }
kbd { font: 11px var(--mono); color: var(--muted); margin-left: 8px; }
hr { border: none; border-top: 1px solid var(--line); margin: 4px 0; }

/* top bar */
#topbar { display: flex; align-items: center; gap: 10px; padding: 6px 12px; background: var(--panel);
          border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.brand { display: flex; align-items: center; gap: 6px; font-weight: 700; color: var(--fg); text-decoration: none; }
.brand img { width: 22px; height: 22px; }
.badge { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--hover); color: var(--muted); }
.docname { font-weight: 600; cursor: pointer; max-width: 30ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.docname.dirty::after { content: " •"; color: var(--danger); }
.menus { display: flex; gap: 6px; align-items: center; margin-left: auto; flex-wrap: wrap; }
details.menu { position: relative; }
details.menu > summary { list-style: none; cursor: pointer; padding: 4px 10px; border-radius: 6px; border: 1px solid transparent; }
details.menu > summary::-webkit-details-marker { display: none; }
details.menu[open] > summary, details.menu > summary:hover { background: var(--hover); }
details.menu > div { position: absolute; right: 0; top: 110%; z-index: 20; background: var(--panel);
  border: 1px solid var(--line); border-radius: 8px; padding: 6px; min-width: 260px;
  box-shadow: 0 8px 24px rgba(0,0,0,.15); display: flex; flex-direction: column; gap: 2px; }
details.menu > div button { border: none; text-align: left; display: flex; justify-content: space-between; }
details.menu > div label { padding: 4px 10px; display: flex; gap: 6px; align-items: center; }

/* library */
#library-view { flex: 1; overflow: auto; }
.library { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
.library-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.library-head h1 { font-size: 22px; margin: 0; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; }
.hint { color: var(--muted); font-size: 13px; }
.licence { color: var(--muted); font-size: 12px; margin-top: 30px; border-top: 1px solid var(--line); padding-top: 8px; }
.library.drop { outline: 2px dashed var(--accent); outline-offset: 8px; }

/* tables */
.table { width: 100%; border-collapse: collapse; background: var(--panel); }
.table th, .table td { padding: 5px 8px; border-bottom: 1px solid var(--line); text-align: left; white-space: nowrap; }
.table th { position: sticky; top: 0; background: var(--panel); font-weight: 600; font-size: 12px; color: var(--muted); cursor: default; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table tbody tr:hover { background: var(--hover); cursor: pointer; }
.table tbody tr.selected { background: var(--sel); }
.table.compact th, .table.compact td { padding: 3px 6px; font-size: 12.5px; }
.table .mono { font-family: var(--mono); font-size: 12px; }
.swatch { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; vertical-align: -1px; }
.tablewrap { flex: 1; overflow: auto; border: 1px solid var(--line); border-radius: 6px; min-height: 120px; }

/* editor */
#editor-view { flex: 1; display: flex; min-height: 0; }
.pane { background: var(--panel); min-width: 0; min-height: 0; }
#map-pane { width: var(--map-w); min-width: 260px; display: flex; }
#map { width: 100%; height: 100%; user-select: none; }
#seq-pane { flex: 1; min-width: 300px; position: relative; }
#seqwrap { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; outline: none; }
#seqcanvas { position: absolute; left: 0; top: 0; outline: none; cursor: text; }
#side { width: var(--side-w); min-width: 280px; display: flex; flex-direction: column; border-left: 1px solid var(--line); }
.splitter { width: 5px; cursor: col-resize; background: var(--line); flex: none; }
.splitter:hover { background: var(--accent); }
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button { border: none; border-radius: 0; flex: 1; padding: 8px; border-bottom: 2px solid transparent; }
.tabs button.active { border-bottom-color: var(--accent); font-weight: 600; }
.tab { flex: 1; display: flex; flex-direction: column; gap: 6px; padding: 8px; min-height: 0; }
.row { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.row > button { flex: 1; }
.row label { display: flex; gap: 6px; align-items: center; flex: 1; }
.row label select { flex: 1; }

/* status */
#status { display: flex; justify-content: space-between; gap: 16px; padding: 3px 12px; font-size: 12.5px;
          background: var(--panel); border-top: 1px solid var(--line); color: var(--muted); }
#toast { position: fixed; bottom: 36px; left: 50%; transform: translateX(-50%); background: var(--fg); color: var(--bg);
         padding: 8px 14px; border-radius: 8px; z-index: 100; max-width: 80vw; }
#toast.error { background: var(--danger); color: #fff; }

/* dialogs */
dialog { border: 1px solid var(--line); border-radius: 10px; padding: 0; background: var(--panel); color: var(--fg);
         max-width: min(1100px, 96vw); max-height: 94vh; box-shadow: 0 16px 48px rgba(0,0,0,.25); }
dialog::backdrop { background: rgba(0,0,0,.35); }
dialog > form { display: flex; flex-direction: column; max-height: 94vh; }
.dlg-head { padding: 12px 16px; border-bottom: 1px solid var(--line); font-weight: 700; }
.dlg-body { padding: 12px 16px; overflow: auto; display: flex; flex-direction: column; gap: 10px; }
.dlg-foot { padding: 10px 16px; border-top: 1px solid var(--line); display: flex; gap: 8px; justify-content: flex-end; flex-wrap: wrap; }
.form { display: grid; grid-template-columns: max-content 1fr; gap: 6px 10px; align-items: center; }
.form .full { grid-column: 1 / -1; }
fieldset { border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 0; }
legend { color: var(--muted); font-size: 12px; padding: 0 4px; }
.grid3 { display: grid; grid-template-columns: max-content repeat(3, 90px); gap: 4px 8px; align-items: center; }
.cols { display: flex; gap: 12px; flex-wrap: wrap; }
.cols > * { flex: 1; min-width: 260px; }
.details { border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; min-height: 80px; }
.details h4 { margin: 4px 0; }
.warn { color: var(--danger); }
.good { color: var(--ok); }
.oligo { font-family: var(--mono); word-break: break-all; }
.oligo .tail { color: var(--danger); text-transform: lowercase; }
.enzlist { max-height: 380px; overflow: auto; border: 1px solid var(--line); border-radius: 6px; padding: 4px; min-width: 200px; }
.enzlist label { display: block; padding: 1px 4px; white-space: nowrap; }
.gel { background: #1b1b22; border-radius: 6px; }
pre.out { font-family: var(--mono); white-space: pre-wrap; word-break: break-all; margin: 0; font-size: 12.5px; }

@media (max-width: 900px) {
  #editor-view { flex-direction: column; overflow: auto; }
  #map-pane { width: auto; height: 380px; }
  #seq-pane { min-height: 420px; }
  #side { width: auto; min-height: 420px; border-left: none; }
  .splitter { display: none; }
}

/* login page */
.login-body { overflow: auto; }
.login-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 32px 16px; }
.login-card { width: min(420px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
              padding: 24px 28px; box-shadow: 0 10px 30px rgba(0,0,0,.08); }
.login-brand { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 18px; margin-bottom: 14px; }
.login-brand img { width: 30px; height: 30px; }
.login-form { display: flex; flex-direction: column; gap: 10px; }
.login-form h1 { font-size: 20px; margin: 4px 0; }
.login-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.login-form input, .login-form textarea { font-size: 15px; padding: 7px 9px; color: var(--fg); font-family: var(--sans); }
.login-form button.primary { padding: 8px; font-size: 15px; margin-top: 4px; }
.form-msg { color: var(--danger); min-height: 1.2em; margin: 0; font-size: 13px; }
.switch { text-align: center; font-size: 13px; margin: 4px 0 0; }
.switch a, .login-form a { color: var(--accent); }
.login-licence { max-width: 420px; text-align: center; border: none; }

/* user menu and admin page */
.usermenu > summary { display: flex; align-items: center; gap: 6px; }
.count { background: var(--danger); color: #fff; border-radius: 10px; font-size: 11px; padding: 0 6px; font-weight: 700; }
#admin-view { flex: 1; overflow: auto; }
.admin { max-width: 1100px; margin: 24px auto; padding: 0 16px; display: flex; flex-direction: column; gap: 18px; }
.admin h1 { font-size: 22px; margin: 0; }
.admin h2 { font-size: 16px; margin: 8px 0; }
.admin .request { border: 1px solid var(--line); border-radius: 10px; background: var(--panel); padding: 10px 14px;
                  display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.admin .request .msg { white-space: pre-wrap; color: var(--muted); margin-top: 4px; }
.admin .request .actions { display: flex; gap: 6px; align-items: flex-start; }
.pill { font-size: 11px; padding: 1px 7px; border-radius: 10px; background: var(--hover); }
.pill.admin { background: var(--accent); color: var(--accent-fg); }
.pill.disabled { background: var(--danger); color: #fff; }
#editor-menu[hidden] + #usermenu { margin-left: auto; }

/* account button and page */
.usermenu > summary { border: 1px solid var(--line); border-radius: 18px; padding: 3px 10px 3px 4px; background: var(--panel); }
.avatar { width: 26px; height: 26px; border-radius: 50%; background: var(--accent); color: var(--accent-fg);
          display: inline-flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; }
.caret { color: var(--muted); font-size: 11px; }
.usercard { display: flex; flex-direction: column; padding: 6px 10px 4px; }
#account-view { flex: 1; overflow: auto; }
.account .form { grid-template-columns: max-content minmax(220px, 1fr); }
.account fieldset { background: var(--panel); padding: 14px 16px; }
