:root {
    color-scheme: light;
    --canvas: #eef5f6;
    --surface: #ffffff;
    --surface-raised: #ffffff;
    --surface-muted: #f3f7f8;
    --sidebar: #0d2530;
    --sidebar-muted: #9db2b9;
    --sidebar-hover: #163946;
    --sidebar-active: #1c4e58;
    --text: #14282f;
    --text-muted: #60747b;
    --line: #d7e2e5;
    --line-strong: #bfd0d4;
    --primary: #0b747a;
    --primary-hover: #075e63;
    --primary-soft: #dff3f2;
    --accent: #29c3b1;
    --danger: #b8333b;
    --danger-hover: #92272e;
    --danger-soft: #fff0f0;
    --focus: #22a8c5;
    --shadow: 0 18px 50px rgba(24, 55, 64, 0.16);
    --radius-sm: 0.55rem;
    --radius-md: 0.85rem;
    --radius-lg: 1.15rem;
    --sidebar-width: 18.5rem;
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 16px;
}

@media (prefers-color-scheme: dark) {
    :root {
        color-scheme: dark;
        --canvas: #0d171b;
        --surface: #132228;
        --surface-raised: #172a31;
        --surface-muted: #192c32;
        --sidebar: #08171d;
        --sidebar-muted: #8fa6ad;
        --sidebar-hover: #122d36;
        --sidebar-active: #17424b;
        --text: #edf6f7;
        --text-muted: #a1b4ba;
        --line: #294047;
        --line-strong: #38535b;
        --primary: #29a8a8;
        --primary-hover: #38bdb8;
        --primary-soft: #153b3d;
        --accent: #45d2be;
        --danger: #e26d72;
        --danger-hover: #f18185;
        --danger-soft: #3c2024;
        --focus: #4bc5de;
        --shadow: 0 18px 60px rgba(0, 0, 0, 0.38);
    }
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
    min-height: 100%;
    margin: 0;
}

body {
    overflow: hidden;
    background: var(--canvas);
    color: var(--text);
    line-height: 1.45;
    -webkit-font-smoothing: antialiased;
}

button,
input {
    color: inherit;
    font: inherit;
}

button {
    -webkit-tap-highlight-color: transparent;
}

button:not(:disabled) {
    cursor: pointer;
}

button:disabled,
input:disabled {
    cursor: not-allowed;
    opacity: 0.58;
}

[hidden] {
    display: none !important;
}

:focus-visible {
    outline: 3px solid var(--focus);
    outline-offset: 2px;
}

svg {
    width: 1.25rem;
    height: 1.25rem;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 1.8;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.app-shell {
    display: grid;
    grid-template-columns: var(--sidebar-width) minmax(0, 1fr);
    width: 100%;
    height: 100vh;
    height: 100dvh;
}

body.access-locked .app-shell {
    grid-template-columns: minmax(0, 1fr);
}

body.access-locked .sidebar,
body.access-locked .sidebar-scrim {
    display: none;
}

.sidebar {
    position: relative;
    z-index: 20;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto auto;
    min-width: 0;
    padding: 1.15rem 0.9rem max(1rem, env(safe-area-inset-bottom));
    overflow: hidden;
    background: var(--sidebar);
    color: #f1fbfc;
}

.brand-row,
.sidebar-heading,
.list-header,
.section-heading,
.dialog-heading,
.dialog-actions,
.copy-row,
.rename-row,
.inline-actions {
    display: flex;
    align-items: center;
}

.brand-row {
    justify-content: space-between;
    min-height: 3rem;
    padding: 0 0.35rem 1rem;
}

.brand {
    display: inline-flex;
    gap: 0.7rem;
    align-items: center;
    color: inherit;
    font-size: 1.15rem;
    font-weight: 750;
    letter-spacing: -0.02em;
    text-decoration: none;
}

.brand-mark {
    display: grid;
    width: 2rem;
    height: 2rem;
    place-items: center;
    border-radius: 0.6rem;
    background: var(--accent);
    color: #052e31;
}

.brand-mark svg {
    width: 1.15rem;
}

.sidebar-heading {
    justify-content: space-between;
    margin: 0.45rem 0.35rem 0.6rem;
    color: var(--sidebar-muted);
    font-size: 0.875rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.list-navigation {
    display: flex;
    min-height: 0;
    flex-direction: column;
    gap: 0.3rem;
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
}

.list-link {
    display: grid;
    grid-template-columns: 2rem minmax(0, 1fr);
    gap: 0.7rem;
    align-items: center;
    width: 100%;
    min-height: 3.25rem;
    padding: 0.55rem 0.65rem;
    border: 0;
    border-radius: 0.75rem;
    background: transparent;
    color: #dcebed;
    text-align: left;
}

.list-link:hover {
    background: var(--sidebar-hover);
}

.list-link[aria-current="page"] {
    background: var(--sidebar-active);
    color: #ffffff;
}

.list-monogram {
    display: grid;
    width: 2rem;
    height: 2rem;
    place-items: center;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 0.55rem;
    background: rgba(69, 210, 190, 0.13);
    color: #73e0d2;
    font-size: 0.85rem;
    font-weight: 800;
    text-transform: uppercase;
}

.list-link-name {
    overflow: hidden;
    font-weight: 650;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sidebar-empty {
    align-self: start;
    padding: 0.8rem 0.65rem;
    color: var(--sidebar-muted);
    font-size: 0.875rem;
    line-height: 1.5;
}

.sidebar-footer {
    padding-top: 0.8rem;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar .secondary-button {
    border-color: rgba(255, 255, 255, 0.16);
    background: rgba(255, 255, 255, 0.06);
    color: #eaf5f6;
}

.sidebar .secondary-button:hover {
    background: rgba(255, 255, 255, 0.11);
}

.sidebar-scrim {
    display: none;
}

.main-surface {
    min-width: 0;
    min-height: 0;
    background: var(--canvas);
}

.welcome {
    position: relative;
    display: grid;
    min-height: 100%;
    padding: 2rem;
    place-items: center;
}

.welcome-card {
    width: min(100%, 34rem);
    padding: clamp(1.7rem, 5vw, 3.25rem);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface);
    box-shadow: var(--shadow);
    text-align: center;
}

.welcome-mark {
    display: grid;
    width: 4.7rem;
    height: 4.7rem;
    margin: 0 auto 1.3rem;
    place-items: center;
    border-radius: 1.2rem;
    background: var(--primary-soft);
    color: var(--primary);
}

.welcome-mark svg {
    width: 3rem;
    height: 3rem;
    stroke-width: 2.6;
}

.welcome h1,
.list-header h1,
.dialog-heading h2,
.unavailable-state h2 {
    margin: 0;
    letter-spacing: -0.035em;
    line-height: 1.15;
}

.welcome h1 {
    font-size: clamp(1.8rem, 5vw, 2.45rem);
}

.welcome p {
    max-width: 27rem;
    margin: 0.85rem auto 1.6rem;
    color: var(--text-muted);
    font-size: 1rem;
}

.welcome-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.7rem;
    justify-content: center;
}

.access-form {
    display: grid;
    gap: 0.7rem;
    margin-top: 1.5rem;
    text-align: left;
}

.access-form label {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 650;
}

.access-form .primary-button {
    width: 100%;
    margin-top: 0.2rem;
}

.list-view {
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto;
    height: 100%;
    min-height: 0;
}

.list-header {
    position: relative;
    z-index: 5;
    min-height: 5.5rem;
    gap: 0.85rem;
    padding: 1rem clamp(1rem, 4vw, 2.5rem);
    border-bottom: 1px solid var(--line);
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(14px);
}

.list-title-group {
    min-width: 0;
    margin-right: auto;
}

.list-header h1 {
    overflow: hidden;
    max-width: min(58vw, 42rem);
    font-size: clamp(1.35rem, 3vw, 1.85rem);
    text-overflow: ellipsis;
    white-space: nowrap;
}

.sync-status {
    display: block;
    min-height: 1.2rem;
    margin-top: 0.22rem;
    color: var(--text-muted);
    font-size: 0.8rem;
}

.sync-status[data-state="error"] {
    color: var(--danger);
}

.header-actions {
    display: flex;
    gap: 0.5rem;
    align-items: center;
}

.list-content {
    min-height: 0;
    padding: 1.25rem clamp(1rem, 4vw, 2.5rem) 2rem;
    overflow-y: auto;
    overscroll-behavior: contain;
}

#items-region,
.loading-state,
.unavailable-state {
    width: min(100%, 52rem);
    margin: 0 auto;
}

.section-heading {
    min-height: 2.4rem;
    justify-content: space-between;
    margin-bottom: 0.35rem;
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.items-list {
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    padding: 0;
    margin: 0;
    list-style: none;
}

.item-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    gap: 0.8rem;
    align-items: center;
    min-height: 4.1rem;
    padding: 0.65rem 0.65rem 0.65rem 0.85rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: var(--surface);
    box-shadow: 0 2px 5px rgba(26, 55, 61, 0.025);
}

.item-row:hover {
    border-color: var(--line-strong);
}

.check-control {
    position: relative;
    display: grid;
    width: 2.75rem;
    height: 2.75rem;
    place-items: center;
}

.item-checkbox {
    width: 1.5rem;
    height: 1.5rem;
    margin: 0;
    border: 2px solid var(--line-strong);
    border-radius: 0.42rem;
    appearance: none;
    background: var(--surface-raised);
}

.item-checkbox:checked {
    border-color: var(--primary);
    background: var(--primary);
}

.item-checkbox:checked + .check-icon::after {
    position: absolute;
    top: 0.78rem;
    left: 1.03rem;
    width: 0.42rem;
    height: 0.72rem;
    border: solid #ffffff;
    border-width: 0 2px 2px 0;
    content: "";
    transform: rotate(45deg);
}

.item-copy {
    min-width: 0;
}

.item-name {
    display: block;
    overflow-wrap: anywhere;
    font-size: 1rem;
    font-weight: 650;
}

.item-quantity {
    display: inline-block;
    margin-top: 0.18rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.completed-list .item-row {
    background: var(--surface-muted);
    box-shadow: none;
}

.completed-list .item-name {
    color: var(--text-muted);
    font-weight: 520;
    text-decoration: line-through;
    text-decoration-thickness: 1px;
}

.completed-section {
    margin-top: 1.35rem;
    padding-top: 0.45rem;
    border-top: 1px solid var(--line);
}

.completed-heading {
    margin-bottom: 0.45rem;
}

.empty-list {
    display: grid;
    min-height: 16rem;
    place-items: center;
    align-content: center;
    color: var(--text-muted);
    text-align: center;
}

.empty-list svg {
    width: 3.2rem;
    height: 3.2rem;
    margin-bottom: 0.8rem;
    color: var(--primary);
    opacity: 0.68;
}

.empty-list strong {
    margin-bottom: 0.25rem;
    color: var(--text);
    font-size: 1.05rem;
}

.empty-list span {
    font-size: 0.9rem;
}

.loading-state {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
    padding-top: 1.8rem;
}

.loading-state span {
    display: block;
    height: 4rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: linear-gradient(90deg, var(--surface) 20%, var(--surface-muted) 50%, var(--surface) 80%);
    background-size: 220% 100%;
    animation: loading 1.25s ease-in-out infinite;
}

.loading-state span:nth-child(2) {
    animation-delay: 0.12s;
}

.loading-state span:nth-child(3) {
    animation-delay: 0.24s;
}

@keyframes loading {
    from { background-position: 100% 0; }
    to { background-position: -100% 0; }
}

.unavailable-state {
    padding: 3rem 1rem;
    text-align: center;
}

.unavailable-state h2 {
    font-size: 1.35rem;
}

.unavailable-state p {
    max-width: 32rem;
    margin: 0.65rem auto 1.25rem;
    color: var(--text-muted);
}

.inline-actions {
    flex-wrap: wrap;
    gap: 0.65rem;
    justify-content: center;
}

.add-item-form {
    position: relative;
    z-index: 4;
    display: grid;
    grid-template-columns: minmax(5.5rem, 0.2fr) minmax(6.5rem, 0.25fr) minmax(12rem, 1fr) auto;
    gap: 0.65rem;
    padding: 1rem clamp(1rem, 4vw, 2.5rem) max(1rem, env(safe-area-inset-bottom));
    border-top: 1px solid var(--line);
    background: var(--surface);
}

.add-item-form > * {
    min-width: 0;
}

input[type="text"] {
    width: 100%;
    min-height: 3rem;
    padding: 0.65rem 0.8rem;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius-sm);
    background: var(--surface-raised);
    color: var(--text);
}

input[type="text"]::placeholder {
    color: color-mix(in srgb, var(--text-muted) 78%, transparent);
}

input[type="text"]:focus {
    border-color: var(--focus);
    outline: 3px solid color-mix(in srgb, var(--focus) 20%, transparent);
}

.primary-button,
.secondary-button,
.danger-button,
.text-button,
.danger-text-button,
.icon-button {
    min-height: 2.75rem;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-weight: 700;
}

.primary-button,
.secondary-button,
.danger-button {
    display: inline-flex;
    gap: 0.5rem;
    align-items: center;
    justify-content: center;
    padding: 0.62rem 0.95rem;
    border: 1px solid transparent;
}

.primary-button {
    background: var(--primary);
    color: #ffffff;
}

.primary-button:hover {
    background: var(--primary-hover);
}

.secondary-button {
    border-color: var(--line-strong);
    background: var(--surface-raised);
    color: var(--text);
}

.secondary-button:hover {
    background: var(--surface-muted);
}

.danger-button {
    background: var(--danger);
    color: #ffffff;
}

.danger-button:hover {
    background: var(--danger-hover);
}

.text-button,
.danger-text-button {
    min-height: 2.5rem;
    padding: 0.35rem 0.25rem;
    border: 0;
    background: transparent;
    color: var(--primary);
}

.text-button:hover,
.danger-text-button:hover {
    text-decoration: underline;
}

.danger-text-button {
    color: var(--danger);
}

.icon-button {
    display: inline-grid;
    width: 2.75rem;
    min-width: 2.75rem;
    padding: 0;
    place-items: center;
    border: 1px solid var(--line);
    background: var(--surface-raised);
    color: var(--text-muted);
}

.icon-button:hover {
    border-color: var(--line-strong);
    background: var(--surface-muted);
    color: var(--text);
}

.icon-button.compact {
    width: 2.25rem;
    min-width: 2.25rem;
    min-height: 2.25rem;
    border-color: rgba(255, 255, 255, 0.13);
    background: rgba(255, 255, 255, 0.06);
    color: #deedef;
}

.icon-button.compact:hover {
    background: rgba(255, 255, 255, 0.12);
}

.full-width {
    width: 100%;
}

.mobile-menu,
.sidebar-close {
    display: none;
}

dialog {
    width: min(calc(100% - 2rem), 34rem);
    max-height: min(calc(100dvh - 2rem), 44rem);
    padding: 0;
    overflow: visible;
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    background: var(--surface-raised);
    color: var(--text);
    box-shadow: var(--shadow);
}

dialog::backdrop {
    background: rgba(3, 17, 22, 0.62);
    backdrop-filter: blur(3px);
}

.dialog-card {
    display: flex;
    max-height: min(calc(100dvh - 2rem), 44rem);
    flex-direction: column;
    gap: 0.65rem;
    padding: 1.35rem;
    overflow-y: auto;
}

.dialog-heading {
    gap: 1rem;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 0.65rem;
}

.dialog-heading h2 {
    font-size: 1.35rem;
}

.dialog-heading p {
    margin: 0.4rem 0 0;
    color: var(--text-muted);
    font-size: 0.9rem;
}

.dialog-card > label,
.field-group > label,
.optional-label {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-weight: 650;
}

.optional-label {
    font-weight: 450;
}

.field-pair {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 0.65rem;
}

.field-group {
    display: grid;
    gap: 0.4rem;
    min-width: 0;
}

.dialog-actions {
    gap: 0.65rem;
    justify-content: flex-end;
    margin-top: 0.85rem;
}

.split-actions {
    justify-content: space-between;
}

.split-actions > div {
    display: flex;
    gap: 0.65rem;
}

.copy-row,
.rename-row {
    gap: 0.55rem;
}

.copy-row input,
.rename-row input {
    min-width: 0;
    flex: 1;
}

.token-details {
    margin-top: 0.35rem;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.token-details summary {
    padding: 0.45rem 0;
    font-weight: 650;
}

.token-row {
    margin-top: 0.45rem;
}

.share-qr {
    display: grid;
    gap: 0.65rem;
    justify-items: center;
    margin-top: 0.35rem;
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: var(--radius-md);
    background: #ffffff;
    color: #14282f;
}

.share-qr > span {
    font-size: 0.875rem;
    font-weight: 700;
}

.share-qr canvas {
    display: block;
    max-width: 100%;
    height: auto !important;
}

.share-actions {
    justify-content: space-between;
}

.management-actions {
    display: grid;
    gap: 0.65rem;
    margin-top: 1.1rem;
    padding-top: 1.1rem;
    border-top: 1px solid var(--line);
}

.field-error {
    margin: 0;
    color: var(--danger);
    font-size: 0.875rem;
}

.toast {
    position: fixed;
    z-index: 100;
    right: 1rem;
    bottom: max(1rem, env(safe-area-inset-bottom));
    max-width: min(calc(100% - 2rem), 28rem);
    padding: 0.8rem 1rem;
    border: 1px solid rgba(255, 255, 255, 0.13);
    border-radius: var(--radius-sm);
    background: #102c34;
    color: #ffffff;
    box-shadow: var(--shadow);
    font-size: 0.9rem;
    font-weight: 620;
}

.toast[data-kind="error"] {
    background: #6d242b;
}

@media (max-width: 800px) {
    .app-shell {
        display: block;
    }

    .sidebar {
        position: fixed;
        inset: 0 auto 0 0;
        width: min(86vw, var(--sidebar-width));
        padding-top: max(1rem, env(safe-area-inset-top));
        transform: translateX(-105%);
        transition: transform 180ms ease;
    }

    body.sidebar-open .sidebar {
        transform: translateX(0);
    }

    .sidebar-scrim {
        position: fixed;
        z-index: 15;
        inset: 0;
        width: 100%;
        height: 100%;
        border: 0;
        background: rgba(2, 13, 17, 0.58);
        opacity: 0;
        pointer-events: none;
        transition: opacity 180ms ease;
    }

    body.sidebar-open .sidebar-scrim {
        display: block;
        opacity: 1;
        pointer-events: auto;
    }

    .sidebar-close,
    .mobile-menu {
        display: inline-grid;
    }

    .sidebar-close {
        border-color: rgba(255, 255, 255, 0.12);
        background: rgba(255, 255, 255, 0.05);
        color: #e8f3f4;
    }

    .main-surface,
    .welcome,
    .list-view {
        width: 100%;
        height: 100vh;
        height: 100dvh;
    }

    .welcome {
        padding: max(4.75rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
    }

    .list-header {
        min-height: 4.7rem;
        padding-top: max(0.65rem, env(safe-area-inset-top));
    }

    .list-header h1 {
        max-width: 48vw;
    }

    .share-button span {
        display: none;
    }

    .share-button {
        width: 2.75rem;
        min-width: 2.75rem;
        padding: 0;
    }

    .list-content {
        padding-bottom: 1.4rem;
    }

    .add-item-form {
        grid-template-columns: minmax(5.5rem, 0.2fr) minmax(6.5rem, 0.25fr) minmax(0, 1fr) auto;
        padding-top: 0.75rem;
    }

    .add-button span {
        display: none;
    }

    .add-button {
        width: 3rem;
        min-width: 3rem;
        padding-inline: 0;
    }
}

@media (max-width: 540px) {
    .welcome-card {
        padding: 1.55rem 1.2rem;
    }

    .welcome-actions,
    .welcome-actions > button {
        width: 100%;
    }

    .list-header {
        gap: 0.55rem;
        padding-inline: 0.75rem;
    }

    .list-header h1 {
        max-width: 42vw;
        font-size: 1.2rem;
    }

    .sync-status {
        font-size: 0.75rem;
    }

    .list-content {
        padding-inline: 0.75rem;
    }

    .item-row {
        gap: 0.45rem;
        padding-left: 0.55rem;
    }

    .add-item-form {
        grid-template-columns: minmax(0, 0.72fr) minmax(0, 1fr) auto;
        padding-inline: 0.75rem;
    }

    #new-item-name {
        grid-row: 2;
        grid-column: 1 / 3;
    }

    .quantity-input {
        grid-row: 1;
        grid-column: 1;
    }

    .unit-input {
        grid-row: 1;
        grid-column: 2 / 4;
    }

    .add-button {
        grid-row: 2;
        grid-column: 3;
    }

    dialog {
        width: min(calc(100% - 1rem), 34rem);
        max-height: calc(100dvh - 1rem);
    }

    .dialog-card {
        max-height: calc(100dvh - 1rem);
        padding: 1.1rem;
    }

    .copy-row,
    .rename-row,
    .split-actions,
    .split-actions > div {
        align-items: stretch;
        flex-direction: column;
    }

    .split-actions > div > button,
    .rename-row > button,
    .copy-row > button {
        width: 100%;
    }

    .dialog-actions:not(.split-actions) {
        flex-wrap: wrap;
    }

    .share-actions > button {
        flex: 1;
    }

    .toast {
        right: 0.75rem;
        bottom: max(0.75rem, env(safe-area-inset-bottom));
        left: 0.75rem;
        max-width: none;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        scroll-behavior: auto !important;
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}
