:root {
    color-scheme: light;
}

body {
    display: flex;
    flex-direction: column;
    background: var(--bg);
    color: var(--text);
}

.app-shell {
    flex: 1;
    width: min(1320px, calc(100% - 2rem));
    overflow-x: visible;
}

.theme-setting {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 1rem;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface-soft);
}

.theme-setting p {
    margin: .3rem 0 0;
}

.theme-toggle {
    display: inline-flex;
    align-items: center;
    gap: .65rem;
    flex: 0 0 auto;
    padding: .4rem .6rem;
    border: 0;
    background: transparent;
    color: var(--text);
    cursor: pointer;
}

.theme-toggle-track {
    position: relative;
    display: block;
    width: 3.7rem;
    height: 2rem;
    overflow: hidden;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: linear-gradient(135deg, #77c8ed, #f7ce67);
    box-shadow: inset 0 2px 5px rgb(0 0 0 / 15%);
    transition: background .35s ease;
}

.theme-toggle-sky {
    position: absolute;
    inset: 0;
    background: linear-gradient(135deg, #263a69, #111827);
    opacity: 0;
    transition: opacity .35s ease;
}

.theme-toggle-sun,
.theme-toggle-moon {
    position: absolute;
    top: 50%;
    z-index: 1;
    width: .85rem;
    height: .85rem;
    border-radius: 50%;
    transform: translateY(-50%);
    transition: opacity .25s ease, transform .35s ease;
}

.theme-toggle-sun {
    left: .52rem;
    background: #fff3ae;
    box-shadow: 0 0 9px rgb(255 243 174 / 80%);
}

.theme-toggle-moon {
    right: .48rem;
    background: #dce9ff;
    opacity: 0;
    transform: translate(6px, -50%);
    box-shadow: 0 0 8px rgb(220 233 255 / 65%);
}

.theme-toggle-knob {
    position: absolute;
    top: .15rem;
    left: .15rem;
    z-index: 2;
    width: 1.6rem;
    height: 1.6rem;
    border: 1px solid rgb(0 0 0 / 8%);
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 2px 5px rgb(0 0 0 / 22%);
    transition: transform .35s cubic-bezier(.4, -.3, .6, 1.3);
}

.theme-toggle[aria-pressed="true"] .theme-toggle-sky {
    opacity: 1;
}

.theme-toggle[aria-pressed="true"] .theme-toggle-sun {
    opacity: 0;
}

.theme-toggle[aria-pressed="true"] .theme-toggle-moon {
    opacity: 1;
    transform: translate(0, -50%);
}

.theme-toggle[aria-pressed="true"] .theme-toggle-knob {
    transform: translateX(1.65rem);
}

.theme-toggle:focus-visible {
    outline: 3px solid var(--primary);
    outline-offset: 3px;
    border-radius: 10px;
}

.page-legal {
    display: grid;
    gap: 1rem;
    width: min(100%, 960px);
    margin: 1rem auto;
}

.page-legal .card {
    min-width: 0;
    padding: clamp(1.1rem, 3vw, 2rem);
}

.legal-intro h1 {
    margin: .45rem 0 .7rem;
    font-size: clamp(1.7rem, 4vw, 2.4rem);
    line-height: 1.15;
    text-wrap: pretty;
}

.legal-intro > p:last-child {
    max-width: 70ch;
    margin-bottom: 0;
    line-height: 1.65;
}

.legal-content {
    line-height: 1.7;
    overflow-wrap: anywhere;
}

.legal-content h2 {
    margin: 1.65rem 0 .5rem;
    font-size: clamp(1.1rem, 2.5vw, 1.35rem);
    line-height: 1.3;
    text-wrap: pretty;
}

.legal-content h2:first-child {
    margin-top: 0;
}

.legal-content p {
    margin: 0 0 1rem;
    max-width: 80ch;
    line-height: 1.7;
}

.app-header {
    width: 100%;
    background: var(--surface);
}

.nav-toggle {
    display: none;
}

.main-nav a[aria-current="page"] {
    color: var(--primary);
    background: var(--primary-soft);
    border-radius: 10px;
}

.bike-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(100%, 290px), 1fr));
    gap: 1rem;
}

.task-create-card {
    display: grid;
    gap: 1.25rem;
    margin-top: 1rem;
    padding: clamp(1.1rem, 3vw, 1.75rem);
}

.task-create-heading {
    display: grid;
    gap: .35rem;
}

.task-create-heading .eyebrow,
.task-create-heading h2,
.task-create-heading p {
    margin: 0;
}

.task-create-heading h2 {
    font-size: 1.25rem;
}

.task-create-heading .muted {
    max-width: 62ch;
    line-height: 1.5;
}

.task-create-form {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 1.1rem 1.25rem;
    align-items: start;
}

.task-field {
    display: grid;
    gap: .5rem;
    min-width: 0;
    font-weight: 700;
    color: var(--text);
}

.task-field input,
.task-field select,
.task-field textarea {
    width: 100%;
    min-width: 0;
}

.task-field-title,
.task-field-description,
.task-form-actions {
    grid-column: 1 / -1;
}

.task-field textarea {
    min-height: 7rem;
    resize: vertical;
}

.task-field input:focus-visible,
.task-field select:focus-visible,
.task-field textarea:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.task-form-actions {
    display: flex;
    justify-content: flex-end;
}

.task-form-actions .button {
    min-width: 12rem;
}

.stock-history {
    display: grid;
    gap: .25rem;
    margin-top: 1rem;
    padding: clamp(1.1rem, 3vw, 1.5rem);
}

.stock-history > .section-head {
    margin-bottom: .5rem;
}

.stock-history .section-head h2 {
    margin: 0;
}

.stock-history .section-head p {
    margin: .25rem 0 0;
}

.stock-history-list {
    display: grid;
}

.stock-history-item {
    display: grid;
    grid-template-columns: 2.5rem minmax(0, 1fr) auto;
    align-items: center;
    gap: .9rem;
    padding: .9rem .25rem;
    border-bottom: 1px solid var(--line);
}

.stock-history-item:last-child {
    border-bottom: 0;
}

.stock-history-icon {
    display: grid;
    width: 2.35rem;
    height: 2.35rem;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--surface-soft);
    color: var(--text);
    font-size: 1.15rem;
    font-weight: 800;
}

.stock-history-icon.is-increase {
    color: var(--green);
}

.stock-history-icon.is-decrease {
    color: var(--red);
}

.stock-history-details {
    display: grid;
    gap: .25rem;
    min-width: 0;
}

.stock-history-details strong {
    overflow-wrap: anywhere;
}

.stock-history-details time {
    color: var(--muted);
    font-size: .875rem;
}

.stock-movement-quantity {
    display: inline-flex;
    min-width: 3.5rem;
    justify-content: center;
    padding: .4rem .65rem;
    border: 1px solid var(--line);
    border-radius: 999px;
    background: var(--surface-soft);
    font-weight: 800;
    font-variant-numeric: tabular-nums;
}

.stock-movement-quantity.is-increase {
    border-color: var(--green);
    background: var(--surface);
    color: var(--green);
}

.stock-movement-quantity.is-decrease {
    border-color: var(--red);
    background: var(--surface);
    color: var(--red);
}

.stock-history-empty {
    margin: 0;
    padding: 1rem;
    border: 1px dashed var(--line);
    border-radius: 12px;
    color: var(--muted);
    text-align: center;
}

.form-grid .irreparable-option {
    grid-column: 1 / -1;
}

.stacked-form label.irreparable-option {
    display: flex;
    align-items: center;
    gap: .9rem;
    padding: 1rem;
    border: 1px solid var(--line);
    border-left: 4px solid var(--red);
    border-radius: 12px;
    background: var(--surface-soft);
    cursor: pointer;
}

.irreparable-option input[type="checkbox"] {
    flex: 0 0 1.25rem;
    width: 1.25rem;
    height: 1.25rem;
    margin: 0;
    padding: 0;
    border: 0;
    background: transparent;
    accent-color: var(--red);
}

.irreparable-option-copy {
    display: grid;
    gap: .2rem;
}

.irreparable-option-copy small {
    color: var(--muted);
    font-weight: 400;
}

.irreparable-badge {
    display: inline-flex;
    align-items: center;
    padding: .25rem .55rem;
    border: 1px solid var(--red);
    border-radius: 999px;
    background: var(--surface-soft);
    color: var(--red);
    font-size: .8rem;
    font-weight: 800;
}

body[data-bike-locked="true"] form[action="/photos"],
body[data-bike-locked="true"] form[action^="/photos/"],
body[data-bike-locked="true"] form[action^="/bikes/"][action$="/task"],
body[data-bike-locked="true"] form[action^="/tasks/"] {
    display: none;
}

.bike-card {
    overflow: hidden;
    padding: 0;
    transition: transform .18s ease, box-shadow .18s ease;
}

.bike-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 16px 36px rgba(18, 49, 94, .13);
}

.bike-card-image {
    position: relative;
    display: grid;
    min-height: 190px;
    overflow: hidden;
    place-items: center;
    background: linear-gradient(135deg, var(--bg-strong), var(--surface-soft));
}

.bike-card-image img {
    display: block;
    width: 100%;
    height: 210px;
    object-fit: cover;
}

.bike-card-placeholder {
    display: grid;
    width: 100%;
    height: 210px;
    place-items: center;
    color: var(--primary);
}

.bike-card-placeholder svg {
    width: 126px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 3;
}

.bike-card-status {
    position: absolute;
    top: .8rem;
    left: .8rem;
    max-width: calc(100% - 1.6rem);
    padding: .4rem .7rem;
    border: 1px solid rgba(16, 35, 61, .08);
    border-radius: 999px;
    color: #10233d;
    font-size: .76rem;
    font-weight: 800;
}

.badge {
    color: #10233d;
}

.bike-card-content {
    padding: 1rem 1.1rem 1.1rem;
}

.bike-card-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: .75rem;
}

.bike-card-title .eyebrow {
    font-size: .68rem;
}

.bike-card-title h2 {
    margin: .3rem 0 0;
    font-size: 1.2rem;
}

.bike-card-open,
.bike-empty-mark {
    display: grid;
    width: 38px;
    height: 38px;
    flex: 0 0 auto;
    place-items: center;
    border-radius: 50%;
    background: var(--primary-soft);
    color: var(--primary-dark);
    font-size: 1.2rem;
    font-weight: 800;
}

.bike-card-model {
    min-height: 1.5em;
    margin: .35rem 0 .9rem;
    color: var(--muted);
}

.bike-card-details {
    display: grid;
    gap: .55rem;
    margin: 0;
    padding: .8rem 0;
    border-top: 1px solid var(--line);
    border-bottom: 1px solid var(--line);
}

.bike-card-details div {
    display: flex;
    justify-content: space-between;
    gap: .75rem;
}

.bike-card-details dt {
    color: var(--muted);
}

.bike-card-details dd {
    overflow-wrap: anywhere;
    margin: 0;
    text-align: right;
    font-weight: 700;
}

.bike-card-link {
    display: flex;
    justify-content: space-between;
    margin-top: .9rem;
    color: var(--primary);
    font-weight: 800;
}

.bike-empty {
    display: grid;
    justify-items: center;
    padding: clamp(2rem, 7vw, 4rem) 1.5rem;
    text-align: center;
}

.bike-empty h2 {
    margin: 1rem 0 .25rem;
}

.bike-empty p {
    max-width: 36rem;
    margin: .25rem 0 1.25rem;
}

.filter-reset {
    flex: 0 0 auto;
    color: var(--text);
}

.legal-footer {
    margin-top: 2rem;
    border-top: 1px solid var(--line);
    background: var(--surface);
    color: var(--muted);
}

.footer-inner {
    width: min(1320px, calc(100% - 2rem));
    margin: 0 auto;
}

.footer-top,
.footer-bottom {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1.5rem;
    padding: 1.4rem 0;
}

.footer-top {
    border-bottom: 1px solid var(--line);
}

.footer-brand {
    display: flex;
    align-items: center;
    gap: .75rem;
    color: var(--text);
}

.footer-brand strong,
.footer-brand small {
    display: block;
}

.footer-brand small {
    margin-top: .2rem;
    color: var(--muted);
}

.legal-footer nav {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: .5rem 1.25rem;
}

.legal-footer nav a,
.footer-back-top {
    color: var(--muted);
}

.legal-footer nav a:hover,
.footer-back-top:hover {
    color: var(--primary);
}

.footer-bottom {
    padding: .9rem 0 1.2rem;
    font-size: .86rem;
}

.footer-bottom p {
    margin: 0;
}

body[data-theme="dark"] {
    color-scheme: dark;
    --bg: #101722;
    --bg-strong: #1d2938;
    --surface: #182230;
    --surface-soft: #202d3c;
    --line: #344356;
    --text: #e8eef6;
    --muted: #a8b5c6;
    --primary: #83b4ff;
    --primary-dark: #c7ddff;
    --primary-soft: #263d59;
    --yellow: #ffd45b;
    --yellow-strong: #ffdf7c;
    --green: #6bd49e;
    --red: #ff8989;
    --shadow: 0 10px 28px rgba(0, 0, 0, .28);
    background: var(--bg);
}

body[data-theme="dark"] .app-header {
    background: rgba(24, 34, 48, .96);
}

body[data-theme="dark"] .card,
body[data-theme="dark"] .stat-card,
body[data-theme="dark"] .details-card,
body[data-theme="dark"] .status-card,
body[data-theme="dark"] .auth-card,
body[data-theme="dark"] .menu-panel,
body[data-theme="dark"] .flash {
    background-color: var(--surface);
    border-color: var(--line);
    color: var(--text);
}

body[data-theme="dark"] button,
body[data-theme="dark"] input,
body[data-theme="dark"] select,
body[data-theme="dark"] textarea {
    background-color: var(--surface-soft);
    border-color: var(--line);
    color: var(--text);
}

body[data-theme="dark"] input::placeholder,
body[data-theme="dark"] textarea::placeholder {
    color: var(--muted);
}

body[data-theme="dark"] .menu-panel a,
body[data-theme="dark"] .menu-panel button {
    color: var(--text);
}

@media (max-width: 768px) {
    .theme-setting {
        align-items: flex-start;
        flex-direction: column;
    }

    .auth-page {
        grid-template-columns: minmax(0, 1fr);
        width: 100%;
        min-width: 0;
        padding: 1rem;
    }

    .auth-card {
        width: 100%;
        min-width: 0;
        padding: 1.25rem;
    }

    .app-header {
        grid-template-columns: minmax(0, 1fr) auto auto;
        align-items: center;
    }

    .brand {
        min-width: 0;
    }

    .brand span:last-child {
        display: block;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .nav-toggle {
        display: none;
        width: 42px;
        height: 42px;
        place-content: center;
        gap: 5px;
        padding: 0;
        border: 1px solid var(--line);
        border-radius: 12px;
        background: var(--surface);
        color: var(--text);
        cursor: pointer;
    }

    .app-header.nav-enhanced .nav-toggle {
        display: grid;
    }

    .nav-toggle span {
        display: block;
        width: 18px;
        height: 2px;
        border-radius: 2px;
        background: currentColor;
        transition: transform .18s ease, opacity .18s ease;
    }

    .app-header.is-nav-open .nav-toggle span:first-child {
        transform: translateY(7px) rotate(45deg);
    }

    .app-header.is-nav-open .nav-toggle span:nth-child(2) {
        opacity: 0;
    }

    .app-header.is-nav-open .nav-toggle span:last-child {
        transform: translateY(-7px) rotate(-45deg);
    }

    .app-header.nav-enhanced:not(.is-nav-open) .main-nav {
        display: none;
        grid-column: 1 / -1;
        grid-row: 2;
        min-width: 0;
        margin: .25rem -.25rem 0;
        padding: .35rem;
        overflow: visible;
        border-top: 1px solid var(--line);
    }

    .app-header.is-nav-open .main-nav {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: .4rem;
    }

    .main-nav a {
        padding: .75rem .6rem;
        border-radius: 10px;
        text-align: center;
    }

    .main-nav a:hover,
    .main-nav a[aria-current="page"] {
        background: var(--bg-strong);
    }

    .user-menu {
        grid-column: auto;
        justify-self: end;
        min-width: 0;
    }

    .user-menu > div:first-child {
        max-width: 7rem;
    }

    .user-menu strong {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .app-shell,
    .card,
    .details-card,
    .toolbar {
        overflow-x: visible;
    }

    .stacked-form {
        grid-template-columns: minmax(0, 1fr);
        min-width: 0;
    }

    .form-grid {
        grid-template-columns: minmax(0, 1fr);
        min-width: 0;
    }

    .form-grid > *,
    .stacked-form > *,
    .details-card > * {
        min-width: 0;
    }

    .form-grid input,
    .form-grid select,
    .form-grid textarea,
    .stacked-form input,
    .stacked-form select,
    .stacked-form textarea {
        width: 100%;
        min-width: 0;
    }

    input[type="file"] {
        width: 100%;
        min-width: 0;
    }

    .section-head > form {
        width: 100%;
        min-width: 0;
    }

    .toolbar {
        display: grid;
        grid-template-columns: minmax(0, 1fr);
        align-items: stretch;
    }

    .toolbar > * {
        width: 100%;
        min-width: 0;
    }

    .toolbar > label {
        display: grid;
        gap: .42rem;
    }

    .toolbar input,
    .toolbar select {
        width: 100%;
        min-width: 0;
    }

    .table-wrap {
        overflow: visible;
        padding: .75rem;
    }

    .table-wrap .data-table,
    .table-wrap .data-table tbody {
        display: block;
        width: 100%;
        min-width: 0;
    }

    .table-wrap .data-table thead {
        position: absolute;
        width: 1px;
        height: 1px;
        padding: 0;
        margin: -1px;
        overflow: hidden;
        clip: rect(0, 0, 0, 0);
        white-space: nowrap;
        border: 0;
    }

    .table-wrap .data-table tr {
        display: grid;
        gap: .65rem;
        margin-bottom: .75rem;
        padding: .9rem;
        border: 1px solid var(--line);
        border-radius: 14px;
        background: var(--surface);
        box-shadow: var(--shadow);
    }

    .table-wrap .data-table tr:last-child {
        margin-bottom: 0;
    }

    .table-wrap .data-table td {
        display: grid;
        grid-template-columns: minmax(6.5rem, 38%) minmax(0, 1fr);
        align-items: start;
        gap: .65rem;
        min-width: 0;
        padding: .35rem 0;
        border-bottom: 1px solid var(--line);
        overflow-wrap: anywhere;
    }

    .table-wrap .data-table td::before {
        content: attr(data-label);
        color: var(--muted);
        font-size: .78rem;
        font-weight: 700;
    }

    .table-wrap .data-table td.data-table-primary {
        display: block;
        padding: 0 0 .65rem;
        border-bottom: 1px solid var(--line);
        font-size: 1rem;
    }

    .table-wrap .data-table td.data-table-action {
        display: block;
        padding: .25rem 0 0;
        border-bottom: 0;
    }

    .table-wrap .data-table td.data-table-action::before {
        content: none;
    }

    .table-wrap .data-table .data-table-action .button {
        width: 100%;
    }

    .table-wrap .data-table .status,
    .table-wrap .data-table .stock-label {
        justify-self: start;
    }
}

@media (max-width: 480px) {
    .user-menu > div:first-child {
        max-width: 5.5rem;
    }

    .user-menu small {
        display: none;
    }
}

body[data-theme="dark"] .button.primary {
    color: #1b2a3a;
}

body[data-theme="dark"] .button.danger {
    background: #512b32;
    color: #ffd9dc;
}

body[data-theme="dark"] .auth-page {
    background: linear-gradient(135deg, #1d2938 0, #101722 100%);
}

body[data-theme="dark"] .status-card,
body[data-theme="dark"] .details-card {
    background: var(--surface);
}

body[data-theme="dark"] .file-dropzone,
body[data-theme="dark"] .bike-card-image {
    background: linear-gradient(135deg, var(--bg-strong), var(--surface-soft));
}

body[data-theme="dark"] .flash-success {
    background: #173b30;
    color: #b9f4d1;
}

body[data-theme="dark"] .flash-error {
    background: #48272d;
    color: #ffd3d6;
}

@media (max-width: 560px) {
    .task-create-form {
        grid-template-columns: 1fr;
    }

    .task-field-title,
    .task-field-description,
    .task-form-actions {
        grid-column: auto;
    }

    .task-form-actions .button {
        width: 100%;
    }

    .stock-history-item {
        grid-template-columns: 2.25rem minmax(0, 1fr) auto;
        gap: .65rem;
        padding: .75rem 0;
    }

    .stock-history-icon {
        width: 2.1rem;
        height: 2.1rem;
    }
}

body[data-theme="dark"] .legal-footer {
    background: var(--surface);
}

@media (max-width: 768px) {
    .app-shell,
    .footer-inner {
        width: min(100% - 1rem, 1320px);
    }

    .page-legal {
        width: 100%;
        gap: .75rem;
        margin: .75rem auto;
    }

    .page-legal .card {
        padding: 1.1rem;
    }

    .legal-content h2 {
        margin-top: 1.35rem;
    }

    .footer-top,
    .footer-bottom {
        align-items: flex-start;
        flex-direction: column;
    }

    .legal-footer nav {
        justify-content: flex-start;
        flex-direction: row;
    }
}
