:root {
    --md-ref-typeface-brand: 'Roboto', sans-serif;
    --md-ref-typeface-plain: 'Roboto', sans-serif;
    --md-icon-font: 'Material Symbols Outlined';

    /* Material 3 Light Theme Tokens (Peanut Amber & Forest Green) */
    --md-sys-color-primary: #6d5e00;
    --md-sys-color-on-primary: #ffffff;
    --md-sys-color-primary-container: #ffe24b;
    --md-sys-color-on-primary-container: #211b00;
    --md-sys-color-secondary: #2e6b34;
    --md-sys-color-on-secondary: #ffffff;
    --md-sys-color-secondary-container: #b0f4ae;
    --md-sys-color-on-secondary-container: #002106;
    --md-sys-color-tertiary: #196584;
    --md-sys-color-on-tertiary: #ffffff;
    --md-sys-color-tertiary-container: #c2e8ff;
    --md-sys-color-on-tertiary-container: #001e2b;
    --md-sys-color-error: #ba1a1a;
    --md-sys-color-on-error: #ffffff;
    --md-sys-color-error-container: #ffdad6;
    --md-sys-color-on-error-container: #410002;
    --md-sys-color-background: #fdf9f0;
    --md-sys-color-on-background: #1d1c16;
    --md-sys-color-surface: #fdf9f0;
    --md-sys-color-on-surface: #1d1c16;
    --md-sys-color-surface-variant: #e9e2d0;
    --md-sys-color-on-surface-variant: #4a4739;
    --md-sys-color-surface-container-lowest: #ffffff;
    --md-sys-color-surface-container-low: #f7f3ea;
    --md-sys-color-surface-container: #f1ede4;
    --md-sys-color-surface-container-high: #ece8df;
    --md-sys-color-surface-container-highest: #e6e2d9;
    --md-sys-color-outline: #7c7767;
    --md-sys-color-outline-variant: #ccc6b5;
}

*, *::before, *::after {
    box-sizing: border-box;
}

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--md-ref-typeface-plain);
    background-color: var(--md-sys-color-background);
    color: var(--md-sys-color-on-background);
    min-height: 100vh;
}

body {
    display: flex;
    flex-direction: column;
}

a {
    color: var(--md-sys-color-primary);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

h1 {
    font-family: 'Outfit', var(--md-ref-typeface-brand);
    font-size: 2rem;
    font-weight: 400;
    letter-spacing: -0.01em;
    line-height: 2.5rem;
    margin: 1rem 0 0.75rem 0;
}

h2 {
    font-family: 'Outfit', var(--md-ref-typeface-brand);
    font-size: 1.5rem;
    font-weight: 400;
    letter-spacing: -0.01em;
    line-height: 2rem;
    margin: 1rem 0 0.5rem 0;
}

md-icon,
.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 250, 'GRAD' 0, 'opsz' 24;
}

pre {
    margin: 0;
}

/* Top App Bar */
.m3-top-app-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    background-color: var(--md-sys-color-surface-container-low);
    color: var(--md-sys-color-on-surface);
    border-bottom: 1px solid var(--md-sys-color-outline-variant);
    box-shadow: none;
}

.m3-top-app-bar-inner {
    max-width: 1280px;
    margin: 0 auto;
    padding: 0.5rem 1rem;
    min-height: 64px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.m3-top-app-bar-start {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.m3-brand {
    display: inline-flex;
    align-items: center;
    gap: 0.625rem;
    color: var(--md-sys-color-on-surface);
    text-decoration: none;
}

.m3-brand:hover {
    text-decoration: none;
}

.m3-brand-logo {
    width: 28px;
    height: 28px;
    object-fit: contain;
}

.m3-brand-title {
    font-family: 'Outfit', var(--md-ref-typeface-brand);
    font-size: 1.25rem;
    font-weight: 300;
    letter-spacing: 0.04em;
    color: var(--md-sys-color-on-surface);
}

.m3-top-nav {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    --md-text-button-label-text-color: var(--md-sys-color-on-surface);
    --md-text-button-hover-label-text-color: var(--md-sys-color-on-surface);
    --md-text-button-focus-label-text-color: var(--md-sys-color-on-surface);
    --md-text-button-pressed-label-text-color: var(--md-sys-color-on-surface);
    --md-text-button-label-text-weight: 400;
    --md-text-button-icon-color: var(--md-sys-color-on-surface-variant);
    --md-text-button-hover-icon-color: var(--md-sys-color-on-surface);
}

/* Mobile Navigation Drawer */
.m3-drawer-scrim {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 200;
}

.m3-drawer-scrim.open {
    display: block;
}

.m3-drawer {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    max-width: 85vw;
    background-color: var(--md-sys-color-surface-container-low);
    color: var(--md-sys-color-on-surface);
    z-index: 201;
    transform: translateX(-100%);
    transition: transform 0.2s ease-out;
    border-radius: 0 16px 16px 0;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
    overflow-y: auto;
}

.m3-drawer.open {
    transform: translateX(0);
}

.m3-drawer-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 1rem;
}

/* Main & Footer */
.m3-main {
    flex: 1 0 auto;
    padding: 1.5rem 0 2.5rem 0;
}

.m3-container {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    padding: 0 1rem;
}

.m3-footer {
    background-color: var(--md-sys-color-secondary);
    color: var(--md-sys-color-on-secondary);
    padding: 0.875rem 0;
    margin-top: auto;
}

/* Responsive visibility */
.m3-mobile-only {
    display: none;
}

@media (max-width: 768px) {
    .m3-desktop-only {
        display: none;
    }
    .m3-mobile-only {
        display: inline-flex;
    }
}

/* Layout & Cards */
.m3-page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

.m3-card {
    background-color: var(--md-sys-color-surface-container-lowest);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 16px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.m3-card-tonal {
    background-color: var(--md-sys-color-surface-container-low);
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 16px;
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}

.m3-grid {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: 1rem;
    align-items: start;
}

.m3-col-12 { grid-column: span 12; }
.m3-col-9  { grid-column: span 9; }
.m3-col-8  { grid-column: span 8; }
.m3-col-6  { grid-column: span 6; }
.m3-col-4  { grid-column: span 4; }
.m3-col-3  { grid-column: span 3; }

@media (max-width: 768px) {
    .m3-col-9, .m3-col-8, .m3-col-6, .m3-col-4, .m3-col-3 {
        grid-column: span 12;
    }
}

.m3-field {
    width: 100%;
}

.m3-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin-top: 0.5rem;
}

.m3-inline-group {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 1rem;
    min-height: 56px;
}

.m3-label-control {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    cursor: pointer;
    font-size: 0.9375rem;
    color: var(--md-sys-color-on-surface);
}

.m3-fab-link {
    display: inline-flex;
    text-decoration: none;
}

.m3-fab-link:hover {
    text-decoration: none;
}

.m3-btn-error {
    --md-outlined-button-label-text-color: var(--md-sys-color-error);
    --md-outlined-button-hover-label-text-color: var(--md-sys-color-error);
    --md-outlined-button-focus-label-text-color: var(--md-sys-color-error);
    --md-outlined-button-pressed-label-text-color: var(--md-sys-color-error);
    --md-outlined-button-outline-color: var(--md-sys-color-error);
}

.m3-error-banner {
    background-color: var(--md-sys-color-error-container);
    color: var(--md-sys-color-on-error-container);
    padding: 0.75rem 1rem;
    border-radius: 12px;
    margin-top: 1rem;
}

/* Chips */
.m3-chip-link {
    display: inline-flex;
    text-decoration: none;
    margin: 2px;
    vertical-align: middle;
}

.m3-chip-link:hover {
    text-decoration: none;
}

.m3-chip {
    --md-assist-chip-container-height: 24px;
    --md-assist-chip-label-text-size: 0.75rem;
    --md-assist-chip-icon-size: 16px;
    vertical-align: middle;
}

.m3-chip-node {
    --md-assist-chip-container-color: #d3e3fd;
    --md-assist-chip-label-text-color: #041e49;
    --md-assist-chip-icon-color: #041e49;
}

.m3-chip-profile {
    --md-assist-chip-container-color: #c4eed0;
    --md-assist-chip-label-text-color: #072711;
    --md-assist-chip-icon-color: #072711;
}

.m3-chip-package {
    --md-assist-chip-container-color: #ffefc1;
    --md-assist-chip-label-text-color: #241a00;
    --md-assist-chip-icon-color: #241a00;
}

.m3-chip-inactive {
    --md-assist-chip-container-color: #e3e3e3;
    --md-assist-chip-label-text-color: #444746;
    --md-assist-chip-icon-color: #444746;
}

.m3-chip-user {
    --md-assist-chip-container-color: var(--md-sys-color-surface-container-low);
    --md-assist-chip-label-text-color: var(--md-sys-color-on-surface);
    --md-assist-chip-icon-color: var(--md-sys-color-on-surface-variant);
}

/* Semantic Status & Icons */
.m3-status-green { color: #146c2e; }
.m3-status-red   { color: #b3261e; }
.m3-status-amber { color: #b06000; }
.m3-status-muted { color: var(--md-sys-color-on-surface-variant); }

.icon-img {
    width: 24px;
    height: 24px;
    vertical-align: middle;
}

.circle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background-color: var(--md-sys-color-tertiary);
    color: #ffffff;
    font-size: 12px;
    font-weight: 500;
}

.circle.green { background-color: #146c2e; }
.circle.red   { background-color: #b3261e; }
.circle.grey  { background-color: #747775; }

.m3-health-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background-color: var(--md-sys-color-surface-container);
    font-size: 0.75rem;
    font-weight: 500;
}

.small-font {
    font-size: 0.75rem;
    color: var(--md-sys-color-on-surface-variant);
}

/* Console & Editors */
#output {
    font-family: monospace;
    font-size: 0.75rem;
    line-height: 1;
    overflow: auto;
    height: 50vh;
    background-color: #1e1e1e;
    color: #f3f3f3;
    padding: 0.75rem;
    border-radius: 12px;
}

#output pre {
    line-height: 1;
}

.m3-console-meta-bar {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    background-color: var(--md-sys-color-surface-container-high);
    color: var(--md-sys-color-on-surface);
    padding: 0.5rem 0.75rem;
    border-radius: 10px;
    font-size: 0.75rem;
    cursor: pointer;
    overflow: hidden;
}

.m3-console-meta-bar:hover {
    background-color: var(--md-sys-color-surface-container-highest);
}

.editor {
    height: 80vh;
    border-radius: 12px;
    border: 1px solid var(--md-sys-color-outline-variant);
}

.scriptarea {
    height: 36vh;
    border-radius: 12px;
    border: 1px solid var(--md-sys-color-outline-variant);
}

/* Tabs */
.m3-tab-panel {
    padding-top: 1rem;
}

.m3-tab-panel[hidden] {
    display: none;
}

/* Multi-select checklist (M3 replacement for <select multiple>) */
.m3-checklist-box {
    border: 1px solid var(--md-sys-color-outline-variant);
    border-radius: 12px;
    max-height: 240px;
    overflow-y: auto;
    background-color: var(--md-sys-color-surface-container-lowest);
    padding: 0.25rem 0.5rem;
}

.m3-checklist-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.35rem 0.5rem;
    border-radius: 8px;
    cursor: pointer;
}

.m3-checklist-item:hover {
    background-color: var(--md-sys-color-surface-container-low);
}

/* Code blocks */
.m3-code-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem;
    background-color: var(--md-sys-color-surface-container);
    border-radius: 10px;
    padding: 0.35rem 0.5rem 0.35rem 1rem;
}

.m3-code-row .m3-code-block {
    flex: 1;
    min-width: 0;
    padding: 0.4rem 0;
    background: transparent;
    border-radius: 0;
}

.m3-code-block {
    display: block;
    background-color: var(--md-sys-color-surface-container);
    color: var(--md-sys-color-on-surface);
    padding: 0.75rem 1rem;
    border-radius: 10px;
    font-family: monospace;
    font-size: 0.875rem;
    overflow-x: auto;
}

/* DataTables M3 integration */
.m3-table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.m3-chip-wrap {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    align-items: center;
}

.m3-nowrap {
    white-space: nowrap;
}

.dataTables_wrapper {
    width: 100%;
    overflow-x: auto;
    font-size: 0.875rem;
    color: var(--md-sys-color-on-surface);
}

.dataTables_wrapper .dataTables_filter input {
    border: 1px solid var(--md-sys-color-outline);
    border-radius: 8px;
    padding: 0.35rem 0.625rem;
    background-color: var(--md-sys-color-surface-container-lowest);
    color: var(--md-sys-color-on-surface);
    margin-left: 0.5rem;
}

table.dataTable {
    border-collapse: collapse !important;
    width: 100% !important;
}

table.dataTable thead th {
    border-bottom: 1px solid var(--md-sys-color-outline-variant) !important;
    color: var(--md-sys-color-on-surface-variant);
    font-weight: 500;
    padding: 0.4rem 0.6rem !important;
    text-align: left;
}

table.dataTable tbody td {
    border-bottom: 1px solid var(--md-sys-color-surface-container-high);
    padding: 0.2rem 0.6rem !important;
    vertical-align: middle;
}

table.dataTable md-filled-tonal-icon-button,
table.dataTable md-icon-button {
    --md-filled-tonal-icon-button-container-width: 28px;
    --md-filled-tonal-icon-button-container-height: 28px;
    --md-filled-tonal-icon-button-icon-size: 18px;
    --md-icon-button-state-layer-width: 28px;
    --md-icon-button-state-layer-height: 28px;
    --md-icon-button-icon-size: 18px;
    width: 28px;
    height: 28px;
    vertical-align: middle;
}

table.dataTable.striped tbody tr:nth-child(odd) {
    background-color: var(--md-sys-color-surface-container-low);
}

table.dataTable tbody tr:hover {
    background-color: var(--md-sys-color-surface-container);
}

.m3-row-muted {
    color: var(--md-sys-color-on-surface-variant);
    opacity: 0.75;
}

/* Key-value system info grid */
.m3-kv-key {
    font-weight: 500;
    color: var(--md-sys-color-on-surface-variant);
    text-align: right;
}

@media (max-width: 768px) {
    .m3-kv-key {
        text-align: left;
    }

    .m3-hide-mobile {
        display: none !important;
    }

    div.m3-mobile-only {
        display: block;
    }

    .m3-main {
        padding: 0.75rem 0 1.5rem 0;
    }

    .m3-container {
        padding: 0 0.5rem;
    }

    .m3-card,
    .m3-card-tonal {
        padding: 0.75rem 0.625rem;
        border-radius: 12px;
    }

    table.dataTable {
        font-size: 0.8125rem;
    }

    table.dataTable thead th,
    table.dataTable tbody td {
        padding: 0.375rem 0.35rem !important;
    }

    .dataTables_wrapper .dataTables_filter {
        float: none !important;
        text-align: left !important;
        margin-bottom: 0.5rem;
    }

    .dataTables_wrapper .dataTables_filter label {
        display: flex;
        align-items: center;
        gap: 0.5rem;
        width: 100%;
    }

    .dataTables_wrapper .dataTables_filter input {
        flex: 1;
        margin-left: 0;
        width: 100%;
    }

    .m3-chip {
        --md-assist-chip-container-height: 24px;
        --md-assist-chip-label-text-size: 0.7rem;
        --md-assist-chip-icon-size: 14px;
        --md-assist-chip-leading-space: 6px;
        --md-assist-chip-trailing-space: 8px;
        --md-assist-chip-icon-label-space: 4px;
        max-width: 100%;
    }

    .circle {
        width: 18px;
        height: 18px;
        font-size: 10px;
    }
}
