@layer reset, base, components, utilities;

@layer base {
  *, *:before, *:after {
    box-sizing: inherit;
  }

  html {
    box-sizing: border-box;
    font-family: sans-serif;
    font-size: 15px;
    line-height: 1.5em;
    font-weight: 400;
    height: 100%;

    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  body {
    background-color: #979799;
    color: #040405;
    position: relative;

    .skip-link {
      position: fixed;
      left: 1rem;
      top: 1rem;
      z-index: 1000;
      transform: translateY(-150%);
      padding: 0.55rem 0.85rem;
      border: 2px solid var(--foreground-color, #040405);
      border-radius: 0.35rem;
      background: var(--background-color, #ffffff);
      color: var(--foreground-color, #040405);
      font-weight: 700;
      text-decoration: none;
      transition: transform 160ms ease;
    }

    .skip-link:focus-visible {
      transform: translateY(0);
      outline: 2px solid currentColor;
      outline-offset: 2px;
    }

    .loader {
      position: fixed;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      opacity: 0;
      z-index: -1;
      background: rgba(243, 246, 250, 0.74);
      backdrop-filter: blur(2px);
      -webkit-backdrop-filter: blur(2px);

      & > .preloader {
        background: transparent;
        position: fixed;
        inset: 0;

        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        will-change: background-color;

        & > * {
          opacity: 0;
        }

        & > .loader-logo {
          width: 6.25rem;
          max-width: 48%;
          max-height: 38%;
          height: auto;
          position: relative;
          z-index: 2;
          filter: drop-shadow(0 4px 12px rgba(15, 23, 42, 0.16));
          object-fit: contain;
        }

        & > .loader-logo-gray {
          display: block;
        }

        & > .loader-logo-light,
        & > .loader-logo-dark {
          display: none;
        }

        & > .loader-title {
          margin: 0;
          position: absolute;
          left: 50%;
          top: calc(50% + 8.9rem);
          transform: translateX(-50%);
          z-index: 2;
          font-size: 0.98rem;
          font-weight: 700;
          letter-spacing: 0.08em;
          text-transform: uppercase;
          color: #5a5a5a;
          text-align: center;
          white-space: nowrap;
          text-shadow: 0 1px 0 rgba(255, 255, 255, 0.7);
        }

        & > object {
          height: 2.4rem;
          position: relative;
          z-index: 2;

          & > img {
            height: 2.4rem;
          }
        }

        &::before {
          content: "";
          position: absolute;
          width: 15rem;
          height: 15rem;
          border-radius: 999px;
          background: linear-gradient(90deg, #ffffff 0%, #d0d0d0 100%);
          border: 5px solid #ffffff;
          box-shadow:
            inset 0 -2px 4px rgba(115, 115, 115, 0.16),
            0 4px 9px rgba(15, 23, 42, 0.2),
            6px 6px 14px rgba(15, 23, 42, 0.22);
          z-index: 0;
        }

        &::after {
          content: "";
          position: absolute;
          width: 15rem;
          height: 15rem;
          border-radius: 999px;
          transform: translateZ(0);
          background:
            conic-gradient(
              from 180deg,
              #5a5a5a 0 65%,
              transparent 65% 100%
            );
          -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 15px), #000 calc(100% - 14px));
          mask: radial-gradient(farthest-side, transparent calc(100% - 15px), #000 calc(100% - 14px));
          animation: spinner-rotate 1s linear infinite;
          z-index: 1;
        }
      }

      &.animating {
        transition: opacity 350ms var(--animation-function) 350ms, z-index 0ms linear 700ms;

        & > .preloader {
          transition: background-color 350ms var(--animation-function);

          & > * {
            transition: opacity 350ms var(--animation-function) 650ms;
          }
        }
      }
    }

    &.loading {
      .loader {
        z-index: 900;
        opacity: 1;

        & > .preloader {
          z-index: 920;

          & > * {
            opacity: 1;
          }
        }

        &.animating {
          transition: all 350ms var(--animation-function);
        }
      }
    }

    html.theme-dark & {
      .loader {
        background: rgba(15, 20, 26, 0.72);
      }

      .loader > .preloader > .loader-title {
        color: #d4d4d4;
        text-shadow: 0 1px 0 rgba(0, 0, 0, 0.45);
      }

    }

    .log-files {
      margin-top: 0.5rem;
      display: flex;
      flex-direction: column;
      gap: 0.5rem;
    }

    .log-summary {
      display: grid;
      grid-template-columns: minmax(10rem, 1fr) auto auto;
      align-items: center;
      gap: 0.75rem;
    }

    .log-file {
      display: grid;
      grid-template-columns: minmax(10rem, 1fr) auto auto;
      align-items: center;
      gap: 0.75rem;
    }

    .log-name {
      font-weight: 600;
      min-width: 12rem;
    }

    .log-meta {
      display: flex;
      gap: 0.5rem;
      justify-self: end;
    }

    .log-actions {
      display: flex;
      gap: 0.5rem;
      justify-self: end;
    }

    .log-tabs {
      display: flex;
      gap: 0.5rem;
      flex-wrap: wrap;
      margin-bottom: 0.75rem;
    }

    .log-tabs .tab {
      padding: 0.25rem 0.75rem;
      border-radius: 999px;
      background: rgba(0, 0, 0, 0.06);
    }

    .log-tabs .tab.active {
      background: rgba(0, 0, 0, 0.15);
      font-weight: 600;
    }

    .log-filters {
      margin-bottom: 0.75rem;
    }

    .button-icon.small {
      padding: 0.35rem 0.5rem;
      font-size: 0.85rem;
    }

    .log-more {
      margin-top: 0.75rem;
      display: flex;
      gap: 0.5rem;
    }

    @media (max-width: 900px) {
      .log-summary,
      .log-file {
        grid-template-columns: 1fr;
      }

      .log-meta,
      .log-actions {
        justify-self: start;
      }
    }
  }
}

@layer components {
  .error-page {
    min-height: calc(100vh - 8rem);
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 1rem;
    background: #e6ecf2;
  }

  .error-card {
    width: min(60rem, 100%);
    position: relative;
    overflow: hidden;
    border: 1px solid #d7dee8;
    border-left: 0.35rem solid #d02825;
    border-radius: 0.5rem;
    background: #ffffff;
    box-shadow: 0 0.25rem 0.75rem rgba(15, 23, 42, 0.08);
    padding: 1rem;
  }

  .error-eyebrow {
    display: inline-flex;
    gap: 0.5rem;
    align-items: center;
    margin: 0 0 0.5rem;
    color: #d02825;
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
  }

  .error-title {
    margin: 0;
    color: #000000;
    font-size: 1.25rem;
    line-height: 1.25;
  }

  .error-message {
    margin: 0.75rem 0 0;
    color: #334155;
    font-size: 0.85rem;
    line-height: 1.55;
  }

  .error-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    margin-top: 1rem;
  }

  .error-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 2rem;
    padding: 0.35rem 0.75rem;
    border-radius: 0.25rem;
    background: #1574c4;
    color: #ffffff;
    font-size: 0.75rem;
    font-weight: 600;
    text-decoration: none;
  }

  .error-action-secondary {
    background: #e6ecf2;
    color: #000000;
  }
}

@layer utilities {
  .button {
    /* base box/layout */
    outline: none;
    border: none;
    cursor: pointer;
    position: relative;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: center;

    /* typography & sizing */
    font-size: 1.5em;
    line-height: 1.5em;
    border-radius: 0.25em;
    padding: 0.25em;
    text-align: center;
    min-height: 2em;

    /* text/decoration */
    text-transform: uppercase;
    text-decoration: none;

    /* palette via CSS vars */
    --button-color: #000000;
    --button-text-color: #ffffff;

    background-color: var(--button-color);
    color: var(--button-text-color);

    /* hover (disabled-safe) */
    &:not(.is-disabled):not([aria-disabled="true"]):hover {
      background-color: var(--button-text-color);
      color: var(--button-color);
    }

    /* content parts */
    > .text {
      margin: 0 1em;
      font-size: 1em;
      line-height: 1.5em;
      white-space: nowrap;
    }

    > .icon {
      display: inline-flex;
      align-items: center;
      justify-content: center;
      margin: 0;
      width: 1.25em;
      min-width: 1.25em;
      text-align: center;
      font-size: 1em;
      line-height: 1em;
    }

    /* icon-only helper */
    &.icon-only > .text {
      display: none;
    }

    /* transparent/icon style */
    &.icon {
      background-color: transparent;
      color: var(--button-color);

      &:not(.is-disabled):not([aria-disabled="true"]):hover {
        background-color: #ffffff;
        color: #000000;
      }
    }

    /* dropdown container */
    > .more {
      position: absolute;
      top: 100%;
      min-width: 200%;
      padding: 0;
      background-color: #ffffff;
      right: 0;
      box-shadow: 0 -0.5px 0.5px 0 #f3f9ff;

      > a {
        display: block;
        padding: 0.5em 1em;
        line-height: 1.2em;
        text-decoration: none;
        color: #000000;

        &:hover {
          background-color: #f3f9ff;
        }
      }
    }

    /* ===== STATES ===== */

    /* disabled (works for <a> with aria-disabled and for <button> with is-disabled) */
    &.is-disabled,
    &.disabled,
    &[aria-disabled="true"] {
      pointer-events: none;
      cursor: default;
      opacity: 0.6; /* tweak if needed */
    }

    &.is-disabled:hover,
    &.disabled:hover,
    &[aria-disabled="true"]:hover {
      background-color: var(--button-color);
      color: var(--button-text-color);
    }

    /* loading state */
    &.is-loading {
      cursor: progress;
    }

    &.hidden {
      display: none;
    }

    /* optional spinner (uses currentColor) */
    &.is-loading::after {
      content: "";
      width: 1em;
      height: 1em;
      margin-left: 0.5em;
      border: 2px solid currentColor;
      border-right-color: transparent;
      border-radius: 50%;
      animation: btnspin 0.8s linear infinite;
    }

    &.btn-primary   { --button-color: #10a6af; --button-text-color: #ffffff; } /* add */
    &.btn-danger    { --button-color: #ef413d; --button-text-color: #ffffff; } /* delete */
    &.btn-info      { --button-color: #1b6cb7; --button-text-color: #ffffff; } /* show/info */
    &.btn-warning   { --button-color: #eba40a; --button-text-color: #ffffff; } /* edit */
    &.btn-success   { --button-color: #86af10; --button-text-color: #ffffff; } /* list/success */
    &.btn-muted     { --button-color: #e0e0e0; --button-text-color: #ffffff; }

    /* sizes */
    &.btn-sm {
      font-size: 1.2em;
      padding: 0.2em;
      min-height: 1.8em;
    }
    &.btn-md {
      /* your base sizing already corresponds to md */
    }
    &.btn-lg {
      font-size: 1.75em;
      padding: 0.35em;
      min-height: 2.25em;
    }
  }

  /* spinner keyframes */
  @keyframes btnspin {
    to { transform: rotate(360deg); }
  }
}

/* Keyframes MUST be top-level */
@keyframes spinner-rotate {
  from { transform: rotate(0deg); }
  to   { transform: rotate(360deg); }
}

@layer components {
  .spinner {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    background: rgba(243, 246, 250, 0.74);
    background: color-mix(in srgb, var(--background-color) 72%, transparent);
    backdrop-filter: blur(2px);
    -webkit-backdrop-filter: blur(2px);
    opacity: 0;
    transition: opacity 260ms cubic-bezier(.4,0,.2,1), z-index 0ms linear 260ms;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: -1;
  }

  .spinner.active {
    opacity: 1;
    z-index: 500;
    transition: opacity 180ms cubic-bezier(.4,0,.2,1), z-index 0ms linear 0ms;
  }

  /* body-level spinner overlay */
  body > .spinner {
    position: fixed;
  }

  .spinner.spinner-fixed {
    position: fixed;
  }

  .spinner > .spinner-circle {
    width: 4.75rem;
    height: 4.75rem;
    border-radius: 999px;
    position: relative;
    background: linear-gradient(90deg, #ffffff 0%, #d0d0d0 100%);
    border: 5px solid #ffffff;
    box-shadow:
      inset 0 -2px 4px rgba(115, 115, 115, 0.16),
      0 4px 9px rgba(15, 23, 42, 0.2),
      6px 6px 14px rgba(15, 23, 42, 0.22);
  }

  .spinner > .spinner-circle::before {
    content: "";
    position: absolute;
    inset: 50%;
    width: 1.35rem;
    height: 1.35rem;
    transform: translate(-50%, -50%);
    border-radius: 999px;
    background: #5b5b5b;
    box-shadow:
      0 0 0 3px rgba(255, 255, 255, 0.8),
      0 2px 5px rgba(15, 23, 42, 0.16);
  }

  .spinner > .spinner-circle::after {
    content: "";
    display: block;
    position: absolute;
    inset: -15px;
    border-radius: inherit;
    background:
      conic-gradient(
        from 180deg,
        #5a5a5a 0 65%,
        transparent 65% 100%
      );
    -webkit-mask: radial-gradient(farthest-side, transparent calc(100% - 15px), #000 calc(100% - 14px));
    mask: radial-gradient(farthest-side, transparent calc(100% - 15px), #000 calc(100% - 14px));
    animation: spinner-rotate 1s linear infinite;
    will-change: transform;
    z-index: 500;
  }

  html.theme-dark .spinner {
    background: rgba(15, 20, 26, 0.72);
    background: color-mix(in srgb, #0f141a 70%, transparent);
  }

  html.theme-dark .spinner > .spinner-circle {
    background: linear-gradient(90deg, #f5f5f5 0%, #cbcbcb 100%);
  }
}

@layer components {
  .expandable {
    position: relative;

    &:after {
      content: url(/assets/images/arrow-down.4e696c2c.svg);
      margin-left: 0.5rem;
    }

    & + .more {
      display: none;
      position: absolute;
      padding: 0;
      z-index: 100;
    }

    &.expanded {
      border-bottom-left-radius: 0;
      border-bottom-right-radius: 0;

      &:after {
        transform: rotate(180deg);
      }

      & + .more {
        display: block;
      }
    }
  }
}

@layer utilities {
  .Notifications {
    display: flex;
    flex-direction: column;
    position: fixed;
    width: min(24rem, calc(100vw - 2rem));
    left: 50%;
    top: 4rem;
    transform: translateX(-50%);
    z-index: 600;

    & > .Notification {
      display: flex;
      position: relative;
      overflow: hidden;
      width: 100%;
      justify-content: space-between;
      align-items: flex-start;
      flex-direction: row;
      background-color: #31a93c;
      color: #ffffff;
      padding: 0.55rem 0.7rem;
      margin-top: 0.25em;
      border-radius: 0.25em;
      box-shadow: 0 0.35rem 0.75rem rgba(15, 23, 42, 0.18);
      animation: notification-in 160ms ease-out;
      font-size: 0.9rem;
      line-height: 1.35;

      & > p {
        margin: 0;
        padding-right: 0.85rem;
        overflow-wrap: anywhere;

        & > a {
          color: #ffffff;
          text-decoration: underline;
        }
      }

      & > .close {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 0;
        border: 0;
        background: transparent;
        color: #ffffff;
        font-size: 0.9rem;
        line-height: 1;
        cursor: pointer;
      }

      &.Notification-warning {
        background-color: #ce9c1d;
      }

      &.Notification-error {
        background-color: #a9151d;
      }

      &.closing {
        animation: notification-out 180ms ease-in forwards;
      }

      & > .progress {
        display: none;
        position: absolute;
        inset: auto 0 0 0;
        height: 0.18rem;
        background: rgba(255, 255, 255, 0.72);
        transform-origin: left center;
      }

      &.auto-hide > .progress {
        display: block;
        animation: notification-timeout var(--notification-timeout, 7000ms) linear forwards;
      }
    }
  }

  @keyframes notification-in {
    from {
      opacity: 0;
      transform: translateY(-0.35rem);
    }

    to {
      opacity: 1;
      transform: translateY(0);
    }
  }

  @keyframes notification-out {
    from {
      opacity: 1;
      transform: translateY(0);
    }

    to {
      opacity: 0;
      transform: translateY(-0.35rem);
    }
  }

  @keyframes notification-timeout {
    from {
      transform: scaleX(1);
    }

    to {
      transform: scaleX(0);
    }
  }
}

:root {
  --popup-radius: 0.5rem;
  --popup-shadow: 0 20px 45px rgb(15 23 42 / 18%);
  --popup-border-color: #d7dde5;

  --popup-header-bg: #f7f9fb;
  --popup-header-fg: #111827;

  --popup-body-bg: #ffffff;
  --popup-body-fg: #111827;

  --popup-footer-bg: #ffffff;

  --popup-gap: 0.75rem;
  --popup-pad: 1rem;
  --popup-title-size: 1.125rem;

  --popup-width-min: 320px;
  --popup-width: 64vw;
  --popup-width-max: 1180px;

  --popup-height-min: 240px;
  --popup-height: auto;
  --popup-height-max: 85vh;

  --focus-ring: 0 0 0 3px rgba(66, 153, 225, 0.6);
}

.popup {
  position: relative;
  display: grid;
  grid-template-rows: auto 1fr auto;
  align-items: stretch;
  overflow: hidden;

  width: clamp(var(--popup-width-min), var(--popup-width), var(--popup-width-max));
  height: clamp(var(--popup-height-min), var(--popup-height), var(--popup-height-max));
  max-width: 100vw;
  max-height: calc(100vh - 30px);

  background: var(--popup-body-bg);
  color: var(--popup-body-fg);
  border: 1px solid var(--popup-border-color);
  border-radius: var(--popup-radius);
  box-shadow: var(--popup-shadow);

  /* For tiny-modal frame that uses width:min-content; ensure it shrinks nicely */
  container-type: inline-size;
}

/* Header */
.popup > header {
  position: sticky; /* stays visible when content scrolls */
  top: 0;
  z-index: 1;
  display: grid;
  grid-template-columns: 1fr auto auto; /* title | nav | close */
  align-items: center;
  gap: var(--popup-gap);
  padding: var(--popup-pad);
  background-color: var(--popup-header-bg);
  border-bottom: 1px solid var(--popup-border-color);
  color: var(--popup-header-fg);
}

.popup > header > h2 {
  margin: 0;
  font-size: var(--popup-title-size);
  line-height: 1.2;
  font-weight: 600;
  color: var(--popup-header-fg);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Optional nav container injected when onPrev/onNext provided */
.popup > header > .nav {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}

/* Close button (simple anchor with icon span) */
.popup > header > a {
  justify-self: end;
  font-size: 1rem;
  color: #526071;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.75rem;
  height: 1.75rem;
  padding: 0.25rem;
  border-radius: 0.25rem;
  outline: none;
}

.popup > header > a:hover {
  color: #1b6cb7;
  background: #eaf3ff;
}

.popup > header > a:focus-visible {
  box-shadow: var(--focus-ring);
}

/* If you use <span class="fa fa-close"> */
.popup > header > a > span {
  display: block;
  line-height: 1;
}

/* Body */
.popup > main {
  overflow: auto;
  padding: var(--popup-pad);
  background-color: var(--popup-body-bg);
  color: var(--popup-body-fg);
}

/* Footer */
.popup > footer {
  position: sticky; /* stays visible when content scrolls */
  bottom: 0;
  z-index: 1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 1rem;

  padding: calc(var(--popup-pad) * 0.75) var(--popup-pad);
  background: var(--popup-footer-bg);
  border-top: 1px solid var(--popup-border-color);
}

/* Works with your Button.css (.button base class) */
.popup > footer .button {
  min-height: 2rem;
  margin: 0; /* gap handles spacing */
  padding: 0.35rem 0.75rem;
  gap: 0.375rem;
  font-size: 0.875rem;
  text-transform: none;
}

.popup > footer .button.primary,
.popup > footer .button.btn-primary {
  --button-color: #1b6cb7;
  --button-text-color: #ffffff;
}

.popup > footer .button > .text,
.popup > footer .button > .icon {
  margin: 0;
}

/* Responsive tweaks */
@media (max-width: 768px) {
  :root {
    --popup-title-size: 1rem;
  }

  .popup {
    width: min(92vw, var(--popup-width-max));
  }

  .popup > header {
    grid-template-columns: 1fr auto auto;
    padding: 0.6rem 0.75rem;
  }

  .popup > main {
    padding: 0.6rem 0.75rem;
  }

  .popup > footer {
    gap: 0.75rem;
  }
}

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
  .popup, .popup * {
    transition: none !important;
    animation: none !important;
  }
}

@layer component {
  .modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    font-size: 1rem;
    background-color: #ffffffaa;

    &:empty {
      opacity: 0;
      z-index: -1;
      transition: opacity 250ms cubic-bezier(.4, 0, 0, 1) 150ms, z-index 0ms cubic-bezier(.4, 0, 0, 1) 400ms;
    }

    &:not(:empty) {
      opacity: 1;
      z-index: 1000;
      transition: opacity 250ms cubic-bezier(.4, 0, 0, 1) 0ms, z-index 0ms cubic-bezier(.4, 0, 0, 1) 0s;
    }

    & > div {
      width: 100%;
      height: 100%;
      display: flex;
      flex-direction: column;
      align-items: center;
      justify-content: center;
      opacity: 0;
      transition: opacity 500ms cubic-bezier(.4, 0, 0, 1);

      &.active {
        opacity: 1;
      }

      & > div {
        width: min-content;
        height: min-content;
        max-width: 100vw;
        max-height: calc(100vh - 30px);
        background-color: #ffffff;
        color: #000000;
      }
    }
  }
}

