/* Viewer chrome and account pages. The entry itself is styled by entry.css. */
:root {
  --bg: #fdfcfa;           /* entry.css --bg */
  --side-bg: #f2f0ec;
  --bar-bg: #f7f5f2;
  --fg: #1d1b19;
  --muted: #6b645c;
  --rule: #e2ddd5;
  --hover: rgba(60, 40, 20, 0.07);
  --selected: rgba(122, 46, 31, 0.13);
  --accent: #7a2e1f;
  --accent-fg: #ffffff;
  --field-bg: #ffffff;
  --field-border: #d6d0c6;
  --error: #c01c28;
  --ok: #26803a;
  --shadow: 0 6px 24px rgba(30, 20, 10, 0.18), 0 0 0 1px rgba(30, 20, 10, 0.08);
  --row-h: 36px;
  --radius: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1e1e1e;
    --side-bg: #262422;
    --bar-bg: #2b2826;
    --fg: #e8e4de;
    --muted: #a39b91;
    --rule: #3a3632;
    --hover: rgba(255, 245, 230, 0.07);
    --selected: rgba(227, 154, 131, 0.18);
    --accent: #e39a83;
    --accent-fg: #1d1b19;
    --field-bg: #1b1a19;
    --field-border: #48433e;
    --error: #ff7b7b;
    --ok: #7bd88f;
    --shadow: 0 6px 24px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.08);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1e1e1e;
  --side-bg: #262422;
  --bar-bg: #2b2826;
  --fg: #e8e4de;
  --muted: #a39b91;
  --rule: #3a3632;
  --hover: rgba(255, 245, 230, 0.07);
  --selected: rgba(227, 154, 131, 0.18);
  --accent: #e39a83;
  --accent-fg: #1d1b19;
  --field-bg: #1b1a19;
  --field-border: #48433e;
  --error: #ff7b7b;
  --ok: #7bd88f;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(255, 255, 255, 0.08);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--fg);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Cantarell, sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button, input, select { font: inherit; color: inherit; }
a { color: var(--accent); }

.icon {
  width: 18px; height: 18px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round;
}
.icon.big { width: 56px; height: 56px; stroke-width: 1.2; opacity: 0.45; }

/* --- buttons and fields --- */
.icon-btn, .flat-btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 34px; height: 34px; padding: 0 8px;
  border: 0; border-radius: 6px; background: transparent; cursor: pointer;
}
.icon-btn:hover:not(:disabled), .flat-btn:hover { background: var(--hover); }
.icon-btn:disabled { opacity: 0.35; cursor: default; }
.icon-btn[aria-pressed="true"] { color: var(--accent); }
.icon-btn.small { min-width: 28px; height: 28px; padding: 0 5px; }
.linked { display: inline-flex; }

button.primary, button.pill, .page button, a.button {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 36px; padding: 0 16px;
  border: 1px solid var(--field-border); border-radius: 6px;
  background: var(--field-bg); cursor: pointer; text-decoration: none; color: var(--fg);
}
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 600; }
button.pill { border-radius: 99px; padding: 0 28px; }
button.danger { color: var(--error); }
button:focus-visible, input:focus-visible, select:focus-visible, a:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--accent) 45%, transparent); outline-offset: 1px;
}

input[type="text"], input[type="search"], input[type="password"], select {
  height: 36px; padding: 0 10px; min-width: 0;
  border: 1px solid var(--field-border); border-radius: 6px; background: var(--field-bg);
}
input.invalid { border-color: var(--error); outline-color: var(--error); color: var(--error); }

.segmented {
  display: inline-flex; padding: 3px; gap: 2px;
  background: var(--hover); border-radius: 8px;
}
.segmented button {
  border: 0; background: transparent; border-radius: 6px;
  padding: 4px 16px; min-height: 28px; cursor: pointer;
}
.segmented button[aria-checked="true"] {
  background: var(--field-bg); font-weight: 600; box-shadow: 0 1px 2px rgba(0, 0, 0, 0.15);
}

/* --- layout --- */
.viewer { overflow: hidden; }
#app { display: flex; height: 100dvh; }
#sidebar {
  flex: 0 0 clamp(280px, 30vw, 400px);
  display: flex; flex-direction: column; min-height: 0;
  background: var(--side-bg); border-right: 1px solid var(--rule);
}
#content { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }

.bar {
  display: flex; align-items: center; gap: 4px;
  min-height: 46px; padding: 6px 6px; padding-top: max(6px, env(safe-area-inset-top));
  background: var(--bar-bg); border-bottom: 1px solid var(--rule);
}
#sidebar .bar { background: var(--side-bg); border-bottom: 0; }
.bar-title {
  flex: 1; margin: 0; text-align: center; font-size: 15px; font-weight: 700;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.entry-title { display: flex; flex-direction: column; line-height: 1.2; }
#entry-pos { font-weight: 400; font-size: 12px; color: var(--muted); }
#entry-pos:empty { display: none; }

.lookup { position: relative; margin: 0 12px 6px; }
.lookup .icon { position: absolute; left: 10px; top: 9px; color: var(--muted); pointer-events: none; }
.lookup input { width: 100%; padding-left: 34px; padding-right: 40px; }
.lookup .clear-btn { position: absolute; right: 0; top: 0; height: 100%; color: var(--muted); }
.lookup .clear-btn .icon { position: static; }
#lookup::-webkit-search-cancel-button { -webkit-appearance: none; display: none; }

.tabs { display: flex; gap: 2px; margin: 0 12px 6px; }
.tabs button {
  flex: 1; display: flex; justify-content: center; align-items: center;
  height: 32px; border: 0; border-radius: 6px; background: transparent; cursor: pointer; color: var(--muted);
}
.tabs button:hover { background: var(--hover); }
.tabs button[aria-selected="true"] { background: var(--selected); color: var(--accent); }

.panes { flex: 1; position: relative; min-height: 0; }
.pane { position: absolute; inset: 0; display: flex; flex-direction: column; }

.sort-bar {
  display: flex; justify-content: center; padding: 6px;
  padding-bottom: max(6px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--rule);
}

/* --- lists --- */
.vlist { flex: 1; position: relative; overflow-y: auto; overscroll-behavior: contain; }
.vlist.quotes { --row-h: 52px; }
.vlist-rows { position: absolute; top: 0; left: 0; right: 0; }
.vlist-spacer { width: 1px; }
.vlist .row { position: absolute; left: 6px; right: 6px; height: var(--row-h); }

.row {
  display: flex; align-items: center; gap: 8px;
  padding: 0 10px; border-radius: 6px; cursor: pointer;
}
.row:hover { background: var(--hover); }
.row.selected { background: var(--selected); }
.hw { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hw small { font-variant: small-caps; font-size: inherit; }
.year { flex: none; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.two-line { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.two-line .sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.list { flex: 1; margin: 0; padding: 0 6px; list-style: none; overflow-y: auto; }
.list .row { min-height: var(--row-h); }
.list .remove { opacity: 0.6; }
.wide-btn { margin: 6px 12px; border-top: 1px solid var(--rule); border-radius: 0; height: 40px; }

.count-bar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 2px 12px 4px 18px; font-size: 12px; font-weight: 700; color: var(--muted);
}

.status {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 4px; color: var(--muted);
}
.status p { margin: 0; font-weight: 600; }
.spinner {
  width: 32px; height: 32px; border-radius: 50%;
  border: 3px solid var(--rule); border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* --- entry --- */
.entry-area { flex: 1; position: relative; min-height: 0; }
#entry { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: var(--bg); }
.welcome img { width: 112px; height: 112px; margin-bottom: 12px; }
.welcome h2 { margin: 0; color: var(--fg); font-size: 26px; }

.find-bar {
  display: flex; align-items: center; gap: 6px; justify-content: center;
  padding: 6px; padding-bottom: max(6px, env(safe-area-inset-bottom));
  background: var(--bar-bg); border-top: 1px solid var(--rule);
}
.find-bar input { width: min(260px, 50vw); }
.find-count { min-width: 9ch; text-align: center; font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; }

/* --- menus and dialogs --- */
.menu {
  position: fixed; inset: auto; margin: 0; min-width: 230px; padding: 6px;
  border: 0; border-radius: 12px; background: var(--field-bg); color: var(--fg); box-shadow: var(--shadow);
}
.menu-section + .menu-section { border-top: 1px solid var(--rule); margin-top: 6px; padding-top: 6px; }
.menu-section.only-narrow + .menu-section { border-top: 0; margin-top: 0; padding-top: 0; }
.menu-section form { margin: 0; }
.menu-item {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 7px 10px; border: 0; border-radius: 6px; background: transparent;
  text-align: left; cursor: pointer; color: var(--fg); text-decoration: none; white-space: nowrap;
}
.menu-item:hover { background: var(--hover); }
.menu-item .check { width: 16px; height: 16px; visibility: hidden; }
.menu-item[aria-checked="true"] .check { visibility: visible; }
.menu-item kbd { margin-left: auto; padding-left: 16px; font: 12px system-ui, sans-serif; color: var(--muted); }
.zoom-row { display: flex; justify-content: space-between; }
.zoom-row .flat-btn { flex: 1; font-variant-numeric: tabular-nums; }

dialog {
  width: min(600px, calc(100vw - 32px)); max-height: calc(100dvh - 32px); padding: 0;
  border: 0; border-radius: 14px; background: var(--bg); color: var(--fg); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.35); }
dialog .bar { background: var(--bg); border-bottom: 0; padding-top: 6px; }
.dialog-body { padding: 4px 24px 24px; display: flex; flex-direction: column; }
.dialog-body h3 { margin: 18px 0 8px; font-size: 14px; }
.segmented.centered { align-self: center; }
.terms { display: flex; flex-direction: column; gap: 8px; }
.term { display: grid; grid-template-columns: 92px minmax(110px, 190px) 1fr; gap: 6px; }
.term .text, .term .language { width: 100%; }
.group {
  display: flex; flex-direction: column;
  border: 1px solid var(--rule); border-radius: 10px; background: var(--field-bg);
}
.group .row { justify-content: space-between; min-height: 50px; cursor: default; border-radius: 0; }
.group .row:hover { background: transparent; }
.group .row + .row { border-top: 1px solid var(--rule); }
.group .row input, .group .row select { width: 55%; }
.dialog-body button.pill { align-self: center; margin-top: 20px; }
.dialog-body .flash { margin: 12px 0 0; }

.about { padding: 28px 24px 22px; text-align: center; }
.about img { width: 96px; height: 96px; }
.about h2 { margin: 8px 0 0; }
.about p { margin: 8px 0; }
.about form { margin-top: 18px; }
.dim { color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 10;
  padding: 10px 18px; border-radius: 99px; background: #2e2a27; color: #f5f2ee; box-shadow: var(--shadow);
}

/* --- phones: one pane at a time --- */
.only-narrow { display: none; }
@media (max-width: 660px) {
  #sidebar { flex: 1; border-right: 0; }
  #content { display: none; }
  .show-content #sidebar { display: none; }
  .show-content #content { display: flex; }
  .icon-btn.only-narrow { display: inline-flex; }
  .menu-section.only-narrow { display: block; }
  .menu-section.only-narrow + .menu-section { border-top: 1px solid var(--rule); margin-top: 6px; padding-top: 6px; }
  .wide-only { display: none; }
  /* Find bar under the header, where the keyboard can't cover it. */
  #content > .bar { order: -2; }
  .find-bar { order: -1; border-top: 0; border-bottom: 1px solid var(--rule); padding-bottom: 6px; }
  .find-bar input { flex: 1; width: auto; }
  .term { grid-template-columns: 92px 1fr; }
  .term .text, .term .language { grid-column: 1 / -1; }
  .term .op-pad { display: none; }
  .term:first-child .field { grid-column: 1 / -1; }
  .menu-item kbd { display: none; }
  .dialog-body { padding: 4px 16px 20px; }
}

/* --- account pages --- */
.page { display: flex; justify-content: center; align-items: flex-start; min-height: 100dvh; padding: 8vh 16px 32px; }
.card {
  width: 100%; max-width: 380px; padding: 28px;
  background: var(--side-bg); border: 1px solid var(--rule); border-radius: 14px;
}
.wide .card { max-width: 720px; }
.card h1 { margin: 0 0 18px; font-size: 22px; text-align: center; }
.card h2 { margin: 28px 0 10px; font-size: 16px; }
.card .logo { display: block; width: 72px; height: 72px; margin: 0 auto 10px; }
.card form { display: flex; flex-direction: column; gap: 6px; }
.card label { font-size: 13px; font-weight: 600; margin-top: 8px; }
.card form > button { margin-top: 16px; }
.card form + form { margin-top: 10px; }
.card form + form button { width: 100%; }
.flash { margin: 8px 0 0; padding: 8px 12px; border-radius: 6px; font-size: 14px; }
.flash.error { color: var(--error); background: color-mix(in srgb, var(--error) 10%, transparent); }
.flash.ok { color: var(--ok); background: color-mix(in srgb, var(--ok) 10%, transparent); }
.message { text-align: center; color: var(--muted); word-break: break-all; }
.card a.button { display: flex; margin-top: 18px; }
.back-link { display: inline-flex; align-items: center; gap: 2px; margin: -8px 0 8px -6px; text-decoration: none; font-size: 14px; }

.users { width: 100%; border-collapse: collapse; }
.users td { padding: 8px 0; border-top: 1px solid var(--rule); vertical-align: middle; }
.users .name { font-weight: 600; }
.users .actions form { flex-direction: row; flex-wrap: wrap; justify-content: flex-end; gap: 6px; }
.users button { min-height: 30px; padding: 0 10px; font-size: 13px; }
.tag { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--accent); }
.inline-form { flex-direction: row !important; flex-wrap: wrap; }
.inline-form input { flex: 1; min-width: 160px; }
.inline-form button { margin-top: 0 !important; }
.link-box { margin-bottom: 18px; }
.link-box label { display: block; margin-bottom: 6px; }
.copy-row { display: flex; gap: 6px; }
.copy-row input { flex: 1; }
@media (max-width: 560px) {
  .users td { display: block; border-top: 0; padding: 4px 0; }
  .users tr { display: block; border-top: 1px solid var(--rule); padding: 6px 0; }
  .users .actions form { justify-content: flex-start; }
}

/* Last, so it overrides the sizes above. */
/* Touch screens: fingertip-sized targets, and 16px text so iOS doesn't zoom on focus. */
@media (pointer: coarse) {
  :root { --row-h: 44px; }
  .icon-btn { min-width: 44px; height: 44px; }
  .icon-btn.small { min-width: 44px; height: 44px; }
  .flat-btn { height: 44px; }
  .tabs button { height: 44px; }
  .segmented button { min-height: 44px; }
  button.primary, button.pill, .page button, a.button { min-height: 44px; }
  .menu-item { padding: 12px; }
  input[type="text"], input[type="search"], input[type="password"], select { height: 44px; font-size: 16px; }
  .lookup .icon { top: 13px; }
}
