:root {
    --bg: #f5f7fa;
    --panel: #ffffff;
    --panel-soft: #f9fbfd;
    --line: #dce3ec;
    --line-strong: #cbd5e1;
    --text: #1f2937;
    --muted: #64748b;
    --pos: #138a55;
    --neg: #c2414b;
    --accent: #2563eb;
    --accent-soft: #eaf2ff;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    font: 14px/1.5 system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
}

header {
    padding: 28px 24px 10px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
    border-bottom: 1px solid var(--line);
}

h1 {
    margin: 0 0 4px;
    font-size: 24px;
    letter-spacing: -0.02em;
}

.sub {
    margin: 0;
    color: var(--muted);
}

.muted {
    color: var(--muted);
    margin-left: 8px;
}

.kpis {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 12px;
    padding: 12px 24px 4px;
}

.kpi {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px 14px;
    box-shadow: 0 1px 2px rgb(15 23 42 / 5%);
}

.kpi-val {
    font-size: 22px;
    font-weight: 700;
    line-height: 1.2;
}

.kpi-val.pos {
    color: var(--pos);
}

.kpi-val.neg {
    color: var(--neg);
}

.kpi-label {
    margin-top: 2px;
    font-size: 12px;
    color: var(--muted);
}

.kpi-label .muted {
    margin-left: 0;
}

.quick-actions {
    display: flex;
    justify-content: flex-end;
    padding: 12px 24px 4px;
    gap: 8px;
}

.quick-actions button {
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 7px 12px;
    cursor: pointer;
    font: inherit;
}

.quick-actions button:hover {
    border-color: var(--accent);
}

.quick-actions button.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.account-bar {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    gap: 8px;
    padding: 0 24px;
}

.account-bar button,
.dialog-actions button {
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 7px 12px;
    cursor: pointer;
    font: inherit;
}

.account-bar button:hover,
.dialog-actions button:hover {
    border-color: var(--accent);
}

@media (max-width: 640px) {
        body {
            font-size: 15px;
        }

        header {
            padding: 18px 14px 12px;
        }

        h1 {
            font-size: 22px;
        }

    .kpis {
        grid-template-columns: repeat(2, 1fr);
            gap: 8px;
            padding: 10px 12px 4px;
        }

        .kpi {
            padding: 10px 11px;
        }

        .account-bar {
            justify-content: flex-start;
            flex-wrap: wrap;
            padding: 10px 12px 0;
        }

        .account-bar .muted {
            width: 100%;
            margin-left: 0;
            order: -1;
        }

        .account-bar button,
        .quick-actions button {
            min-height: 42px;
        }

        .quick-actions {
            justify-content: stretch;
            padding: 10px 12px 4px;
        }

        .quick-actions button {
            flex: 1;
        }

        .section-head,
        .overview-heading {
            align-items: flex-start;
            flex-wrap: wrap;
            gap: 7px;
            padding: 14px 12px 10px;
        }

        .section-head h2 {
            width: 100%;
        }

        .scope-note {
            white-space: normal;
        }

        .seg {
            width: 100%;
        }

        .seg button {
            flex: 1;
            min-height: 40px;
            padding: 7px 8px;
        }

        table {
            width: auto;
            margin: 0 12px 22px;
            border: 0;
            background: transparent;
            box-shadow: none;
            overflow: visible;
        }

        table thead {
            display: none;
        }

        table tbody {
            display: grid;
            gap: 10px;
        }

        table tbody tr {
            display: grid;
            grid-template-columns: repeat(2, minmax(0, 1fr));
            gap: 0;
            overflow: hidden;
            background: var(--panel);
            border: 1px solid var(--line);
            border-radius: 10px;
            box-shadow: 0 1px 3px rgb(15 23 42 / 6%);
        }

        table tbody tr:hover {
            background: var(--panel);
        }

        table td {
            display: block;
            min-width: 0;
            padding: 9px 11px;
            border-bottom: 1px solid #edf1f6;
            text-align: left;
        }

        table td::before {
            content: attr(data-label);
            display: block;
            margin-bottom: 2px;
            color: var(--muted);
            font-size: 10px;
            font-weight: 600;
            letter-spacing: 0.02em;
            text-transform: uppercase;
        }

        table td.num {
            text-align: left;
        }

        table td.mobile-wide {
            grid-column: 1 / -1;
        }

        table td.empty {
            grid-column: 1 / -1;
            border: 0;
        }

        .overview table tbody tr {
            border-left: 4px solid var(--accent);
        }

        .overview-model {
            font-size: 18px;
            font-weight: 700;
            background: var(--panel-soft);
        }

        .listing-cell {
            grid-template-columns: 64px minmax(0, 1fr);
            align-items: start;
        }

        .thumb {
            width: 64px;
            height: 50px;
        }

        .listing-title {
            font-size: 15px;
        }

        .listing-ignore {
            min-height: 32px;
            font-size: 12px;
            color: #1d5fbf;
        }

        .room {
            white-space: normal;
        }

        .detail-head {
            display: block;
            padding: 0 12px;
        }

        .detail-head h2 {
            font-size: 18px;
        }

        .filters {
            align-items: stretch;
            flex-direction: column;
            margin-bottom: 12px;
        }

        .chart {
            padding: 0 12px 10px;
            overflow-x: auto;
        }

        .legend {
            flex-wrap: wrap;
            gap: 8px 14px;
        }

        .linechart {
            min-width: 560px;
        }

        .dialog {
            width: calc(100% - 20px);
            max-height: calc(100dvh - 20px);
        }

        .dialog form {
            padding: 16px;
            max-height: calc(100dvh - 20px);
            overflow-y: auto;
        }

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

        .model-setting {
            grid-template-columns: minmax(90px, 1fr) 100px 78px;
        }

        .search-table-wrap {
            max-height: none;
            overflow: visible;
        }

        .search-config-table tbody tr {
            grid-template-columns: repeat(2, minmax(0, 1fr));
        }

        .search-config-table td::before {
            display: none;
        }

        .search-config-table .row-actions {
            justify-content: flex-start;
        }
    }
}

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

.controls label {
    display: flex;
    align-items: center;
    gap: 6px;
    color: var(--muted);
}

.controls label.check {
    color: var(--text);
}

.controls input[type="number"] {
    width: 90px;
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--text);
    padding: 6px 8px;
    border-radius: 6px;
}

.controls select {
    background: var(--panel);
    border: 1px solid var(--line);
    color: var(--text);
    padding: 6px 8px;
    border-radius: 6px;
}

.count {
    margin-left: auto;
    color: var(--muted);
}

table {
    width: calc(100% - 48px);
    margin: 0 24px 40px;
    border-collapse: collapse;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgb(15 23 42 / 4%);
}

.section-head {
    display: flex;
    align-items: baseline;
    gap: 12px;
    padding: 14px 24px 8px;
}

.section-head h2 {
    margin: 0;
    font-size: 16px;
}

.scope-note {
    display: inline-flex;
    align-items: center;
    padding: 2px 7px;
    color: #53657b;
    background: #eef3f8;
    border: 1px solid #dce5ef;
    border-radius: 999px;
    font-size: 11px;
    white-space: nowrap;
}

.overview-heading {
    padding-bottom: 12px;
}

.overview-heading + table {
    margin-top: 0;
}

.filters .scope-note {
    margin-right: 2px;
}

.new-listings table {
    margin-bottom: 24px;
}

.new-listings tbody tr {
    cursor: pointer;
}

.opportunities tbody tr {
    cursor: pointer;
}

th,
td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--line);
}

th {
    cursor: pointer;
    user-select: none;
    font-weight: 600;
    color: var(--muted);
    white-space: nowrap;
}

th:hover {
    color: var(--text);
}

th.sorted-asc::after {
    content: " \25B2";
    color: var(--accent);
}

th.sorted-desc::after {
    content: " \25BC";
    color: var(--accent);
}

.num {
    text-align: right;
}

tbody tr:hover {
    background: #f2f6fc;
}

td a {
    color: var(--accent);
    text-decoration: none;
}

td a:hover {
    text-decoration: underline;
}

.searchlink {
    opacity: 0.55;
    font-size: 0.85em;
}

.searchlink:hover {
    opacity: 1;
}

.listing-cell {
    display: grid;
    grid-template-columns: 54px minmax(0, 1fr);
    align-items: center;
    gap: 10px;
}

.listing-title {
    min-width: 0;
}

.listing-actions {
    display: flex;
    gap: 6px;
    align-items: center;
    margin-top: 4px;
}

.listing-ignore {
    appearance: none;
    border: 0;
    background: transparent;
    color: var(--muted);
    font-family: inherit;
    font-size: 11px;
    cursor: pointer;
    padding: 0;
}

.listing-ignore:hover {
    color: var(--neg);
    text-decoration: underline;
}

.thumb {
    width: 54px;
    height: 42px;
    object-fit: cover;
    border-radius: 6px;
    border: 1px solid var(--line);
    background: #eef2f7;
}

.empty-thumb {
    display: inline-block;
}

.pos {
    color: var(--pos);
    font-weight: 600;
}

.neg {
    color: var(--neg);
}

.tag {
    display: inline-block;
    margin-left: 6px;
    padding: 0 6px;
    font-size: 11px;
    border-radius: 4px;
    background: #edf2f7;
    color: #4b5a70;
}

.tag.new {
    background: #e7f7ee;
    color: #16734a;
    font-weight: 600;
}

.tag.seen {
    background: #eaf2ff;
    color: #1d5fbf;
}

.tag.drop {
    background: #e4f7ed;
    color: #157347;
}

.tag.increase {
    background: #fdebed;
    color: #b23b49;
}

.tag.ship {
    background: #e6f2fb;
    color: #176b9c;
}

.tag.buy {
    background: #fff5d9;
    color: #8b5b08;
}

.newpill {
    display: inline-block;
    margin-left: 6px;
    padding: 0 6px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 4px;
    background: #e7f7ee;
    color: #16734a;
}

.listing-price {
    display: inline-grid;
    justify-items: end;
    gap: 1px;
}

.previous-price {
    color: var(--muted);
    font-size: 11px;
    text-decoration: line-through;
}

.empty {
    text-align: center;
    padding: 18px 12px;
}

.room {
    display: inline-grid;
    gap: 2px;
    line-height: 1.15;
    white-space: nowrap;
}

.room .main {
    font-weight: 700;
}

.room .sub {
    color: var(--muted);
    font-size: 11px;
    font-weight: 400;
}

.overview tbody tr {
    cursor: pointer;
}

.overview tbody tr.selected {
    background: var(--accent-soft);
}

.hidden {
    display: none;
}

.detail {
    margin-top: 8px;
}

.detail-head {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 24px;
}

.filters {
    display: flex;
    gap: 10px;
    flex-wrap: wrap;
}

.detail-head h2 {
    font-size: 16px;
    margin: 12px 0;
}

.seg {
    display: inline-flex;
    border: 1px solid var(--line);
    border-radius: 6px;
    overflow: hidden;
}

.seg button {
    background: var(--panel);
    color: var(--muted);
    border: none;
    padding: 6px 14px;
    cursor: pointer;
    font: inherit;
}

.seg button:not(:last-child) {
    border-right: 1px solid var(--line);
}

.seg button.active {
    background: var(--accent);
    color: #fff;
}

.badge {
    display: inline-block;
    min-width: 34px;
    text-align: center;
    padding: 1px 6px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 4px;
}

.badge.pc {
    background: #f1eafe;
    color: #7048aa;
}

.badge.gpu {
    background: #e4f7ed;
    color: #157347;
}

.badge.bundle {
    background: #fff4d7;
    color: #8b6508;
}

.badge.review {
    background: #fdebed;
    color: #b23b49;
}

.datecell {
    white-space: nowrap;
}

.depth {
    font-variant-numeric: tabular-nums;
}

.depth.thin {
    color: var(--neg);
    font-weight: 700;
}

.depth.shallow {
    color: #9a6700;
}

.depth.deep {
    color: var(--muted);
}

.warn {
    color: #9a6700;
    cursor: help;
}

.med {
    display: block;
    font-size: 11px;
    font-weight: 400;
    color: var(--muted);
    cursor: help;
}

.hint {
    font-size: 10px;
    font-weight: 400;
    color: var(--muted);
}

.age {
    display: inline-block;
    margin-left: 6px;
    padding: 0 5px;
    font-size: 11px;
    font-weight: 600;
    border-radius: 4px;
    vertical-align: middle;
}

.age.fresh {
    background: #e4f7ed;
    color: #157347;
}

.age.recent {
    background: #fff4d7;
    color: #8b6508;
}

.age.stale {
    background: #f8e9eb;
    color: #a94452;
}

.trend {
    white-space: nowrap;
}

.spark {
    vertical-align: middle;
}

.delta {
    margin-left: 6px;
    font-size: 12px;
}

.chart {
    padding: 0 24px 8px;
}

.chart .muted {
    padding: 8px 0;
}

.linechart {
    width: 100%;
    max-width: 760px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.linechart .axis {
    fill: var(--muted);
    font-size: 10px;
}

.dialog {
    width: min(520px, calc(100% - 32px));
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0;
    box-shadow: 0 18px 50px rgb(15 23 42 / 22%);
}

.dialog::backdrop {
    background: rgb(0 0 0 / 68%);
}

.dialog form {
    display: grid;
    gap: 12px;
    padding: 20px;
}

.dialog h2,
.dialog h3 {
    margin: 0;
}

.dialog label {
    display: grid;
    gap: 4px;
    color: var(--muted);
}

.dialog input,
.dialog select {
    width: 100%;
    padding: 8px 10px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 6px;
}

.dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 4px;
}

.form-error {
    min-height: 1.5em;
    margin: 0;
    color: var(--neg);
}

.settings-dialog {
    width: min(720px, calc(100% - 32px));
}

.search-dialog {
    width: min(920px, calc(100% - 32px));
}

.ignored-dialog {
    width: min(720px, calc(100% - 32px));
}

.ignored-listings {
    display: grid;
    gap: 8px;
}

.ignored-row {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 12px;
    align-items: center;
    padding: 10px 12px;
    border: 1px solid var(--line);
    border-radius: 7px;
}

.ignored-row .ignored-title {
    min-width: 0;
}

.ignored-row .muted {
    margin: 2px 0 0;
    display: block;
}

.dialog-title-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 16px;
}

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

.search-form-grid {
    display: grid;
    grid-template-columns: 2fr 0.8fr repeat(3, 1fr);
    gap: 10px;
    align-items: end;
}

.inline-check {
    display: flex !important;
    align-items: center;
    min-height: 38px;
}

.search-table-wrap {
    max-height: 360px;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
}

.search-config-table {
    width: 100%;
    margin: 0;
    border: 0;
    border-radius: 0;
}

.search-config-table .row-actions {
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

.search-config-table button {
    background: var(--panel);
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 5px;
    padding: 4px 8px;
    cursor: pointer;
}

.search-config-table button.danger {
    color: var(--neg);
}

.model-settings {
    display: grid;
    gap: 8px;
    max-height: 320px;
    overflow: auto;
}

.model-setting {
    display: grid;
    grid-template-columns: minmax(130px, 1fr) 130px 90px;
    gap: 10px;
    align-items: center;
}

.model-setting label {
    display: flex;
    align-items: center;
    gap: 7px;
}

@media (max-width: 640px) {
    .settings-grid {
        grid-template-columns: 1fr;
    }

    .model-setting {
        grid-template-columns: 1fr 110px 80px;
    }

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

    .dialog-title-row {
        align-items: flex-start;
        flex-direction: column;
        gap: 4px;
    }
}

.legend {
    display: flex;
    gap: 16px;
    align-items: center;
    margin: 4px 0 8px;
    color: var(--muted);
    font-size: 12px;
}

.legend i {
    display: inline-block;
    width: 10px;
    height: 10px;
    border-radius: 2px;
    margin-right: 5px;
    vertical-align: middle;
}