:root {
    --bg: #f6f7f4;
    --panel: #ffffff;
    --ink: #20231f;
    --muted: #687064;
    --line: #dfe4da;
    --green: #2f7d4f;
    --orange: #b86125;
    --red: #b63e35;
    --blue: #276b8f;
    --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(1120px, 100%);
    margin: 0 auto;
    padding: 18px 14px 88px;
}

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

.top-actions,
.quick-links {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

.top-actions {
    flex-wrap: wrap;
}

.quick-links {
    flex-wrap: wrap;
}

.quick-links a {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--green);
    background: var(--panel);
    text-decoration: none;
    font-size: 13px;
    font-weight: 900;
}

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

h1,
h2,
h3,
p {
    margin-top: 0;
}

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

.user-chip {
    display: grid;
    gap: 2px;
    min-width: 112px;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    text-align: right;
}

.user-chip span {
    font-size: 14px;
    color: var(--ink);
}

.user-chip strong {
    color: var(--green);
    font-size: 12px;
}

.summary-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 22px;
}

.summary-card {
    min-height: 88px;
    padding: 14px;
    border: 1px solid var(--line);
    border-left: 5px solid var(--green);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
}

.summary-card span {
    display: block;
    margin-bottom: 6px;
    font-size: 28px;
    font-weight: 800;
}

.summary-card p {
    margin-bottom: 0;
    color: var(--muted);
    font-size: 14px;
}

.summary-card.alert {
    border-left-color: var(--red);
}

.summary-card.warning {
    border-left-color: var(--orange);
}

.summary-card.ai {
    border-left-color: var(--blue);
}

.summary-card.picking {
    border-left-color: #4f7b2f;
}

.summary-card.delivery {
    border-left-color: #2f7382;
}

.summary-card.completed {
    border-left-color: #696f62;
}

.summary-card.line-pending {
    border-left-color: #c7952f;
}

.work-section {
    margin-top: 26px;
}

.section-title {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
}

.section-title h2 {
    margin-bottom: 0;
    font-size: 21px;
}

.section-title span {
    color: var(--muted);
    font-size: 13px;
    white-space: nowrap;
}

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

.task-card {
    position: relative;
    display: grid;
    gap: 9px;
    padding: 14px;
    border: 1px solid var(--line);
    border-top: 4px solid var(--green);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: var(--shadow);
    cursor: pointer;
}

.task-card:hover {
    border-color: #b8c5b1;
    box-shadow: 0 12px 30px rgba(31, 38, 29, 0.12);
}

.line-intake-meta,
.inventory-alert-meta {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
    margin: 0;
}

.line-intake-meta div,
.inventory-alert-meta div {
    padding: 8px 10px;
    border-radius: 8px;
    background: #f7f8f4;
}

.line-intake-meta dt,
.inventory-alert-meta dt {
    color: var(--muted);
    font-size: 12px;
    font-weight: 800;
}

.line-intake-meta dd,
.inventory-alert-meta dd {
    margin: 2px 0 0;
    font-weight: 900;
}

.btn.danger,
.btn-secondary.danger {
    color: var(--red);
    border-color: #e5c8c4;
    background: #fff8f7;
}

.line-intake-editor {
    display: grid;
    gap: 8px;
    padding: 14px;
    border: 1px solid #ead8aa;
    border-radius: 8px;
    background: #fffaf0;
}

.line-intake-editor[hidden] {
    display: none;
}

.line-intake-editor p {
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.5;
}

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

.icon-btn.dots {
    display: inline-grid;
    place-items: center;
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    color: var(--muted);
    background: transparent;
    font: inherit;
    font-size: 16px;
    font-weight: 900;
    letter-spacing: 1px;
    cursor: pointer;
}

.icon-btn.dots:hover,
.icon-btn.dots:focus {
    color: var(--ink);
    background: #eef2ea;
    outline: none;
}

.editor-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    z-index: 5;
    width: 190px;
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 12px 32px rgba(20, 26, 19, 0.18);
}

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

.editor-menu button {
    width: 100%;
    min-height: 40px;
    border: 0;
    border-radius: 8px;
    padding: 8px 10px;
    color: var(--ink);
    background: transparent;
    font: inherit;
    font-size: 14px;
    font-weight: 900;
    text-align: left;
    cursor: pointer;
}

.editor-menu button:hover {
    background: #f9e8e5;
}

.editor-menu button[data-action="editor-delete"] {
    color: var(--red);
}

.task-card.priority-urgent {
    border-top-color: var(--red);
}

.task-card.priority-high {
    border-top-color: var(--orange);
}

.task-card.priority-low {
    border-top-color: var(--blue);
}

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

.source-pill,
.priority-pill {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 5px 9px;
    border-radius: 8px;
    background: #eef2ea;
    color: var(--green);
    font-size: 13px;
    font-weight: 700;
}

.priority-pill {
    background: #fff3e8;
    color: var(--orange);
}

.task-card h3 {
    margin-bottom: 0;
    font-size: 19px;
    line-height: 1.35;
}

.description {
    margin-bottom: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.55;
    display: -webkit-box;
    overflow: hidden;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
}

.flow-status {
    width: max-content;
    max-width: 100%;
    padding: 5px 8px;
    border-radius: 8px;
    color: var(--green);
    background: #edf5ea;
    font-size: 13px;
    font-weight: 900;
}

.card-actions {
    display: flex;
    align-items: center;
    gap: 8px;
    padding-top: 4px;
}

.order-link,
.flow-confirm {
    min-height: 38px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    padding: 8px 11px;
    font-size: 14px;
    font-weight: 900;
    text-decoration: none;
}

.order-link {
    border: 1px solid var(--line);
    color: var(--green);
    background: #f7f8f4;
}

.flow-confirm {
    flex: 1 1 auto;
    border: 0;
    color: #ffffff;
    background: var(--green);
    cursor: pointer;
}

.flow-confirm.archive {
    background: #696f62;
}

.inventory-alert-meta {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 7px;
    margin: 0;
}

.inventory-alert-meta div {
    min-width: 0;
    padding: 8px;
    border: 1px solid #efdbc0;
    border-radius: 8px;
    background: #fff8ec;
}

.inventory-alert-meta dt {
    color: #8a5a18;
    font-size: 12px;
    font-weight: 900;
}

.inventory-alert-meta dd {
    margin: 3px 0 0;
    overflow-wrap: anywhere;
    color: var(--ink);
    font-size: 14px;
    font-weight: 900;
}

.card-date {
    width: max-content;
    max-width: 100%;
    padding: 6px 9px;
    border-radius: 8px;
    color: #765000;
    background: #fff2c4;
    font-size: 14px;
    font-weight: 900;
}

.card-more-toggle {
    justify-self: start;
    min-height: 32px;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 5px 10px;
    color: var(--green);
    background: #f7f8f4;
    font: inherit;
    font-size: 13px;
    font-weight: 900;
    cursor: pointer;
}

.card-more {
    display: grid;
    gap: 10px;
    padding-top: 8px;
    border-top: 1px solid var(--line);
}

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

.task-card.is-expanded {
    cursor: default;
}

.task-card.is-expanded .description {
    display: block;
    overflow: visible;
}

.task-checklist-summary,
.order-checklist {
    display: grid;
    gap: 8px;
    padding: 0;
    border: 0;
    background: transparent;
}

.checklist-toggle {
    display: inline-flex;
    width: max-content;
    align-items: center;
    gap: 8px;
    min-height: 32px;
    border: 0;
    border-radius: 8px;
    padding: 4px 6px;
    color: var(--muted);
    background: transparent;
    font: inherit;
    font-size: 16px;
    font-weight: 800;
    cursor: pointer;
}

.checklist-toggle:hover,
.checklist-toggle:focus {
    color: var(--ink);
    background: #f1f4ec;
    outline: none;
}

.checklist-icon {
    display: inline-grid;
    place-items: center;
    width: 22px;
    height: 22px;
    border: 2px solid #7f887a;
    border-radius: 5px;
    color: #555e51;
    font-size: 15px;
    line-height: 1;
}

.order-checklist {
    padding: 11px;
    border: 1px solid #dce6d6;
    border-radius: 8px;
    background: #fbfcf8;
}

.editor-task-checklist,
.editor-order-block {
    display: grid;
    gap: 10px;
    padding: 12px;
    border: 1px solid #dce6d6;
    border-radius: 8px;
    background: #fbfcf8;
}

.editor-task-checklist[hidden],
.editor-order-block[hidden] {
    display: none;
}

.checklist-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 10px;
}

.checklist-head strong {
    font-size: 14px;
}

.checklist-head span {
    padding: 4px 8px;
    border-radius: 8px;
    color: var(--green);
    background: #edf5ea;
    font-size: 12px;
    font-weight: 800;
    white-space: nowrap;
}

.task-checklist-summary ul,
.order-checklist ul {
    display: grid;
    gap: 7px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.task-checklist-summary ul {
    display: none;
    padding: 9px 10px;
    border: 1px solid #dce6d6;
    border-radius: 8px;
    background: #fbfcf8;
}

.task-checklist-summary.is-open ul {
    display: grid;
}

.editor-order-block ul {
    display: grid;
    gap: 7px;
    margin: 0;
    padding: 0;
    list-style: none;
}

.checklist-lines {
    display: grid;
    gap: 8px;
}

.task-checklist-summary li,
.order-checklist li {
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    min-height: 30px;
    color: var(--ink);
    font-size: 14px;
}

.task-checklist-summary .trello-check-row {
    display: flex;
    grid-template-columns: none;
    min-height: 34px;
}

.task-checklist-summary .trello-check {
    flex: 0 0 18px;
    width: 18px;
    min-width: 18px;
    height: 18px;
    min-height: 18px;
    margin: 0;
    padding: 0;
    border: 1px solid #9bad92;
    border-radius: 5px;
    accent-color: var(--green);
    cursor: pointer;
}

.task-checklist-summary .trello-line {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    min-height: 34px;
    border: 1px solid transparent;
    border-radius: 8px;
    padding: 6px 7px;
    color: var(--ink);
    background: transparent;
    font: inherit;
    font-size: 14px;
    cursor: text;
}

.task-checklist-summary .trello-line:hover,
.task-checklist-summary .trello-line:focus {
    border-color: #cbd4c4;
    background: #ffffff;
    outline: none;
}

.task-checklist-summary li.is-checked .check-text,
.order-checklist li.is-checked .check-text,
.order-checklist li.is-checked strong {
    color: var(--muted);
    text-decoration: line-through;
}

.checklist-edit-row {
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr) 72px 54px 34px;
    align-items: center;
    gap: 7px;
}

.trello-checklist {
    display: grid;
    gap: 8px;
}

.trello-check-row {
    display: flex;
    flex-wrap: nowrap;
    align-items: center;
    gap: 7px;
    min-width: 0;
    cursor: text;
    border-bottom: 1px solid #d8e0d2;
}

.editor-form .trello-check {
    flex: 0 0 19px;
    width: 19px;
    min-width: 19px;
    height: 19px;
    min-height: 19px;
    margin: 0;
    padding: 0;
    border: 1px solid #9bad92;
    border-radius: 5px;
    accent-color: var(--green);
    cursor: pointer;
}

.editor-form .trello-check-row input[type="text"],
.editor-form .trello-check-row input[type="number"] {
    width: 100%;
    min-width: 0;
    min-height: 38px;
    border: 1px solid #d8e0d2;
    border-radius: 8px;
    padding: 7px 8px;
    color: var(--ink);
    background: transparent;
    font: inherit;
    font-size: 14px;
    cursor: text;
    border: none;
}

.trello-line {
    flex: 1 1 auto;
    min-width: 0;
}

.trello-check-row .icon-btn {
    flex: 0 0 34px;
    cursor: pointer;
}

.editor-form .trello-check-row input:hover,
.editor-form .trello-check-row input:focus {
    border-color: #cbd4c4;
    /*background: #ffffff;*/
    outline: none;
    border: none;
}

.trello-check-row:has(.trello-check:checked) .trello-name {
    color: var(--muted);
    text-decoration: line-through;
}

.trello-check-row:has(.trello-check:checked) .trello-line {
    color: var(--muted);
    text-decoration: line-through;
}

.editor-order-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.autosave-state {
    grid-column: 1 / -1;
    min-height: 18px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 700;
}

.checklist-edit-row input {
    width: 100%;
    min-width: 0;
    min-height: 36px;
    border: 1px solid #cbd4c4;
    border-radius: 8px;
    padding: 7px 8px;
    color: var(--ink);
    background: #ffffff;
    font: inherit;
    font-size: 14px;
}

.checklist-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.btn-small {
    min-height: 38px;
    font-size: 14px;
}

.editor-order-block li {
    display: grid;
    grid-template-columns: 18px minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    min-height: 30px;
    color: var(--ink);
    font-size: 14px;
}

.editor-order-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 7px;
}

.editor-order-meta span {
    padding: 6px 8px;
    border-radius: 8px;
    color: var(--muted);
    background: #f1f4ec;
    font-size: 12px;
    font-weight: 800;
}

.check-box {
    width: 16px;
    height: 16px;
    border: 2px solid #aebba7;
    border-radius: 5px;
    background: #ffffff;
}

.check-text {
    min-width: 0;
    overflow-wrap: anywhere;
}

.meta-list {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 9px;
    margin: 0;
}

.meta-list div {
    min-width: 0;
    padding: 10px;
    border-radius: 8px;
    background: #f7f8f4;
}

.meta-list dt {
    margin-bottom: 4px;
    color: var(--muted);
    font-size: 12px;
}

.meta-list dd {
    margin: 0;
    overflow-wrap: anywhere;
    font-size: 14px;
    font-weight: 700;
}

.card-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

.btn {
    min-height: 44px;
    border: 0;
    border-radius: 8px;
    color: #ffffff;
    background: var(--green);
    font-size: 15px;
    font-weight: 800;
    cursor: pointer;
}

.btn-complete {
    background: #1f5d78;
}

.btn-danger {
    background: var(--red);
}

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

.btn:disabled {
    cursor: not-allowed;
    opacity: 0.42;
}

.modal-backdrop {
    position: fixed;
    inset: 0;
    z-index: 30;
    display: grid;
    align-items: end;
    padding: 18px 12px;
    background: rgba(25, 30, 24, 0.46);
}

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

.task-editor {
    width: min(720px, 100%);
    max-height: min(760px, calc(100vh - 36px));
    margin: 0 auto;
    overflow: auto;
    border-radius: 8px;
    background: var(--panel);
    box-shadow: 0 22px 60px rgba(20, 26, 19, 0.28);
}

.editor-head {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 18px;
    border-bottom: 1px solid var(--line);
    background: var(--panel);
}

.editor-head h2 {
    margin-bottom: 0;
    font-size: 22px;
}

.editor-head-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #f7f8f4;
    color: var(--ink);
    font-size: 28px;
    line-height: 1;
    cursor: pointer;
}

.icon-btn.mini {
    width: 34px;
    height: 34px;
    font-size: 22px;
}

.icon-btn.dots {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 50%;
    background: transparent;
    font-size: 16px;
    line-height: 1;
}

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

.editor-form label {
    display: grid;
    gap: 7px;
    color: var(--muted);
    font-size: 13px;
    font-weight: 700;
}

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

.editor-form textarea {
    min-height: 110px;
    resize: vertical;
}

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

.editor-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
    padding-top: 4px;
}

.empty-state {
    padding: 18px;
    border: 1px dashed #c9d1c2;
    border-radius: 8px;
    color: var(--muted);
    background: rgba(255, 255, 255, 0.72);
    text-align: center;
}

.empty-state.compact {
    padding: 11px;
    font-size: 13px;
}

.toast {
    position: fixed;
    right: 14px;
    bottom: 18px;
    left: 14px;
    z-index: 20;
    transform: translateY(16px);
    opacity: 0;
    pointer-events: none;
    padding: 13px 16px;
    border-radius: 8px;
    color: #ffffff;
    background: #263126;
    text-align: center;
    transition: opacity 160ms ease, transform 160ms ease;
}

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

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

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

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

    .modal-backdrop {
        align-items: center;
    }

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

@media (min-width: 1040px) {
    .summary-grid {
        grid-template-columns: repeat(6, minmax(0, 1fr));
    }

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

/* Full-screen editor, Trello-style: close left, actions right, content scrolls inside. */
.modal-backdrop {
    display: block;
    padding: 0;
}

.task-editor {
    width: 100%;
    height: 100vh;
    height: 100dvh;
    max-height: none;
    margin: 0;
    border-radius: 0;
    box-shadow: none;
}

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

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

.editor-head-menu {
    justify-self: end;
}

.editor-head .icon-btn {
    width: 42px;
    height: 42px;
}

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