/* ==========================================================================
   RelayEngine Core: basestyles.css
   Modern Native CSS Foundation with Hex Master Palette & color-mix()
   ========================================================================== */

:root {
    /* ==========================================================================
     1. MASTER 6-COLOR PALETTE (Standard Hex Codes)
     ========================================================================== */
    --color-canvas: #f8fafc;
    /* 1. Base page background */
    --color-surface: #ffffff;
    /* 2. Card, modal, panel, and dropdown surfaces */
    --color-content: #0f172a;
    /* 3. Headings, body copy, and main readable text */
    --color-primary: #2563eb;
    /* 4. Primary buttons, active states, key focus borders */
    --color-secondary: #475569;
    /* 5. Secondary buttons, subtle borders, subtext */
    --color-accent: #0284c7;
    /* 6. Badges, status highlights, telemetry indicators */

    /* ==========================================================================
     2. THEMEABLE GEOMETRY & LAYOUT
     ========================================================================== */
    --container-max-w: 1200px;
    --section-padding: clamp(2.5rem, 6vw, 5rem);
    --card-padding: clamp(1.25rem, 3vw, 2rem);
    --card-radius: 12px;
    --card-border-width: 1px;
    --btn-radius: 6px;
    --input-radius: 6px;
    --gap-base: clamp(1rem, 2vw, 1.5rem);

    /* Typography */
    --font-sans: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, monospace;
    --font-base: 16px;
    --line-height-body: 1.6;
    --line-height-heading: 1.2;

    /* ==========================================================================
     3. DERIVED ELEMENT TOKENS (Computed via color-mix)
     ========================================================================== */
    --text-main: var(--color-content);
    --text-muted: color-mix(in srgb, var(--color-content) 65%, transparent);
    --text-subtle: color-mix(in srgb, var(--color-content) 40%, transparent);
    --text-inverse: var(--color-canvas);

    --border-subtle: color-mix(in srgb, var(--color-content) 12%, transparent);
    --border-focus: var(--color-primary);

    --bg-page: var(--color-canvas);
    --bg-card: var(--color-surface);
    --bg-card-hover: color-mix(in srgb, var(--color-content) 4%, var(--color-surface));
    --card-shadow: 0 4px 20px -2px color-mix(in srgb, var(--color-content) 6%, transparent);

    --btn-primary-bg: var(--color-primary);
    --btn-primary-txt: var(--color-canvas);
    --btn-primary-hover: color-mix(in srgb, var(--color-primary) 85%, black);

    --input-bg: var(--color-surface);
    --input-border: color-mix(in srgb, var(--color-content) 20%, transparent);

    /* Status Colors */
    --status-success: #16a34a;
    --status-warning: #ca8a04;
    --status-danger: #dc2626;
    --status-info: var(--color-accent);
}

/* ==========================================================================
   GLOBAL RESET & DOCUMENT SKELETON
   ========================================================================== */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-page);
    color: var(--text-main);
    font-family: var(--font-sans);
    font-size: var(--font-base);
    line-height: var(--line-height-body);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

main {
    flex: 1 0 auto;
}

img,
svg,
video {
    display: block;
    max-width: 100%;
    height: auto;
}

/* ==========================================================================
   TYPOGRAPHY
   ========================================================================== */
h1,
h2,
h3,
h4,
h5,
h6 {
    color: var(--text-main);
    line-height: var(--line-height-heading);
    font-weight: 600;
    letter-spacing: -0.02em;
    margin-bottom: 0.5em;
}

h1 {
    font-size: clamp(2rem, 5vw, 3rem);
}

h2 {
    font-size: clamp(1.5rem, 3.5vw, 2.25rem);
}

h3 {
    font-size: clamp(1.25rem, 2.5vw, 1.65rem);
}

h4 {
    font-size: 1.2rem;
}

p {
    margin-bottom: 1em;
    color: var(--text-muted);

    &:last-child {
        margin-bottom: 0;
    }
}

small {
    font-size: 0.85em;
    color: var(--text-subtle);
}

code,
pre,
kbd {
    font-family: var(--font-mono);
}

/* ==========================================================================
   CONTAINERS, SECTIONS & FLEX/GRID LAYOUTS
   ========================================================================== */
.container {
    width: 100%;
    max-width: var(--container-max-w);
    margin-inline: auto;
    padding-inline: var(--gap-base);

    &.narrow {
        max-width: 768px;
    }

    &.fluid {
        max-width: 100%;
    }
}

.section {
    padding-block: var(--section-padding);
    width: 100%;
}

.row {
    display: flex;
    flex-direction: column;
    gap: var(--gap-base);
    width: 100%;

    @media (min-width: 768px) {
        flex-direction: row;
        flex-wrap: wrap;
    }
}

.col {
    flex: 1 1 0%;
    min-width: 0;

    @media (min-width: 768px) {
        &.col-2 {
            flex: 0 0 calc(50% - (var(--gap-base) / 2));
        }

        &.col-3 {
            flex: 0 0 calc(33.333% - (var(--gap-base) * 2 / 3));
        }

        &.col-4 {
            flex: 0 0 calc(25% - (var(--gap-base) * 3 / 4));
        }
    }
}

/* ==========================================================================
   CARDS & PANELS
   ========================================================================== */
.card,
.panel {
    background-color: var(--bg-card);
    border: var(--card-border-width) solid var(--border-subtle);
    border-radius: var(--card-radius);
    padding: var(--card-padding);
    box-shadow: var(--card-shadow);
    display: flex;
    flex-direction: column;
    transition: border-color 0.2s ease, transform 0.2s ease, background-color 0.2s ease;

    .card-header {
        border-bottom: 1px solid var(--border-subtle);
        padding-bottom: 0.75rem;
        margin-bottom: 1rem;
    }

    .card-body {
        flex: 1 1 auto;
    }

    .card-footer {
        border-top: 1px solid var(--border-subtle);
        padding-top: 0.75rem;
        margin-top: 1rem;
    }

    /* Modifiers */
    &.interactive:hover {
        border-color: var(--border-focus);
        background-color: var(--bg-card-hover);
        transform: translateY(-2px);
        cursor: pointer;
    }

    &.fullwidth {
        width: 100%;
        flex: 1 1 100%;
    }

    &.featured {
        border-color: color-mix(in srgb, var(--color-primary) 40%, transparent);
        border-top: 3px solid var(--color-primary);
    }
}

/* ==========================================================================
   NAVIGATION & HEADERS
   ========================================================================== */
.navbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem var(--gap-base);
    background-color: var(--color-surface);
    border-bottom: 1px solid var(--border-subtle);
    width: 100%;

    .nav-brand {
        font-weight: 700;
        font-size: 1.15rem;
        color: var(--text-main);
        text-decoration: none;
    }

    .nav-menu {
        display: flex;
        align-items: center;
        gap: 1.25rem;
        list-style: none;
    }

    .nav-link {
        color: var(--text-muted);
        text-decoration: none;
        font-size: 0.95rem;
        font-weight: 500;
        transition: color 0.15s ease;

        &:hover,
        &.active {
            color: var(--color-primary);
        }
    }
}

/* ==========================================================================
   ARTICLES & PROSE
   ========================================================================== */
.article {
    line-height: 1.75;

    p {
        color: var(--text-main);
        margin-bottom: 1.25em;
    }

    blockquote {
        border-left: 3px solid var(--color-primary);
        padding-left: 1rem;
        margin: 1.5rem 0;
        color: var(--text-muted);
        font-style: italic;
    }

    img {
        border-radius: var(--card-radius);
        border: 1px solid var(--border-subtle);
        margin: 1.5rem 0;
    }
}

/* ==========================================================================
   FORMS & INPUT CONTROLS
   ========================================================================== */
.form-group {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-bottom: 1.25rem;
    width: 100%;

    label {
        font-size: 0.875rem;
        font-weight: 500;
        color: var(--text-main);
    }

    input,
    select,
    textarea {
        width: 100%;
        padding: 0.65rem 0.85rem;
        background-color: var(--input-bg);
        border: 1px solid var(--input-border);
        border-radius: var(--input-radius);
        color: var(--text-main);
        font-family: inherit;
        font-size: 0.95rem;
        transition: border-color 0.15s ease, box-shadow 0.15s ease;

        &:focus {
            outline: none;
            border-color: var(--border-focus);
            box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 15%, transparent);
        }
    }

    textarea {
        min-height: 120px;
        resize: vertical;
    }
}

/* ==========================================================================
   BUTTONS & BADGES
   ========================================================================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.6rem 1.25rem;
    font-size: 0.95rem;
    font-weight: 500;
    border-radius: var(--btn-radius);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    background-color: var(--btn-primary-bg);
    color: var(--btn-primary-txt);
    transition: background-color 0.15s ease, transform 0.15s ease;

    &:hover {
        background-color: var(--btn-primary-hover);
    }

    &.btn-secondary {
        background-color: transparent;
        border-color: var(--border-subtle);
        color: var(--text-main);

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

    &.fullwidth {
        width: 100%;
    }

    &.btn-sm {
        padding: 0.35rem 0.75rem;
        font-size: 0.825rem;
    }

    &.btn-lg {
        padding: 0.85rem 1.75rem;
        font-size: 1.05rem;
    }
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.2rem 0.5rem;
    font-size: 0.75rem;
    font-weight: 600;
    border-radius: 4px;
    background-color: color-mix(in srgb, var(--color-accent) 12%, transparent);
    border: 1px solid color-mix(in srgb, var(--color-accent) 25%, transparent);
    color: var(--color-accent);

    &.badge-primary {
        background-color: color-mix(in srgb, var(--color-primary) 12%, transparent);
        border-color: color-mix(in srgb, var(--color-primary) 25%, transparent);
        color: var(--color-primary);
    }
}

/* ==========================================================================
   DATA TABLES & LISTS
   ========================================================================== */
.table-wrapper {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-bottom: 1.5rem;
}

table,
.table {
    width: 100%;
    border-collapse: collapse;

    th,
    td {
        padding: 0.75rem 1rem;
        text-align: left;
        border-bottom: 1px solid var(--border-subtle);
        font-size: 0.9rem;
    }

    th {
        font-weight: 600;
        color: var(--text-muted);
        background-color: color-mix(in srgb, var(--color-surface) 60%, transparent);
    }

    tr:hover td {
        background-color: var(--bg-card-hover);
    }
}

/* ==========================================================================
   MODALS & DIALOGS
   ========================================================================== */
dialog,
.modal {
    background-color: var(--color-surface);
    color: var(--text-main);
    border: 1px solid var(--border-subtle);
    border-radius: var(--card-radius);
    padding: var(--card-padding);
    box-shadow: 0 16px 40px -8px color-mix(in srgb, var(--color-content) 20%, transparent);
    max-width: 540px;
    width: 90%;
    margin: auto;

    &::backdrop {
        background-color: color-mix(in srgb, var(--color-content) 40%, transparent);
        backdrop-filter: blur(4px);
    }
}

/* ==========================================================================
   UTILITY MODIFIERS
   ========================================================================== */
.text-center {
    text-align: center;
}

.text-left {
    text-align: left;
}

.text-right {
    text-align: right;
}

.text-muted {
    color: var(--text-muted);
}

.text-subtle {
    color: var(--text-subtle);
}

.text-mono {
    font-family: var(--font-mono);
}

.w-full {
    width: 100%;
}

.h-full {
    height: 100%;
}

.m-0 {
    margin: 0 !important;
}

.mt-sm {
    margin-top: 0.5rem;
}

.mt-md {
    margin-top: 1rem;
}

.mt-lg {
    margin-top: 1.5rem;
}

.mb-sm {
    margin-bottom: 0.5rem;
}

.mb-md {
    margin-bottom: 1rem;
}

.mb-lg {
    margin-bottom: 1.5rem;
}

.hidden {
    display: none !important;
}

@media (max-width: 767px) {
    .hidden-mobile {
        display: none !important;
    }
}

@media (min-width: 768px) {
    .hidden-desktop {
        display: none !important;
    }
}