:root {
    --bg: #f6f7f4;
    --panel: #ffffff;
    --ink: #20231f;
    --muted: #687064;
    --line: #dfe4da;
    --green: #2f7d4f;
    --blue: #276b8f;
    --gold: #bd8b2c;
    --red: #b63e35;
    --soft: #f0f4ed;
    --shadow: 0 10px 28px rgba(31, 38, 29, 0.08);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", Arial, sans-serif;
    -webkit-text-size-adjust: 100%;
}

button,
input,
select,
textarea {
    font: inherit;
    font-size: 16px;
}

.app-shell {
    width: min(1440px, 100%);
    margin: 0 auto;
    padding: 18px 14px 88px;
}

.topbar,
.quick-links,
.section-head,
.form-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.topbar {
    align-items: flex-start;
    margin-bottom: 16px;
}

.quick-links {
    flex-wrap: wrap;
    justify-content: flex-end;
}

.quick-links a,
.btn {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    font-weight: 900;
    text-decoration: none;
}

.quick-links a {
    padding: 8px 11px;
    border: 1px solid var(--line);
    color: var(--green);
    background: var(--panel);
}

.eyebrow,
p {
    margin-top: 0;
}

.eyebrow {
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 900;
}

h1,
h2,
h3 {
    margin: 0;
}

h1 {
    font-size: clamp(34px, 5vw, 68px);
    line-height: 0.95;
}

h2 {
    font-size: 24px;
}

.notice-card,
.stage-card,
.metric-card,
.panel-card,
.factor-chip,
.activity-card {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.notice-card {
    display: grid;
    gap: 6px;
    margin-bottom: 14px;
    padding: 14px;
    border-left: 5px solid var(--green);
    line-height: 1.5;
}

.notice-card span,
.stage-card li,
.activity-card span,
.factor-chip span,
.factor-chip em {
    color: var(--muted);
}

.stage-grid,
.metric-grid,
.carbon-layout,
.summary-layout,
.source-layout,
.allocation-layout {
    display: grid;
    gap: 12px;
}

.stage-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin-bottom: 12px;
}

.stage-card {
    display: grid;
    gap: 10px;
    padding: 14px;
    border-left: 5px solid var(--line);
}

.stage-card.active {
    border-left-color: var(--green);
}

.stage-card div {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.stage-card b {
    color: var(--green);
}

.stage-card span {
    border-radius: 999px;
    padding: 5px 8px;
    color: var(--green);
    background: #edf6ef;
    font-size: 12px;
    font-weight: 900;
    white-space: nowrap;
}

.stage-card ul {
    display: grid;
    gap: 6px;
    margin: 0;
    padding-left: 18px;
}

.metric-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    margin: 14px 0;
}

.allocation-layout {
    grid-template-columns: repeat(3, minmax(0, 1fr));
    margin-bottom: 12px;
}

.carbon-actions {
    display: flex;
    align-items: stretch;
    justify-content: space-between;
    gap: 12px;
    margin: 12px 0;
}

.factor-import-form {
    min-width: min(520px, 100%);
    display: flex;
    align-items: flex-end;
    justify-content: flex-end;
    gap: 10px;
}

.factor-import-form label {
    flex: 1;
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 900;
}

.factor-import-form input {
    width: 100%;
    min-height: 42px;
    border: 1px solid #cfd8c8;
    border-radius: 8px;
    padding: 8px 10px;
    background: #fff;
}

.metric-card {
    display: grid;
    gap: 4px;
    padding: 16px;
}

.metric-card strong {
    font-size: clamp(30px, 4vw, 46px);
    line-height: 1;
}

.metric-card span {
    color: var(--muted);
    font-weight: 900;
}

.metric-card em {
    color: var(--green);
    font-style: normal;
    font-size: 13px;
    font-weight: 900;
}

.carbon-layout {
    grid-template-columns: minmax(360px, 0.95fr) minmax(420px, 1.05fr);
}

.summary-layout {
    grid-template-columns: minmax(460px, 1.2fr) minmax(340px, 0.8fr);
    margin-top: 12px;
}

.source-layout {
    grid-template-columns: minmax(460px, 1fr) minmax(340px, 0.8fr);
    margin-top: 12px;
}

.panel-card {
    min-width: 0;
    padding: 16px;
}

.section-head {
    align-items: flex-start;
    margin-bottom: 12px;
}

.btn {
    border: 0;
    padding: 10px 14px;
    color: #fff;
    background: var(--green);
    cursor: pointer;
}

.btn.secondary {
    border: 1px solid var(--line);
    color: var(--green);
    background: var(--panel);
}

.carbon-form {
    display: grid;
    gap: 10px;
}

.carbon-form label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 900;
}

.form-row > label {
    flex: 1;
    min-width: 0;
}

.carbon-form input,
.carbon-form select,
.carbon-form textarea {
    width: 100%;
    min-height: 44px;
    border: 1px solid #cfd8c8;
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--ink);
    background: #fff;
    font-weight: 850;
}

.carbon-form textarea {
    resize: vertical;
}

.compact-readonly input {
    background: var(--soft);
}

.factor-list,
.activity-list,
.bar-list,
.allocation-list {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.factor-chip {
    width: 100%;
    display: grid;
    gap: 4px;
    padding: 12px;
    text-align: left;
    cursor: pointer;
}

.factor-chip strong {
    font-size: 18px;
}

.factor-chip em {
    font-style: normal;
    font-weight: 900;
}

.factor-chip.inactive {
    opacity: 0.55;
}

.activity-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 12px;
    cursor: pointer;
}

.allocation-card {
    display: grid;
    gap: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    background: #fbfcfa;
}

.allocation-card strong,
.allocation-card span {
    display: block;
}

.allocation-card strong {
    font-size: 18px;
}

.allocation-card span {
    color: var(--muted);
    line-height: 1.45;
    font-weight: 850;
}

.allocation-values {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 10px;
}

.allocation-values b {
    font-size: 20px;
}

.allocation-values em {
    color: var(--green);
    font-style: normal;
    font-weight: 900;
    text-align: right;
}

.activity-card > div:first-child {
    min-width: 0;
}

.activity-card strong,
.activity-card span {
    display: block;
}

.activity-values {
    display: grid;
    gap: 2px;
    min-width: 150px;
    text-align: right;
}

.activity-values b {
    font-size: 17px;
}

.activity-values em {
    color: var(--green);
    font-style: normal;
    font-weight: 900;
}

.activity-values i {
    justify-self: end;
    width: fit-content;
    border-radius: 999px;
    padding: 3px 8px;
    color: var(--green);
    background: #edf6ef;
    font-size: 12px;
    font-style: normal;
    font-weight: 900;
}

.source-list,
.import-run-list {
    display: grid;
    gap: 10px;
}

.source-card,
.import-run-card {
    display: grid;
    gap: 5px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
    color: inherit;
    text-decoration: none;
    background: #fbfcfa;
}

.source-card strong,
.import-run-card strong {
    color: var(--green);
    font-size: 17px;
}

.source-card span,
.import-run-card span,
.import-run-card em {
    color: var(--muted);
    font-style: normal;
    font-weight: 850;
    line-height: 1.45;
}

.bar-row {
    display: grid;
    gap: 6px;
}

.bar-row div {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.bar-row span {
    color: var(--muted);
    font-weight: 900;
}

.bar-row i {
    height: 12px;
    border-radius: 999px;
    background: var(--green);
}

.month-bars {
    display: flex;
    align-items: flex-end;
    gap: 10px;
    min-height: 170px;
    margin-top: 18px;
    overflow-x: auto;
    padding-bottom: 6px;
}

.month-bar {
    min-width: 74px;
    display: grid;
    justify-items: center;
    gap: 6px;
    color: var(--muted);
    font-weight: 900;
}

.month-bar span {
    width: 30px;
    border-radius: 8px 8px 0 0;
    background: var(--blue);
}

.month-bar em {
    color: var(--ink);
    font-style: normal;
    font-size: 12px;
}

.empty-state {
    border: 1px dashed var(--line);
    border-radius: 8px;
    padding: 16px;
    color: var(--muted);
    font-weight: 900;
    text-align: center;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 20px;
    z-index: 30;
    transform: translateX(-50%) translateY(20px);
    opacity: 0;
    pointer-events: none;
    border-radius: 999px;
    padding: 10px 16px;
    color: #fff;
    background: rgba(31, 38, 29, 0.9);
    font-weight: 900;
    transition: opacity 0.2s ease, transform 0.2s ease;
}

.toast.is-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

@media (max-width: 1020px) {
    .stage-grid,
    .metric-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .carbon-layout,
    .summary-layout,
    .source-layout,
    .allocation-layout {
        grid-template-columns: 1fr;
    }

    .carbon-actions,
    .factor-import-form {
        display: grid;
        justify-content: stretch;
    }
}

@media (max-width: 640px) {
    .app-shell {
        padding: 72px 12px 88px;
    }

    .topbar {
        display: block;
    }

    .quick-links {
        display: none;
    }

    .stage-grid,
    .metric-grid {
        grid-template-columns: 1fr;
    }

    .form-row,
    .activity-card {
        display: grid;
        grid-template-columns: 1fr;
    }

    .activity-values {
        min-width: 0;
        text-align: left;
    }

    .activity-values i {
        justify-self: start;
    }
}
