:root {
  --background: #f9f9f9;
  --foreground: #080808;
  --accent: #0881A0;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:is([hidden]) {
  display: none !important;
}

html {
  font: 16px/1.4 Georgia;
}

body {
  padding: 1rem;
  background: var(--background);
  color: var(--foreground);
}

body > * {
  max-width: 45rem;
  margin-inline: auto;
}

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

a:hover {
  opacity: .75;
}

h1, h2, h3 {
  font-family: Verdana, sans-serif;
  margin-block-end: 1rem;

  a {
    color: inherit;
    text-decoration: none;
  }
}

p {
  margin-block: 1rem;
}

header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-block-end: 1rem;
}

header h1 {
  font-family: sans-serif;
  color: var(--accent);
  margin: 0;
  font-size: 1rem;
  line-height: 1.5rem;
}

body > header .actions {
  margin: 0;
}

body > header .btn {
  background: oklch(from var(--foreground) l c h / 0.5);
  padding: 0 1rem;
  line-height: 1.5rem;
}

header a {
  text-decoration: none;
  color: inherit;
}

article :is(h1, h2, h3, h4, h5, h6, p, ul, ol, blockquote, iframe, div, figure) {
  margin-block-end: 1rem;
}

label:not(.btn),
.label {
  font-family: sans-serif;
  display: block;
  letter-spacing: 0.1ch;
  font-size: .75rem;
  line-height: 1rem;
  margin-block-end: .25rem;
  cursor: pointer;
}

.form-field {
  padding: .5rem;
  margin: -.5rem -.5rem .5rem;
  position: relative;
  overflow: hidden;

  &:last-child {
    margin-block-end: 0;
  }
}

textarea,
input[type="text"],
input[type="password"],
input[type="date"] {
  display: block;
  width: 100%;
  font: inherit;
  border: 1px solid #eee;
  padding: calc(.5rem - 1px);
  border-radius: .25rem;
}

textarea[name$="--json"] {
  font-family: monospace;
  font-size: .75rem;
}

input[type="checkbox"] {
  position: absolute;
  left: 100vw;
}

input[type="checkbox"] + label:before {
  content: "⬜️";
  display: inline-block;
  margin-right: .5ch;
}

input[type="checkbox"]:checked + label:before {
  content: "🔳";
}

button,
.btn {
  appearance: none;
  cursor: pointer;
  font: inherit;
  font-family: sans-serif;
  font-weight: bold;
  white-space: nowrap;
  line-height: 1.5rem;
  border-radius: 1.25rem;
  background: var(--foreground);
  color: #fff;
  padding: .5rem 1.5rem;
  border: 0;
  text-decoration: none;
  display: block;
  width: fit-content;
}

.btn-secondary {
  background: transparent;
  color: var(--foreground);
  padding: calc(.5rem - 1px) calc(1.5rem - 1px);
  border: 1px solid #ccc;
}

.btn-create,
.btn-edit {
  overflow: hidden;
  text-indent: -100vw;
  white-space: nowrap;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath fill='currentColor' d='M16.738 3.727a1.3 1.3 0 0 1 1.838 0l1.697 1.697a1.3 1.3 0 0 1 0 1.838L8.818 18.718a.5.5 0 0 1-.255.136l-3.536.707a.5.5 0 0 1-.588-.588l.707-3.535a.5.5 0 0 1 .137-.256z'/%3E%3C/svg%3E");
  padding: 0;
  width: 1lh;
  height: 2rem;
  background-size: 1lh;
  background-repeat: no-repeat;
  background-position: center center;
  opacity: .4;
  display: inline-block;
  margin-inline-start: .5rem;

  &:hover {
    opacity: 1;
  }
}

.btn-create {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Cpath fill='currentColor' d='M11.005 9H16v2h-4.995v5.005h-2V11H4V9h5.005V4.005h2z'/%3E%3C/svg%3E");
}

:where(button.btn:not(:disabled), .btn:not(.btn-disabled)):hover {
  background: #888;
}

.btn[disabled], .btn-disabled {
  cursor: default;
  opacity: .5;
}

.actions {
  margin: 2rem 0;
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
}

main.loading {
  * {
    display: none;
  }

  &:before {
    content: "Loading…";
    display: block;
  }
}

main h1 {
  width: fit-content;
}

.header {
  display: flex;
  justify-content: space-between;
  margin-block-end: 1.5rem;
  line-height: 1.5rem;

  &:not(:first-child) {
    margin-block-start: 2rem;
  }

  > div {
    display: flex;
    gap: .5rem;
  }

  * {
    margin: 0;
  }
}

main > .header {
  line-height: 2rem;
  margin: 0;

  h1 {
    white-space: nowrap;
    margin: 0;
    line-height: inherit;
    line-height: 2.5rem;
  }

  .btn-edit {
    margin: 0;
  }
}

ul.records {
  display: flex;
  flex-direction: column;
  gap: .5rem;
  margin-block: 1rem;

  li {
    list-style: none;
    font-size: 1.5rem;
    line-height: 1.5rem;

    a {
      font-weight: bold;
      text-decoration: none;
    }
  }

  p:only-child,
  p:has(+ .footer) {
    margin-block: 0;
  }

  .footer {
    color: var(--foreground);
    font-weight: normal;
    font-size: 1rem;
  }

  &.records--cards {
    gap: 1rem;

    li {
      background: #fff;
      padding: .5rem;
      margin-inline: -.5rem;
      font-size: 1.2rem;
    }

    .header,
    .footer {
      display: flex;
      justify-content: space-between;
      font-size: 1rem;
    }

    p {
      margin-block: 0;

      & + p {
        margin-block-start: .5rem;
      }
    }

    a {
      font-weight: normal;
      text-decoration: none;
      color: inherit;
    }

    .header {
      margin-block-end: .5rem;
    }

    .footer {
      margin-block-start: .5rem;
    }
  }
}

.record {
  display: flex;
  flex-direction: column;
  margin-block: 1rem;
  line-height: 1.25rem;

  .btn-edit {
    height: 1.25rem;
  }
}

ul.tasks {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-block: 1rem;

  li {
    list-style: none;
    font-size: 1.2rem;
    line-height: 1.5rem;
  }

  a {
    text-decoration: none;
    color: inherit;
  }

  a span:first-child {
    text-decoration: underline;
    color: var(--accent);
  }
}

.button-bar {
  display: flex;
  justify-content: flex-start;
  gap: 0;
  margin-block: 1rem;

  .btn {
    font-size: .75rem;
    padding-block: .25rem;
    border-radius: 0;

    &:first-child {
      border-start-start-radius: 1.25rem;
      border-end-start-radius: 1.25rem;
    }

    &:last-child {
      border-start-end-radius: 1.25rem;
      border-end-end-radius: 1.25rem;
    }
  }

  [aria-current="false"] {
    opacity: .8;
  }
}

.type {
  margin-block: 1rem;
}

div.store {
  margin-block: 1rem;
  font-family: monospace;
}

ul.operations {
  list-style: none;
  display: grid;
  grid-template-columns: auto 1fr auto;
  grid-column-gap: 1rem;
  grid-row-gap: 1rem;
  margin-block: 1rem;

  > li {
    display: grid;
    grid-column: 1 / span 3;
    grid-template-columns: subgrid;

    > * {
      line-height: 1rem;
    }

    small:last-child {
      text-align: right;
    }
  }
}

ul.settings {
  list-style: none;
  display: grid;
  grid-template-columns: auto 1fr;
  grid-column-gap: 1rem;
  grid-row-gap: 1rem;
  margin-block: 1rem;

  > li {
    display: grid;
    grid-column: 1 / span 2;
    grid-template-columns: subgrid;

    > * {
      line-height: 1rem;
    }
  }
}

.visible-object {
  tt {
    display: inline-block;
  }

  ul {
    margin: 0;
    padding: 0;
    list-style: none;
    display: grid;
    grid-template-columns: auto 1fr;
    grid-row-gap: .25rem;
    grid-column-gap: .5rem;

    li {
      grid-column: 1 / span 2;
      display: grid;
      grid-template-columns: subgrid;
    }

    ul {
      grid-column: 1 / span 2;
      margin-inline-start: 1rem;
    }

    tt {
      font-size: .75rem;
      line-height: 1.25rem;
    }
  }
}

ul.fields {
  margin-inline-start: 1.5rem;
}

ul.field-history {
  list-style: none;
  display: grid;
  grid-template-columns: repeat(3, auto);
  grid-gap: .25rem;
  margin-block: 1rem;

  li {
    display: grid;
    grid-column: 1 / span 3;
    grid-template-columns: subgrid;
  }
}

dialog {
  max-width: unset;
  width: 45rem;
  padding: 1rem;
  border: 0;
  box-shadow: 0 .5rem .5rem #00000080;
  margin-inline: auto;
  margin-block-start: 2rem;
  position: relative;

  --close-button-size: 2.5rem;

  form[method="dialog"] {
    position: absolute;
    inset-inline-end: 1rem;
    inset-block-start: 1rem;
    margin: 0;

    button {
      width: var(--close-button-size);
      height: var(--close-button-size);
      padding: 0;
      font-size: .5rem;
      line-height: var(--close-button-size);
    }

    + h2 {
      padding-inline-end: calc(var(--close-button-size) + 1rem);
      min-block-size: var(--close-button-size);
    }
  }

  > :last-child {
    margin-block-end: 0;
  }
}

ul.errors {
  background: #FFBAB2;
  padding: .5rem;
  border-radius: .25rem;
  list-style: none;
  margin-block: 1rem;
}


.calendar {
  margin-block: 1rem;
  border: 1px solid oklch(from currentColor l c h / 0.2);
  padding: calc(.5rem - 1px);

  .head {
    display: flex;
    justify-content: flex-start;
    gap: 1rem;
    line-height: 1.5rem;
    padding-block: .5rem;

    div {
      display: flex;
      justify-content: flex-end;
      gap: 1rem;
    }

    button {
      appearance: none;
      cursor: pointer;
      display: block;
      border: 0;
      background: transparent no-repeat center center;
      background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 15 15'%3E%3Cpath fill='currentColor' d='M8.293 2.293a1 1 0 0 1 1.414 0l4.5 4.5a1 1 0 0 1 0 1.414l-4.5 4.5a1 1 0 0 1-1.414-1.414L11 8.5H1.5a1 1 0 0 1 0-2H11L8.293 3.707a1 1 0 0 1 0-1.414'/%3E%3C/svg%3E");
      overflow: hidden;
      text-indent: -100vw;
      white-space: nowrap;
      width: 1.5rem;
      height: 1.5rem;
      background-size: 1rem;

      &.prev {
        transform: rotate(180deg);
      }
    }
  }

  .body {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    column-gap: .25rem;
    row-gap: .25rem;

    > div {
      text-align: center;
      line-height: 2rem;
    }

    .other {
      color: #9A9183;
    }
  }
}
