:root {
    color-scheme: light;
    --ink: #1d2421;
    --muted: #66736d;
    --line: #dfe5e1;
    --paper: #fbfaf6;
    --surface: #ffffff;
    --green: #183a2e;
    --green-soft: #e7efe9;
    --burgundy: #762b3a;
    --gold: #b7893a;
    --danger: #a73535;
    --shadow: 0 12px 30px rgba(32, 45, 39, 0.08);
}

* {
    box-sizing: border-box;
}

html {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background: var(--paper);
    color: var(--ink);
}

body {
    margin: 0;
}

a {
    color: inherit;
}

.app-header {
    align-items: center;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    display: flex;
    gap: 24px;
    justify-content: space-between;
    padding: 14px clamp(16px, 4vw, 48px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.brand {
    align-items: center;
    display: inline-flex;
    font-weight: 750;
    gap: 10px;
    text-decoration: none;
}

.brand-mark {
    align-items: center;
    background: var(--green);
    border-radius: 8px;
    color: #fff;
    display: inline-flex;
    font-size: 0.8rem;
    height: 34px;
    justify-content: center;
    width: 34px;
}

.top-nav {
    align-items: center;
    display: flex;
    gap: 8px;
}

.top-nav a {
    border-radius: 8px;
    color: var(--muted);
    font-size: 0.95rem;
    padding: 8px 10px;
    text-decoration: none;
}

.top-nav a:hover {
    background: var(--green-soft);
    color: var(--green);
}

.page {
    margin: 0;
    max-width: none;
    padding: 28px clamp(8px, 1.5vw, 24px) 48px;
    width: 100%;
}

.page-heading {
    align-items: end;
    display: flex;
    gap: 20px;
    justify-content: space-between;
    margin-bottom: 22px;
}

.page-heading.compact {
    align-items: center;
}

.eyebrow {
    color: var(--burgundy);
    font-size: 0.78rem;
    font-weight: 750;
    margin: 0 0 6px;
    text-transform: uppercase;
}

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

h1 {
    font-size: clamp(2rem, 5vw, 3.25rem);
    line-height: 1.02;
    margin-bottom: 8px;
}

h2 {
    font-size: 1.05rem;
    margin-bottom: 14px;
}

.muted,
.help {
    color: var(--muted);
}

.heading-actions,
.form-actions,
.filter-actions,
.card-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.button,
button.button {
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--ink);
    cursor: pointer;
    display: inline-flex;
    font: inherit;
    font-weight: 700;
    justify-content: center;
    min-height: 42px;
    padding: 10px 14px;
    text-decoration: none;
}

.button:hover {
    border-color: var(--gold);
}

.button.primary {
    background: var(--green);
    border-color: var(--green);
    color: #fff;
}

.button.ghost {
    background: transparent;
}

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

.button:disabled,
button.button:disabled {
    cursor: wait;
    opacity: 0.75;
}

.save-status {
    background: #fff7df;
    border: 1px solid #efd28c;
    border-left: 5px solid var(--gold);
    border-radius: 8px;
    color: #4d3910;
    font-weight: 700;
    margin-top: 14px;
    padding: 12px 14px;
}

.form-panel.is-submitting {
    cursor: wait;
}

.mobile-cellar-controls-toggle,
.mobile-tasting-controls-toggle {
    display: none;
}

.messages {
    display: grid;
    gap: 10px;
    margin-bottom: 18px;
}

.message {
    background: var(--surface);
    border: 1px solid var(--line);
    border-left: 5px solid var(--gold);
    border-radius: 8px;
    padding: 12px 14px;
}

.message-success {
    border-left-color: var(--green);
}

.message-error {
    border-left-color: var(--danger);
}

.filters,
.form-panel,
.empty-state,
.admin-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
}

.filters {
    align-items: end;
    display: grid;
    gap: 14px;
    grid-template-columns: minmax(160px, 0.8fr) minmax(200px, 1.15fr) repeat(3, minmax(130px, 0.75fr)) auto;
    margin-bottom: 18px;
    padding: 16px;
}

label,
.field label {
    color: var(--ink);
    display: grid;
    font-size: 0.88rem;
    font-weight: 720;
    gap: 7px;
}

input,
select,
textarea {
    background: #fff;
    border: 1px solid #cfd8d3;
    border-radius: 8px;
    color: var(--ink);
    font: inherit;
    min-height: 42px;
    padding: 10px 12px;
    width: 100%;
}

select:disabled {
    background: #f3f5f1;
    color: var(--muted);
    cursor: not-allowed;
}

.checkbox-line {
    align-items: center;
    display: inline-flex;
    gap: 8px;
    min-height: 42px;
}

input[type="checkbox"] {
    accent-color: var(--green);
    flex: 0 0 auto;
    height: 18px;
    min-height: 18px;
    padding: 0;
    width: 18px;
}

textarea {
    resize: vertical;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--gold);
    outline: 3px solid rgba(183, 137, 58, 0.2);
}

.table-shell {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    overflow-x: auto;
    width: 100%;
}

table {
    border-collapse: collapse;
    min-width: 100%;
    table-layout: fixed;
    width: 100%;
}

th,
td {
    border-bottom: 1px solid var(--line);
    overflow-wrap: anywhere;
    padding: 13px 14px;
    text-align: left;
    vertical-align: top;
}

th {
    background: #f3f5f1;
    color: var(--muted);
    font-size: 0.78rem;
    text-transform: uppercase;
}

td strong,
td span {
    display: block;
}

td span,
.stacked-value span {
    color: var(--muted);
    font-size: 0.88rem;
    margin-top: 3px;
}

tr:last-child td {
    border-bottom: 0;
}

.actions-col {
    min-width: 100px;
    width: 100px;
}

.col-photo {
    width: 86px;
}

.col-bottles {
    max-width: 100px;
    width: 100px;
}

.col-price {
    max-width: 100px;
    width: 100px;
}

.col-year {
    width: 72px;
}

.col-tav {
    width: 76px;
}

th.col-bottles,
td.col-bottles,
th.col-price,
td.col-price,
th.col-year,
td.col-year,
th.col-tav,
td.col-tav,
th.col-photo,
td.col-photo,
th.actions-col,
td.row-actions {
    padding-left: 6px;
    padding-right: 6px;
}

.row-actions {
    min-width: 100px;
    white-space: normal;
}

.row-actions-list {
    display: grid;
    gap: 7px;
    justify-items: start;
}

.row-actions-list a {
    color: var(--green);
    font-weight: 700;
    text-decoration: none;
}

.row-actions-list .danger-link {
    color: var(--danger);
}

.wine-photo-strip {
    display: flex;
    gap: 6px;
}

.wine-photo-strip a {
    display: block;
    flex: 0 0 auto;
}

.wine-photo-strip img {
    aspect-ratio: 3 / 4;
    background: #f3f5f1;
    border: 1px solid var(--line);
    border-radius: 6px;
    display: block;
    object-fit: cover;
    width: 34px;
}

.mobile-list {
    display: none;
}

.wine-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: grid;
    gap: 16px;
    padding: 16px;
}

.wine-card h2 {
    font-size: 1.22rem;
    margin-bottom: 4px;
}

.wine-card p {
    color: var(--muted);
    margin-bottom: 0;
}

.wine-category {
    color: var(--burgundy) !important;
    font-size: 0.78rem;
    font-weight: 760;
    text-transform: uppercase;
}

.mobile-wine-photos {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.mobile-wine-photos a {
    display: block;
}

.mobile-wine-photos img {
    aspect-ratio: 4 / 5;
    background: #f3f5f1;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: block;
    object-fit: cover;
    width: 100%;
}

dl {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    margin: 0;
}

dt {
    color: var(--muted);
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
}

dd {
    margin: 2px 0 0;
}

.stacked-value strong,
.stacked-value span {
    display: block;
}

.wine-detail-name {
    grid-column: 1 / -1;
}

.mobile-summary-row {
    display: grid;
    gap: 10px;
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mobile-summary-row > div {
    min-width: 0;
}

.mobile-summary-row dd {
    overflow-wrap: anywhere;
}

.mobile-wine-facts,
.mobile-wine-identity {
    display: grid;
    gap: 10px;
    grid-column: 1 / -1;
}

.mobile-wine-facts {
    border: 1px solid var(--line);
    border-radius: 8px;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    padding: 10px;
}

.mobile-wine-facts-rosso {
    background: linear-gradient(90deg, #f1dbe0 0%, #fff7f8 100%);
    border-color: #d9aeb8;
}

.mobile-wine-facts-bianco {
    background: linear-gradient(90deg, #fff1b8 0%, #fffdf0 100%);
    border-color: #ead37f;
}

.mobile-wine-facts-spumante {
    background: linear-gradient(90deg, #dceff8 0%, #f7fcff 100%);
    border-color: #acd3e8;
}

.mobile-wine-facts-rosato {
    background: linear-gradient(90deg, #f8dbe5 0%, #fff7fa 100%);
    border-color: #e5b3c2;
}

.mobile-wine-facts-dolce {
    background: linear-gradient(90deg, #f4e4bc 0%, #fff9eb 100%);
    border-color: #dfc37c;
}

.mobile-wine-facts-default {
    background: linear-gradient(90deg, #edf2ef 0%, #fbfdfb 100%);
    border-color: #d2ddd7;
}

.mobile-wine-identity {
    grid-template-columns: minmax(0, 1.35fr) minmax(0, 0.85fr);
}

.mobile-tasting-identity {
    grid-template-columns: 1fr;
}

.mobile-tasting-photos {
    margin-top: 2px;
}

.mobile-wine-facts > div,
.mobile-wine-identity > div {
    min-width: 0;
}

.mobile-wine-facts dt,
.mobile-wine-identity dt {
    overflow-wrap: anywhere;
}

.mobile-wine-facts dd,
.mobile-wine-identity dd {
    overflow-wrap: anywhere;
}

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

.form-panel.narrow {
    max-width: 680px;
}

.form-section {
    border-bottom: 1px solid var(--line);
    padding-bottom: 18px;
}

.form-section:last-of-type {
    border-bottom: 0;
    padding-bottom: 0;
}

.wine-form {
    gap: 22px;
}

.wine-section {
    border-left: 5px solid var(--line);
    padding-left: 14px !important;
}

.tasting-form {
    gap: 22px;
}

.tasting-form .form-section {
    border-bottom: 0;
    padding: 0 0 4px;
}

.tasting-section {
    border-left: 5px solid var(--line);
    padding-left: 14px !important;
}

.section-title-band {
    border: 1px solid var(--line);
    border-left: 0;
    border-radius: 0 8px 8px 0;
    margin: 0 0 16px -14px;
    padding: 12px 14px;
}

.section-title-band h2,
.section-title-band .phase-label {
    margin-bottom: 0;
}

.section-title-wine-main {
    background: linear-gradient(90deg, #e8f1ed 0%, #f7fbf8 100%);
    border-color: #c8ddd5;
}

.wine-section-main {
    border-left-color: #477a68;
}

.section-title-wine-features {
    background: linear-gradient(90deg, #e7eef6 0%, #f8fbff 100%);
    border-color: #cad9ea;
}

.wine-section-features {
    border-left-color: #4f759b;
}

.section-title-wine-stock {
    background: linear-gradient(90deg, #f3eadf 0%, #fffaf1 100%);
    border-color: #e2cfad;
}

.wine-section-stock {
    border-left-color: var(--gold);
}

.section-title-wine-images {
    background: linear-gradient(90deg, #edf0df 0%, #fbfcf4 100%);
    border-color: #d7ddbd;
}

.wine-section-images {
    border-left-color: #7a8a3a;
}

.wine-image-preview-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(2, minmax(120px, 220px));
    margin-bottom: 16px;
}

.wine-image-preview {
    display: block;
}

.wine-image-preview img {
    aspect-ratio: 4 / 5;
    background: #f3f5f1;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: block;
    object-fit: cover;
    width: 100%;
}

.image-upload-field {
    align-content: start;
}

.image-input-actions {
    display: grid;
    gap: 10px;
}

.image-input-actions .camera-trigger {
    justify-self: start;
}

.section-title-meta {
    background: linear-gradient(90deg, #e8f1ed 0%, #f7fbf8 100%);
    border-color: #c8ddd5;
}

.tasting-section-meta {
    border-left-color: #477a68;
}

.section-title-wine {
    background: linear-gradient(90deg, #f3eadf 0%, #fffaf1 100%);
    border-color: #e2cfad;
}

.tasting-section-wine {
    border-left-color: var(--gold);
}

.section-title-visual {
    background: linear-gradient(90deg, #e7eef6 0%, #f8fbff 100%);
    border-color: #cad9ea;
}

.tasting-section-visual {
    border-left-color: #4f759b;
}

.section-title-olfactory {
    background: linear-gradient(90deg, #f4e8ec 0%, #fff8fa 100%);
    border-color: #e4cbd3;
}

.tasting-section-olfactory {
    border-left-color: var(--burgundy);
}

.section-title-taste {
    background: linear-gradient(90deg, #edf0df 0%, #fbfcf4 100%);
    border-color: #d7ddbd;
}

.tasting-section-taste {
    border-left-color: #7a8a3a;
}

.section-title-retro {
    background: linear-gradient(90deg, #ece8f1 0%, #fbf9ff 100%);
    border-color: #d7cde2;
}

.tasting-section-retro {
    border-left-color: #6f5e83;
}

.section-title-tasting-images {
    background: linear-gradient(90deg, #edf0df 0%, #fbfcf4 100%);
    border-color: #d7ddbd;
}

.tasting-section-images {
    border-left-color: #7a8a3a;
}

.phase-section {
    position: relative;
}

.phase-label {
    color: var(--burgundy);
    font-size: 0.78rem;
    font-weight: 760;
    letter-spacing: 0;
    margin-bottom: 4px;
    text-transform: uppercase;
}

.subsection-title {
    color: var(--muted);
    font-size: 0.9rem;
    margin: 18px 0 10px;
    text-transform: uppercase;
}

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

.form-grid .full-span {
    grid-column: 1 / -1;
}

.field {
    display: grid;
    gap: 7px;
}

.radio-row > div {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.radio-row label {
    align-items: center;
    background: #f7f8f5;
    border: 1px solid var(--line);
    border-radius: 8px;
    display: inline-flex;
    gap: 8px;
    min-height: 42px;
    padding: 9px 12px;
}

input[type="radio"] {
    accent-color: var(--green);
    height: 17px;
    min-height: 17px;
    padding: 0;
    width: 17px;
}

.spumante-fields {
    margin-top: 14px;
}

[hidden] {
    display: none !important;
}

.tasting-filters {
    grid-template-columns: minmax(150px, 0.75fr) minmax(260px, 1.35fr) repeat(2, minmax(150px, 0.8fr)) auto;
}

.detail-panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    box-shadow: var(--shadow);
    display: grid;
    gap: 0;
    overflow: hidden;
}

.detail-section {
    border-bottom: 1px solid var(--line);
    padding: 18px;
}

.detail-section:last-child {
    border-bottom: 0;
}

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

.errorlist {
    color: var(--danger);
    font-size: 0.88rem;
    list-style: none;
    margin: 0;
    padding: 0;
}

.delete-warning {
    font-size: 1.05rem;
    margin-bottom: 0;
}

.empty-state {
    display: grid;
    gap: 10px;
    justify-items: start;
    padding: 24px;
}

.admin-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.access-choice-grid {
    display: grid;
    gap: 16px;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    max-width: 920px;
}

.access-choice-card {
    min-height: 260px;
}

.access-choice-form {
    display: grid;
    gap: 12px;
}

.access-badge {
    background: var(--green-soft);
    border: 1px solid rgba(47, 103, 71, 0.22);
    border-radius: 8px;
    color: var(--green);
    font-weight: 750;
    padding: 8px 10px;
}

.admin-card {
    align-content: start;
    display: grid;
    gap: 12px;
    padding: 18px;
}

.admin-card h2,
.admin-card p {
    margin-bottom: 0;
}

.checkbox-field {
    align-items: center;
    display: flex;
    gap: 10px;
}

.checkbox-field input {
    width: auto;
}

.checkbox-field label {
    display: block;
}

.pagination {
    align-items: center;
    display: flex;
    gap: 12px;
    justify-content: center;
    margin-top: 20px;
}

.pagination a,
.pagination span {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 9px 12px;
    text-decoration: none;
}

.image-viewer-page {
    display: grid;
    gap: 18px;
}

.image-viewer-header {
    align-items: end;
    display: flex;
    gap: 18px;
    justify-content: space-between;
}

.image-viewer-header h1 {
    font-size: clamp(1.7rem, 4vw, 2.6rem);
}

.image-viewer-actions {
    align-items: center;
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    justify-content: flex-end;
}

.image-viewer-actions .button {
    min-width: 56px;
}

.image-viewer-stage {
    align-items: start;
    background: #101412;
    border-radius: 8px;
    display: grid;
    justify-items: center;
    min-height: min(72vh, 780px);
    overflow: auto;
    padding: 18px;
}

.image-viewer-stage img {
    border-radius: 8px;
    display: block;
    max-height: 72vh;
    max-width: 100%;
    object-fit: contain;
}

@media (max-width: 980px) {
    .filters {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

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

    .filter-actions {
        grid-column: 1 / -1;
    }
}

@media (max-width: 820px) {
    .app-header {
        align-items: flex-start;
        flex-direction: column;
        gap: 12px;
    }

    .top-nav {
        overflow-x: auto;
        padding-bottom: 2px;
        width: 100%;
    }

    .page-heading {
        align-items: stretch;
        flex-direction: column;
    }

    .filters {
        grid-template-columns: 1fr;
    }

    .filter-actions {
        grid-column: auto;
    }

    .table-shell {
        display: none;
    }

    .mobile-list {
        display: grid;
        gap: 14px;
    }

    .form-grid {
        grid-template-columns: 1fr;
    }

    .admin-grid {
        grid-template-columns: 1fr;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    .heading-actions,
    .form-actions,
    .filter-actions,
    .card-actions {
        align-items: stretch;
        flex-direction: column;
    }

    .button,
    button.button {
        width: 100%;
    }

    .image-viewer-header {
        align-items: stretch;
        flex-direction: column;
    }

    .image-viewer-actions {
        justify-content: stretch;
    }

    .image-viewer-actions .button {
        flex: 1 1 82px;
        width: auto;
    }

    .image-viewer-stage {
        min-height: 58vh;
        padding: 10px;
    }

    .image-input-actions .camera-trigger {
        justify-self: stretch;
    }

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

    .mobile-cellar-controls-toggle,
    .mobile-tasting-controls-toggle {
        align-items: center;
        background: var(--green);
        border: 1px solid var(--green);
        border-radius: 50%;
        box-shadow: var(--shadow);
        color: #fff;
        cursor: pointer;
        display: inline-flex;
        font: inherit;
        font-size: 1.2rem;
        font-weight: 800;
        height: 40px;
        justify-content: center;
        line-height: 1;
        position: fixed;
        right: max(12px, env(safe-area-inset-right));
        top: max(12px, env(safe-area-inset-top));
        width: 40px;
        z-index: 1000;
    }

    .mobile-cellar-controls-toggle:hover,
    .mobile-cellar-controls-toggle:focus,
    .mobile-tasting-controls-toggle:hover,
    .mobile-tasting-controls-toggle:focus {
        border-color: var(--gold);
        outline: 3px solid rgba(183, 137, 58, 0.2);
    }

    .cellar-mobile-controls-hidden,
    .tasting-mobile-controls-hidden {
        display: none !important;
    }
}

@media (max-width: 520px) {
    .wine-details {
        grid-template-columns: 1fr;
    }

    .mobile-summary-row {
        gap: 8px;
    }

    .mobile-wine-facts,
    .mobile-wine-identity {
        gap: 8px;
    }

    .mobile-wine-facts {
        grid-template-columns: repeat(5, minmax(0, 1fr));
    }

    .mobile-wine-identity {
        grid-template-columns: minmax(0, 1.25fr) minmax(0, 0.75fr);
    }

    .mobile-tasting-identity {
        grid-template-columns: 1fr;
    }

    .mobile-wine-facts dt {
        font-size: 0.62rem;
    }

    .mobile-wine-facts dd {
        font-size: 0.88rem;
    }

    .mobile-wine-facts .stacked-value span {
        font-size: 0.74rem;
    }
}
