:root {
    --bg: #f5f7f2;
    --panel: #ffffff;
    --ink: #20231f;
    --muted: #687064;
    --line: #dfe5d8;
    --green: #2f7d4f;
    --amber: #bd8a2b;
    --red: #b6453c;
    --shadow: 0 12px 28px rgba(28, 35, 27, 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;
}

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

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

.topbar,
.pane-head,
.tool-strip,
.form-actions {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

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

.eyebrow, p, h1, h2, h3 { margin-top: 0; }
.eyebrow {
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 850;
}
h1 { margin-bottom: 0; font-size: 34px; line-height: 1.05; }
h2, h3 { margin-bottom: 0; }

.quick-links {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.btn,
.quick-links a {
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 14px;
    border: 1px solid var(--green);
    border-radius: 8px;
    background: var(--green);
    color: #fff;
    text-decoration: none;
    font-weight: 950;
}

.btn.ghost,
.quick-links a {
    border-color: var(--line);
    background: var(--panel);
    color: var(--green);
}

.btn.compact {
    min-height: 36px;
    padding: 7px 10px;
    font-size: 14px;
}

.summary-grid,
.board-grid,
.form-grid {
    display: grid;
    gap: 12px;
}

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

.summary-grid article,
.panel,
.material-card,
.mini-row {
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.summary-grid article {
    padding: 16px;
}

.summary-grid span {
    display: block;
    margin-bottom: 4px;
    font-size: 31px;
    font-weight: 950;
}

.summary-grid p {
    margin-bottom: 0;
    color: var(--muted);
    font-weight: 850;
}

.tool-strip {
    flex-wrap: wrap;
    justify-content: flex-start;
    margin-bottom: 14px;
}

.panel {
    margin-bottom: 14px;
    padding: 16px;
}

.board-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    align-items: start;
}

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

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

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-weight: 900;
}

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

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

.status-toggle {
    min-height: 44px;
    width: 100%;
    display: inline-flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
    padding: 8px 12px;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: #f8faf5;
    color: var(--muted);
    font-weight: 950;
}

.status-toggle span {
    width: 48px;
    height: 26px;
    display: inline-flex;
    align-items: center;
    padding: 3px;
    border-radius: 999px;
    background: #c8d1c4;
}

.status-toggle span::after {
    content: "";
    width: 20px;
    height: 20px;
    display: block;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, .18);
    transition: transform .16s ease;
}

.status-toggle.is-on {
    border-color: rgba(47, 125, 79, .35);
    background: #eef7ee;
    color: var(--green);
}

.status-toggle.is-on span {
    background: var(--green);
}

.status-toggle.is-on span::after {
    transform: translateX(22px);
}

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

.wide { grid-column: 1 / -1; }

.card-list,
.mini-list {
    display: grid;
    gap: 10px;
    margin-top: 14px;
}

.compact-head {
    margin-bottom: 8px;
}

.rule-material-panel {
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcf8;
}

.rule-material-list {
    display: grid;
    gap: 8px;
}

.rule-material-row {
    display: grid;
    grid-template-columns: minmax(220px, 1fr) minmax(120px, 180px) auto;
    gap: 8px;
    align-items: end;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.rule-material-row label {
    min-width: 0;
}

.rule-material-row .rule-row-remove {
    align-self: end;
}

.rule-row-remove {
    width: 100%;
}

.material-card {
    display: grid;
    gap: 10px;
    padding: 13px;
    border-left: 5px solid var(--green);
}

.material-card.low {
    border-left-color: var(--red);
}

.material-card.inactive {
    opacity: .64;
}

.card-main {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
}

.card-main strong {
    font-size: 18px;
    line-height: 1.25;
}

.card-main span,
.meta-line {
    color: var(--muted);
    font-weight: 850;
}

.big-number {
    text-align: right;
    font-size: 26px;
    font-weight: 950;
    white-space: nowrap;
}

.pill-row {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.pill {
    display: inline-flex;
    min-height: 28px;
    align-items: center;
    padding: 5px 9px;
    border-radius: 999px;
    background: #eef5ec;
    color: var(--green);
    font-size: 13px;
    font-weight: 900;
}

.pill.warn {
    background: #fff1d8;
    color: #a06716;
}

.pill.danger {
    background: #fff0ed;
    color: var(--red);
}

.mini-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px;
    align-items: center;
    padding: 12px;
}

.mini-row.is-inactive {
    opacity: .62;
}

.rule-group-card {
    display: grid;
    gap: 10px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.rule-group-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: flex-start;
}

.rule-group-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 8px;
}

.rule-group-head strong {
    font-size: 18px;
}

.rule-group-rows {
    display: grid;
    gap: 8px;
}

.rule-line {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 8px;
    align-items: center;
    padding: 9px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fbfcf8;
}

.rule-line.is-inactive {
    opacity: .62;
}

.rule-line span {
    display: block;
    color: var(--muted);
    font-weight: 850;
}

.mini-row strong {
    display: block;
    font-size: 16px;
}

.mini-row span {
    color: var(--muted);
    font-weight: 800;
}

.mini-row button,
.material-card button,
.rule-group-actions button,
.rule-line button {
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--green);
    font-weight: 950;
}

.toast {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 160;
    max-width: min(360px, calc(100vw - 32px));
    padding: 12px 14px;
    border-radius: 8px;
    background: #1f2a22;
    color: #fff;
    font-weight: 900;
    opacity: 0;
    transform: translateY(8px);
    transition: opacity .18s ease, transform .18s ease;
    pointer-events: none;
}

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

@media (max-width: 860px) {
    .summary-grid,
    .board-grid,
    .form-grid,
    .compact-grid,
    .rule-material-row {
        grid-template-columns: 1fr;
    }

    .topbar,
    .pane-head {
        display: grid;
    }

    h1 {
        font-size: 31px;
    }

    .tool-strip .btn {
        flex: 1 1 150px;
    }

    .mini-row {
        grid-template-columns: 1fr;
    }

    .rule-group-head,
    .rule-line {
        display: grid;
    }

    .rule-material-row .toggle-field,
    .rule-material-row .rule-row-remove {
        grid-column: auto;
    }
}
