:root {
    --bg: #f5f5f3;
    --surface: #ffffff;
    --surface-soft: #f8f8f7;
    --border: #e4e4e1;
    --text: #171717;
    --muted: #6f6f6a;
    --accent: #b08a47;
    --accent-dark: #8e6f39;
    --danger: #c62828;
    --shadow: 0 8px 24px rgba(0, 0, 0, 0.05);
    --radius-lg: 20px;
    --radius-md: 16px;
    --radius-sm: 12px;
}

* {
    box-sizing: border-box;
}

body.app-body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: Inter, Arial, sans-serif;
}

/* Layout */
.app-container {
    max-width: 760px;
    padding-top: 20px;
    padding-bottom: 28px;
}

.homepage-container {
    max-width: 1480px;
    padding: 20px 16px 32px;
}

.edit-container {
    max-width: 100%;
    padding: 18px 14px 28px;
}

/* Header */
.page-header {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 14px;
}

.page-kicker {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--accent);
    font-weight: 700;
    margin-bottom: 4px;
}

.page-title {
    font-size: 30px;
    line-height: 1.1;
    margin: 0 0 6px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.page-subtitle {
    margin: 0;
    color: var(--muted);
    font-size: 15px;
    line-height: 1.45;
}

.page-actions {
    display: none;
}

/* Buttons */
.btn-accent {
    background: var(--accent);
    color: #fff;
    border: 1px solid var(--accent);
    border-radius: 14px;
    padding: 12px 16px;
    font-weight: 600;
    min-height: 48px;
}

.btn-accent:hover,
.btn-accent:focus {
    background: var(--accent-dark);
    border-color: var(--accent-dark);
    color: #fff;
}

.btn-secondary-soft {
    background: #fff;
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 12px 16px;
    font-weight: 600;
    min-height: 48px;
}

.btn-secondary-soft:hover,
.btn-secondary-soft:focus {
    background: #f0f0ee;
    color: var(--text);
}

/* Panels */
.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 14px;
    margin-bottom: 14px;
}

.panel-title {
    margin: 0 0 4px;
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.01em;
}

.panel-subtitle {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.4;
}

.collection-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 12px;
    margin-bottom: 12px;
}

/* Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    margin-bottom: 14px;
}

.stats-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 14px;
    box-shadow: var(--shadow);
}

.stats-card-label {
    font-size: 12px;
    color: var(--muted);
    margin-bottom: 6px;
}

.stats-card-value {
    font-size: 20px;
    line-height: 1.15;
    font-weight: 700;
    color: var(--text);
}

/* Search + filters */
.search-panel {
    padding: 12px;
}

.search-toolbar {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.search-input,
.filter-input {
    min-height: 48px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface-soft);
    padding: 12px 14px;
    font-size: 15px;
}

.search-input:focus,
.filter-input:focus,
.form-input-custom:focus,
.edit-input:focus {
    border-color: #d6c19a;
    box-shadow: 0 0 0 0.2rem rgba(176, 138, 71, 0.10);
    background: #fff;
}

.reset-filter-btn {
    min-height: 44px;
}

/* Desktop table */
.desktop-table-wrap {
    width: 100%;
    overflow-x: auto;
}

.homepage-table {
    width: 100%;
    table-layout: fixed;
    font-size: 13px;
}

.homepage-table thead th {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    background: #fff;
    padding: 10px;
}

.homepage-table tbody td {
    border-bottom: 1px solid #ecece8;
    padding: 10px;
    vertical-align: middle;
    overflow: hidden;
    text-overflow: ellipsis;
}

.homepage-table tbody tr:last-child td {
    border-bottom: none;
}

.homepage-table tbody td.cell-overflow-visible {
    overflow: visible;
}

.col-photo { width: 86px; }
.col-name { width: 260px; }
.col-color { width: 110px; }
.col-year { width: 70px; }
.col-collection { width: 170px; }
.col-origin { width: 160px; }
.col-acquired-wide { width: 190px; }
.col-price { width: 150px; }
.col-sale { width: 110px; }

.homepage-thumb,
.homepage-no-image {
    width: 65px;
    height: 65px;
    border-radius: 12px;
}

.homepage-thumb {
    object-fit: cover;
    border: 1px solid var(--border);
    background: #fff;
    display: block;
}

.homepage-no-image {
    border: 1px dashed #d4d4cf;
    background: #f7f7f5;
    color: #8a8a84;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 11px;
    padding: 4px;
    line-height: 1.2;
}

.homepage-name {
    font-weight: 600;
    color: var(--text);
    line-height: 1.3;
    white-space: normal;
    word-break: break-word;
}

/* Hover preview */
.image-hover-wrap {
    position: relative;
    width: 65px;
    height: 65px;
    overflow: visible;
}

.image-hover-preview {
    display: none;
    position: absolute;
    top: 0;
    left: 78px;
    z-index: 999;
    width: 150px;
    height: 150px;
    padding: 6px;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 16px;
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.14);
}

.image-hover-preview-img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 12px;
    display: block;
}

.image-hover-wrap:hover .image-hover-preview {
    display: block;
}

/* Mobile list */
.mobile-ornament-list {
    display: grid;
    gap: 10px;
}

.mobile-ornament-item {
    border: 1px solid var(--border);
    border-radius: 16px;
    background: #fff;
    overflow: hidden;
}

.mobile-ornament-summary {
    width: 100%;
    border: 0;
    background: transparent;
    text-align: left;
    display: grid;
    grid-template-columns: 72px 1fr 20px;
    gap: 10px;
    align-items: center;
    padding: 10px;
    cursor: pointer;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
}

.mobile-ornament-photo-wrap {
    width: 72px;
    height: 72px;
}

.mobile-ornament-photo,
.mobile-no-photo {
    width: 72px;
    height: 72px;
    border-radius: 12px;
}

.mobile-ornament-photo {
    object-fit: cover;
    border: 1px solid var(--border);
    background: #fff;
    display: block;
}

.mobile-no-photo {
    border: 1px dashed #d4d4cf;
    background: #f7f7f5;
    color: #8a8a84;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    font-size: 11px;
    padding: 6px;
    line-height: 1.2;
}

.mobile-ornament-main {
    min-width: 0;
}

.mobile-ornament-name {
    font-size: 15px;
    line-height: 1.3;
    font-weight: 700;
    color: var(--text);
    margin: 0;
}

.mobile-ornament-toggle {
    font-size: 20px;
    line-height: 1;
    color: var(--muted);
    text-align: right;
}

.mobile-ornament-details {
    display: none;
    padding: 0 10px 10px;
    border-top: 1px solid #efefec;
}

.mobile-detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 10px;
    padding-top: 10px;
}

.mobile-detail-item {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.mobile-detail-label {
    font-size: 11px;
    color: var(--muted);
}

.mobile-detail-value {
    font-size: 13px;
    color: var(--text);
    word-break: break-word;
}

.mobile-detail-image-link-wrap {
    margin-top: 14px;
}

.mobile-detail-image-link {
    font-size: 11px;
    color: #171717;
    text-decoration: none;
    font-weight: 500;
}

.mobile-detail-image-link:hover,
.mobile-detail-image-link:focus {
    color: #171717;
    text-decoration: underline;
}

/* Price helpers */
.price-old {
    color: #777;
    text-decoration: line-through;
    text-decoration-color: var(--danger);
    text-decoration-thickness: 2px;
}

.price-note {
    display: inline-block;
    margin-left: 6px;
    font-size: 11px;
    color: #8d8d88;
    line-height: 1.2;
}

.estimated-text {
    color: #9a9a94 !important;
    font-style: italic;
}

/* Forms */
.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 14px;
}

.form-field {
    min-width: 0;
}

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

.form-label-custom {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 600;
    color: var(--muted);
}

.form-input-custom {
    min-height: 48px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: var(--surface-soft);
    padding: 12px 14px;
    font-size: 16px;
}

.form-actions {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
}

.form-actions-inline {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* Edit table */
.edit-table {
    min-width: 1450px;
}

.edit-table thead th {
    position: sticky;
    top: 0;
    background: #fff;
    z-index: 2;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
    padding: 10px 8px;
}

.edit-table tbody td {
    padding: 8px;
    border-bottom: 1px solid #ecece8;
    vertical-align: middle;
}

.edit-input {
    min-width: 120px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: #fff;
    font-size: 13px;
    padding: 8px 10px;
}

.edit-input-xs {
    min-width: 78px;
    max-width: 90px;
}

.edit-input-price {
    min-width: 95px;
    max-width: 110px;
}

.edit-input-name {
    min-width: 260px;
}

.edit-code {
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
}

.big-checkbox {
    width: 18px;
    height: 18px;
}

/* Sticky */
.sticky-actions {
    position: sticky;
    bottom: 12px;
    z-index: 10;
    background: rgba(255, 255, 255, 0.92);
    backdrop-filter: blur(8px);
}

/* Helpers */
.nowrap-money,
.nowrap-cell {
    white-space: nowrap !important;
    word-break: normal !important;
    overflow-wrap: normal !important;
}

.empty-state {
    text-align: center;
    padding: 20px 8px 8px;
}

.empty-state-title {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 8px;
}

.empty-state-text {
    color: var(--muted);
    margin-bottom: 16px;
}

/* Tablet / desktop */
@media (min-width: 768px) {
    .app-container {
        max-width: 1180px;
        padding-top: 28px;
        padding-bottom: 40px;
    }

    .homepage-container {
        padding: 24px 24px 40px;
    }

    .page-header {
        margin-bottom: 18px;
    }

    .stats-grid {
        grid-template-columns: repeat(4, 1fr);
        gap: 14px;
        margin-bottom: 18px;
    }

    .panel {
        padding: 16px;
        margin-bottom: 16px;
    }

    .form-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    .form-actions {
        grid-template-columns: auto auto;
        justify-content: end;
    }
}

@media (min-width: 992px) {
    .search-toolbar {
        grid-template-columns: minmax(260px, 1.5fr) repeat(4, minmax(135px, 1fr)) max-content;
        gap: 10px;
        align-items: center;
    }

    .reset-filter-btn {
        white-space: nowrap;
        min-width: 132px;
    }

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

/* Mobile compact mode */
@media (max-width: 767px) {
    .homepage-container {
        padding: 12px 12px 24px;
    }

    .page-header {
        margin-bottom: 10px;
        gap: 6px;
    }

    .page-kicker,
    .page-subtitle {
        display: none;
    }

    .page-title {
        font-size: 24px;
        margin: 0;
    }

    .stats-grid {
        gap: 8px;
        margin-bottom: 10px;
    }

    .stats-card {
        padding: 10px 12px;
        border-radius: 14px;
    }

    .stats-card-label {
        font-size: 11px;
        margin-bottom: 4px;
    }

    .stats-card-value {
        font-size: 17px;
    }

    .panel {
        padding: 10px;
        margin-bottom: 10px;
        border-radius: 16px;
    }

    .search-toolbar {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }

    .search-toolbar > input {
        grid-column: 1 / -1;
    }

    .search-input,
    .filter-input,
    .reset-filter-btn {
        min-height: 42px;
        font-size: 14px;
        padding: 10px 12px;
        border-radius: 12px;
    }

    .reset-filter-btn {
        grid-column: 1 / -1;
    }

    .collection-panel-header {
        margin-bottom: 10px;
    }

    .panel-title {
        font-size: 16px;
    }

    .panel-subtitle {
        font-size: 13px;
    }
}