/* nanoyay web interface.
 *
 * One screen, no modal windows: the form, all three views and the audit are
 * visible at the same time, which is the whole reason this exists next to the
 * tkinter window. The panes are white because they are printed and pasted
 * into notes; everything around them is grey so the drawings carry the eye.
 */

:root {
  --ink: #1c2024;
  --dim: #5b646e;
  --line: #ccd2d9;
  --chrome: #eceff2;
  --paper: #ffffff;
  --accent: #1f6feb;
  --bad: #a02c2a;
  --good: #10646f;
  --pane-gap: 8px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  font: 13px/1.45 "Segoe UI", system-ui, sans-serif;
  color: var(--ink);
  background: var(--chrome);
}

body {
  display: grid;
  grid-template-rows: auto 1fr auto;
}

/* ---- chrome ---------------------------------------------------------- */

header {
  display: flex;
  align-items: baseline;
  gap: 16px;
  padding: 8px 14px;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
}

header h1 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: .04em;
}

.status { color: var(--dim); }
.status.busy { color: var(--accent); }
.status.done { color: var(--good); }
.status.bad  { color: var(--bad); font-weight: 600; }

footer {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 14px;
  background: var(--paper);
  border-top: 1px solid var(--line);
}

.estimate { color: var(--dim); }
.error { color: var(--bad); font-weight: 600; }

/* ---- layout ---------------------------------------------------------- */

main {
  display: grid;
  grid-template-columns: 30px 372px 1fr;
  min-height: 0;
}

#sidebar {
  overflow-y: auto;
  padding: 10px 12px 20px;
  background: var(--paper);
  border-right: 1px solid var(--line);
}

#sidebar section { margin-bottom: 18px; }

#sidebar h2 {
  margin: 0 0 2px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--dim);
  /* Stays at the top while its section scrolls under it, so the panel
     always says which group the fields belong to. */
  position: sticky;
  top: -10px;
  z-index: 1;
  padding: 6px 0 4px;
  background: var(--paper);
}

/* ---- section rail ------------------------------------------------------ */

#rail {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 8px 2px;
  background: var(--chrome);
  border-right: 1px solid var(--line);
  overflow: hidden;
}

/* One tab of settings shows at a time. */
#sidebar .tab[hidden] { display: none; }

table.facts { width: 100%; border-collapse: collapse; margin: 6px 0 10px;
              font-variant-numeric: tabular-nums; }
table.facts td { padding: 3px 0; border-bottom: 1px solid var(--chrome); }
table.facts td.num { text-align: right; font-weight: 600; }
table.facts tr.warn td { color: var(--bad); }

#rail a {
  /* Vertical text read bottom to top, as on a book's spine. */
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 12px 0;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  text-decoration: none;
  color: var(--dim);
  border-radius: 3px;
  white-space: nowrap;
  cursor: pointer;
}

#rail a:hover { color: var(--ink); background: var(--paper); }

/* Settings of the interface itself sit apart, at the bottom of the rail. */
#rail a.settings { margin-top: auto; }

/* "#rail a" outranks "body.public .server-only", so the hidden sections'
   links need saying again. */
body.public #rail a.server-only { display: none; }

#rail a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* The open tab: dark, on white, with an accent bar on the edge facing the
   settings (the left edge in the label's own turned frame). */
#rail a.active {
  color: var(--ink);
  background: var(--paper);
  box-shadow: inset 0 0 0 1px var(--line), inset 3px 0 0 var(--accent);
}

.hint { margin: 0 0 8px; font-size: 11px; color: var(--dim); }

/* Four panes, always all four. A viewport you have to switch to is a
 * viewport you stop looking at. */
#viewports {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-template-rows: 1fr 1fr;
  gap: var(--pane-gap);
  padding: var(--pane-gap);
  min-height: 0;
}

.pane {
  display: flex;
  flex-direction: column;
  margin: 0;
  min-height: 0;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
}

.pane figcaption {
  flex: 0 0 auto;
  padding: 4px 8px;
  font-size: 11px;
  font-weight: 600;
  color: var(--dim);
  background: var(--chrome);
  border-bottom: 1px solid var(--line);
}

.pane figcaption .axes { font-weight: 400; opacity: .75; }
.pane figcaption .note { float: right; font-weight: 400; opacity: .75; }
/* The side pane's view switch: x-z or 3D, the one on show filled in. */
.pane figcaption .modes { display: inline-flex; margin-left: 6px; vertical-align: middle; }
.pane figcaption .modes button {
  padding: 0 8px;
  font-size: 11px;
  font-weight: 600;
  line-height: 16px;
  color: var(--dim);
  background: var(--paper);
}
.pane figcaption .modes button + button { margin-left: -1px; }
.pane figcaption .modes button.active,
.pane figcaption .modes button.active:hover { color: #fff; background: var(--accent); border-color: var(--accent); }

.pane canvas { flex: 1 1 auto; width: 100%; min-height: 0; display: block; }

/* Enlarge (in the caption, at its right end) and save (over the drawing,
 * bottom right). */
.pane { position: relative; }
.pane svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.6; }
.pane figcaption .pane-max {
  float: right;
  margin: -2px 0 -2px 8px;
  padding: 1px 3px;
  line-height: 0;
  color: var(--dim);
  background: none;
  border-color: transparent;
}
.pane figcaption .pane-max:hover { color: var(--ink); background: var(--paper); border-color: var(--line); }
.pane-max .restore, .pane.max .pane-max .enlarge { display: none; }
.pane.max .pane-max .restore { display: inline; }
#viewports.maximized > .pane:not(.max) { display: none; }
#viewports.maximized > .pane.max { grid-column: 1 / -1; grid-row: 1 / -1; }
.pane-save {
  display: none;
  position: absolute;
  right: 6px;
  bottom: 6px;
  padding: 5px;
  line-height: 0;
  color: var(--dim);
  background: rgba(255, 255, 255, .9);
}
#viewports.built .pane-save { display: block; }
.pane-save:hover { color: var(--accent); border-color: var(--accent); }
.save-menu {
  position: absolute;
  right: 6px;
  bottom: 40px;
  z-index: 2;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px;
  font-size: 12px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 3px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, .12);
}
.save-menu[hidden] { display: none; }
.save-menu label { cursor: pointer; white-space: nowrap; }
.save-scale { display: flex; gap: 8px; align-items: center; }
.save-scale > span { color: var(--dim); }
.save-size { margin: 0; color: var(--dim); font-variant-numeric: tabular-nums; }

.pane-text { overflow: hidden; }
.audit { flex: 1 1 auto; overflow-y: auto; padding: 8px 10px; }

/* ---- form ------------------------------------------------------------ */

.field {
  display: grid;
  grid-template-columns: 1fr 92px;
  align-items: center;
  gap: 6px;
  margin-bottom: 4px;
}

.field label { font-size: 12px; }

input[type="text"], .field select {
  width: 100%;
  padding: 3px 6px;
  font: inherit;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 2px;
}

input:focus, select:focus, button:focus {
  outline: 2px solid var(--accent);
  outline-offset: -1px;
}

input.bad { border-color: var(--bad); background: #fdf2f2; }

table#shells { width: 100%; border-collapse: collapse; font-size: 12px;
               table-layout: fixed; }
/* Fixed column widths: the structure names (zincblende, rocksalt) need room,
   c is used by hcp only and can be narrow. */
table#shells col.n   { width: 18px; }
table#shells col.el  { width: 19%; }
table#shells col.lat { width: 27%; }
table#shells col.a   { width: 17%; }
table#shells col.c   { width: 15%; }
table#shells col.th  { width: 18%; }
table#shells th { font-weight: 600; color: var(--dim); text-align: left; padding: 0 2px 2px; }
table#shells td { padding: 1px; }
table#shells td:first-child { color: var(--dim); text-align: right; padding-right: 4px; }
table#shells input, table#shells select {
  width: 100%;
  padding: 2px 4px;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--paper);
}

.swatch {
  display: inline-block;
  width: 8px; height: 8px;
  margin-right: 3px;
  border-radius: 50%;
  vertical-align: baseline;
}

.formats { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-bottom: 8px; }
.formats label { font-size: 12px; cursor: pointer; user-select: none; }

.stem {
  margin-bottom: 6px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 10px;
  color: var(--dim);
  word-break: break-all;
}

button {
  padding: 4px 12px;
  font: inherit;
  color: var(--ink);
  background: var(--chrome);
  border: 1px solid var(--line);
  border-radius: 2px;
  cursor: pointer;
}

button:hover:not(:disabled) { background: #e2e6ea; }
button:disabled { opacity: .5; cursor: default; }

button.primary {
  font-weight: 600;
  color: #fff;
  background: var(--accent);
  border-color: var(--accent);
}

button.primary:hover:not(:disabled) { background: #1a5fd0; }

.written {
  margin-top: 6px;
  font-family: ui-monospace, Consolas, monospace;
  font-size: 10px;
  color: var(--good);
  word-break: break-all;
}

/* ---- lists ----------------------------------------------------------- */

.recent { margin: 0; padding: 0; list-style: none; }
.recent li { padding: 2px 0; border-bottom: 1px solid var(--chrome); }
.recent li.empty { color: var(--dim); border: none; }
.recent button {
  width: 100%;
  padding: 3px 6px;
  font-size: 11px;
  text-align: left;
  background: none;
  border: none;
  border-radius: 2px;
  cursor: pointer;
}
.recent button:hover { background: var(--chrome); }
.recent .when { float: right; color: var(--dim); }

.audit p { margin: 0 0 8px; }
.audit .empty { color: var(--dim); }
.audit .check { display: flex; gap: 6px; align-items: flex-start; }
.audit .flag { flex: 0 0 auto; font-weight: 700; font-family: ui-monospace, Consolas, monospace; }
.audit .ok .flag { color: var(--good); }
.audit .no .flag { color: var(--bad); }
.audit .no { color: var(--bad); font-weight: 600; }
.audit h3 {
  margin: 12px 0 4px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--dim);
}
.audit table { width: 100%; border-collapse: collapse; font-size: 11px; }
.audit td { padding: 1px 4px 1px 0; }
.audit td.num { text-align: right; font-variant-numeric: tabular-nums; }

/* The side pane turns into a 3D view while dragged. */
canvas.rotatable, canvas.movable { cursor: grab; touch-action: none; }
canvas.rotatable.dragging, canvas.movable.dragging { cursor: grabbing; }
#shells input:disabled { background: #f1f3f5; }
/* A shell carved from a file: its button and what the file holds, in the
 * a and c columns. */
#shells .bulk { display: flex; align-items: center; gap: 6px; min-width: 0; }
#shells .bulk[hidden] { display: none; }
label.switch { display: flex; gap: 6px; align-items: flex-start; margin-top: 6px;
               font-size: 12px; cursor: pointer; }
label.switch input { margin-top: 2px; }
#shells .bulk button { padding: 2px 8px; font-size: 12px; width: 100%;
                       overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.buttons { display: flex; gap: 6px; }
.buttons button { flex: 1; }
.presets { margin: 0 0 8px; }
.presets button { font-family: ui-monospace, Consolas, monospace; }

/* A public instance does not write to the server: the page hides the parts
 * that would only be refused. */
body.public .server-only { display: none; }

.hint code { font-family: ui-monospace, Consolas, monospace; font-size: 10.5px; }

#orient-view { width: 100%; height: 300px; display: block;
               background: #fff; border: 1px solid var(--chrome); border-radius: 4px; }
