/* ==========================================================================
   Layout & Responsive Viewports (Super Mobile-Friendly)
   ========================================================================== */

header {
  background-color: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 30;
  box-shadow: var(--shadow-sm);

  & nav {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;

    & h1 {
      margin: 0;
      font-size: 1.15rem;
      font-weight: 700;

      & a {
        display: inline-flex;
        align-items: center;
        gap: 0.5rem;
        color: var(--primary);
        text-decoration: none;
      }
    }

    & ul {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      list-style: none;
      margin: 0;
      padding: 0;

      & a {
        display: inline-flex;
        align-items: center;
        gap: 0.35rem;
        text-decoration: none;
        color: var(--text-muted);
        font-weight: 500;
        font-size: 0.95rem;
        padding: 0.5rem 0.75rem;
        min-height: 44px;
        border-radius: var(--radius-sm);
        transition: background-color 0.15s, color 0.15s;

        &:hover, &[aria-current="page"] {
          background-color: var(--primary-subtle);
          color: var(--primary);
        }
      }
    }

    & aside {
      display: flex;
      align-items: center;
      gap: 0.5rem;
      flex-wrap: wrap;

      & output {
        display: inline-flex;
        align-items: center;
        gap: 0.35rem;
        font-size: 0.85rem;
        color: var(--text-muted);
        background-color: var(--surface-alt);
        border: 1px solid var(--border);
        padding: 0.4rem 0.65rem;
        border-radius: var(--radius-sm);
      }

      & form {
        margin: 0;

        & button {
          display: inline-flex;
          align-items: center;
          gap: 0.35rem;
          background: transparent;
          color: var(--danger);
          border: 1px solid var(--border);
          padding: 0.4rem 0.65rem;
          min-height: 40px;
          border-radius: var(--radius-sm);
          cursor: pointer;
          font-size: 0.85rem;

          &:hover {
            background-color: var(--danger-bg);
            border-color: var(--danger-border);
          }
        }
      }
    }
  }
}

main {
  flex: 1;
  max-width: 1200px;
  width: 100%;
  margin: 1.5rem auto;
  padding: 0 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.25rem;

  & > header {
    background: transparent;
    border: none;
    box-shadow: none;
    position: static;
    padding: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    flex-wrap: wrap;

    & h2 {
      margin: 0;
      font-size: 1.4rem;
      font-weight: 700;
    }
  }

  & > section {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    box-shadow: var(--shadow-sm);

    & header {
      background: transparent;
      border-bottom: 1px solid var(--border);
      box-shadow: none;
      position: static;
      padding: 0 0 0.75rem 0;
      margin-bottom: 1rem;
      display: flex;
      justify-content: space-between;
      align-items: center;
      gap: 0.75rem;
      flex-wrap: wrap;

      & h3 {
        margin: 0;
        font-size: 1.15rem;
      }
    }
  }
}

/* KPI Summary Cards Grid */
aside[data-grid="stats"] {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.85rem;

  & article {
    background-color: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.1rem;
    box-shadow: var(--shadow-sm);
    display: flex;
    flex-direction: column;
    gap: 0.35rem;

    & h4 {
      margin: 0;
      color: var(--text-muted);
      font-size: 0.85rem;
      font-weight: 500;
    }

    & p {
      margin: 0;
      font-size: 1.7rem;
      font-weight: 700;
      color: var(--primary);
    }
  }
}

footer {
  border-top: 1px solid var(--border);
  padding: 1.25rem 1rem;
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-top: auto;
  background-color: var(--surface);
}

/* Brand Logo & Login Header */
.nav-logo {
  width: 28px;
  height: 28px;
  display: block;
  flex-shrink: 0;
}

.login-brand {
  text-align: center;
  margin-bottom: 1.5rem;

  & .login-logo-img {
    width: 64px;
    height: 64px;
    margin: 0 auto 0.75rem auto;
    display: block;
    filter: drop-shadow(0 4px 8px rgba(37, 99, 235, 0.2));
  }

  & h2 {
    font-size: 1.4rem;
    font-weight: 800;
    color: var(--text-main);
    margin: 0 0 0.35rem 0;
  }

  & p {
    font-size: 0.9rem;
    color: var(--text-muted);
    margin: 0;
  }
}

/* Mobile Screens (< 640px) */
@media (max-width: 640px) {
  header nav {
    flex-direction: column;
    align-items: stretch;
    gap: 0.5rem;

    & ul {
      justify-content: flex-start;
      overflow-x: auto;
      padding-bottom: 0.25rem;
    }

    & aside {
      justify-content: space-between;
    }
  }

  main {
    margin: 1rem auto;
    padding: 0 0.75rem;

    & > section {
      padding: 1rem;
    }
  }
}
