body {
    font-family: Arial;
    margin: 24px;
    color: #111
}

h1 {
    margin: 0 0 12px 0;
    font-size: 20px
}

.top {
    display: flex;
    gap: 16px;
    align-items: center;
    flex-wrap: wrap;
    margin: 16px 0 12px 0;
    width: 100%;
}

.controls {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

input[type="search"],
input[type="text"],
select,
button {
    padding: 8px 10px;
    border-radius: 6px;
    border: 1px solid #ccc;
    min-width: 100px
}

table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 6px;
}

th,
td {
    text-align: left;
    padding: 8px 6px;
    border-bottom: 1px solid #eee;
    border-right: 1px solid #eee;
}

th {
    user-select: none;
    cursor: pointer;
    background: #fafafa
}

th.sort-asc::after {
    content: " ▲";
    font-size: 8px
}

th.sort-desc::after {
    content: " ▼";
    font-size: 8px
}

tr:hover td {
    background: #fbfbff
}

.pagination {
    margin-top: 10px;
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap
}

.page-btn {
    padding: 6px 10px;
    border-radius: 6px;
    border: 1px solid #ccc;
    background: #fff;
    cursor: pointer
}

.page-btn[disabled] {
    opacity: 0.5;
    cursor: default
}

.meta {
    color: #444;
    font-size: 13px
}

.no-results {
    padding: 14px;
    color: #666
}

.admin-btn {
    padding: 8px 14px;
    border-radius: 6px;
    border: 1px solid #667eea;
    background: #667eea;
    color: #fff;
    cursor: pointer;
    font-size: 14px;
    margin-left: auto;
}

.admin-btn:hover {
    background: #5568d3;
    border-color: #5568d3;
}

.grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    align-items: start
}

#admin-card {
    position: relative;
    bottom: auto;
    left: auto;
    right: auto;
    width: 100%;
    max-height: none;
    overflow: visible;
    padding: 12px 0 0;
    background: transparent;
    border-top: none;
    box-shadow: none;
    z-index: auto;
}

/* #admin-card { position: fixed; bottom: 30px; right: 0; width: auto; max-height: 100vh; overflow-y: auto; padding: 12px; } */
.dates-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    align-items: start
}

.card {
    border: 1px solid #eee;
    padding: 12px;
    border-radius: 8px;
    background: #fff
}

.formula-table {
    width: 100%;
    border-collapse: collapse;
    margin: 0;
    font-size: 0.92rem;
}

.formula-table th,
.formula-table td {
    padding: 6px 8px;
    border: 1px solid #ddd;
    text-align: left;
}

.formula-table th {
    background: #fafafa;
    font-weight: 600;
}

/* .formula-table td {
vertical-align: top;
} */

.formula-table tr:nth-child(even) td {
    background: #fafbff;
}

label {
    display: block;
    margin-bottom: 8px;
    font-size: 13px
}

.header-row {
    display: flex;
    align-items: end;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 12px
}

.logo {
    width: 150px;
    height: auto;
    display: block;
}

.tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 0;
}

.tab {
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid #ccc;
    background: #fff;
    cursor: pointer;
    width: 100px
}

.tab.active {
    background: #f0f4ff;
    border-color: #9fb0ff
}

pre {
    max-height: 600px;
    overflow: auto;
    background: #0f1720;
    color: #e6eef8;
    padding: 12px;
    border-radius: 6px;
    font-size: 13px
}

.small {
    font-size: 13px;
    color: #555
}

.err {
    color: #b00020;
    font-size: 13px
}

.format-list {
    margin-top: 8px;
    font-size: 13px;
    color: #444
}

input.upper {
    text-transform: uppercase;
}

.date-cell {
    font-family: monospace;
    white-space: pre;
    text-align: center;
}

.small-txt {
    font-size: smaller;
}

button#copyJsonViewBtn {
    min-width: 36px;
    height: 36px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 18px
}

#viewTable,
#viewDates,
#viewJson,
#viewMixes {
    display: none;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.modal-overlay.active {
    display: flex;
}

.modal-box {
    background: #fff;
    padding: 24px;
    border-radius: 8px;
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
    /* max-width:800px; */
    min-width: 40%;
}

.modal-box h2 {
    margin: 0;
}

.modal-form {
    display: flex;
    flex-direction: column;
    /*gap:12px;*/
    margin: 0 auto;
}

.modal-form label {
    display: flex;
    flex-direction: column;
}

.modal-form input {
    padding: 8px;
    border: 1px solid #ccc;
    border-radius: 4px;
    font-size: 1.4rem;
}

.modal-preview-warn {
    color: #b00020;
    font-weight: 600;
    text-align: center;
    font-size: 13px;
}

.modal-titlebar {
    display: flex;
    flex-direction: column;
    margin: -24px -24px 16px -24px;
    padding: 10px;
    background: #f5f5f5;
    border-bottom: 1px solid #ddd;
    border-radius: 8px 8px 0 0;
}

.modal-product-meta {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr 1fr;
    gap: 12px;
    margin: 0 0 16px 0;
}

.modal-product-meta .meta-item {
    background: #f9f9ff;
    padding: 14px 12px;
    border-radius: 8px;
    text-align: center;
    border: 1px solid #dde0f2;
}

.modal-product-meta .meta-item span {
    display: block;
    font-size: 0.75rem;
    color: #556;
    margin-bottom: 6px;
}

.modal-product-meta .meta-item strong {
    display: block;
    font-size: 1.1em;
    color: #111;
    line-height: 1.1;
}

.modal-product-meta .meta-warning {
    background: #f4e3e3;
    border: 1px solid #eec4c4;
}

.modal-titlebar h2 {
    margin: 0;
    text-align: center;
}

.modal-titlebar #modalTitleProduct {
    font-size: 18px;
    font-weight: 600;
    color: #000;
}

/* .modal-titlebar #modalTitle { font-size:14px; font-weight:400; color:#666; margin:0; } */
.modal-actions {
    display: flex;
    gap: 8px;
    /* margin-top: 16px; */
}

.modal-actions button {
    flex: 1;
    padding: 8px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

#modalOk {
    background: #0066cc;
    color: #fff;
}

#modalCancel {
    background: #ccc;
    color: #000;
}

.json {
    display: none;
}

#productsTable {
    width: 90%;
    margin: 0 auto;
    font-size: 0.9rem;
    max-width: 1100px;
    border-left: 1px solid #eee;
    border-top: 1px solid #eee;
}

#productsTable th:last-child,
#productsTable td:last-child {
    display: none;
}

#productsTable tr {
    line-height: 1.4rem;
}

#productsTable td:nth-child(1) {
    font-family: monospace;
}


td.desc-glf {
    display: flex;
    align-items: center;
    /* gap: 0.3rem; */
}

td.desc-glf .glf {
    margin-left: 0;
    font-family: monospace;
}

td.desc-glf .glf,
td.desc-glf .bagSize {
    display: inline-block;
    padding: 0.18rem 0.5rem;
    /* vertical | horizontal */
    font-size: 0.75rem;
    /* smaller text */
    line-height: 1;
    /* border-radius: 999px; */
    /* pill shape */
    background: #e6f4ff;
    /* light background */
    color: #0366d6;
    /* accent text color */
    border: 1px solid rgba(3, 102, 214, 0.12);
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.02) inset;
    white-space: nowrap;
}

td.desc-glf .bagSize {
    border-radius: 0;
    background: #f3f2f2;
    color: #333;
    padding: 0.3rem;
}

td.desc-glf .desc {
    padding: 0 1rem;
}

#viewJSON {
    display: none;
}

#viewJulian {
    width: 30%;
    margin: 0 auto;
}

.formulaProductName {
    font-style: italic;
    color: #666;
}

.formula-table td span {
    display: inline-block;
    width: 50%;
    /* gap:1rem; */
}

.formula-table td span:nth-child(2) {
    font-style: italic;
    color: #666;
    text-align: right;
}

.formula-table th {
    max-width: 25%;
    overflow: hidden;
    background-color: #fafbf8;
}

.formula-table {
    font-family: monospace;
    max-width: 80%;
    margin: 0 auto;
}


/* mobile: stack desc and glf vertically */
@media (max-width: 600px) {
    td.desc-glf {
        /* flex-direction: column; */
        align-items: flex-start;
    }

    td.desc-glf .glf {
        margin-left: 0;
        align-self: flex-start;
    }

    td.desc-glf .desc {
        display: block;
    }

    body {
        margin: 5px;
    }

    #productsTable {
        width: 100%;
        margin: 0;
    }

    #productsTable th {
        font-size: smaller;
        font-weight: bold;
    }

    #productsTable th:nth-child(n+3):nth-child(-n+5) {
        width: 40px;
    }

    .formula-table {
        font-size: small;
        max-width: 100%;
    }

    .formula-table th {
        font-weight: bold;
    }
}

:root {
    color-scheme: light;
    --page: #f3f3f6;
    --surface: #fff;
    --surface-soft: #f7f7fa;
    --ink: #1c1c29;
    --muted: #666b74;
    --line: #dddce5;
    --accent: #17426b;
    --accent-hover: #111054;
    --accent-soft: #e8eaf3;
    --warning-soft: #fff2e8;
    --warning-ink: #994317;
    --focus: #2b3d8e;
}

* {
    box-sizing: border-box;
}

body {
    max-width: 1440px;
    margin: 0 auto;
    padding: 20px 28px 36px;
    background: var(--page);
    color: var(--ink);
    font-family: "Aptos", "Trebuchet MS", sans-serif;
    line-height: 1.45;
}

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

button,
input[type="search"],
input[type="text"],
select {
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
}

button {
    cursor: pointer;
    transition: background-color 140ms ease, border-color 140ms ease, color 140ms ease;
}

button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 3px solid color-mix(in srgb, var(--focus) 32%, transparent);
    outline-offset: 2px;
    border-color: var(--focus);
}

.header-row {
    align-items: center;
    gap: 24px;
    margin-bottom: 20px;
    padding-bottom: 14px;
    border-bottom: 1px solid var(--line);
}

.logo {
    width: 136px;
}

.main-header {
    flex: 1;
    min-width: 0;
}

.tabs {
    flex-wrap: wrap;
    gap: 4px;
    border-bottom: 1px solid var(--line);
}

.tab {
    width: auto;
    min-width: 88px;
    padding: 8px 14px;
    border: 1px solid transparent;
    border-radius: 5px 5px 0 0;
    background: transparent;
    color: var(--muted);
    font-weight: 600;
}

.tab:hover {
    background: var(--surface-soft);
    color: var(--ink);
}

.tab.active {
    border-color: var(--line) var(--line) var(--surface);
    margin-bottom: -1px;
    background: var(--surface);
    color: var(--accent);
}

.top {
    margin: 14px 0 0;
}

.controls {
    width: 100%;
    gap: 14px;
}

.search-control {
    display: flex;
    flex: 1;
    align-items: center;
    gap: 12px;
    min-width: 240px;
    margin: 0;
    color: var(--muted);
    font-size: 13px;
    font-weight: 600;
}

.search-control input {
    flex: 1;
    width: 100%;
    min-width: 0;
    padding: 8px 12px;
    color: var(--ink);
}

.search-control input::placeholder {
    color: #878893;
}

#resultCount {
    padding: 6px 10px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: var(--surface);
    color: var(--muted);
    white-space: nowrap;
}

#viewTable {
    max-width: 1240px;
    margin: 0 auto;
}

.table-scroll {
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 7px;
    background: var(--surface);
}

#productsTable {
    width: 100%;
    max-width: none;
    margin: 0;
    border: 0;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 14px;
}

#productsTable th,
#productsTable td {
    padding: 11px 14px;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    vertical-align: middle;
}

#productsTable th {
    background: #eaeaf1;
    color: #353547;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

#productsTable th:hover {
    background: #e1e1ec;
}

#productsTable th.sort-asc::after,
#productsTable th.sort-desc::after {
    color: var(--accent);
    font-size: 10px;
}

#productsTable tbody tr:nth-child(even) td {
    background: var(--surface-soft);
}

#productsTable tbody tr:hover td {
    background: var(--accent-soft);
}

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

#productsTable td:nth-child(1) {
    color: #354740;
    font-weight: 700;
}

.pagination {
    justify-content: flex-end;
    margin-top: 14px;
}

.page-btn {
    min-width: 72px;
    padding: 7px 12px;
    border-color: var(--line);
    background: var(--surface);
    color: var(--ink);
}

.page-btn:not([disabled]):hover {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
}

.page-btn[disabled] {
    color: #89948f;
}

.meta {
    color: var(--muted);
}

.no-results {
    margin-top: 8px;
    border: 1px solid var(--line);
    border-radius: 6px;
    background: var(--surface);
    color: var(--muted);
}

.modal-overlay {
    padding: 16px;
    background: rgb(16 31 25 / 58%);
    backdrop-filter: blur(3px);
}

.modal-box {
    width: min(760px, 100%);
    min-width: 0;
    max-height: calc(100vh - 32px);
    max-height: calc(100dvh - 32px);
    overflow: auto;
    padding: 24px;
    border: 1px solid rgb(255 255 255 / 70%);
    border-radius: 8px;
    box-shadow: 0 20px 60px rgb(14 32 25 / 22%);
}

.modal-titlebar {
    background: var(--surface-soft);
    border-bottom-color: var(--line);
}

.modal-titlebar #modalTitleProduct {
    color: var(--ink);
}

.modal-product-meta {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
}

.modal-product-meta .meta-item {
    border-color: var(--line);
    border-radius: 6px;
    background: var(--surface-soft);
}

.modal-product-meta .meta-item span {
    color: var(--muted);
}

.modal-product-meta .meta-warning {
    border-color: #f1d0b8;
    background: var(--warning-soft);
}

.modal-product-meta .meta-warning strong {
    color: var(--warning-ink);
}

.modal-form input {
    min-width: 0;
    background: var(--surface);
}

.modal-preview-warn {
    margin-bottom: 8px;
    color: var(--warning-ink);
}

.modal-actions button {
    min-height: 40px;
}

#modalCancel {
    border: 1px solid var(--line);
    background: var(--surface-soft);
    color: var(--ink);
}

#modalCancel:hover {
    background: #edf2ef;
}

.formula-table {
    width: 100%;
    max-width: 100%;
    color: var(--ink);
}

.formula-table th {
    background: #eaf1ed;
}

.formula-table tr:nth-child(even) td {
    background: var(--surface-soft);
}

.card {
    border-color: var(--line);
    border-radius: 7px;
    background: var(--surface);
}

@media (max-width: 760px) {
    body {
        padding: 16px;
    }

    .header-row {
        align-items: flex-start;
        gap: 12px;
    }

    .logo {
        width: 110px;
    }

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

@media (max-width: 600px) {
    body {
        padding: 12px;
    }

    .header-row {
        display: block;
    }

    .logo {
        width: 104px;
        margin-bottom: 14px;
    }

    .tabs {
        gap: 2px;
    }

    .tab {
        flex: 1 1 auto;
        min-width: 0;
        padding: 8px 9px;
    }

    .controls {
        align-items: stretch;
    }

    .search-control {
        flex-basis: 100%;
        min-width: 0;
    }

    #resultCount {
        align-self: flex-start;
    }

    .table-scroll #productsTable {
        min-width: 600px;
    }

    .pagination {
        justify-content: space-between;
    }

    .modal-overlay {
        padding: 10px;
        align-items: flex-start;
        overflow-y: auto;
    }

    .modal-box {
        /*max-height: calc(100vh - 20px);*/
        max-height: calc(100dvh - 20px);
        flex: 0 0 auto;
        margin: auto 0;
        overscroll-behavior: contain;
        padding: 18px;
    }

    .modal-titlebar {
        margin: -18px -18px 14px;
    }

    .modal-product-meta {
        gap: 6px;
    }

    .modal-product-meta .meta-item {
        padding: 10px 8px;
    }
}

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

.modal-titlebar {
    align-items: flex-start;
    justify-content: flex-start;
    padding: 14px 20px;
    background: var(--surface-soft);
}

.modal-heading {
    min-width: 0;
}

.modal-eyebrow {
    margin: 0 0 3px;
    color: var(--accent);
    font-size: 11px;
    font-weight: 700;
}

.modal-titlebar h2,
.modal-titlebar #modalTitleProduct {
    text-align: left;
    overflow-wrap: anywhere;
}

.modal-titlebar #modalTitleProduct {
    font-size: 20px;
}

.modal-form {
    gap: 12px;
}

.modal-section {
    min-width: 0;
    margin: 0;
    padding: 12px 14px 14px;
    border: 1px solid var(--line);
    border-radius: 6px;
}

.modal-section legend {
    padding: 0 6px;
    color: var(--ink);
    font-size: 13px;
    font-weight: 700;
}

.date-inputs {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 10px;
}

.date-inputs label {
    display: flex;
    min-width: 0;
    flex-direction: column;
    gap: 5px;
    margin: 0;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.date-inputs input {
    width: 100%;
    min-width: 0;
    min-height: 44px;
    padding: 8px 10px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: var(--surface);
    color: var(--ink);
    font-size: 18px;
    font-variant-numeric: tabular-nums;
}

.modal-preview-warn {
    margin: 0 0 9px;
    text-align: left;
    font-size: 12px;
}

#modalPreview {
    max-width: 100%;
    margin: 0;
    padding: 10px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: var(--surface-soft);
    font-family: monospace;
    white-space: pre-wrap;
}

/* #modalPreview svg {
    display: block;
    max-width: 100%;
} */

.modal-actions {
    justify-content: flex-end;
    margin-top: 2px;
}

.modal-actions #modalCancel {
    flex: 0 0 auto;
    min-width: 112px;
    border: 1px solid var(--line);
    border-radius: 5px;
    background: var(--surface);
    color: var(--ink);
}

.modal-actions #modalCancel:hover {
    border-color: var(--accent);
    background: var(--accent-soft);
    color: var(--accent);
}

@media (max-width: 420px) {
    .modal-box {
        padding: 16px;
    }

    .modal-titlebar {
        margin: -16px -16px 14px;
        padding: 12px 16px;
    }

    .modal-section {
        padding: 10px 10px 12px;
    }

    .date-inputs {
        gap: 6px;
    }

    .date-inputs input {
        padding: 7px;
        font-size: 16px;
    }
}