@import url("https://fonts.googleapis.com/css2?family=Lato:wght@300;400;700;900&display=swap");

/* 1. Design Tokens */
:root {
    --nzb-lime: #99FF99;
    --nzb-lime-dim: #6EE06E;
    --nzb-black: #0D0D0D;
    --nzb-ash: #3D4A3E;

    --nzb-bg: #F5F5F0;
    --nzb-surface: #FFFFFF;
    --nzb-surface-raised: #FAFAF7;
    --nzb-surface-zebra: #F0F0EB;
    --nzb-border: #E0E0D8;
    --nzb-border-strong: #C8C8C0;

    --nzb-text-primary: #0D0D0D;
    --nzb-text-secondary: #3D4A3E;
    --nzb-text-muted: #7A8A7B;
    --nzb-text-inverse: #F5F5F0;

    --nzb-success: #99FF99;
    --nzb-warning: #F5C842;
    --nzb-danger: #E05050;
    --nzb-info: #6699CC;

    --nzb-weight-black: 900;
    --nzb-weight-bold: 700;
    --nzb-weight-regular: 400;
    --nzb-weight-light: 300;

    --nzb-size-hero: 80px;
    --nzb-size-2xl: 32px;
    --nzb-size-xl: 24px;
    --nzb-size-md: 16px;
    --nzb-size-base: 14px;
    --nzb-size-sm: 12px;
    --nzb-size-xs: 11px;

    --nzb-sidebar-width: 240px;
    --nzb-sidebar-collapsed: 56px;
    --nzb-topbar-height: 56px;
    --nzb-card-padding: 24px;
    --nzb-radius: 4px;
    --nzb-gap: 24px;

    --nzb-duration-bar: 800ms;
    --nzb-duration-ui: 150ms;
    --nzb-duration-sidebar: 250ms;
    --nzb-ease-out: cubic-bezier(0.16, 1, 0.3, 1);
}

/* 2. Global Reset */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-rendering: optimizeLegibility;
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-height: 100vh;
    background: var(--nzb-bg);
    color: var(--nzb-text-primary);
    font-family: "Lato", sans-serif;
    font-size: var(--nzb-size-base);
    line-height: 1.5;
}

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

a {
    color: var(--nzb-text-primary);
    text-decoration: none;
    transition: color var(--nzb-duration-ui) ease-out;
}

a:hover,
a:focus-visible {
    color: var(--nzb-ash);
}

button,
input,
select,
textarea {
    font: inherit;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--nzb-border);
    border-radius: var(--nzb-radius);
    background: var(--nzb-surface);
    color: var(--nzb-text-primary);
    padding: 12px 14px;
    transition: border-color var(--nzb-duration-ui) ease-out, background-color var(--nzb-duration-ui) ease-out;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
    outline: 2px solid var(--nzb-lime);
    outline-offset: 0;
}

input::placeholder,
textarea::placeholder {
    color: var(--nzb-text-muted);
}

table,
.nzb-data,
[data-numeric] {
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
}

code,
pre {
    font-family: "Lato", sans-serif;
}

/* 3. Typography Scale */
h1,
.nzb-h1 {
    margin: 0;
    color: var(--nzb-text-primary);
    font-size: var(--nzb-size-2xl);
    font-weight: var(--nzb-weight-black);
    line-height: 1.1;
}

h2,
.nzb-h2 {
    margin: 0;
    color: var(--nzb-text-primary);
    font-size: var(--nzb-size-xl);
    font-weight: var(--nzb-weight-bold);
    letter-spacing: 0.08em;
    line-height: 1.2;
    text-transform: uppercase;
}

h3,
.nzb-h3 {
    margin: 0;
    color: var(--nzb-text-primary);
    font-size: var(--nzb-size-md);
    font-weight: var(--nzb-weight-bold);
    line-height: 1.3;
}

p,
.nzb-body {
    margin: 0;
    color: var(--nzb-text-secondary);
    font-size: var(--nzb-size-base);
}

.nzb-meta,
label,
summary,
.header-container,
.conclusion-container {
    color: var(--nzb-text-secondary);
    font-size: var(--nzb-size-xs);
    font-weight: var(--nzb-weight-light);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.nzb-caption,
small {
    color: var(--nzb-text-muted);
    font-size: var(--nzb-size-sm);
    font-weight: var(--nzb-weight-light);
}

.nzb-score-number {
    color: var(--nzb-text-primary);
    font-size: var(--nzb-size-hero);
    font-weight: var(--nzb-weight-black);
    letter-spacing: -0.02em;
    line-height: 1;
}

/* 4. Layout */
.wrapper,
.nzb-page {
    width: min(1180px, calc(100% - 48px));
    margin: 0 auto;
}

.wrapper {
    padding: 32px 0 48px;
}

.nzb-shell {
    display: flex;
    min-height: 100vh;
}

.nzb-sidebar {
    width: var(--nzb-sidebar-width);
    flex: 0 0 var(--nzb-sidebar-width);
    background: var(--nzb-black);
    color: var(--nzb-text-inverse);
    transition: width var(--nzb-duration-sidebar) ease-in-out, flex-basis var(--nzb-duration-sidebar) ease-in-out;
}

.nzb-main {
    flex: 1;
    min-width: 0;
    background: var(--nzb-bg);
}

.nzb-topbar {
    min-height: var(--nzb-topbar-height);
    border-bottom: 1px solid var(--nzb-border);
    background: var(--nzb-surface);
}

.nzb-grid,
.flex-section {
    display: grid;
    grid-template-columns: repeat(12, minmax(0, 1fr));
    gap: var(--nzb-gap);
    align-items: start;
}

.nzb-col-4 {
    grid-column: span 4;
}

.nzb-col-6 {
    grid-column: span 6;
}

.nzb-col-8 {
    grid-column: span 8;
}

.nzb-col-12 {
    grid-column: span 12;
}

.flex-section > *:first-child {
    grid-column: span 8;
}

.flex-section > *:last-child {
    grid-column: span 4;
}

/* 5. Components */
.nzb-card,
form,
.highlight-box,
body > .wrapper > header,
.button-container,
.call-to-action,
pre#log {
    background: var(--nzb-surface);
    border: 1px solid var(--nzb-border);
    border-radius: var(--nzb-radius);
    box-shadow: 0 8px 24px color-mix(in srgb, var(--nzb-black) 5%, transparent);
}

body > .wrapper > header {
    padding: 24px;
    margin-bottom: 24px;
}

body > .wrapper > header h1 {
    margin-bottom: 8px;
}

form {
    padding: var(--nzb-card-padding);
}

.nzb-card__header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
}

.nzb-card__body {
    display: grid;
    gap: 16px;
}

.nzb-score-block {
    display: grid;
    gap: 12px;
    padding: var(--nzb-card-padding);
    border: 1px solid var(--nzb-border);
    border-radius: var(--nzb-radius);
    background: var(--nzb-surface);
}

.nzb-score-block__label {
    color: var(--nzb-text-muted);
    font-size: var(--nzb-size-xs);
    font-weight: var(--nzb-weight-light);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.nzb-score-block__number {
    display: flex;
    align-items: baseline;
    gap: 8px;
}

.nzb-score-block__unit {
    color: var(--nzb-text-muted);
    font-size: var(--nzb-size-md);
    font-weight: var(--nzb-weight-regular);
}

.nzb-score-block__meta {
    color: var(--nzb-text-secondary);
    font-size: var(--nzb-size-sm);
}

.nzb-bar {
    overflow: hidden;
    height: 8px;
    border-radius: var(--nzb-radius);
    background: var(--nzb-border);
}

.nzb-bar--sm {
    height: 6px;
}

.nzb-bar--lg {
    height: 10px;
}

.nzb-bar__fill {
    width: 0;
    height: 100%;
    background: var(--nzb-lime);
    animation: nzb-bar-resolve var(--nzb-duration-bar) var(--nzb-ease-out) var(--nzb-bar-delay, 0ms) forwards;
}

.nzb-bar--indeterminate .nzb-bar__fill {
    width: 30%;
    animation: nzb-bar-travel 1.4s ease-in-out infinite;
}

@keyframes nzb-bar-resolve {
    from {
        width: 0;
    }
    to {
        width: var(--nzb-bar-value, 100%);
    }
}

@keyframes nzb-bar-travel {
    0% {
        margin-left: 0;
    }
    50% {
        margin-left: 70%;
    }
    100% {
        margin-left: 0;
    }
}

.nzb-btn,
button,
.call-to-action a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    padding: 10px 16px;
    border: 1px solid var(--nzb-black);
    border-radius: var(--nzb-radius);
    background: var(--nzb-black);
    color: var(--nzb-lime);
    cursor: pointer;
    font-size: var(--nzb-size-base);
    font-weight: var(--nzb-weight-bold);
    line-height: 1;
    transition: background-color var(--nzb-duration-ui) ease-out, color var(--nzb-duration-ui) ease-out, border-color var(--nzb-duration-ui) ease-out;
}

.nzb-btn:hover,
.nzb-btn:focus-visible,
button:hover,
button:focus-visible,
.call-to-action a:hover,
.call-to-action a:focus-visible {
    background: var(--nzb-ash);
    border-color: var(--nzb-ash);
    color: var(--nzb-text-inverse);
}

.nzb-btn--secondary {
    background: var(--nzb-surface);
    color: var(--nzb-text-primary);
}

.nzb-btn--secondary:hover,
.nzb-btn--secondary:focus-visible {
    background: var(--nzb-surface-zebra);
    color: var(--nzb-text-primary);
}

.nzb-btn--ghost {
    background: transparent;
    color: var(--nzb-text-primary);
}

.nzb-btn--danger {
    background: var(--nzb-danger);
    border-color: var(--nzb-danger);
    color: var(--nzb-text-inverse);
}

.nzb-btn--sm {
    min-height: 36px;
    padding: 8px 12px;
    font-size: var(--nzb-size-sm);
}

.nzb-btn--lg {
    min-height: 48px;
    padding: 12px 18px;
}

.nzb-btn--loading,
button:disabled {
    cursor: wait;
    opacity: 0.7;
}

.nzb-badge {
    display: inline-flex;
    align-items: center;
    min-height: 24px;
    padding: 4px 8px;
    border: 1px solid var(--nzb-border-strong);
    border-radius: var(--nzb-radius);
    background: var(--nzb-surface-zebra);
    color: var(--nzb-text-primary);
    font-size: var(--nzb-size-xs);
    font-weight: var(--nzb-weight-bold);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

.nzb-badge--low,
.nzb-badge--ai {
    background: color-mix(in srgb, var(--nzb-lime) 20%, var(--nzb-surface));
    border-color: var(--nzb-lime);
}

.nzb-badge--medium {
    background: color-mix(in srgb, var(--nzb-warning) 20%, var(--nzb-surface));
    border-color: var(--nzb-warning);
}

.nzb-badge--high {
    background: color-mix(in srgb, var(--nzb-danger) 16%, var(--nzb-surface));
    border-color: var(--nzb-danger);
}

.nzb-badge--scope1,
.nzb-badge--scope2,
.nzb-badge--scope3,
.nzb-badge--neutral {
    background: var(--nzb-surface-zebra);
    border-color: var(--nzb-border-strong);
}

.nzb-field,
.mode-block {
    gap: 8px;
}

.mode-block {
    display: none;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid var(--nzb-border);
}

.nzb-label,
label {
    display: block;
    margin-bottom: 0;
}

.nzb-input,
.nzb-select,
.nzb-textarea {
    width: 100%;
}

form > div:first-child {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 12px;
}

form > div:first-child label {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 8px 12px;
    border: 1px solid var(--nzb-border);
    border-radius: var(--nzb-radius);
    background: var(--nzb-surface-raised);
    color: var(--nzb-text-primary);
    cursor: pointer;
    font-size: var(--nzb-size-base);
    font-weight: var(--nzb-weight-bold);
    letter-spacing: 0;
    text-transform: none;
}

input[type="radio"] {
    width: 14px;
    height: 14px;
    margin: 0;
    accent-color: var(--nzb-black);
}

input[type="file"] {
    padding: 10px;
    background: var(--nzb-surface-raised);
}

select[multiple],
#name_suggestions {
    min-height: 144px;
    background: var(--nzb-surface-raised);
}

hr {
    margin: 20px 0;
    border: 0;
    border-top: 1px solid var(--nzb-border);
}

.nzb-table-wrapper {
    overflow-x: auto;
    border: 1px solid var(--nzb-border);
    border-radius: var(--nzb-radius);
}

table,
.nzb-table,
table.table {
    width: 100%;
    border-collapse: collapse;
    background: var(--nzb-surface);
    font-size: var(--nzb-size-base);
    text-align: left;
}

thead th,
th {
    padding: 12px 14px;
    border-bottom: 1px solid var(--nzb-border-strong);
    background: var(--nzb-surface-zebra);
    color: var(--nzb-text-secondary);
    font-size: var(--nzb-size-xs);
    font-weight: var(--nzb-weight-bold);
    letter-spacing: 0.08em;
    text-transform: uppercase;
}

tbody td,
td {
    padding: 12px 14px;
    border-bottom: 1px solid var(--nzb-border);
    color: var(--nzb-text-primary);
    vertical-align: middle;
}

tbody tr:nth-child(even) td {
    background: var(--nzb-surface-zebra);
}

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

.nzb-table__rank {
    width: 64px;
    font-weight: var(--nzb-weight-bold);
}

.nzb-measures {
    display: grid;
    gap: 12px;
    padding: 0;
    margin: 0;
    list-style: none;
}

.nzb-measure-item {
    display: grid;
    grid-template-columns: 48px 1fr minmax(180px, 240px);
    gap: 16px;
    align-items: center;
    padding: 16px;
    border: 1px solid var(--nzb-border);
    border-radius: var(--nzb-radius);
    background: var(--nzb-surface);
}

.nzb-measure-item__rank {
    color: var(--nzb-text-muted);
    font-size: var(--nzb-size-md);
    font-weight: var(--nzb-weight-black);
}

.nzb-measure-item__body,
.nzb-measure-item__bar {
    display: grid;
    gap: 8px;
}

.nzb-measure-item__name,
.nzb-measure-item__value {
    color: var(--nzb-text-primary);
    font-weight: var(--nzb-weight-bold);
}

.nzb-empty {
    display: grid;
    gap: 12px;
    justify-items: start;
    padding: var(--nzb-card-padding);
    border: 1px solid var(--nzb-border);
    border-radius: var(--nzb-radius);
    background: var(--nzb-surface);
}

.call-to-action {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-top: 24px;
    padding: 20px 24px;
}

.call-to-action p {
    color: var(--nzb-text-primary);
}

.button-container {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: flex-start;
    gap: 16px;
    margin: 24px 0;
    padding: 20px;
}

.button-container form {
    flex: 0 0 auto;
    margin: 0;
    padding: 0;
    background: transparent;
    border: 0;
    box-shadow: none;
}

.highlight-box {
    padding: 20px;
    width: 100%;
}

details {
    border-top: 1px solid var(--nzb-border);
    padding: 12px 0;
}

details:first-of-type {
    border-top: 0;
}

summary {
    cursor: pointer;
    list-style: none;
}

summary::-webkit-details-marker {
    display: none;
}

ul {
    padding-left: 20px;
}

li + li {
    margin-top: 8px;
}

footer {
    padding: 24px;
    color: var(--nzb-text-muted);
    text-align: center;
    font-size: var(--nzb-size-sm);
}

.footer-logo img {
    margin-top: 10px;
}

pre#log {
    overflow: auto;
    min-height: 240px;
    margin-top: 20px;
    padding: 16px;
    background: var(--nzb-black);
    border-color: var(--nzb-black);
    font-size: var(--nzb-size-sm);
    line-height: 1.6;
    white-space: pre-wrap;
}

#status {
    color: var(--nzb-text-primary);
}

.spinner {
    margin: 20px auto;
    border: 8px solid var(--nzb-border);
    border-top: 8px solid var(--nzb-black);
    border-radius: 50%;
    width: 60px;
    height: 60px;
    animation: nzb-spinner 1.2s linear infinite;
}

@keyframes nzb-spinner {
    0% {
        transform: rotate(0deg);
    }
    100% {
        transform: rotate(360deg);
    }
}

/* 6. Utilities */
.nzb-stack {
    display: grid;
    gap: 16px;
}

.nzb-inline {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

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

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

.nzb-sitebar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    min-height: 52px;
    padding: 0 24px;
    border-bottom: 1px solid var(--nzb-border);
    background: var(--nzb-surface-raised);
}

.nzb-sitebar__brand {
    color: var(--nzb-text-primary);
    font-size: var(--nzb-size-sm);
    font-weight: var(--nzb-weight-bold);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.nzb-sitebar__brand strong {
    font-weight: var(--nzb-weight-black);
}

.nzb-top-actions {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 12px;
}

.nzb-home-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 40px;
    padding: 8px 14px;
    border: 1px solid var(--nzb-black);
    border-radius: var(--nzb-radius);
    background: var(--nzb-black);
    color: var(--nzb-text-inverse);
    font-size: var(--nzb-size-sm);
    font-weight: var(--nzb-weight-bold);
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.nzb-home-button:hover,
.nzb-home-button:focus-visible {
    background: var(--nzb-ash);
    border-color: var(--nzb-ash);
    color: var(--nzb-text-inverse);
}

.nzb-home-button__icon {
    width: 14px;
    height: 14px;
    stroke: currentColor;
    stroke-width: 1.8;
    fill: none;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.nzb-site-footer {
    padding: 14px 24px 18px;
    border-top: 1px solid var(--nzb-border);
    background: var(--nzb-surface-raised);
    color: var(--nzb-text-muted);
    font-size: var(--nzb-size-xs);
    line-height: 1.5;
}

.nzb-site-footer strong {
    color: var(--nzb-text-secondary);
    font-weight: var(--nzb-weight-bold);
}

.nzb-commercial-block {
    display: grid;
    gap: 20px;
    align-items: stretch;
    margin: 0 0 24px;
    padding: 24px;
    border: 1px solid var(--nzb-border);
    border-radius: var(--nzb-radius);
    background: var(--nzb-surface);
    box-shadow: 0 8px 24px color-mix(in srgb, var(--nzb-black) 5%, transparent);
}

.nzb-commercial-copy {
    display: grid;
    align-content: center;
    gap: 12px;
}

.nzb-commercial-copy h1 {
    font-size: var(--nzb-size-2xl);
    font-weight: var(--nzb-weight-black);
}

.nzb-commercial-copy h2 {
    margin-top: 8px;
}

.nzb-commercial-copy p {
    max-width: 780px;
    color: var(--nzb-text-secondary);
    font-size: var(--nzb-size-md);
}

.nzb-commercial-copy .nzb-commercial-subtitle {
    color: var(--nzb-text-secondary);
    font-size: var(--nzb-size-xs);
    font-weight: var(--nzb-weight-light);
    letter-spacing: 0.1em;
    text-transform: uppercase;
}

.nzb-commercial-metrics {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}

.nzb-commercial-metric {
    display: grid;
    align-content: center;
    gap: 8px;
    min-height: 118px;
    padding: 16px;
    border: 1px solid var(--nzb-border);
    border-radius: var(--nzb-radius);
    background: var(--nzb-surface-raised);
}

.nzb-commercial-metric strong {
    color: var(--nzb-text-primary);
    font-size: var(--nzb-size-xl);
    font-weight: var(--nzb-weight-black);
    letter-spacing: -0.02em;
    line-height: 1;
}

.nzb-commercial-metric span {
    color: var(--nzb-text-secondary);
    font-size: var(--nzb-size-xs);
    font-weight: var(--nzb-weight-bold);
    letter-spacing: 0.08em;
    line-height: 1.35;
    text-transform: uppercase;
}

/* 7. Dark Mode */
[data-theme="dark"],
.dark {
    --nzb-bg: #0D0D0D;
    --nzb-surface: #1A1A1A;
    --nzb-surface-raised: #222222;
    --nzb-surface-zebra: #161616;
    --nzb-border: #2A2A2A;
    --nzb-border-strong: #3A3A3A;
    --nzb-text-primary: #F0F0EB;
    --nzb-text-secondary: #8A9E8B;
    --nzb-text-muted: #5A6B5B;
}

/* Legacy template adjustments */
body > .wrapper > h1,
body > .wrapper > h2 {
    margin-bottom: 16px;
}

body > .wrapper > h2 {
    color: var(--nzb-text-secondary);
    font-size: var(--nzb-size-md);
}

.nzb-form-title {
    margin-bottom: 24px;
}

.nzb-home-submit {
    margin-top: 36px;
}

@media (max-width: 960px) {
    .wrapper,
    .nzb-page {
        width: calc(100% - 32px);
    }

    .nzb-sitebar {
        padding: 10px 16px;
    }

    .nzb-sitebar__brand {
        font-size: var(--nzb-size-xs);
        line-height: 1.4;
    }

    .nzb-commercial-block {
        grid-template-columns: 1fr;
        padding: 20px;
    }

    .nzb-commercial-metrics {
        grid-template-columns: 1fr;
    }

    .flex-section,
    .nzb-grid {
        grid-template-columns: 1fr;
    }

    .flex-section > *,
    .nzb-col-4,
    .nzb-col-6,
    .nzb-col-8,
    .nzb-col-12 {
        grid-column: auto;
    }

    .nzb-measure-item {
        grid-template-columns: 1fr;
    }

    .button-container {
        flex-direction: column;
        align-items: stretch;
        flex-wrap: wrap;
    }

    .button-container form {
        width: 100%;
    }
}

@media print {
    body {
        background: var(--nzb-surface);
    }

    .wrapper,
    .nzb-page {
        width: 100%;
    }

    .call-to-action,
    form,
    .highlight-box,
    pre#log {
        box-shadow: none;
    }
}
