/* ================================================================
   PERSONAL ERP D8 — TASK PANEL AND DIRECT EDITING
   Adaptive list-detail workflow with autosave and undo feedback.
   ================================================================ */

html[data-theme] .d8-task-panel {
    width: min(520px, 100vw);
    max-width: none;
    height: 100dvh;
    max-height: none;
    margin: 0 0 0 auto;
    padding: 0;
    overflow: hidden;
    border: 0;
    background: transparent;
    color: var(--ui-text);
}

html[data-theme] .d8-task-panel::backdrop {
    background: rgba(15, 23, 42, .38);
    backdrop-filter: blur(2px);
}

html[data-theme] .d8-task-panel-surface {
    width: 100%;
    height: 100%;
    overflow-y: auto;
    overscroll-behavior: contain;
    background: var(--ui-surface);
    box-shadow: -18px 0 44px rgba(15, 23, 42, .18);
}

html[data-theme] .d8-task-panel-content {
    display: flex;
    min-height: 100%;
    flex-direction: column;
}

html[data-theme] .d8-panel-header {
    position: sticky;
    z-index: 4;
    top: 0;
    display: flex;
    min-height: 66px;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    padding: 11px 14px;
    border-bottom: 1px solid var(--ui-border);
    background: color-mix(in srgb, var(--ui-surface) 94%, transparent);
    backdrop-filter: blur(16px);
}

html[data-theme] .d8-panel-header > div:first-child {
    display: grid;
    gap: 1px;
}

html[data-theme] .d8-panel-header .eyebrow {
    margin: 0;
}

html[data-theme] .d8-save-state {
    color: var(--ui-text-muted);
    font-size: .68rem;
    font-weight: 750;
}

html[data-theme] .d8-save-state[data-state="saving"] {
    color: var(--ui-primary);
}

html[data-theme] .d8-save-state[data-state="saved"] {
    color: var(--ui-success);
}

html[data-theme] .d8-save-state[data-state="error"] {
    color: var(--ui-danger);
}

html[data-theme] .d8-panel-header-actions {
    display: flex;
    align-items: center;
    gap: 5px;
}

html[data-theme] .d8-panel-header-actions a,
html[data-theme] .d8-panel-header-actions button {
    display: grid;
    width: 42px;
    height: 42px;
    place-items: center;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: var(--ui-text-muted);
    cursor: pointer;
}

html[data-theme] .d8-panel-header-actions a:hover,
html[data-theme] .d8-panel-header-actions button:hover {
    background: var(--ui-bg-subtle);
    color: var(--ui-text);
}

html[data-theme] .d8-inline-form {
    display: grid;
    gap: 15px;
    padding: 18px;
}

html[data-theme] .d8-panel-title {
    display: block;
}

html[data-theme] .d8-panel-title input {
    width: 100%;
    min-height: 54px;
    padding: 7px 9px;
    border: 1px solid transparent;
    border-radius: 12px;
    background: transparent;
    color: var(--ui-text);
    font-size: clamp(1.35rem, 2.2vw, 1.8rem);
    font-weight: 850;
    line-height: 1.18;
}

html[data-theme] .d8-panel-title input:hover {
    background: var(--ui-bg-subtle);
}

html[data-theme] .d8-panel-title input:focus {
    border-color: var(--ui-primary);
    background: var(--ui-surface-raised);
}

html[data-theme] .d8-panel-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

html[data-theme] .d8-panel-badges .d31-priority,
html[data-theme] .d8-panel-badges .d31-status-pill,
html[data-theme] .d8-panel-badges .d31-visibility-pill {
    display: inline-flex;
    min-height: 25px;
    align-items: center;
    padding: 5px 8px;
    font-size: .66rem;
}

html[data-theme] .d8-panel-fields {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
}

html[data-theme] .d8-panel-fields label,
html[data-theme] .d8-panel-description {
    display: grid;
    min-width: 0;
    gap: 6px;
}

html[data-theme] .d8-panel-fields label > span,
html[data-theme] .d8-panel-description > span {
    color: var(--ui-text-muted);
    font-size: .7rem;
    font-weight: 800;
}

html[data-theme] .d8-panel-fields input,
html[data-theme] .d8-panel-fields select,
html[data-theme] .d8-panel-description textarea {
    width: 100%;
    min-height: 44px;
    border-color: var(--ui-border);
    background: var(--ui-surface-raised);
}

html[data-theme] .d8-panel-field-wide {
    grid-column: 1 / -1;
}

html[data-theme] .d8-panel-description textarea {
    min-height: 112px;
    resize: vertical;
}

html[data-theme] .d8-inline-form :disabled {
    cursor: not-allowed;
    opacity: .66;
}

html[data-theme] .d8-panel-checklist {
    display: grid;
    gap: 10px;
    margin: 0 18px 16px;
    padding: 15px;
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-md);
    background: var(--ui-surface-raised);
}

html[data-theme] .d8-panel-checklist > header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

html[data-theme] .d8-panel-checklist > header .eyebrow {
    margin: 0 0 1px;
}

html[data-theme] .d8-panel-checklist > header h2 {
    margin: 0;
    color: var(--ui-text);
    font-size: 1rem;
}

html[data-theme] .d8-panel-checklist > header > span {
    display: grid;
    min-width: 34px;
    min-height: 30px;
    place-items: center;
    border-radius: 999px;
    background: var(--ui-bg-subtle);
    color: var(--ui-text-muted);
    font-size: .7rem;
    font-weight: 850;
}

html[data-theme] .d8-checklist-add {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 7px;
}

html[data-theme] .d8-checklist-add input {
    min-width: 0;
    min-height: 44px;
}

html[data-theme] .d8-checklist-add button {
    min-height: 44px;
    padding: 8px 13px;
    border: 0;
    border-radius: 11px;
    background: var(--ui-primary);
    color: #fff;
    cursor: pointer;
    font-weight: 800;
}

html[data-theme] .d8-checklist-list {
    display: grid;
    gap: 4px;
}

html[data-theme] .d8-checklist-list > article {
    display: grid;
    min-height: 46px;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 8px;
    padding: 4px;
    border-radius: 11px;
}

html[data-theme] .d8-checklist-list > article:hover {
    background: var(--ui-bg-subtle);
}

html[data-theme] .d8-checklist-list > article.completed > span {
    color: var(--ui-text-muted);
    text-decoration: line-through;
}

html[data-theme] .d8-checklist-toggle,
html[data-theme] .d8-checklist-delete {
    display: grid;
    width: 38px;
    height: 38px;
    place-items: center;
    border-radius: 10px;
    background: transparent;
    cursor: pointer;
}

html[data-theme] .d8-checklist-toggle {
    border: 2px solid var(--ui-border-strong);
    color: var(--ui-success);
}

html[data-theme] .completed .d8-checklist-toggle {
    border-color: var(--ui-success);
    background: var(--ui-success-soft);
}

html[data-theme] .d8-checklist-delete {
    border: 0;
    color: var(--ui-text-soft);
    font-size: 1.15rem;
}

html[data-theme] .d8-checklist-delete:hover {
    background: var(--ui-danger-soft);
    color: var(--ui-danger);
}

html[data-theme] .d8-panel-empty {
    padding: 13px;
    border-radius: 11px;
    background: var(--ui-bg-subtle);
    color: var(--ui-text-muted);
    font-size: .76rem;
    line-height: 1.45;
}

html[data-theme] .d8-panel-footer {
    position: sticky;
    z-index: 3;
    bottom: 0;
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: auto;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    border-top: 1px solid var(--ui-border);
    background: color-mix(in srgb, var(--ui-surface) 94%, transparent);
    backdrop-filter: blur(16px);
}

html[data-theme] .d8-panel-footer > form,
html[data-theme] .d8-panel-footer > a {
    flex: 1;
}

html[data-theme] .d8-panel-footer button,
html[data-theme] .d8-panel-footer > a {
    width: 100%;
    min-height: 44px;
}

html[data-theme] .d8-panel-loading {
    display: grid;
    gap: 14px;
    padding: 82px 20px 20px;
}

html[data-theme] .d8-panel-loading span {
    height: 44px;
    border-radius: 12px;
    background:
        linear-gradient(
            90deg,
            var(--ui-bg-subtle) 25%,
            var(--ui-surface-raised) 50%,
            var(--ui-bg-subtle) 75%
        );
    background-size: 200% 100%;
    animation: d8-loading 1.15s linear infinite;
}

html[data-theme] .d8-panel-loading span:first-child {
    width: 72%;
    height: 58px;
}

html[data-theme] .d8-panel-loading span:nth-child(2) {
    width: 45%;
    height: 26px;
}

html[data-theme] .d8-panel-loading span:nth-child(4) {
    height: 150px;
}

@keyframes d8-loading {
    to {
        background-position: -200% 0;
    }
}

html[data-theme] .d8-panel-error {
    display: grid;
    min-height: 100dvh;
    place-content: center;
    gap: 10px;
    padding: 30px;
    text-align: center;
}

html[data-theme] .d8-panel-error strong {
    color: var(--ui-text);
    font-size: 1.1rem;
}

html[data-theme] .d8-panel-error p {
    margin: 0;
    color: var(--ui-text-muted);
}

html[data-theme] .d8-panel-error a {
    color: var(--ui-primary);
    font-weight: 800;
}

/* Compact feedback with an explicit undo path */
html[data-theme] .d8-toast {
    position: fixed;
    z-index: 140;
    right: 18px;
    bottom: 18px;
    display: flex;
    min-height: 48px;
    align-items: center;
    gap: 12px;
    max-width: min(420px, calc(100vw - 28px));
    padding: 10px 12px 10px 15px;
    border: 1px solid var(--ui-border);
    border-radius: 14px;
    background: var(--ui-text);
    color: var(--ui-surface);
    box-shadow: var(--ui-shadow-lg);
}

html[data-theme] .d8-toast[hidden] {
    display: none;
}

html[data-theme] .d8-toast[data-tone="error"] {
    background: var(--ui-danger);
    color: #fff;
}

html[data-theme] .d8-toast span {
    min-width: 0;
    flex: 1;
    font-size: .8rem;
    font-weight: 750;
}

html[data-theme] .d8-toast button {
    min-height: 36px;
    padding: 7px 9px;
    border: 0;
    border-radius: 9px;
    background: rgba(255, 255, 255, .14);
    color: inherit;
    cursor: pointer;
    font-weight: 850;
}

/* Reduce the card-inside-card effect in task collections */
html[data-theme] .d31-task-list {
    gap: 0;
    overflow: visible;
    border: 1px solid var(--ui-border);
    border-radius: var(--ui-radius-md);
    background: var(--ui-surface);
}

html[data-theme] .d31-task-list .d31-task-card {
    border: 0;
    border-bottom: 1px solid var(--ui-border);
    border-radius: 0;
    background: transparent;
}

html[data-theme] .d31-task-list .d31-task-card:first-child {
    border-radius: var(--ui-radius-md) var(--ui-radius-md) 0 0;
}

html[data-theme] .d31-task-list .d31-task-card:last-child {
    border-bottom: 0;
    border-radius: 0 0 var(--ui-radius-md) var(--ui-radius-md);
}

html[data-theme] .d31-task-list .d31-task-card:only-child {
    border-radius: var(--ui-radius-md);
}

html[data-theme] .d8-task-panel :focus-visible,
html[data-theme] .d8-toast :focus-visible {
    outline: 2px solid var(--ui-primary);
    outline-offset: 2px;
}

@media (max-width: 760px) {
    html[data-theme] .d8-task-panel {
        width: 100vw;
        height: 100dvh;
        margin: 0;
    }

    html[data-theme] .d8-task-panel::backdrop {
        background: rgba(15, 23, 42, .22);
        backdrop-filter: none;
    }

    html[data-theme] .d8-task-panel-surface {
        box-shadow: none;
    }

    html[data-theme] .d8-panel-header {
        min-height: 60px;
        padding: 8px 10px;
    }

    html[data-theme] .d8-inline-form {
        gap: 13px;
        padding: 14px 12px;
    }

    html[data-theme] .d8-panel-title input {
        min-height: 52px;
        padding-inline: 5px;
        font-size: 1.42rem;
    }

    html[data-theme] .d8-panel-fields {
        grid-template-columns: 1fr;
        gap: 9px;
    }

    html[data-theme] .d8-panel-field-wide {
        grid-column: 1;
    }

    html[data-theme] .d8-panel-fields input,
    html[data-theme] .d8-panel-fields select {
        min-height: 48px;
    }

    html[data-theme] .d8-panel-checklist {
        margin: 0 10px 12px;
        padding: 12px;
        border-radius: 15px;
    }

    html[data-theme] .d8-checklist-add {
        grid-template-columns: 1fr;
    }

    html[data-theme] .d8-checklist-add button {
        min-height: 46px;
    }

    html[data-theme] .d8-panel-footer {
        gap: 6px;
        padding: 9px 10px calc(9px + env(safe-area-inset-bottom));
    }

    html[data-theme] .d8-panel-footer button,
    html[data-theme] .d8-panel-footer > a {
        min-height: 48px;
        font-size: .76rem;
    }

    html[data-theme] .d8-toast {
        right: 10px;
        bottom: calc(76px + env(safe-area-inset-bottom));
        left: 10px;
        max-width: none;
    }

    html[data-theme] .d31-task-list {
        border-radius: 15px;
    }

    html[data-theme] .d31-task-list .d31-task-card:first-child {
        border-radius: 15px 15px 0 0;
    }

    html[data-theme] .d31-task-list .d31-task-card:last-child {
        border-radius: 0 0 15px 15px;
    }

    html[data-theme] .d31-task-list .d31-task-card:only-child {
        border-radius: 15px;
    }
}

html[data-motion="reduce"] .d8-panel-loading span {
    animation: none;
}
