:root {
    --bg: #f5f7f8;
    --panel: #ffffff;
    --ink: #172026;
    --muted: #64717b;
    --line: #dfe5e8;
    --accent: #0f766e;
    --accent-dark: #0b5852;
    --warn: #b45309;
    --danger: #b91c1c;
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background: var(--bg);
    color: var(--ink);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    -webkit-text-size-adjust: 100%;
}

.topbar {
    align-items: center;
    background: #102027;
    color: #fff;
    display: flex;
    gap: 24px;
    justify-content: space-between;
    padding: 14px 24px;
    position: sticky;
    top: 0;
    z-index: 20;
}

.brand {
    color: #fff;
    font-size: 18px;
    font-weight: 700;
    text-decoration: none;
}

.topbar nav {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 14px;
    justify-content: flex-end;
}

.topbar nav a {
    color: #d9f5f1;
    min-height: 34px;
    padding: 6px 0;
    text-decoration: none;
}

.nav-install {
    background: #ecfdf5;
    border: 0;
    color: #115e59;
    min-height: 0;
    padding: 4px 9px;
    width: auto;
}

.shell {
    margin: 0 auto;
    max-width: 1180px;
    padding: clamp(14px, 2.4vw, 24px);
    width: 100%;
}

.metrics {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
    margin-bottom: 18px;
}

.analytics-hero {
    align-items: center;
    background: #102027;
    border-radius: 8px;
    color: #fff;
    display: flex;
    justify-content: space-between;
    gap: 18px;
    margin-bottom: 18px;
    padding: 22px;
}

.analytics-hero h1 {
    margin-bottom: 6px;
}

.analytics-hero p {
    color: #c9dddc;
    margin: 0;
}

.analytics-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    margin-bottom: 18px;
}

.analytics-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 16px;
}

.analytics-card.primary {
    background: #0f766e;
    color: #fff;
}

.purchase-hero {
    background: #263238;
}

.analytics-card span,
.analytics-card small {
    color: var(--muted);
    display: block;
}

.analytics-card.primary span,
.analytics-card.primary small {
    color: #d9f5f1;
}

.analytics-card strong {
    display: block;
    font-size: 25px;
    margin: 8px 0 4px;
}

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

.bar-list {
    display: grid;
    gap: 14px;
}

.bar-label {
    align-items: baseline;
    display: flex;
    gap: 10px;
    justify-content: space-between;
    margin-bottom: 6px;
}

.bar-label span {
    color: var(--muted);
    font-size: 13px;
    text-align: right;
}

.bar-track {
    background: #edf3f4;
    border-radius: 999px;
    height: 11px;
    overflow: hidden;
}

.bar-track div {
    background: linear-gradient(90deg, #0f766e, #38a3a5);
    height: 100%;
}

.rule-grid {
    display: grid;
    gap: 12px;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.rule-grid div {
    background: #f8fbfb;
    border: 1px solid var(--line);
    border-radius: 8px;
    padding: 12px;
}

.rule-grid strong,
.rule-grid span {
    display: block;
}

.rule-grid span {
    color: var(--muted);
    margin-top: 6px;
}

.action-buy {
    background: #dcfce7;
    color: #166534;
}

.action-watch {
    background: #fef3c7;
    color: #92400e;
}

.action-stop {
    background: #fee2e2;
    color: #991b1b;
}

.action-risk {
    background: #ffedd5;
    color: #9a3412;
}

.mini-metrics {
    display: grid;
    gap: 10px;
    grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
    margin-bottom: 14px;
}

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

.metrics div {
    padding: 16px;
}

.mini-metrics div {
    background: #f8fbfb;
    padding: 12px;
}

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

.mini-metrics strong {
    display: block;
    font-size: 18px;
}

.metrics span,
.mini-metrics span,
.muted {
    color: var(--muted);
}

.panel {
    margin-bottom: 18px;
    padding: clamp(14px, 2.2vw, 20px);
}

h1,
h2 {
    margin: 0 0 14px;
}

h1 {
    font-size: 24px;
}

h2 {
    font-size: 18px;
    margin-top: 18px;
}

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

.form,
.scan-form,
.inline-form {
    display: grid;
    gap: 14px;
}

.compact-form,
.scanner-form {
    border-bottom: 1px solid var(--line);
    padding-bottom: 14px;
}

.scanner-input {
    font-size: 24px;
    font-weight: 700;
    min-height: 54px;
}

.sync-status {
    align-items: center;
    background: #ecfdf5;
    border: 1px solid #99f6e4;
    border-radius: 6px;
    color: #115e59;
    display: grid;
    gap: 6px;
    padding: 10px 12px;
}

.sync-status strong {
    color: inherit;
}

.sync-status span {
    font-size: 14px;
}

.sync-status.offline {
    background: #fff7ed;
    border-color: #fed7aa;
    color: #9a3412;
}

.sync-status.pending {
    background: #fefce8;
    border-color: #fde68a;
    color: #854d0e;
}

.sync-status.error {
    background: #fef2f2;
    border-color: #fecaca;
    color: #991b1b;
}

.tiny-button {
    justify-self: start;
    min-height: 32px;
    padding: 5px 9px;
    width: auto;
}

.offline-shell {
    display: grid;
    min-height: 100vh;
    place-items: center;
}

.offline-panel {
    max-width: 420px;
    text-align: center;
}

.offline-panel img {
    border-radius: 18px;
    margin-bottom: 12px;
}

.inline-form {
    align-items: center;
    display: flex;
}

.inline-form input {
    width: min(320px, 100%);
}

.subtle-form {
    border-top: 1px solid var(--line);
    margin: 12px 0 16px;
    padding-top: 12px;
}

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

input,
select,
button,
.button {
    border: 1px solid var(--line);
    border-radius: 6px;
    font: inherit;
    min-height: 40px;
    padding: 9px 11px;
    width: 100%;
}

button:disabled,
input:disabled {
    cursor: not-allowed;
    opacity: .55;
}

input,
select {
    background: #fff;
    color: var(--ink);
}

button,
.button {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    cursor: pointer;
    font-weight: 700;
    text-align: center;
    text-decoration: none;
}

.title-row .button,
.analytics-hero .button,
.offline-panel .button,
.actions a {
    width: auto;
}

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

.secondary {
    background: #edf3f4;
    border-color: #cfd9dd;
    color: var(--ink);
}

.secondary:hover {
    background: #dfe9ec;
}

.check {
    align-items: center;
    display: flex;
    flex-direction: row;
    gap: 8px;
}

.check input {
    min-height: auto;
    width: auto;
}

.scan-layout {
    display: grid;
    gap: 18px;
    grid-template-columns: minmax(280px, 380px) 1fr;
}

.scan-form {
    align-self: start;
    position: sticky;
    top: 86px;
}

.table-wrap {
    border: 1px solid var(--line);
    border-radius: 8px;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

table {
    border-collapse: collapse;
    min-width: 720px;
    width: 100%;
}

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

th {
    background: #eef3f3;
    color: #34434a;
    font-size: 13px;
    position: sticky;
    top: 0;
    text-transform: uppercase;
    z-index: 1;
}

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

.actions a {
    color: var(--accent);
    font-weight: 700;
}

.pill {
    background: #e6f4f1;
    border-radius: 999px;
    color: var(--accent-dark);
    display: inline-block;
    font-size: 12px;
    font-weight: 700;
    padding: 4px 8px;
}

.flash {
    border-radius: 8px;
    font-weight: 700;
    margin-bottom: 16px;
    padding: 12px 14px;
}

.flash.ok {
    background: #e6f4f1;
    color: var(--accent-dark);
}

.flash.error {
    background: #fee2e2;
    color: var(--danger);
}

.flash.warn {
    background: #fff7ed;
    color: var(--warn);
}

.empty {
    color: var(--muted);
    text-align: center;
}

.done-row {
    background: #f1f8f6;
    color: #61706d;
}

.done-row td:last-child {
    color: var(--accent-dark);
    font-weight: 700;
}

.hidden-file {
    border-style: dashed;
}

@media (max-width: 980px) {
    .analytics-layout,
    .scan-layout {
        grid-template-columns: 1fr;
    }

    .scan-form {
        position: static;
    }
}

@media (max-width: 780px) {
    .topbar,
    .title-row,
    .inline-form {
        align-items: stretch;
        flex-direction: column;
    }

    .topbar {
        gap: 10px;
        padding: 12px 14px;
    }

    .brand {
        font-size: 17px;
    }

    .topbar nav {
        display: grid;
        gap: 8px;
        grid-template-columns: repeat(3, minmax(0, 1fr));
        justify-content: stretch;
        width: 100%;
    }

    .topbar nav a,
    .nav-install {
        background: rgba(255, 255, 255, .08);
        border-radius: 6px;
        color: #ecfdf5;
        min-height: 38px;
        padding: 9px 8px;
        text-align: center;
        width: 100%;
    }

    .analytics-hero,
    .bar-label {
        align-items: stretch;
        flex-direction: column;
    }

    .bar-label span {
        text-align: left;
    }

    .topbar nav {
        flex-wrap: wrap;
    }

    h1 {
        font-size: 22px;
    }

    .scanner-input {
        font-size: 22px;
        min-height: 58px;
    }

    input,
    select,
    button,
    .button {
        min-height: 46px;
    }
}

@media (max-width: 560px) {
    body {
        font-size: 14px;
    }

    .shell {
        padding: 12px;
    }

    .metrics,
    .mini-metrics,
    .analytics-grid,
    .rule-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .metrics div,
    .mini-metrics div,
    .analytics-card {
        padding: 12px;
    }

    .metrics strong,
    .analytics-card strong {
        font-size: 20px;
    }

    .mini-metrics strong {
        font-size: 16px;
    }

    .analytics-hero {
        padding: 16px;
    }

    .panel {
        margin-bottom: 12px;
    }

    .table-wrap {
        margin-left: -2px;
        margin-right: -2px;
    }

    th,
    td {
        padding: 9px 10px;
    }
}

@media (max-width: 420px) {
    .topbar nav {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

    .metrics,
    .mini-metrics,
    .analytics-grid,
    .rule-grid {
        grid-template-columns: 1fr;
    }

    .title-row .button,
    .analytics-hero .button {
        width: 100%;
    }
}
