:root {
    --bg: #f5f7f4;
    --panel: #ffffff;
    --ink: #20231f;
    --muted: #687064;
    --line: #dfe4da;
    --green: #2f7d4f;
    --blue: #276b8f;
    --red: #b63e35;
    --amber: #b98322;
    --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;
}

body.is-modal-open {
    overflow: hidden;
}

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

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

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

.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);
}

.page-tools {
    display: flex;
    justify-content: flex-end;
    margin-bottom: 14px;
}

.more-menu-wrap {
    position: relative;
}

.more-btn {
    width: 42px;
    min-height: 42px;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--panel);
    color: var(--ink);
    cursor: pointer;
    font-size: 24px;
    line-height: 1;
    box-shadow: var(--shadow);
}

.more-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    z-index: 10;
    min-width: 190px;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 16px 38px rgba(31, 38, 29, 0.16);
}

.more-menu[hidden] {
    display: none;
}

.more-menu button {
    width: 100%;
    min-height: 44px;
    border: 0;
    border-bottom: 1px solid var(--line);
    padding: 10px 12px;
    background: #fff;
    color: var(--ink);
    cursor: pointer;
    text-align: left;
    font-weight: 900;
}

.more-menu button:last-child {
    border-bottom: 0;
}

.more-menu button:hover {
    background: #eef7f0;
    color: var(--green);
}

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

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

h1,
h2,
h3 {
    margin: 0;
}

h1 {
    font-size: 30px;
    line-height: 1.1;
}

h2 {
    font-size: 21px;
}

h3 {
    font-size: 18px;
}

.notice-card,
.category-panel,
.unit-panel,
.product-card,
.form-section {
    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(--blue);
}

.notice-card span {
    color: var(--muted);
    line-height: 1.55;
}

.toolbar {
    display: grid;
    gap: 10px;
    margin-bottom: 14px;
}

.filter-panel {
    display: grid;
    gap: 10px;
    margin-bottom: 14px;
    padding: 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
}

.filter-row {
    display: grid;
    gap: 10px;
}

.filter-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.filter-chip {
    min-height: 36px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px 10px;
    background: #f7f8f4;
    color: var(--ink);
    cursor: pointer;
    font-weight: 900;
}

.filter-chip.is-active {
    border-color: var(--green);
    background: #e8f3ed;
    color: var(--green);
}

.search-box,
label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 800;
}

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

input,
select,
textarea {
    width: 100%;
    min-height: 44px;
    padding: 10px 11px;
    border: 1px solid #cbd4c4;
    border-radius: 8px;
    background: #ffffff;
    color: var(--ink);
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    min-height: 44px;
    padding: 8px 10px;
    border: 1px solid #cbd4c4;
    border-radius: 8px;
    background: #ffffff;
    color: var(--ink);
}

.toggle-row span {
    display: grid;
    gap: 2px;
}

.toggle-row strong {
    font-size: 13px;
}

.toggle-row small {
    color: var(--muted);
    font-weight: 900;
}

.toggle-row input[type="checkbox"] {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.toggle-row i {
    position: relative;
    width: 48px;
    height: 28px;
    border-radius: 999px;
    background: #cfd7ca;
    transition: background 0.16s ease;
}

.toggle-row i::after {
    position: absolute;
    left: 3px;
    top: 3px;
    width: 22px;
    height: 22px;
    border-radius: 50%;
    background: #ffffff;
    box-shadow: 0 2px 8px rgba(31, 38, 29, 0.18);
    content: "";
    transition: transform 0.16s ease;
}

.toggle-row input[type="checkbox"]:checked + i {
    background: var(--green);
}

.toggle-row input[type="checkbox"]:checked + i::after {
    transform: translateX(20px);
}

.toggle-row:focus-within {
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(47, 125, 79, 0.12);
}

.card-switch {
    display: inline-flex;
    align-items: center;
    justify-content: start;
    gap: 8px;
    width: max-content;
    color: var(--muted);
    cursor: pointer;
    font-size: 12px;
    font-weight: 900;
}

.card-switch input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.card-switch i {
    position: relative;
    width: 42px;
    height: 24px;
    border-radius: 999px;
    background: #cfd7ca;
    transition: background 0.16s ease;
}

.card-switch i::after {
    position: absolute;
    left: 3px;
    top: 3px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 8px rgba(31, 38, 29, 0.18);
    content: "";
    transition: transform 0.16s ease;
}

.card-switch input:checked + i {
    background: var(--green);
}

.card-switch input:checked + i::after {
    transform: translateX(18px);
}

.card-switch:focus-within i {
    box-shadow: 0 0 0 3px rgba(47, 125, 79, 0.16);
}

.radio-group {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    min-width: 0;
    margin: 0;
    padding: 9px;
    border: 1px solid #cbd4c4;
    border-radius: 8px;
    background: #ffffff;
}

.radio-group legend {
    padding: 0 5px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 900;
}

.radio-group label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 34px;
    padding: 5px 8px;
    border-radius: 8px;
    background: #f7f8f4;
    color: var(--ink);
}

.radio-group input {
    width: auto;
    min-height: 0;
}

input:disabled,
select:disabled,
textarea:disabled {
    background: #eef1ea;
    color: #8a9385;
    cursor: not-allowed;
}

textarea {
    resize: vertical;
}

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

.btn-secondary {
    border: 1px solid var(--line);
    color: var(--ink);
    background: #f7f8f4;
}

.btn.compact {
    min-height: 38px;
}

.category-panel {
    display: grid;
    gap: 12px;
    margin-bottom: 14px;
    padding: 14px;
}

.unit-panel {
    display: grid;
    gap: 12px;
    margin-bottom: 24px;
    padding: 14px;
}

.category-form,
.unit-form {
    display: grid;
    gap: 8px;
}

.category-strip,
.unit-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.category-pill {
    min-height: 38px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 7px 10px;
    background: #f7f8f4;
    color: var(--ink);
    cursor: pointer;
}

.category-pill.is-editing {
    border-color: var(--green);
    background: #eaf4ee;
}

.category-pill small {
    margin-left: 6px;
    color: var(--muted);
}

.unit-list {
    display: grid;
}

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

.unit-card.is-editing {
    border-color: var(--green);
    background: #eaf4ee;
}

.unit-card.is-inactive {
    opacity: 0.72;
}

.unit-card strong,
.unit-card small {
    display: block;
}

.unit-card small {
    margin-top: 4px;
    color: var(--muted);
    font-weight: 800;
}

.unit-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.products-section {
    display: grid;
    gap: 12px;
}

.product-grid {
    display: grid;
    gap: 12px;
}

.product-card {
    display: grid;
    gap: 12px;
    padding: 14px;
}

.image-preview {
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #eef2ea;
}

.image-preview img {
    width: 100%;
    height: 100%;
    display: block;
    object-fit: cover;
}

.image-placeholder {
    min-height: 100%;
    display: grid;
    place-items: center;
    color: var(--muted);
    font-weight: 900;
}

.card-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.short-name {
    display: block;
    margin-top: 5px;
    color: var(--muted);
    font-weight: 800;
}

.tag,
.metric-pill {
    border-radius: 8px;
    background: #eef2ea;
    color: var(--green);
    font-size: 12px;
    font-weight: 900;
}

.tag {
    height: fit-content;
    padding: 6px 9px;
    white-space: nowrap;
}

.meta-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 0;
}

.meta-grid div {
    min-width: 0;
}

.meta-grid dt {
    color: var(--muted);
    font-size: 12px;
}

.meta-grid dd {
    margin: 3px 0 0;
    overflow-wrap: anywhere;
    font-weight: 800;
}

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

.metric-pill {
    padding: 6px 8px;
}

.status-active {
    background: #e6f3ec;
    color: var(--green);
}

.status-inactive {
    background: #f1e6e3;
    color: var(--red);
}

.list-actions {
    display: flex;
    gap: 8px;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    display: grid;
    place-items: center;
    padding: 12px;
    background: rgba(22, 28, 20, 0.42);
    z-index: 20;
}

.modal-backdrop[hidden] {
    display: none;
}

.product-editor {
    width: min(860px, 100%);
    max-height: calc(100vh - 24px);
    overflow: auto;
    border-radius: 8px;
    background: #f7f8f4;
}

.manager-editor {
    width: min(920px, 100%);
    max-height: calc(100vh - 24px);
    overflow: auto;
    border-radius: 8px;
    background: #f7f8f4;
}

.manager-body {
    padding: 14px;
}

.manager-body [hidden] {
    display: none !important;
}

.manager-body .category-panel,
.manager-body .unit-panel {
    margin-bottom: 0;
    box-shadow: none;
}

.editor-head {
    position: sticky;
    top: 0;
    padding: 16px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
    z-index: 2;
}

.icon-btn {
    width: 42px;
    height: 42px;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: #fff;
    cursor: pointer;
    font-size: 24px;
}

.editor-form {
    display: grid;
    gap: 14px;
    padding: 14px;
}

.form-section {
    display: grid;
    gap: 12px;
    padding: 14px;
}

.section-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.label-preview {
    padding: 10px 12px;
    border: 1px solid #d8e1d1;
    border-radius: 8px;
    background: #eef7f0;
    color: var(--green);
    font-weight: 900;
}

.input-with-action {
    display: grid;
    gap: 8px;
}

.html-editor-group {
    display: grid;
    gap: 12px;
}

.editor-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 7px 0;
}

.editor-toolbar button {
    min-height: 34px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 6px 9px;
    background: #f7f8f4;
    color: var(--ink);
    cursor: pointer;
    font-weight: 900;
}

.html-editor {
    min-height: 120px;
    padding: 11px;
    border: 1px solid #cbd4c4;
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    line-height: 1.55;
    overflow-wrap: anywhere;
}

.html-editor:focus {
    outline: 2px solid rgba(47, 125, 79, 0.22);
    border-color: var(--green);
}

.image-list,
.stock-list {
    display: grid;
    gap: 10px;
}

.image-row,
.price-row,
.stock-row {
    display: grid;
    gap: 10px;
    align-items: start;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
}

.image-row {
    grid-template-columns: 92px minmax(0, 1fr) 38px;
}

.price-list {
    display: grid;
    gap: 10px;
}

.price-row-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}

.price-fields {
    display: grid;
    gap: 8px;
}

.stock-row strong,
.stock-row small {
    display: block;
}

.stock-row small {
    margin-top: 4px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.45;
}

.stock-inline-field {
    display: grid;
    gap: 5px;
}

.inline-save-status {
    min-height: 17px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
    opacity: 0;
    transition: opacity 0.16s ease;
}

.stock-inline-field:focus-within .inline-save-status,
.inline-save-status.is-saving,
.inline-save-status.is-saved,
.inline-save-status.is-error {
    opacity: 1;
}

.inline-save-status.is-saving {
    color: var(--blue);
}

.inline-save-status.is-saved {
    color: var(--green);
}

.inline-save-status.is-error {
    color: var(--red);
}

.image-preview {
    position: relative;
    width: 92px;
    aspect-ratio: 1;
    padding: 0;
    cursor: pointer;
}

.usage-badge {
    position: absolute;
    left: 6px;
    bottom: 6px;
    max-width: calc(100% - 12px);
    padding: 3px 6px;
    border-radius: 8px;
    background: rgba(31, 38, 29, 0.82);
    color: #fff;
    font-size: 11px;
    font-weight: 900;
}

.image-fields {
    display: grid;
    gap: 8px;
}

.remove-image {
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 8px;
    background: #f3e4df;
    color: var(--red);
    font-weight: 900;
    cursor: pointer;
}

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

.check-line {
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--ink);
}

.check-line input {
    width: 18px;
    min-height: 18px;
    accent-color: var(--green);
}

.editor-actions {
    grid-template-columns: auto 1fr auto auto;
}

.toast {
    position: fixed;
    left: 50%;
    bottom: 18px;
    transform: translate(-50%, 16px);
    max-width: min(460px, calc(100% - 28px));
    padding: 12px 14px;
    border-radius: 8px;
    background: #1f2a22;
    color: #fff;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease, transform 0.2s ease;
    z-index: 30;
}

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

.empty-state {
    padding: 13px;
    border: 1px dashed #c8d1c0;
    border-radius: 8px;
    color: var(--muted);
    background: #fbfcfa;
}

@media (min-width: 760px) {
    .app-shell {
        padding: 26px 24px 96px;
    }

    .toolbar {
        grid-template-columns: minmax(260px, 1fr) auto;
        align-items: end;
    }

    .filter-row {
        grid-template-columns: minmax(180px, 220px) minmax(160px, 200px);
    }

    .category-form {
        grid-template-columns: minmax(220px, 1fr) minmax(160px, 0.5fr) auto auto;
    }

    .unit-form {
        grid-template-columns: minmax(160px, 1fr) minmax(140px, 0.8fr) minmax(130px, 0.7fr) minmax(120px, 0.65fr) 96px auto auto;
        align-items: end;
    }

    .unit-card {
        grid-template-columns: minmax(240px, 1fr) auto auto;
        align-items: center;
    }

    .product-grid {
        gap: 8px;
    }

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

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

    .stock-row {
        grid-template-columns: minmax(240px, 1fr) minmax(180px, 0.55fr);
        align-items: end;
    }

    .input-with-action {
        grid-template-columns: minmax(0, 1fr) auto;
        align-items: end;
    }

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

@media (min-width: 1080px) {
    .product-grid {
        grid-template-columns: 1fr;
    }

    .product-card {
        grid-template-columns: minmax(230px, 1.35fr) minmax(430px, 2.4fr) minmax(170px, 0.8fr) auto;
        align-items: center;
        gap: 14px;
        padding: 12px 14px;
    }

    .product-card .card-head {
        align-items: center;
    }

    .product-card .tag {
        align-self: center;
    }

    .product-card .meta-grid {
        grid-template-columns: repeat(4, minmax(96px, 1fr));
        gap: 10px 12px;
    }

    .product-card .metric-row {
        align-content: center;
    }

    .product-card .list-actions {
        justify-content: flex-end;
    }
}

/* Full-screen editor, Trello-style: close left, title center area, spacer right. */
.modal-backdrop {
    display: block;
    padding: 0;
}

.product-editor,
.manager-editor {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    border-radius: 0;
}

.editor-head {
    display: grid;
    grid-template-columns: 44px minmax(0, 1fr) 44px;
    align-items: center;
    min-height: 68px;
    padding: 10px 12px;
}

.editor-title {
    min-width: 0;
}

.editor-head-spacer {
    display: block;
    width: 42px;
    height: 42px;
}

.editor-form,
.manager-body {
    width: min(920px, 100%);
    margin: 0 auto;
    padding: 14px 14px 28px;
}
