/* ==========================================================================
   RESET & FOUNDATIONS
   ========================================================================== */

/* Reset */
* {
  margin: 0;
  padding: 0;

  box-sizing: border-box;
  font-size: 100%;
  font: inherit;
  text-decoration: none;
  color: inherit;

  border: 0;
  border-radius: 0;
  background: none;
  list-style: none;

  outline: none;

  width: unset;
  border-collapse: separate;

  text-align: inherit;
}

/* Fonts */
@font-face {
  font-family: JetBrainsMono;
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("../fonts/JetBrainsMono.woff2") format("woff2");
}

/* ==========================================================================
   DESIGN TOKENS & VARIABLES
   ========================================================================== */

:root {
  --unit: 1rem;
  --grid: calc(var(--unit) * 4);

  --page: hsl(0, 0%, 95%);

  --bg: hsl(0, 0%, 100%);
  --bg-secondary: hsl(0, 0%, 95%);
  --bg-tertiary: hsl(0, 0%, 92%);

  --fg: hsl(0, 0%, 0%);
  --fg-secondary: hsla(0, 0%, 0%, 0.5);

  --shadow-offset: 2px;
  --shadow-color: hsla(0, 0%, 0%, 1);

  --inset-shadow-offset: 2px;
  --inset-shadow-color: hsla(0, 0%, 0%, 0.3);

  --padding: 0.5rem 1rem;

  --shadow: 0 calc(var(--shadow-offset) * 2 + 1px) 0
    calc(var(--shadow-offset) * -1) var(--shadow-color);
  --inset-shadow: inset var(--inset-shadow-offset) var(--inset-shadow-offset)
    0px var(--inset-shadow-color);

  --link: hsl(210, 100%, 50%);

  --error: hsl(8, 100%, 40%);
  --success: hsl(160, 70%, 40%);
  --focus: hsla(40, 100%, 90%, 1);
  --focus-fg: hsl(40, 100%, 30%);
}

@media (prefers-color-scheme: dark) {
  :root {
    --hue: 240;
    --page: hsl(var(--hue), 15%, 8%);

    --bg: hsl(var(--hue), 10%, 15%);
    --bg-secondary: hsl(var(--hue), 10%, 20%);
    --bg-tertiary: hsl(var(--hue), 10%, 25%);

    --fg: hsl(0, 0%, 100%, 0.9);
    --fg-secondary: hsl(0, 0%, 100%, 0.5);

    --shadow-color: hsla(0, 0%, 100%, 0.5);
    --inset-shadow-color: hsla(0, 0%, 0%, 0.3);

    --error: hsl(8, 70%, 60%);
    --success: hsl(160, 70%, 60%);
    --focus: hsla(170, 100%, 12%, 1);
    --focus-fg: hsla(170, 100%, 55%, 1);
  }
}

/* ==========================================================================
   BASE ELEMENTS
   ========================================================================== */

/* Selection */
::selection {
  background: var(--fg);
  color: var(--bg);
}

/* HTML & Body */
html {
  font-family: "Berkeley Mono", "JetBrainsMono", "JetBrains Mono", monospace;

  width: 100dvw;
  height: 100dvh;
  overflow-x: hidden;
  overflow-y: auto;

  background-color: var(--page);
  color: var(--fg);

  font-size: 14px;
}

body {
  min-height: 100dvh;
  width: 100dvw;
  margin: 0 auto;
  padding: 1rem;

  max-width: 60rem;

  display: flex;
  flex-direction: column;
  align-items: stretch;
}

/* ==========================================================================
   LAYOUT UTILITIES
   ========================================================================== */

/* Flexbox Layouts */
.v,
.h {
  display: flex;
  flex-wrap: wrap;
}

.v {
  flex-direction: column;
  align-items: stretch;
  max-width: 100%;
}

.h {
  flex-direction: row;
  align-items: center;
  row-gap: 0.5rem;
}

/* Gap Utilities */
.gap-01 {
  gap: calc(var(--unit) * 0.5);
}

.gap-1 {
  gap: var(--unit);
}

.gap-2 {
  gap: calc(var(--unit) * 2);
}

.gap-fill {
  justify-content: space-between;
}

/* Justify Content */
.justify-start {
  justify-content: flex-start;
}

.justify-center {
  justify-content: center;
}

.justify-end {
  justify-content: flex-end;
}

/* Align Items */
.align-start {
  align-items: flex-start;
}

.align-end {
  align-items: flex-end;
}

.align-center {
  align-items: center;
}

/* Align Self */
.align-self-start {
  align-self: flex-start;
}

.align-self-end {
  align-self: flex-end;
}

.align-self-center {
  align-self: center;
}

.align-self-stretch {
  align-self: stretch;
}

/* Flex Utilities */
.flex-1 {
  flex: 1;
}

/* Spacing Utilities */
.padding-1 {
  padding: 1rem;
}

.padding-2 {
  padding: 2rem;
}

/* Text Utilities */
.muted {
  color: var(--fg-secondary);
}

/* ==========================================================================
   COMPONENT STYLES
   ========================================================================== */

/* Paper System */
.paper {
  outline: 1px solid var(--fg);
  box-shadow: var(--shadow);
  background: var(--bg);

  &.danger {
    outline-color: var(--error);
    --shadow-color: var(--error);
    --shadow: 0 calc(var(--shadow-offset) * 2 + 1px) 0
      calc(var(--shadow-offset) * -1) var(--shadow-color);
    color: var(--error);

    tr,
    td,
    th {
      border-color: var(--error);
    }
  }
}

.inset {
  outline: 1px solid var(--fg);
  box-shadow: var(--inset-shadow);
  background: var(--bg);
}

/* Buttons */
.button,
.select {
  display: block;
  padding: 0.3rem 1rem;

  &.taller {
    padding: 0.5rem 1rem;
  }

  &:not(.select):hover:not([disabled]) {
    background-color: var(--fg);
    color: var(--bg);
  }

  &:hover:not([disabled]) {
    cursor: pointer;
  }

  &:focus-visible:not([disabled]) {
    background-color: var(--focus);
  }

  &.contrast-high {
    background-color: var(--fg);
    color: var(--bg);
  }

  &.contrast-medium {
    outline: 1px solid var(--fg);
    box-shadow: var(--shadow);
    background-color: var(--bg);

    &:hover:not([disabled]) {
      background-color: var(--fg);
      color: var(--bg);
    }

    &:focus-visible:not([disabled]) {
      background-color: var(--focus);
    }
  }

  &.error {
    &.contrast-low {
      color: var(--error);
    }

    &.contrast-medium {
      outline-color: var(--error);
      --shadow-color: var(--error);
      --shadow: 0 calc(var(--shadow-offset) * 2 + 1px) 0
        calc(var(--shadow-offset) * -1) var(--shadow-color);
      color: var(--error);
    }

    &.contrast-high {
      background-color: var(--error);
      color: var(--bg);
    }
  }

  &[disabled] {
    opacity: 0.3;
  }

  &:active:not([disabled]) {
    opacity: 0.4;
  }
}

/* Links */
.link {
  text-decoration: underline;

  &.contrast-medium {
    color: var(--fg-secondary);
  }

  &:hover {
    color: var(--fg);
    cursor: pointer;
  }

  &:focus-visible {
    background-color: var(--focus);
    color: var(--focus-fg);
  }
}

/* Form Elements */
input[type="text"],
input[type="password"],
textarea {
  min-width: 0;
  padding: 0.3rem 0.5rem;

  &:focus {
    background-color: var(--focus);
  }
}

textarea {
  resize: vertical;
  min-height: 4rem;
}

select {
  appearance: none;

  color-scheme: light dark;
  background-image: url("data:image/svg+xml;utf8,<svg width='12' height='6' viewBox='0 0 12 6' fill='none' xmlns='http://www.w3.org/2000/svg'><path d='M6 5L2 1H10L6 5Z' fill='black'/></svg>");
  background-size: 12px 6px;
  background-repeat: no-repeat;
  background-position: right 0.5rem center;

  padding-right: 2rem !important;
}

@media (prefers-color-scheme: dark) {
  select {
    background-image: url("data:image/svg+xml;utf8,<svg width='12' height='6' viewBox='0 0 12 6' fill='none' xmlns='http://www.w3.org/2000/svg'><path d='M6 5L2 1H10L6 5Z' fill='white'/></svg>");
  }
}

/* Tables */
.table-container {
  width: 100%;
  overflow-x: auto;
  overscroll-behavior-x: none;
}

table {
  border-spacing: 0;

  thead {
    background-color: var(--bg-secondary);

    background-image: repeating-linear-gradient(
      135deg,
      var(--bg-tertiary) 0,
      var(--bg-tertiary) 4px,
      transparent 4px,
      transparent 8px
    );

    th {
      font-weight: bold;
      border-bottom: 1px solid var(--fg-secondary);
    }
  }

  td + td,
  th + th {
    border-left: 1px solid var(--fg-secondary);
  }

  tr + tr td {
    border-top: 1px solid var(--fg-secondary);
  }

  label {
    padding: 0.5rem;
    min-width: 8rem;
  }

  input {
    width: 100%;
  }

  &.data {
    tbody {
      tr:nth-child(even) {
        background-color: var(--bg-secondary);
      }
    }
    td {
      white-space: nowrap;
    }
  }

  &.padding td,
  &.padding th,
  th .padding,
  td .padding {
    padding: 0.5rem 1rem;
  }

  th.no-padding,
  td.no-padding {
    padding: 0;

    .select,
    .button,
    input {
      padding-top: 0.5rem;
      padding-bottom: 0.5rem;
    }
  }
}

/* Alerts */
.alert {
  padding: calc(1rem - 8px);
  position: relative;
  color: var(--error);
  font-weight: bold;

  border: 8px solid transparent;
  border-image: repeating-linear-gradient(
      135deg,
      var(--error) 0,
      var(--error) 4px,
      transparent 4px,
      transparent 8px
    )
    8 round;

  &.info {
    --error: var(--fg-secondary);
  }
  &.success {
    --error: var(--success);
  }
}

/* Drop Zones */
.drop-zone {
  z-index: 1500;

  &.fullscreen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;

    .content {
      width: 80vw;
      height: 80vh;
    }
  }

  display: flex;
  align-items: center;
  justify-content: center;

  transition: opacity 0.3s ease-in-out;

  &:not(.visible) {
    opacity: 0;
    pointer-events: none;
  }

  .content {
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;

    background-color: var(--bg);
    border: 1px solid var(--fg);
    padding: 2rem;

    pointer-events: none;
  }
}

/* ==========================================================================
   LAYOUT SECTIONS
   ========================================================================== */

/* Header */
#header {
  display: flex;
  flex-direction: row;
  justify-content: space-between;

  padding: 0.2rem;

  margin-bottom: 2rem;

  position: sticky;
  top: 1rem;

  hr {
    flex: 1;
    height: 0;
    border-bottom: 1px dashed var(--fg);
    margin: 0 2rem;
  }

  .button {
    padding: 0.8rem;
  }
}

/* Footer */
#footer {
  display: flex;
  flex-direction: row;
  justify-content: space-between;

  font-size: 80%;
  color: var(--fg-secondary);

  position: sticky;

  padding: 1rem;
}

/* Content Area */
#content {
  flex: 1;

  h1 {
    font-size: 2rem;
    font-weight: bold;
  }

  h2 {
    font-size: 1.5rem;
    font-weight: bold;
  }

  h3 {
    font-size: 1.2rem;
    font-weight: bold;
  }

  hr {
    margin: 0;
    border-bottom: 1px dashed var(--fg);
  }

  > header {
    border-bottom: 1px dashed var(--fg);
    margin-bottom: var(--unit);
    padding-bottom: var(--unit);
  }

  strong {
    font-weight: bold;
  }

  .breadcrumbs {
    flex: 1;
    font-size: 1.2rem;
    font-weight: bold;

    min-height: 2rem;

    display: flex;
    flex-direction: row;
    align-items: center;
    flex-wrap: wrap;

    a {
      text-decoration: underline;

      &:focus-visible {
        background-color: var(--focus);
        color: var(--focus-fg);
      }
    }

    a + a::before {
      content: "/";
      display: inline-block;
      margin: 0 1rem;
    }
  }

  flex-grow: 1;
}

/* ==========================================================================
   SPECIAL ELEMENTS
   ========================================================================== */

/* Environment Banner */
#env-banner {
  position: fixed;
  top: 3rem;
  right: -12rem;
  width: 30rem;

  text-align: center;

  transform: translateY(-50%) rotate(45deg);
  padding: 0.2rem 0;
  background-color: var(--error);
  color: var(--bg);
  font-weight: bold;
  pointer-events: none;
  z-index: 1000;
}

/* Toasts */
.toast {
  position: fixed;
  top: 0.5rem;
  right: 0.5rem;
  transform: translateY(-0.2rem);
  opacity: 0;
  padding: var(--padding);
  z-index: 1200;

  background-color: var(--fg);
  color: var(--bg);

  transition:
    opacity 1.5s ease-in-out,
    transform 1.5s ease-in-out;

  pointer-events: none;

  &.visible {
    opacity: 1;
    transform: translateY(0);
    transition-duration: 0.3s;
  }
}

/* ==========================================================================
   RESPONSIVE DESIGN
   ========================================================================== */

/* Mobile & Tablet */
@media (max-width: 50rem) {
  body {
    padding: 0;
  }

  #header {
    border-inline-start-width: 0;
    border-inline-end-width: 0;
    border-block-start-width: 0;
    top: 0;
  }

  #content {
    padding: 0 1rem;
  }
}

/* Small Mobile */
@media (max-width: 20rem) {
  #content {
    padding: 0 0.5rem;
  }
}
