:root {
    --blue-950: #0b2545;
    --blue-900: #0d315d;
    --blue-800: #0e477f;
    --blue-700: #0a63a8;
    --blue-600: #0877c9;
    --blue-500: #1f8dde;
    --blue-100: #e4f2fc;
    --blue-50: #f2f8fd;
    --ink-900: #172335;
    --ink-700: #435169;
    --ink-600: #5a677b;
    --ink-500: #718097;
    --line-strong: #c4d3e1;
    --line: #dbe5ee;
    --surface: #ffffff;
    --surface-soft: #f7f9fc;
    --surface-muted: #eef3f7;
    --danger: #bd2c35;
    --danger-soft: #fff1f2;
    --success: #14754d;
    --shadow-sm: 0 2px 10px rgba(21, 49, 78, 0.06);
    --shadow-md: 0 16px 46px rgba(15, 47, 78, 0.12);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 18px;
    --focus-ring: 0 0 0 3px rgba(31, 141, 222, 0.22);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC",
        "Hiragino Sans GB", "Microsoft YaHei", Arial, sans-serif;
    color: var(--ink-900);
    background: #edf3f8;
    font-synthesis: none;
    text-rendering: optimizeLegibility;
}

* {
    box-sizing: border-box;
}

html {
    min-width: 320px;
    min-height: 100%;
    background: #edf3f8;
}

body {
    min-height: 100vh;
    margin: 0;
    color: var(--ink-900);
    background:
        radial-gradient(circle at 8% 2%, rgba(69, 157, 219, 0.09), transparent 26rem),
        linear-gradient(180deg, #eef5fa 0, #f4f7fa 22rem, #edf3f8 100%);
    font-size: 14px;
    line-height: 1.55;
}

button,
input,
select {
    font: inherit;
}

button,
select {
    cursor: pointer;
}

button:disabled,
select:disabled {
    cursor: not-allowed;
}

[hidden] {
    display: none !important;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.eyebrow {
    margin: 0 0 4px;
    color: var(--blue-700);
    font-size: 11px;
    font-weight: 750;
    letter-spacing: 0.14em;
    line-height: 1.4;
    text-transform: uppercase;
}

.button {
    display: inline-flex;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    font-weight: 700;
    line-height: 1.2;
    text-decoration: none;
    transition: border-color 150ms ease, background-color 150ms ease,
        color 150ms ease, box-shadow 150ms ease, transform 150ms ease;
}

.button:hover:not(:disabled) {
    transform: translateY(-1px);
}

.button:focus-visible,
input:focus-visible,
select:focus-visible,
.tab-button:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

.button:disabled {
    opacity: 0.58;
}

.button-primary {
    border-color: var(--blue-700);
    color: #ffffff;
    background: linear-gradient(135deg, var(--blue-700), var(--blue-600));
    box-shadow: 0 8px 18px rgba(10, 99, 168, 0.18);
}

.button-primary:hover:not(:disabled) {
    background: linear-gradient(135deg, var(--blue-800), var(--blue-700));
}

.button-secondary {
    border-color: #a9c9e3;
    color: var(--blue-800);
    background: var(--blue-50);
}

.button-secondary:hover:not(:disabled) {
    border-color: var(--blue-500);
    background: var(--blue-100);
}

.button-tertiary {
    min-height: 36px;
    padding: 7px 12px;
    border-color: var(--line-strong);
    color: var(--blue-800);
    background: #ffffff;
    box-shadow: var(--shadow-sm);
    font-size: 12px;
}

.button-tertiary:hover:not(:disabled) {
    border-color: #8fbadd;
    background: var(--blue-50);
}

.button-quiet {
    border-color: rgba(255, 255, 255, 0.35);
    color: #ffffff;
    background: rgba(255, 255, 255, 0.08);
}

.button-quiet:hover:not(:disabled) {
    background: rgba(255, 255, 255, 0.16);
}

.button-block {
    width: 100%;
}

.form-alert {
    padding: 11px 13px;
    border: 1px solid;
    border-radius: var(--radius-sm);
    font-size: 13px;
}

.form-alert-error {
    border-color: #f2bcc1;
    color: #8b1e28;
    background: var(--danger-soft);
}

/* Login */

.login-page {
    display: grid;
    place-items: center;
    padding: 28px;
    background:
        radial-gradient(circle at 14% 18%, rgba(89, 167, 224, 0.22), transparent 30%),
        radial-gradient(circle at 84% 86%, rgba(31, 115, 179, 0.14), transparent 32%),
        linear-gradient(150deg, #eaf3fa 0%, #f6f9fc 48%, #e8f0f7 100%);
}

.login-page::before {
    position: fixed;
    inset: 0;
    pointer-events: none;
    content: "";
    opacity: 0.24;
    background-image:
        linear-gradient(rgba(19, 74, 119, 0.06) 1px, transparent 1px),
        linear-gradient(90deg, rgba(19, 74, 119, 0.06) 1px, transparent 1px);
    background-size: 38px 38px;
    mask-image: linear-gradient(to bottom, black, transparent 75%);
}

.login-shell {
    position: relative;
    width: min(100%, 430px);
    z-index: 1;
}

.login-card {
    padding: 36px 38px 30px;
    border: 1px solid rgba(174, 197, 217, 0.8);
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 26px 72px rgba(17, 55, 88, 0.16);
    backdrop-filter: blur(12px);
}

.login-mark {
    position: relative;
    display: grid;
    width: 48px;
    height: 48px;
    place-items: center;
    margin-bottom: 18px;
    border-radius: 14px;
    background: linear-gradient(145deg, var(--blue-800), var(--blue-600));
    box-shadow: 0 10px 24px rgba(10, 99, 168, 0.24);
}

.login-mark::before {
    width: 16px;
    height: 13px;
    border: 2px solid #ffffff;
    border-radius: 7px 7px 3px 3px;
    border-bottom: 0;
    content: "";
    transform: translateY(-6px);
}

.login-mark span {
    position: absolute;
    width: 22px;
    height: 18px;
    margin-top: 7px;
    border-radius: 5px;
    background: #ffffff;
}

.login-mark span::after {
    position: absolute;
    top: 6px;
    left: 9px;
    width: 4px;
    height: 7px;
    border-radius: 3px;
    content: "";
    background: var(--blue-700);
}

.login-heading {
    margin-bottom: 23px;
}

.login-heading h1 {
    margin: 0;
    font-size: 28px;
    line-height: 1.25;
    letter-spacing: -0.02em;
}

.login-heading > p:last-child {
    margin: 8px 0 0;
    color: var(--ink-600);
}

.login-form {
    display: grid;
    gap: 17px;
    margin-top: 20px;
}

.login-methods {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 4px;
    padding: 4px;
    margin: 0;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: var(--surface-muted);
}

.method-option {
    position: relative;
    cursor: pointer;
}

.method-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.method-option span {
    display: flex;
    min-height: 38px;
    align-items: center;
    justify-content: center;
    border-radius: 7px;
    color: var(--ink-600);
    font-size: 13px;
    font-weight: 700;
    transition: background-color 150ms ease, color 150ms ease, box-shadow 150ms ease;
}

.method-option input:checked + span {
    color: var(--blue-800);
    background: #ffffff;
    box-shadow: var(--shadow-sm);
}

.method-option input:focus-visible + span {
    box-shadow: var(--focus-ring);
}

.field-stack,
.input-field {
    display: grid;
    gap: 7px;
}

.field-stack label,
.input-field > span:first-child {
    color: var(--ink-700);
    font-size: 13px;
    font-style: normal;
    font-weight: 700;
}

.field-stack input,
.input-field input,
.data-table input,
.data-table select {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--line-strong);
    border-radius: 7px;
    color: var(--ink-900);
    background: #ffffff;
    transition: border-color 140ms ease, box-shadow 140ms ease, background-color 140ms ease;
}

.field-stack input,
.input-field input {
    padding: 8px 11px;
}

.field-stack input:hover,
.input-field input:hover,
.data-table input:hover,
.data-table select:hover {
    border-color: #8fb6d5;
}

.field-stack input:focus,
.input-field input:focus,
.data-table input:focus,
.data-table select:focus {
    border-color: var(--blue-500);
    outline: none;
    box-shadow: var(--focus-ring);
}

.field-stack input:user-invalid,
.input-field input:user-invalid,
.data-table input:user-invalid {
    border-color: #df7981;
}

.login-options {
    display: grid;
    gap: 5px;
}

.check-option {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    width: fit-content;
    color: var(--ink-700);
    cursor: pointer;
    font-size: 13px;
}

.check-option input {
    width: 16px;
    height: 16px;
    accent-color: var(--blue-700);
}

.local-save-note {
    color: var(--ink-500);
    font-size: 12px;
}

.login-footnote {
    margin: 22px 0 0;
    color: var(--ink-500);
    font-size: 12px;
    text-align: center;
}

.password-note {
    margin: -5px 0 0;
    color: var(--ink-500);
    font-size: 12px;
}

/* Application shell */

.app-header {
    position: sticky;
    top: 0;
    z-index: 20;
    display: flex;
    min-height: 72px;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding: 12px clamp(18px, 2.6vw, 42px);
    color: #ffffff;
    background: linear-gradient(105deg, var(--blue-950), var(--blue-800) 58%, #0968a6);
    box-shadow: 0 8px 26px rgba(12, 42, 69, 0.16);
}

.brand-block {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 13px;
}

.brand-block h1 {
    margin: 0;
    overflow: hidden;
    font-size: clamp(19px, 2vw, 25px);
    line-height: 1.25;
    letter-spacing: -0.02em;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.brand-block .eyebrow {
    color: #8dd1ff;
}

.brand-symbol {
    display: flex;
    width: 42px;
    height: 42px;
    flex: 0 0 42px;
    align-items: flex-end;
    justify-content: center;
    gap: 3px;
    padding: 9px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.1);
}

.brand-symbol span {
    width: 5px;
    border-radius: 3px 3px 1px 1px;
    background: #ffffff;
}

.brand-symbol span:nth-child(1) {
    height: 10px;
    opacity: 0.62;
}

.brand-symbol span:nth-child(2) {
    height: 17px;
    opacity: 0.82;
}

.brand-symbol span:nth-child(3) {
    height: 23px;
}

.header-actions {
    display: flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 12px;
}

.header-status {
    padding: 5px 10px;
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 999px;
    color: #dff3ff;
    background: rgba(255, 255, 255, 0.08);
    font-size: 12px;
    font-weight: 650;
}

.workspace {
    display: grid;
    grid-template-columns: minmax(0, 0.92fr) minmax(0, 1.08fr);
    gap: 18px;
    width: min(1900px, 100%);
    margin: 0 auto;
    padding: 18px clamp(14px, 2vw, 30px) 36px;
    align-items: start;
}

.parameter-card,
.result-card {
    min-width: 0;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
}

.parameter-card {
    overflow: hidden;
    border-color: #d5e2ec;
    box-shadow: 0 12px 36px rgba(22, 57, 88, 0.08);
}

.result-card {
    overflow: hidden;
}

.results-column {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    min-width: 0;
    gap: 18px;
}

.panel-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    padding: 20px 22px;
    border-bottom: 1px solid var(--line);
}

.panel-heading h2 {
    margin: 0;
    color: var(--blue-950);
    font-size: 20px;
    line-height: 1.35;
}

.panel-heading > p,
.result-heading > div > p:last-child {
    max-width: 560px;
    margin: 5px 0 0;
    color: var(--ink-600);
    font-size: 12px;
}

.compact-heading {
    padding-bottom: 16px;
}

.parameter-tabs {
    display: flex;
    gap: 4px;
    padding: 10px 12px 0;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scroll-padding-inline: 12px;
    scroll-snap-type: x proximity;
    scrollbar-width: thin;
    background: var(--surface-soft);
    border-bottom: 1px solid var(--line);
}

.tab-button {
    position: relative;
    min-height: 41px;
    flex: 0 0 auto;
    padding: 8px 12px 10px;
    border: 0;
    border-radius: 8px 8px 0 0;
    color: var(--ink-600);
    background: transparent;
    font-size: 12px;
    font-weight: 700;
    scroll-snap-align: center;
    white-space: nowrap;
}

.tab-button::after {
    position: absolute;
    right: 12px;
    bottom: 0;
    left: 12px;
    height: 3px;
    border-radius: 3px 3px 0 0;
    content: "";
    background: transparent;
}

.tab-button:hover {
    color: var(--blue-800);
    background: var(--blue-50);
}

.tab-button.is-active {
    color: var(--blue-800);
    background: #ffffff;
}

.tab-button.is-active::after {
    background: var(--blue-600);
}

.parameter-form {
    min-width: 0;
}

.tab-panel {
    min-height: 540px;
    min-width: 0;
    padding: 22px;
    background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
}

.mode-card {
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: space-between;
    gap: 20px;
    padding: 16px;
    margin-bottom: 18px;
    border: 1px solid #cfe0ed;
    border-radius: 14px;
    background:
        linear-gradient(115deg, rgba(231, 244, 253, 0.96), rgba(248, 252, 255, 0.98)),
        #f3f9fd;
    box-shadow: inset 3px 0 0 var(--blue-600);
}

.mode-copy {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 12px;
}

.mode-copy h3,
.mode-panel-toolbar h3,
.ratio-card-heading h3 {
    margin: 0;
    color: var(--blue-950);
    font-size: 15px;
    line-height: 1.35;
}

.mode-copy p,
.mode-panel-toolbar p {
    margin: 4px 0 0;
    color: var(--ink-600);
    font-size: 11px;
}

.mode-icon {
    display: grid;
    width: 38px;
    height: 38px;
    flex: 0 0 38px;
    place-items: center;
    border-radius: 11px;
    color: #ffffff;
    background: linear-gradient(145deg, var(--blue-800), var(--blue-600));
    box-shadow: 0 7px 16px rgba(10, 99, 168, 0.19);
    font-size: 11px;
    font-weight: 850;
    letter-spacing: 0.08em;
}

.mode-switch {
    display: grid;
    min-width: 250px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 4px;
    padding: 4px;
    margin: 0;
    border: 1px solid #c8d9e7;
    border-radius: 11px;
    background: #e8f0f6;
}

.mode-option {
    position: relative;
    min-width: 0;
    cursor: pointer;
}

.mode-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.mode-option > span {
    display: grid;
    min-height: 46px;
    align-content: center;
    justify-items: center;
    padding: 5px 10px;
    border: 1px solid transparent;
    border-radius: 8px;
    color: var(--ink-600);
    line-height: 1.25;
    transition: color 150ms ease, border-color 150ms ease,
        background-color 150ms ease, box-shadow 150ms ease;
}

.mode-option strong {
    font-size: 12px;
}

.mode-option small {
    margin-top: 2px;
    color: var(--ink-500);
    font-size: 9px;
}

.mode-option input:checked + span {
    border-color: #bfd7e9;
    color: var(--blue-900);
    background: #ffffff;
    box-shadow: var(--shadow-sm);
}

.mode-option input:checked + span small {
    color: var(--blue-700);
}

.mode-option input:focus-visible + span {
    box-shadow: var(--focus-ring);
}

.mode-panel {
    min-width: 0;
    animation: mode-in 180ms ease-out;
}

.ratio-card-grid,
.yearly-matrix-grid,
.combination-grid {
    display: grid;
    min-width: 0;
    gap: 14px;
}

.ratio-card-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
}

.yearly-matrix-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 430px), 1fr));
}

.combination-grid {
    grid-template-columns: minmax(0, 1fr);
}

.ratio-card,
.matrix-card {
    min-width: 0;
    padding: 15px;
    border: 1px solid var(--line);
    border-radius: 13px;
    background: #ffffff;
    box-shadow: 0 5px 18px rgba(23, 58, 88, 0.05);
}

.ratio-card-heading,
.matrix-heading,
.mode-panel-toolbar {
    display: flex;
    min-width: 0;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.ratio-card-heading > div {
    display: flex;
    min-width: 0;
    align-items: center;
    gap: 8px;
}

.audience-tag,
.section-kicker,
.shared-badge,
.auto-note {
    display: inline-flex;
    width: fit-content;
    align-items: center;
    border-radius: 999px;
    font-size: 10px;
    font-weight: 800;
    line-height: 1.2;
}

.audience-tag {
    padding: 4px 7px;
    color: #ffffff;
    background: var(--blue-800);
}

.ratio-triplet {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin-top: 13px;
}

.ratio-field {
    display: grid;
    min-width: 0;
    gap: 6px;
}

.ratio-field > span {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--ink-600);
    font-size: 10px;
    font-weight: 700;
}

.ratio-field input {
    width: 100%;
    min-width: 0;
    min-height: 38px;
    padding: 7px 9px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    color: var(--ink-900);
    background: #ffffff;
    font-variant-numeric: tabular-nums;
}

.ratio-field input:hover {
    border-color: #8fb6d5;
}

.ratio-field input:focus {
    border-color: var(--blue-500);
    outline: none;
    box-shadow: var(--focus-ring);
}

.ratio-field input:user-invalid {
    border-color: #df7981;
}

.auto-ratio-field input,
.compact-matrix input[readonly] {
    border-color: #d1dae3;
    color: var(--blue-900);
    background: #edf4f8;
    font-weight: 750;
    cursor: default;
}

.mode-panel-toolbar {
    align-items: flex-end;
    padding: 2px 1px 11px;
}

.matrix-card {
    padding: 0;
    overflow: hidden;
}

.matrix-heading {
    padding: 11px 12px;
    border-bottom: 1px solid var(--line);
    color: var(--ink-500);
    background: var(--surface-soft);
    font-size: 10px;
    font-weight: 700;
}

.compact-matrix-wrap {
    border-radius: 0 0 12px 12px;
}

.compact-matrix {
    min-width: 0;
    table-layout: fixed;
}

.compact-matrix .year-column {
    width: 68px;
}

.compact-matrix th,
.compact-matrix td,
.compact-annual-table th,
.compact-annual-table td {
    padding: 6px 7px;
}

.compact-matrix tbody th {
    width: 62px;
    color: var(--blue-900);
    font-variant-numeric: tabular-nums;
}

.compact-matrix input,
.compact-annual-table input {
    min-width: 0;
    min-height: 32px;
    padding: 4px 6px;
    font-variant-numeric: tabular-nums;
}

.shared-combinations {
    min-width: 0;
    padding-top: 19px;
    margin-top: 20px;
    border-top: 1px solid var(--line);
}

.combination-intro {
    align-items: center;
}

.combination-intro > div {
    display: grid;
    gap: 2px;
}

.section-kicker {
    padding: 3px 7px;
    color: var(--blue-800);
    background: var(--blue-100);
}

.shared-badge {
    flex: 0 0 auto;
    padding: 6px 10px;
    border: 1px solid #b7d9c9;
    color: var(--success);
    background: #effaf5;
}

.combination-table {
    min-width: 0;
    table-layout: fixed;
}

.combination-table .group-column {
    width: 78px;
}

.combination-table select {
    min-width: 0;
}

.combination-table thead th:first-child,
.combination-table tbody th {
    position: sticky;
    left: 0;
}

.combination-table thead th:first-child {
    z-index: 3;
}

.combination-table tbody th {
    z-index: 2;
}

.combination-mobile-title {
    display: none;
}

.combination-table tbody th {
    width: 66px;
}

.culling-mode-panel {
    max-width: 760px;
}

.culling-uniform-card {
    padding: 18px;
}

.culling-uniform-card .form-grid {
    margin-top: 16px;
}

.auto-note {
    padding: 5px 8px;
    color: var(--ink-600);
    background: var(--surface-muted);
}

.section-intro {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 14px;
}

.section-intro h3,
.subsection-title h4,
.detail-section h3 {
    margin: 0;
    color: var(--ink-900);
    line-height: 1.4;
}

.section-intro h3 {
    font-size: 16px;
}

.section-intro p {
    margin: 5px 0 0;
    color: var(--ink-600);
    font-size: 12px;
}

.priority-badge {
    flex: 0 0 auto;
    padding: 5px 10px;
    border: 1px solid #b5d7ef;
    border-radius: 999px;
    color: var(--blue-800);
    background: var(--blue-50);
    font-size: 12px;
    font-weight: 800;
    letter-spacing: 0.03em;
}

.section-divider {
    height: 1px;
    margin: 24px 0 20px;
    background: var(--line);
}

.subsection-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin: 22px 0 10px;
}

.subsection-title h4,
.detail-section h3 {
    font-size: 14px;
}

.subsection-title span {
    color: var(--ink-500);
    font-size: 12px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 15px 16px;
}

.single-row-grid {
    margin-top: 18px;
}

.input-field {
    align-content: start;
}

.input-field small {
    color: var(--ink-500);
    font-size: 11px;
}

.input-with-unit {
    position: relative;
    display: block;
}

.input-with-unit input {
    padding-right: 82px;
}

.input-with-unit em {
    position: absolute;
    top: 50%;
    right: 11px;
    color: var(--ink-500);
    font-size: 11px;
    font-style: normal;
    pointer-events: none;
    transform: translateY(-50%);
}

.table-scroll {
    min-width: 0;
    max-width: 100%;
    overflow-x: auto;
    overscroll-behavior-inline: contain;
    scrollbar-width: thin;
    -webkit-overflow-scrolling: touch;
}

.input-table-wrap,
.summary-table-wrap,
.detail-table-wrap {
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
}

.data-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    color: var(--ink-900);
    font-size: 12px;
}

.data-table th,
.data-table td {
    padding: 9px 10px;
    border-right: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
    text-align: center;
    vertical-align: middle;
}

.data-table tr > :last-child {
    border-right: 0;
}

.data-table tbody tr:last-child > * {
    border-bottom: 0;
}

.data-table thead th {
    color: #ffffff;
    background: var(--blue-800);
    font-weight: 750;
    white-space: nowrap;
}

.data-table thead tr:first-child th:first-child {
    border-top-left-radius: 10px;
}

.data-table thead tr:first-child th:last-child {
    border-top-right-radius: 10px;
}

.data-table tbody th {
    color: var(--ink-700);
    background: var(--surface-soft);
    font-weight: 700;
}

.data-table tbody tr:hover td,
.data-table tbody tr:hover th {
    background-color: #f2f8fc;
}

.data-table input,
.data-table select {
    min-width: 78px;
    min-height: 34px;
    padding: 5px 7px;
    font-size: 12px;
}

.strategy-table {
    min-width: 610px;
}

.strategy-table.combination-table {
    min-width: 0;
}

.data-table.compact-matrix input,
.data-table.combination-table select {
    min-width: 0;
}

.strategy-table tbody th {
    width: 76px;
}

.strategy-table tbody th small {
    display: block;
    margin-top: 3px;
    color: var(--ink-500);
    font-size: 10px;
    font-weight: 500;
}

.group-chip {
    display: inline-grid;
    width: 25px;
    height: 25px;
    place-items: center;
    border-radius: 7px;
    color: #ffffff;
    background: var(--blue-700);
    font-size: 12px;
    font-weight: 850;
}

.group-b,
.group-e {
    background: #637389;
}

.group-c,
.group-f {
    background: #a45152;
}

.auto-ratio-row input[readonly] {
    border-color: #d1dae3;
    color: var(--ink-600);
    background: var(--surface-muted);
    cursor: default;
}

.field-note {
    margin: 9px 1px 0;
    color: var(--ink-500);
    font-size: 11px;
}

.annual-input-table,
.rate-table {
    min-width: 490px;
}

.annual-input-table tbody th,
.rate-table tbody th {
    width: 130px;
}

.calculation-error {
    margin: 0 22px 14px;
}

.form-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    padding: 15px 22px;
    border-top: 1px solid var(--line);
    background: var(--surface-soft);
}

.form-actions p {
    max-width: 480px;
    margin: 0;
    color: var(--ink-500);
    font-size: 11px;
}

.form-actions .button {
    min-width: 128px;
}

.button-loading {
    display: none;
    width: 15px;
    height: 15px;
    border: 2px solid rgba(255, 255, 255, 0.45);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 700ms linear infinite;
}

.button.is-loading .button-loading {
    display: inline-block;
}

/* Results */

.plan-card {
    border-top: 3px solid var(--blue-600);
    box-shadow: 0 14px 38px rgba(17, 55, 88, 0.09);
}

.plan-card .result-heading {
    background: linear-gradient(115deg, #f3f9fd, #ffffff 72%);
}

.result-heading {
    align-items: center;
}

.result-heading .button {
    flex: 0 0 auto;
}

.result-placeholder {
    display: flex;
    min-height: 160px;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 28px;
    color: var(--ink-500);
    text-align: center;
}

.result-placeholder.is-error {
    color: var(--danger);
}

.loading-ring {
    width: 20px;
    height: 20px;
    border: 2px solid #c8deee;
    border-top-color: var(--blue-600);
    border-radius: 50%;
    animation: spin 800ms linear infinite;
}

.summary-table-wrap {
    margin: 20px 20px 8px;
    background: #ffffff;
}

.summary-table {
    min-width: 660px;
    font-size: 13px;
    user-select: text;
}

.summary-table th,
.summary-table td {
    height: 43px;
    padding: 8px 11px;
}

.summary-table .summary-label-column,
.summary-table tbody th {
    min-width: 174px;
    text-align: left;
}

.summary-table thead th {
    position: sticky;
    top: 0;
    z-index: 2;
}

.summary-table thead th:first-child,
.summary-table tbody th {
    position: sticky;
    left: 0;
    z-index: 1;
}

.summary-table thead th:first-child {
    z-index: 3;
}

.summary-table tbody tr:nth-child(-n + 3) td {
    color: var(--ink-900);
    font-weight: 760;
    background: #ffffff;
}

.summary-table tbody tr:first-child th,
.summary-table tbody tr:first-child td {
    font-size: 14px;
}

.summary-table .parameter-summary-row th,
.summary-table .parameter-summary-row td {
    color: #a7242f;
    background: #fffafb;
    font-weight: 700;
}

.summary-table td.is-empty {
    background: #f8fafc;
}

.copy-status {
    min-height: 19px;
    margin: 7px 21px 17px;
    color: var(--success);
    font-size: 11px;
    text-align: right;
}

.detail-results {
    display: grid;
    min-width: 0;
    gap: 20px;
    padding: 20px;
}

.detail-section,
.detail-table-wrap {
    min-width: 0;
}

.detail-section h3 {
    margin-bottom: 9px;
}

.detail-table {
    min-width: 750px;
    user-select: text;
}

.detail-table-wrap {
    max-height: 540px;
    overflow: auto;
}

.detail-table tbody th,
.detail-table thead th:first-child {
    min-width: 190px;
    text-align: left;
}

.detail-table td {
    min-width: 118px;
    white-space: nowrap;
    font-variant-numeric: tabular-nums;
}

.detail-table td.is-negative {
    color: var(--danger);
    background: var(--danger-soft);
    font-weight: 700;
}

.toast {
    position: fixed;
    right: 22px;
    bottom: 22px;
    z-index: 50;
    max-width: min(360px, calc(100vw - 32px));
    padding: 11px 15px;
    border: 1px solid #acd1eb;
    border-radius: 10px;
    color: var(--blue-900);
    background: #ffffff;
    box-shadow: var(--shadow-md);
    font-size: 13px;
    font-weight: 650;
}

.clipboard-fallback {
    position: fixed;
    left: -10000px;
    width: 1px;
    height: 1px;
    opacity: 0;
}

.noscript-banner {
    position: fixed;
    right: 16px;
    bottom: 16px;
    left: 16px;
    z-index: 100;
    padding: 12px 16px;
    border: 1px solid #e2a2a8;
    border-radius: 10px;
    color: #8b1e28;
    background: #fff4f5;
    box-shadow: var(--shadow-md);
    text-align: center;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes mode-in {
    from {
        opacity: 0;
        transform: translateY(3px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@media (min-width: 1241px) and (max-width: 1540px) {
    .ratio-card-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (max-width: 1240px) {
    .workspace {
        grid-template-columns: 1fr;
        max-width: 1080px;
    }

    .tab-panel {
        min-height: 0;
    }
}

@media (max-width: 760px) {
    .app-header {
        position: static;
        align-items: flex-start;
        padding: 13px 15px;
    }

    .brand-symbol {
        display: none;
    }

    .brand-block h1 {
        white-space: normal;
    }

    .header-actions {
        gap: 7px;
    }

    .header-status {
        display: none;
    }

    .button-quiet {
        min-height: 36px;
        padding: 7px 10px;
        font-size: 12px;
    }

    .workspace {
        gap: 13px;
        padding: 12px 10px 24px;
    }

    .parameter-card,
    .result-card {
        border-radius: 13px;
    }

    .app-page input,
    .app-page select {
        font-size: 16px;
    }

    .panel-heading,
    .tab-panel,
    .form-actions {
        padding-right: 15px;
        padding-left: 15px;
    }

    .panel-heading,
    .result-heading,
    .form-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .result-heading .button,
    .form-actions .button {
        width: 100%;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .summary-table-wrap,
    .detail-results {
        margin-right: 12px;
        margin-left: 12px;
    }

    .detail-results {
        padding: 14px 0;
    }

    .section-intro {
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
    }

    .mode-card,
    .mode-panel-toolbar {
        align-items: stretch;
        flex-direction: column;
    }

    .mode-switch {
        width: 100%;
        min-width: 0;
    }

    .ratio-card-grid,
    .yearly-matrix-grid,
    .combination-grid {
        grid-template-columns: minmax(0, 1fr);
    }

    .compact-matrix .year-column {
        width: 62px;
    }

    .compact-matrix th,
    .compact-matrix td {
        padding: 6px 5px;
    }

    .compact-matrix input {
        min-height: 42px;
        padding: 7px 6px;
    }

    .combination-table {
        min-width: 0;
        table-layout: auto;
    }

    .combination-table colgroup,
    .combination-table thead {
        display: none;
    }

    .combination-mobile-title {
        display: flex;
        min-height: 38px;
        align-items: center;
        padding: 9px 11px 0;
        color: var(--blue-900);
        background: var(--surface-soft);
        font-size: 13px;
        font-weight: 800;
    }

    .combination-table tbody {
        display: grid;
        gap: 10px;
        padding: 10px;
        background: var(--surface-soft);
    }

    .combination-table tbody tr {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 9px 10px;
        min-width: 0;
        padding: 11px;
        border: 1px solid var(--line);
        border-radius: 11px;
        background: #ffffff;
        box-shadow: var(--shadow-sm);
    }

    .combination-table tbody th {
        position: static;
        display: flex;
        width: auto;
        grid-column: 1 / -1;
        align-items: center;
        gap: 8px;
        padding: 0 0 8px;
        border-right: 0;
        border-bottom: 1px solid var(--line);
        color: var(--ink-700);
        background: transparent;
        text-align: left;
    }

    .combination-table tbody th small {
        display: inline;
        margin: 0;
        font-size: 12px;
        font-weight: 650;
    }

    .combination-table tbody td {
        display: grid;
        min-width: 0;
        gap: 5px;
        padding: 0;
        border: 0;
        background: transparent;
        text-align: left;
    }

    .combination-table tbody td::before {
        color: var(--ink-500);
        font-size: 11px;
        font-weight: 750;
    }

    .combination-table tbody td:nth-child(2)::before {
        content: "1 配";
    }

    .combination-table tbody td:nth-child(3)::before {
        content: "2 配";
    }

    .combination-table tbody td:nth-child(4)::before {
        content: "3 配";
    }

    .combination-table tbody td:nth-child(5)::before {
        content: "4 配";
    }

    .data-table.combination-table tbody tr:hover td,
    .data-table.combination-table tbody tr:hover th {
        background: transparent;
    }

    .combination-table select {
        min-height: 44px;
        padding: 7px 8px;
    }

    .ratio-card-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .ratio-card-heading > div {
        flex-wrap: wrap;
    }

    .mode-panel-toolbar .button {
        width: 100%;
    }

    .priority-badge {
        align-self: flex-start;
    }

    .copy-status {
        margin-right: 14px;
        margin-left: 14px;
        text-align: left;
    }

    .app-page .button,
    .app-page .tab-button,
    .app-page input,
    .app-page select {
        min-height: 44px;
    }
}

@media (max-width: 520px) {
    .login-page {
        place-items: start center;
        padding: 18px 12px;
    }

    .login-card {
        padding: 28px 22px 24px;
        border-radius: 18px;
    }

    .login-heading h1 {
        font-size: 25px;
    }

    .parameter-tabs {
        padding-right: 8px;
        padding-left: 8px;
    }

    .tab-button {
        padding-right: 10px;
        padding-left: 10px;
    }

    .panel-heading h2 {
        font-size: 18px;
    }

    .mode-copy {
        align-items: flex-start;
    }

    .mode-icon {
        width: 34px;
        height: 34px;
        flex-basis: 34px;
    }

    .ratio-card,
    .culling-uniform-card {
        padding: 12px;
    }

    .ratio-triplet {
        gap: 6px;
    }

    .compact-matrix .year-column {
        width: 58px;
    }

    .compact-matrix {
        font-size: 11px;
    }

    .compact-matrix th,
    .compact-matrix td {
        padding-right: 4px;
        padding-left: 4px;
    }

    .compact-matrix input[type="number"] {
        padding-right: 1px;
        padding-left: 1px;
        appearance: textfield;
        text-align: center;
    }

    .compact-matrix input[readonly] {
        font-weight: 700;
    }

    .compact-matrix input[type="number"]::-webkit-inner-spin-button,
    .compact-matrix input[type="number"]::-webkit-outer-spin-button {
        margin: 0;
        -webkit-appearance: none;
    }

    .ratio-field > span {
        align-items: flex-start;
        flex-direction: column;
        gap: 3px;
    }
}

@media (max-width: 360px) {
    .compact-matrix .year-column {
        width: 52px;
    }

    .compact-matrix thead th[data-short-label] {
        font-size: 0;
    }

    .compact-matrix thead th[data-short-label]::after {
        content: attr(data-short-label);
        font-size: 11px;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        transition-duration: 0.01ms !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
    }
}

@media print {
    .app-header,
    .parameter-card,
    .button,
    .copy-status,
    .toast {
        display: none !important;
    }

    body,
    html {
        background: #ffffff;
    }

    .workspace {
        display: block;
        width: 100%;
        padding: 0;
    }

    .result-card {
        margin-bottom: 14px;
        border: 1px solid #777777;
        box-shadow: none;
        break-inside: avoid;
    }

    .table-scroll {
        overflow: visible;
    }

    .summary-table,
    .detail-table {
        min-width: 0;
        font-size: 9px;
    }
}
