:root {
    --bg: #f4f6f8;
    --panel: #ffffff;
    --text: #18202a;
    --muted: #657386;
    --line: #d8dee8;
    --accent: #0f766e;
    --accent-dark: #115e59;
    --danger: #b42318;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--text);
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    font-size: 14px;
    line-height: 1.5;
}

.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 18px 28px;
    background: #17202b;
    color: #fff;
}

.app-header h1 {
    margin: 0;
    font-size: 22px;
}

.app-header p {
    margin: 2px 0 0;
    color: #c9d3df;
}

.logout {
    color: #fff;
    text-decoration: none;
    border: 1px solid rgba(255,255,255,.3);
    padding: 8px 12px;
    border-radius: 6px;
}

.header-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.container {
    width: min(1440px, calc(100% - 32px));
    margin: 24px auto 48px;
}

.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 16px;
    padding: 16px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.toolbar h2 {
    margin: 0;
    font-size: 17px;
}

.toolbar p {
    margin: 4px 0 0;
    color: var(--muted);
}

.toolbar form {
    flex: 0 0 auto;
}

.sync-form {
    display: grid;
    grid-template-columns: 150px 150px auto;
    gap: 10px;
    align-items: end;
}

.sync-form label {
    min-width: 0;
}

.notice {
    margin-bottom: 16px;
    padding: 12px 14px;
    border-radius: 8px;
    border: 1px solid #b7d8ca;
    background: #ecfdf3;
    color: #065f46;
    font-weight: 700;
}

.notice.error {
    border-color: #f5b7b1;
    background: #fee4e2;
    color: var(--danger);
}

.filters {
    display: grid;
    grid-template-columns: repeat(5, minmax(0, 1fr));
    gap: 12px;
    align-items: end;
    padding: 16px;
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

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

label {
    display: grid;
    gap: 6px;
    color: var(--muted);
    font-weight: 600;
}

input,
select {
    width: 100%;
    min-height: 40px;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 10px;
    color: var(--text);
    background: #fff;
}

button {
    min-height: 40px;
    border: 0;
    border-radius: 6px;
    padding: 8px 16px;
    background: var(--accent);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}

button:hover {
    background: var(--accent-dark);
}

.button-secondary {
    display: inline-grid;
    min-height: 40px;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 8px 16px;
    background: #fff;
    color: var(--text);
    font-weight: 700;
    text-decoration: none;
}

.table-link {
    color: var(--accent-dark);
    font-weight: 700;
    text-decoration: none;
}

.table-link:hover {
    text-decoration: underline;
}

.detail-nav {
    margin: 0 0 24px;
    text-align: right;
}

.metrics {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin: 16px 0;
}

.metrics div,
.panel,
.login-panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
}

.metrics div {
    padding: 16px;
}

.metrics span {
    display: block;
    color: var(--muted);
    font-weight: 700;
}

.metrics strong {
    display: block;
    margin-top: 4px;
    font-size: 24px;
}

.grid {
    display: grid;
    gap: 16px;
    margin-bottom: 16px;
}

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

.panel {
    margin-bottom: 16px;
    overflow: hidden;
}

.panel h2 {
    margin: 0;
    padding: 14px 16px;
    border-bottom: 1px solid var(--line);
    font-size: 17px;
}

.table-wrap {
    overflow-x: auto;
    overflow-y: hidden;
    -webkit-overflow-scrolling: touch;
}

.table-wrap::-webkit-scrollbar {
    height: 10px;
}

.table-wrap::-webkit-scrollbar-track {
    background: transparent;
}

.table-wrap::-webkit-scrollbar-thumb {
    background: var(--line);
    border-radius: 6px;
}

table {
    width: 100%;
    border-collapse: collapse;
}

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

th {
    background: #f8fafc;
    color: var(--muted);
    font-size: 12px;
}

td.name {
    white-space: normal;
    min-width: 260px;
}

.status {
    display: inline-block;
    min-width: 64px;
    padding: 2px 8px;
    border-radius: 999px;
    background: #e8f5f2;
    color: var(--accent-dark);
    text-align: center;
    font-weight: 700;
}

.status.failed {
    background: #fee4e2;
    color: var(--danger);
}

.chart-wrap {
    padding: 16px;
}

.chart {
    width: 100%;
    height: auto;
}

.chart .bar-sales {
    fill: var(--accent);
    opacity: .85;
}

.chart .bar-cost {
    fill: var(--danger);
    opacity: .7;
}

.chart .chart-net {
    fill: none;
    stroke: #17202b;
    stroke-width: 2;
}

.chart .chart-zero {
    stroke: var(--line);
    stroke-width: 1;
}

.chart .chart-gridline {
    stroke: var(--line);
    stroke-width: 1;
    stroke-dasharray: 2 3;
}

.chart .chart-y-label {
    fill: var(--muted);
    font-size: 10px;
    text-anchor: end;
}

.chart .chart-sales-qty {
    fill: none;
    stroke: var(--accent);
    stroke-width: 2;
}

.chart .chart-label {
    fill: var(--muted);
    font-size: 10px;
    text-anchor: middle;
}

.chart-empty {
    margin: 0;
    padding: 16px;
    color: var(--muted);
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    padding: 0 16px 16px;
    color: var(--muted);
    font-size: 12px;
    font-weight: 600;
}

.chart-legend span::before {
    content: "";
    display: inline-block;
    width: 10px;
    height: 10px;
    margin-right: 6px;
    border-radius: 2px;
    vertical-align: middle;
}

.chart-legend .legend-sales::before {
    background: var(--accent);
}

.chart-legend .legend-cost::before {
    background: var(--danger);
}

.chart-legend .legend-net::before {
    background: #17202b;
}

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

.matrix-table th.matrix-head,
.matrix-table td.matrix-head {
    position: sticky;
    left: 0;
    z-index: 1;
    background: #f8fafc;
    min-width: 180px;
    white-space: normal;
}

.matrix-table thead th.matrix-head {
    z-index: 2;
}

.matrix-table tr.matrix-asin-row th.matrix-head {
    background: #eef2f7;
    color: var(--text);
    font-size: 13px;
    font-weight: 700;
    text-align: left;
}

.matrix-table tr.matrix-detail-row td.matrix-head {
    padding-left: 28px;
    color: var(--muted);
    font-weight: 400;
    font-size: 12px;
}

.matrix-table tr.matrix-detail-row td {
    color: var(--muted);
    font-size: 12px;
}

.matrix-table tr.matrix-profit-row td.matrix-head,
.matrix-table tr.matrix-profit-row td {
    font-weight: 700;
    border-top: 2px solid var(--line);
}

.matrix-table thead th:not(.matrix-head),
.matrix-table td:not(.matrix-head) {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.login-page {
    display: grid;
    min-height: 100vh;
    place-items: center;
}

.login-panel {
    width: min(420px, calc(100% - 32px));
    padding: 24px;
}

.login-panel h1 {
    margin: 0 0 18px;
    font-size: 24px;
}

.login-panel form {
    display: grid;
    gap: 14px;
}

.alert {
    margin: 0 0 12px;
    padding: 10px 12px;
    border-radius: 6px;
    background: #fee4e2;
    color: var(--danger);
}

@media (max-width: 960px) {
    .filters,
    .detail-filters,
    .metrics,
    .grid.two {
        grid-template-columns: 1fr;
    }

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

    .sync-form {
        grid-template-columns: 1fr;
        width: 100%;
    }

    .toolbar button,
    .sync-form button {
        width: 100%;
    }

    .app-header {
        align-items: flex-start;
        flex-direction: column;
    }
}
