.glass {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--r);
    box-shadow: var(--shadow)
}

.btn,
.icon-btn {
    background: var(--green);
    color: #fffefa;
    border: 0;
    border-radius: 999px;
    padding: .6rem 1.1rem;
    font: 600 .95rem var(--sans);
    cursor: pointer;
    min-height: 44px;
    text-decoration: none;
    display: inline-block
}

.btn.ghost {
    background: transparent;
    color: var(--ink);
    border: 1px solid var(--line)
}

.btn:hover,
.icon-btn:hover {
    filter: brightness(1.08);
    transform: translateY(-1px)
}

.btn.danger {
    background: #b4533f;
    color: #fff
}

.icon-btn {
    padding: .4rem .9rem;
    min-height: 40px
}

.btn:disabled {
    opacity: .5
}

input,
select,
textarea {
    width: 100%;
    background: #fffefa;
    color: var(--ink);
    border: 1px solid #dcded4;
    border-radius: 11px;
    padding: .76rem .85rem;
    font: inherit;
    transition: border-color .2s, box-shadow .2s
}

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--green);
    box-shadow: 0 0 0 3px rgba(53, 93, 74, .12)
}

label {
    display: block;
    margin: .6rem 0;
    color: var(--ink);
    font-size: .87rem;
    font-weight: 600
}

.badge {
    font: 600 .7rem var(--sans);
    color: var(--green);
    border: 1px solid #b5cbb9;
    border-radius: 999px;
    padding: .1rem .5rem;
    vertical-align: middle
}

.badge.warn {
    color: #e0a06a;
    border-color: #e0a06a
}

#toasts {
    position: fixed;
    top: 4.5rem;
    right: 1rem;
    display: grid;
    gap: .5rem;
    width: min(390px, calc(100vw - 2rem));
    max-height: calc(100vh - 6rem);
    overflow-y: auto;
    z-index: 1100
}

.toast {
    background: var(--surface);
    border: 1px solid var(--line);
    padding: .7rem 1rem;
    border-radius: 10px;
    animation: in .25s
}

.toast.error {
    border: 2px solid #b42318;
    border-left-width: 8px;
    background: #fff1ef;
    color: #68140e;
    padding: 1rem 1.15rem;
    font-weight: 700;
    line-height: 1.45;
    box-shadow: 0 10px 30px rgba(90, 20, 12, .2)
}

.toast.success {
    border-color: var(--green)
}

@keyframes in {
    from {
        transform: translateY(8px);
        opacity: 0
    }
}

dialog {
    background: var(--surface);
    color: var(--ink);
    border: 1px solid var(--line);
    border-radius: var(--r);
    max-width: min(480px, 92vw)
}

dialog h2 {
    margin-bottom: .35rem
}

dialog form {
    display: grid;
    gap: .4rem
}

dialog::backdrop {
    background: rgba(0, 0, 0, .6)
}

.sk {
    min-height: 260px;
    background: linear-gradient(90deg, var(--surface), #30281f, var(--surface));
    background-size: 200% 100%;
    animation: sh 1.4s infinite;
    border-radius: var(--r)
}

@keyframes sh {
    to {
        background-position: -200% 0
    }
}

.empty {
    color: var(--muted);
    padding: 2rem;
    text-align: center;
    grid-column: 1/-1
}

.api-loading {
    position: fixed;
    z-index: 2000;
    inset: 0;
    display: grid;
    place-items: center;
    background: rgba(247, 245, 239, .96);
    opacity: 0;
    visibility: hidden;
    transition: opacity .24s ease, visibility .24s;
    pointer-events: none
}

.api-loading.is-visible {
    opacity: 1;
    visibility: visible
}

.api-loading-dots {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: .55rem;
    min-height: 28px;
    margin-top: 1.1rem
}

.api-loading-dots > span {
    width: 11px;
    height: 11px;
    border-radius: 50%;
    background: #8b6817;
    box-shadow: 0 0 10px rgba(139, 104, 23, .42);
    animation: api-loading-dot 0.9s ease-in-out infinite
}

.api-loading-dots > span:nth-child(2) {
    animation-delay: .15s
}

.api-loading-dots > span:nth-child(3) {
    animation-delay: .3s
}

.pwa-tools {
    position: fixed;
    z-index: 900;
    right: 1rem;
    bottom: 1rem;
    display: flex;
    max-width: min(440px, calc(100vw - 2rem));
    align-items: end;
    gap: .55rem;
    flex-wrap: wrap;
    justify-content: end
}

.pwa-control {
    min-height: 42px;
    padding: .55rem .95rem;
    border: 1px solid rgba(255, 255, 255, .35);
    box-shadow: 0 7px 22px rgba(39, 42, 36, .16);
    font-size: .79rem
}

.pwa-status {
    order: 2;
    width: 100%;
    padding: .65rem .85rem;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    box-shadow: var(--shadow);
    color: var(--ink);
    font-size: .78rem
}

.pwa-status[data-kind="offline"] {
    border-color: #dfc79e;
    background: #fff8e9
}

.pwa-status[data-kind="success"] {
    border-color: #b5cbb9;
    background: #f2f7f0
}

.insight-upload {
    display: block;
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: rgba(255, 254, 250, .72)
}

.insight-upload .field-label {
    margin-bottom: .65rem
}

.upload-file-input {
    display: block;
    width: 100%;
    min-height: 48px;
    padding: .45rem;
    border: 1px dashed #b9c9b9;
    background: #fffefa;
    cursor: pointer
}

.upload-file-input::file-selector-button {
    margin-right: .75rem;
    padding: .45rem .7rem;
    border: 1px solid #c9c9c9;
    border-radius: 4px;
    background: #f2f2f2;
    color: #242424;
    font: 400 .88rem var(--sans);
    cursor: pointer
}

.upload-file-input::file-selector-button:hover {
    background: #e8e8e8
}

.insight-file-input + .field-count,
.upload-selection {
    display: block;
    margin-top: .55rem;
    color: var(--green);
    font-size: .82rem;
    overflow-wrap: anywhere
}

@keyframes api-loading-dot {
    0%, 60%, 100% {
        opacity: .58;
        transform: translateY(0) scale(.82)
    }

    30% {
        opacity: 1;
        transform: translateY(-8px) scale(1.08);
        box-shadow: 0 0 14px rgba(139, 104, 23, .62)
    }
}

@media (max-width: 640px) {
    main {
        padding: .8rem 1rem 3rem
    }

    .pwa-tools {
        right: .75rem;
        bottom: .75rem
    }

    #toasts {
        top: 4rem;
        right: .75rem;
        width: min(390px, calc(100vw - 1.5rem));
        max-height: calc(100vh - 5rem)
    }
}

@media (prefers-reduced-motion: reduce) {
    .api-loading-dots > span {
        animation: none;
        opacity: 1;
        transform: none
    }
}

@media (prefers-color-scheme: dark) {
    input,
    select,
    textarea {
        background: #18201b;
        color: var(--ink);
        border-color: var(--line)
    }

    .btn.ghost {
        color: var(--ink);
        border-color: var(--line)
    }

    .toast.error {
        border-color: #ff796e;
        background: #3a201f;
        color: #ffe3df;
        box-shadow: 0 8px 24px rgba(0, 0, 0, .35)
    }

    .toast.success {
        background: #1d3025;
        color: #d8f1dd
    }

    .sk {
        background: var(--surface);
        animation: none
    }
}
