/* The dashboard: a menu on the left, one tab's content on the right; the pages standing alone
   (setup, an app's consent) keep the content's column only */

:root {
  --accent: #4f46e5;
  --accent-border: #c7d2fe;
  --accent-soft: #eef2ff;
  --background: #f6f7f9;
  --border: #e3e5ea;
  --danger: #b42318;
  --danger-border: #fecdca;
  --danger-soft: #fef3f2;
  --good: #067647;
  --good-border: #abefc6;
  --good-soft: #ecfdf3;
  --input-border: #cfd4dc;
  --muted: #667085;
  --surface: #ffffff;
  --text: #1d2433;
  --warning: #b54708;
  --warning-border: #fedf89;
  --warning-soft: #fffaeb;
  color: var(--text);
  font:
    15px/1.5 system-ui,
    -apple-system,
    "Segoe UI",
    sans-serif;
}

body {
  background: var(--background);
  margin: 0;
}

/* Hidden stays hidden, whatever display a rule below gives the element */
[hidden] {
  display: none !important;
}

/* A page standing alone */
body > main:only-of-type {
  margin: 3rem auto;
  max-width: 44rem;
  padding: 0 1.5rem;
}

/* A page standing alone as a card: signing in, an app's consent */
body > main.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  max-width: 26rem;
  padding: 2rem 2.25rem;
}

/* Tully's name, atop the menu and the pages standing alone */
.brand {
  font-size: 1.15rem;
  font-weight: 700;
}

body > main.panel .brand,
body > main.setup .brand {
  margin-bottom: 1.5rem;
}

body > main.panel h1 {
  margin-bottom: 1.25rem;
}

/* The setup page's steps, apart */
body > main.setup h2 {
  margin: 2rem 0 0.75rem;
}

/* The sign-in page's choices, one per line, full width */
main.panel a.button {
  display: block;
  margin: 0 0 0.6rem;
  padding: 0.65rem 1rem;
  text-align: center;
}

a.button small {
  display: block;
  font-size: 0.8rem;
  font-weight: 400;
  opacity: 0.8;
}

.dashboard {
  display: grid;
  grid-template-columns: 15rem 1fr;
  min-height: 100vh;
}

/* The menu, in place while the page scrolls, scrolling on its own when it's taller than the window */
nav {
  align-self: start;
  background: var(--surface);
  border-right: 1px solid var(--border);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  height: 100vh;
  overflow-y: auto;
  padding: 1.25rem 0.75rem;
  position: sticky;
  top: 0;
}

nav .brand {
  letter-spacing: -0.01em;
  padding: 0 0.75rem 1rem;
}

nav h2 {
  color: var(--muted);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  margin: 1rem 0.75rem 0.25rem;
  text-transform: uppercase;
}

nav a {
  border-radius: 0.5rem;
  color: var(--text);
  padding: 0.4rem 0.75rem;
  text-decoration: none;
}

nav a:hover {
  background: var(--background);
}

nav a[aria-current="page"] {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

/* Who's signed in, at the menu's foot, opening their own menu above it */
nav .who {
  background: none;
  border: none;
  border-radius: 0.5rem;
  border-top: 1px solid var(--border);
  margin: auto 0 0;
  overflow: hidden;
  padding: 1rem 0.75rem 0.5rem;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
}

nav .who::after {
  color: var(--muted);
  content: " ▴";
}

#account-menu {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  box-shadow: 0 8px 24px rgb(16 24 40 / 12%);
  inset: auto auto 4.5rem 0.75rem;
  margin: 0;
  max-width: 22rem;
  padding: 1rem;
  position: fixed;
}

#account-menu .sign-in-name {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 0.75rem;
  word-break: break-all;
}

/* The tab */
.dashboard > main {
  max-width: 64rem;
  padding: 2rem 2.5rem 4rem;
}

h1 {
  font-size: 1.6rem;
  letter-spacing: -0.02em;
  margin: 0 0 0.25rem;
}

h2 {
  font-size: 1.1rem;
  margin: 2rem 0 0.75rem;
}

h3 {
  font-size: 1rem;
  margin: 1.25rem 0 0.5rem;
}

.muted {
  color: var(--muted);
  font-size: 0.85rem;
}

.subtitle,
.hint {
  color: var(--muted);
  margin: 0 0 1.5rem;
}

.hint {
  font-size: 0.9rem;
  margin: 0.25rem 0 0.75rem;
}

a {
  color: var(--accent);
}

code {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.85em;
  word-break: break-all;
}

/* A card: a record, a form, a group of rows */
.card,
fieldset {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  margin: 0 0 1rem;
  padding: 1.25rem 1.5rem;
}

/* A card's padding alone frames it: the margins its first and last elements keep for the page
   don't add to it */
.card > :first-child,
fieldset > legend + * {
  margin-top: 0;
}

.card > :last-child,
fieldset > :last-child {
  margin-bottom: 0;
}

fieldset fieldset {
  background: var(--background);
}

legend {
  font-weight: 600;
  padding: 0 0.25rem;
}

/* Lists of records */
table {
  background: var(--surface);
  border: 1px solid var(--border);
  border-collapse: separate;
  border-radius: 0.75rem;
  border-spacing: 0;
  margin: 0 0 1rem;
  overflow: hidden;
  width: 100%;
}

th,
td {
  border-bottom: 1px solid var(--border);
  padding: 0.6rem 0.9rem;
  text-align: left;
  vertical-align: top;
}

th {
  background: var(--background);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

tr:last-child td {
  border-bottom: none;
}

th.right,
td.right {
  text-align: right;
}

td.actions {
  text-align: right;
  white-space: nowrap;
}

.empty {
  background: var(--surface);
  border: 1px dashed var(--border);
  border-radius: 0.75rem;
  color: var(--muted);
  padding: 1.5rem;
  text-align: center;
}

/* A word about a record's state */
.badge {
  background: var(--background);
  border: 1px solid var(--border);
  border-radius: 999px;
  display: inline-block;
  font-size: 0.75rem;
  font-weight: 600;
  margin: 0 0.25rem 0.15rem 0;
  padding: 0.05rem 0.55rem;
  white-space: nowrap;
}

.badge.good {
  background: var(--good-soft);
  border-color: var(--good-border);
  color: var(--good);
}

.badge.warn {
  background: var(--warning-soft);
  border-color: var(--warning-border);
  color: var(--warning);
}

.badge.bad {
  background: var(--danger-soft);
  border-color: var(--danger-border);
  color: var(--danger);
}

.badge.accent {
  background: var(--accent-soft);
  border-color: var(--accent-border);
  color: var(--accent);
}

/* An attribute's row: its name and its value side by side, its removal at the end */
.attribute {
  display: flex;
  gap: 0.5rem;
  margin: 0 0 0.5rem;
}

/* Weightier than the fields' own width, below, so the row fits its box */
div.attribute input {
  width: 14rem;
}

div.attribute input + input {
  flex: 1;
  min-width: 0;
}

/* A choice among a few kinds, each named, what it's for below */
label.choice {
  padding-left: 1.6rem;
  text-indent: -1.6rem;
}

label.choice .muted {
  margin-top: 0.15rem;
  text-indent: 0;
}

/* "+N more", opening the rest of a list in place */
summary.more {
  color: var(--accent);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
}

/* Forms */
label {
  display: block;
  font-weight: 500;
  margin: 0 0 0.9rem;
}

label > input:not([type="checkbox"], [type="radio"]),
label > select,
label > textarea,
label > span {
  display: block;
  font-weight: 400;
  margin-top: 0.3rem;
}

/* Several controls under one title, spaced as a labelled field */
.group {
  margin: 0 0 0.9rem;
}

.group-title {
  display: block;
  font-weight: 500;
  margin-bottom: 0.3rem;
}

.group > span:not(.group-title) {
  display: block;
}

label:has(> input[type="checkbox"], > input[type="radio"]) {
  font-weight: 400;
}

input,
select,
textarea {
  background: var(--surface);
  border: 1px solid var(--input-border);
  border-radius: 0.5rem;
  box-sizing: border-box;
  color: inherit;
  font: inherit;
  max-width: 100%;
  padding: 0.45rem 0.65rem;
}

/* A select's arrow drawn in, a little in from its edge: the browser's own sits on the border. Two
   gradients, as no image may be loaded inline (the root host's Content-Security-Policy). A search's
   pick shown as a select has it too */
select,
.combobox .chosen {
  appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--muted) 50%),
    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position:
    right 1rem center,
    right calc(1rem - 5px) center;
  background-repeat: no-repeat;
  background-size: 5px 5px;
  padding-right: 2.25rem;
}

/* What a choice shows below it (a scope choice's checkboxes), clear of it */
.choice-detail {
  display: block;
  margin-top: 0.75rem;
}

input:not([type="checkbox"], [type="radio"], [type="file"]),
textarea {
  width: 32rem;
}

textarea.guide-editor {
  width: 100%;
}

textarea {
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.85rem;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  outline: 3px solid var(--accent-soft);
}

/* A button, or a link looking like one (it only opens another page) */
button,
a.button {
  background: var(--surface);
  border: 1px solid var(--input-border);
  border-radius: 0.5rem;
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-weight: 500;
  display: inline-block;
  margin: 0 0.4rem 0.4rem 0;
  padding: 0.4rem 0.9rem;
  text-decoration: none;
}

button:hover,
a.button:hover {
  background: var(--background);
}

button.primary,
a.button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

button.primary:hover,
a.button.primary:hover {
  background: var(--accent);
  filter: brightness(1.08);
}

/* A button looking like a link, opening something in place */
button.link {
  background: none;
  border: none;
  color: var(--accent);
  font-weight: 500;
  margin: 0;
  padding: 0;
}

button.link::after {
  content: " ▸";
}

button.link:hover {
  background: none;
  text-decoration: underline;
}

button.danger {
  border-color: var(--danger-border);
  color: var(--danger);
}

button.danger:hover {
  background: var(--danger-soft);
}

/* A button that can't be used yet, faded, its hover unchanged */
button:disabled,
button:disabled:hover {
  cursor: not-allowed;
  filter: none;
  opacity: 0.45;
}

button.danger:disabled:hover {
  background: var(--surface);
}

/* A search picking one match, as a dropdown: its matches listed under the field, over the page */
.combobox {
  margin: 0 0 1rem;
  max-width: 44rem;
  position: relative;
}

.combobox input {
  width: 100%;
}

/* Its pick, looking like a select showing its option */
.combobox .chosen {
  background-color: var(--surface);
  border: 1px solid var(--input-border);
  border-radius: 0.5rem;
  color: inherit;
  font: inherit;
  font-weight: inherit;
  margin: 0;
  overflow: hidden;
  padding: 0.45rem 2.25rem 0.45rem 0.65rem;
  text-align: left;
  text-overflow: ellipsis;
  white-space: nowrap;
  width: 100%;
}

.options .picked {
  font-weight: 600;
}

.options .picked::after {
  content: " ✓";
}

.options {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.5rem;
  box-shadow: 0 8px 24px rgb(16 24 40 / 12%);
  left: 0;
  margin-top: 0.25rem;
  max-height: 18rem;
  overflow-y: auto;
  padding: 0.25rem;
  position: absolute;
  right: 0;
  top: 100%;
  z-index: 5;
}

.options [role="option"],
.options .none {
  border-radius: 0.375rem;
  padding: 0.5rem 0.75rem;
}

/* One line each, cut short if it must be */
.options [role="option"] {
  cursor: pointer;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.options [role="option"]:hover,
.options [aria-selected="true"] {
  background: var(--accent-soft);
}

/* A condition on accounts: its attribute, how it compares, its values and its removal on a line */
.condition {
  align-items: flex-start;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  margin: 0 0 0.5rem;
}

.condition > button {
  margin: 0;
}

/* Weightier than the fields' own width */
div.condition > input {
  width: 12rem;
}

.condition-values {
  flex: 1;
  min-width: 16rem;
}

/* Several values picked, as chips in a field */
.multi-pick {
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--input-border);
  border-radius: 0.5rem;
  cursor: text;
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin: 0;
  max-width: none;
  padding: 0.25rem 0.4rem;
}

.multi-pick:focus-within {
  border-color: var(--accent);
  outline: 3px solid var(--accent-soft);
}

.multi-pick .chips {
  display: contents;
}

div.multi-pick input {
  border: none;
  flex: 1;
  min-width: 8rem;
  outline: none;
  padding: 0.2rem;
  width: auto;
}

.chip {
  align-items: center;
  background: var(--accent-soft);
  border-radius: 999px;
  display: inline-flex;
  gap: 0.25rem;
  padding: 0.1rem 0.25rem 0.1rem 0.6rem;
}

.chip button {
  background: none;
  border: none;
  line-height: 1;
  margin: 0;
  padding: 0.15rem 0.3rem;
}

/* A backend's scopes to tick: the box and its type's badge as narrow as they can be */
.scopes-table table {
  width: auto;
}

.scopes-table td label {
  font-weight: 400;
  margin: 0;
}

/* A row under the one before it, as a person's key under them */
.indented {
  display: inline-block;
  padding-left: 1.5rem;
}

/* A part of a key's access: its backend and its removal on a line, its accounts and scopes below */
.access-part > div:first-child {
  align-items: flex-end;
  display: flex;
  gap: 0.5rem;
}

.access-part > div:first-child label {
  flex: 1;
}

/* A log entry's records, before and after: long values wrapped, a changed field marked */
dialog.review table td:not(.nowrap) {
  overflow-wrap: anywhere;
}

td.changed {
  background: var(--warning-soft);
}

/* What stays on one line */
.nowrap {
  white-space: nowrap;
}

/* A table's buttons, under it */
.below-table {
  margin: 0 0 2rem;
}

/* Why a change failed, at the top of the tab; what an admin must fix, on its page */
#error:not(:empty),
.problem {
  background: var(--danger-soft);
  border: 1px solid var(--danger-border);
  border-radius: 0.5rem;
  color: var(--danger);
  margin: 0 0 1.25rem;
  padding: 0.75rem 1rem;
}

/* What a change warned of, at the top of the tab until the next action */
#warnings:not(:empty) {
  background: var(--warning-soft);
  border: 1px solid var(--warning-border);
  border-radius: 0.5rem;
  color: var(--warning);
  margin: 0 0 1.25rem;
  padding: 0.75rem 1rem;
}

#warnings p {
  margin: 0;
}

#warnings p + p {
  margin-top: 0.5rem;
}

/* What a change did, for a moment at the bottom of the window, wherever the change was */
#status {
  bottom: 1.5rem;
  left: 50%;
  margin: 0;
  max-width: min(32rem, calc(100vw - 3rem));
  position: fixed;
  transform: translateX(-50%);
  z-index: 10;
}

#status:not(:empty) {
  background: var(--good-soft);
  border: 1px solid var(--good-border);
  border-radius: 0.5rem;
  box-shadow: 0 4px 12px rgb(16 24 40 / 12%);
  color: var(--good);
  padding: 0.75rem 1rem;
}

.secret {
  background: var(--warning-soft);
  border: 1px solid var(--warning-border);
  border-radius: 0.75rem;
  padding: 1rem 1.25rem;
}

dialog {
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  max-width: 48rem;
}

/* A text to copy, such as a prompt for an assistant */
pre.copyable {
  border: 1px solid var(--border);
  font-family: inherit;
  white-space: pre-wrap;
}

.card.attention {
  background: var(--warning-soft);
  border-color: var(--warning-border);
}

/* An upload's review: readable at a glance, its full changes folded away */
dialog.review {
  padding: 1.5rem 1.75rem;
  width: min(40rem, 90vw);
}

dialog.review h2 {
  margin-top: 0;
}

/* Labels and their values, side by side */
dl.details {
  display: grid;
  gap: 0.6rem 1.25rem;
  grid-template-columns: max-content 1fr;
  margin: 0 0 1rem;
}

dl.details dt {
  color: var(--muted);
  font-weight: 500;
}

dl.details dd {
  margin: 0;
}

dl.details dd .hint {
  margin: 0.2rem 0 0;
}

/* A text viewed whole: the dialog its own size, the text scrolling inside */
dialog.text {
  padding: 0;
  width: min(48rem, 90vw);
}

dialog.text pre {
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0;
  max-height: 70vh;
  padding: 1.25rem;
}

dialog.text button {
  margin: 0.75rem 1.25rem;
}

pre {
  background: var(--background);
  border-radius: 0.5rem;
  overflow: auto;
  padding: 0.75rem;
}

/* A document: as wide as the page's other cards, its code broken between words, a word too long
   for a line within it, and its code blocks as written */
.doc {
  line-height: 1.6;
}

.doc code {
  overflow-wrap: anywhere;
  word-break: normal;
}

.doc pre code {
  white-space: pre;
}

/* A table's column is as wide as its longest word: a name never broken in two */
.doc td code {
  overflow-wrap: normal;
}

/* A definition list, drawn as a table turned on its side: each term a header cell in a column of
   its own, its definition beside it */
.doc dl {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0.75rem;
  display: grid;
  grid-template-columns: max-content 1fr;
  margin: 0 0 1rem;
  overflow: hidden;
}

.doc dt,
.doc dd {
  border-bottom: 1px solid var(--border);
  margin: 0;
  padding: 0.6rem 0.9rem;
}

.doc dt {
  background: var(--background);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.doc dt:last-of-type,
.doc dd:last-of-type {
  border-bottom: none;
}

.doc li + li {
  margin-top: 0.25rem;
}

@media (max-width: 48rem) {
  .dashboard {
    grid-template-columns: 1fr;
  }

  /* On a narrow screen the menu sits above the page and scrolls away with it */
  nav {
    border-bottom: 1px solid var(--border);
    border-right: none;
    height: auto;
    position: static;
  }

  .dashboard > main {
    padding: 1.5rem 1rem 3rem;
  }
}
