:root {
    --jewelry-red: #cc0000;
    --jewelry-blue: #0000ff;
    --jewelry-line: #000000;
    --jewelry-soft: #f5f5f5;
    --jewelry-muted: #666666;
}

body {
    padding-bottom: 40px;
}

.jewelry-shell {
    max-width: none;
}

.jewelry-toolbar {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 24px;
    margin-bottom: 18px;
    border-bottom: 1px solid var(--jewelry-line);
    padding-bottom: 14px;
}

.jewelry-toolbar h1 {
    margin: 0 0 6px 0;
    max-width: none;
    border-bottom: 0;
    padding-bottom: 0;
    font-size: 2rem;
}

.jewelry-meta,
.order-meta,
.detail-kicker,
.empty-note,
#import-status {
    color: var(--jewelry-muted);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 0.78rem;
    line-height: 1.4;
}

.jewelry-meta,
.detail-kicker {
    margin: 0;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.jewelry-actions,
.import-actions,
.detail-actions,
.pieces-toolbar {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.jewelry-actions {
    justify-content: flex-end;
}

.tool-button {
    appearance: none;
    border: 1px solid var(--jewelry-line);
    background: #ffffff;
    color: var(--jewelry-blue);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    min-height: 32px;
    padding: 6px 10px;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 0.72rem;
    font-weight: bold;
    letter-spacing: 0.08em;
    line-height: 1;
    text-transform: uppercase;
    text-decoration: none;
}

.tool-button:hover,
.tool-button:focus-visible,
.tool-button.active {
    background: var(--jewelry-blue);
    color: #ffffff;
    text-decoration: none;
}

.tool-button:disabled {
    border-color: #aaaaaa;
    color: #666666;
    cursor: default;
}

.import-panel,
.jewelry-filters,
.materials-view,
.orders-view,
.pieces-view,
.local-only-message {
    border: 1px solid var(--jewelry-line);
    background: #ffffff;
}

.import-panel,
.jewelry-filters {
    margin-bottom: 14px;
    padding: 12px;
}

.import-panel label,
.jewelry-filters span,
.field-row span {
    color: var(--jewelry-red);
    display: block;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 0.72rem;
    font-weight: bold;
    letter-spacing: 0.08em;
    margin-bottom: 6px;
    text-transform: uppercase;
}

.import-panel textarea,
.field-row textarea,
.field-row input,
.field-row select,
.jewelry-filters input,
.jewelry-filters select {
    box-sizing: border-box;
    width: 100%;
    border: 1px solid #d7d7d7;
    background: #ffffff;
    padding: 8px;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 0.88rem;
    line-height: 1.4;
}

.import-panel textarea,
.field-row textarea {
    resize: vertical;
}

.import-actions {
    align-items: center;
    margin-top: 8px;
}

.jewelry-filters {
    display: grid;
    grid-template-columns: minmax(240px, 1fr) minmax(180px, 260px) minmax(180px, 260px);
    gap: 12px;
}

.materials-view {
    display: grid;
    grid-template-columns: minmax(0, 1.35fr) minmax(340px, 0.65fr);
    min-height: 520px;
}

[hidden] {
    display: none !important;
}

.table-scroll {
    overflow: auto;
    max-height: calc(100vh - 250px);
    border-right: 1px solid var(--jewelry-line);
}

.materials-table {
    width: 100%;
    min-width: 1460px;
    border-collapse: collapse;
    table-layout: fixed;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 0.82rem;
    line-height: 1.35;
}

.materials-table th,
.materials-table td {
    border-bottom: 1px solid #d7d7d7;
    border-right: 1px solid #e0e0e0;
    vertical-align: top;
}

.materials-table th {
    position: sticky;
    top: 0;
    z-index: 2;
    background: var(--jewelry-soft);
    color: var(--jewelry-red);
    padding: 8px;
    text-align: left;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    cursor: grab;
    user-select: none;
}

.materials-table th:active {
    cursor: grabbing;
}

.materials-table th.column-dragging {
    opacity: 0.45;
}

.materials-table th.column-drop-target {
    box-shadow: inset 3px 0 0 var(--jewelry-blue);
    color: var(--jewelry-blue);
}

.column-sort-button {
    appearance: none;
    border: 0;
    background: transparent;
    color: inherit;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 0;
    font: inherit;
    letter-spacing: inherit;
    text-align: left;
    text-transform: inherit;
}

.column-sort-button:hover,
.column-sort-button:focus-visible,
.detail-kicker a {
    color: var(--jewelry-blue);
}

.number-sort-header {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-width: 0;
}

.sort-arrows {
    display: inline-flex;
    align-items: center;
    gap: 2px;
}

.sort-arrow-button {
    appearance: none;
    border: 1px solid #d7d7d7;
    background: #ffffff;
    color: var(--jewelry-muted);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    padding: 0;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--jewelry-muted);
    font-size: 0.62rem;
    line-height: 1;
}

.sort-arrow-button:hover,
.sort-arrow-button:focus-visible,
.sort-arrow-button.active {
    border-color: var(--jewelry-blue);
    background: var(--jewelry-blue);
    color: #ffffff;
}

.materials-table td {
    min-height: 60px;
    padding: 8px;
    background: #ffffff;
    overflow-wrap: anywhere;
}

.materials-table tr {
    cursor: pointer;
}

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

.materials-table tr:hover td,
.materials-table tr.selected td {
    background: #eeeeff;
}

.material-title {
    color: var(--jewelry-blue);
    font-weight: bold;
}

.image-cell {
    width: 74px;
}

.material-thumb {
    display: block;
    width: 58px;
    height: 58px;
    object-fit: cover;
    border: 1px solid #d7d7d7;
    background: var(--jewelry-soft);
}

.material-detail {
    min-width: 0;
    max-height: calc(100vh - 250px);
    overflow: auto;
    padding: 12px;
}

.material-detail header {
    border-bottom: 1px solid var(--jewelry-line);
    margin-bottom: 10px;
    padding-bottom: 10px;
}

.detail-media {
    margin-bottom: 12px;
}

.detail-media img {
    display: block;
    width: min(100%, 300px);
    aspect-ratio: 1;
    object-fit: cover;
    border: 1px solid #d7d7d7;
    background: var(--jewelry-soft);
}

.material-detail h2,
.order-card h2 {
    max-width: none;
    margin: 0;
    border: 0;
    padding: 0;
    font-size: 1.25rem;
}

.detail-actions {
    margin-bottom: 12px;
}

.detail-fields {
    display: grid;
    gap: 10px;
}

.field-row {
    display: block;
}

.field-row input:focus,
.field-row textarea:focus,
.field-row select:focus,
.jewelry-filters input:focus,
.jewelry-filters select:focus,
.import-panel textarea:focus {
    border-color: var(--jewelry-blue);
    outline: none;
    box-shadow: inset 0 0 0 1px var(--jewelry-blue);
}

.orders-view,
.pieces-view {
    display: grid;
    gap: 12px;
    padding: 12px;
}

.order-card,
.piece-card {
    border: 1px solid #d7d7d7;
    padding: 12px;
}

.order-card ul {
    margin: 8px 0 0;
    padding-left: 18px;
}

.order-card button {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--jewelry-blue);
    cursor: pointer;
    padding: 0;
    font: inherit;
    text-align: left;
}

.order-card button:hover,
.order-card button:focus-visible {
    text-decoration: underline;
}

.piece-card {
    display: grid;
    gap: 10px;
}

.local-only-message {
    max-width: 720px;
    padding: 20px;
}

.local-only-message h1 {
    margin-top: 0;
}

.local-only-message p {
    max-width: 58ch;
    color: var(--jewelry-muted);
    font-family: Arial, Helvetica, sans-serif;
    line-height: 1.45;
}

@media (max-width: 900px) {
    .jewelry-toolbar {
        align-items: stretch;
        flex-direction: column;
        gap: 12px;
    }

    .jewelry-actions {
        justify-content: flex-start;
    }

    .jewelry-filters,
    .materials-view {
        grid-template-columns: 1fr;
    }

    .table-scroll,
    .material-detail {
        max-height: none;
    }

    .table-scroll {
        border-right: 0;
        border-bottom: 1px solid var(--jewelry-line);
    }

    .tool-button {
        min-height: 36px;
    }
}
