:root {
    --bg: #f3f5f8;
    --surface: #ffffff;
    --text: #1c2430;
    --muted: #6b7785;
    --line: #e4e9ef;
    --accent: #3f6ad8;
    --accent-soft: #e8effc;
    --green: #1f8a5b;
    --green-soft: #e6f6ee;
    --teal: #0f7c86;
    --teal-soft: #e4f5f6;
    --amber: #b86b0b;
    --amber-soft: #fff4e5;
    --rose: #c23b4d;
    --rose-soft: #fdecef;
    --slate: #4a5564;
    --slate-soft: #eef1f5;
    --purple: #5b4db8;
    --purple-soft: #efecfb;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(28, 36, 48, 0.04), 0 8px 24px rgba(28, 36, 48, 0.05);
    --font: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: var(--font);
    color: var(--text);
    background: var(--bg);
}

body.widget {
    background: transparent;
    min-height: 100%;
}

body.page {
    background:
        radial-gradient(1200px 400px at 10% -10%, #dfe8fb 0%, transparent 55%),
        radial-gradient(900px 360px at 100% 0%, #dff3ef 0%, transparent 50%),
        var(--bg);
}

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

code {
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    font-size: 0.85em;
    background: var(--slate-soft);
    padding: 0.15em 0.4em;
    border-radius: 4px;
}

.widget-header {
    display: flex;
    flex-direction: column;
    gap: 0.85rem;
    padding: 0.9rem 1rem 0.85rem;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius) var(--radius) 0 0;
}

.widget-title-block h1 {
    margin: 0;
    font-size: 1.1rem;
    font-weight: 650;
    letter-spacing: -0.01em;
}

.widget-header .meta {
    margin: 0.25rem 0 0;
    color: var(--muted);
    font-size: 0.82rem;
}

.filters {
    display: flex;
    flex-direction: column;
    gap: 0.65rem;
}

.period-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
}

.period-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
    min-width: 72px;
    padding: 0.55rem 0.9rem;
    border-radius: 10px;
    font-size: 0.92rem;
    font-weight: 600;
    color: var(--text);
    background: var(--slate-soft);
    border: 1px solid var(--line);
    text-decoration: none;
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
}

.period-btn:hover {
    background: var(--accent-soft);
    color: var(--accent);
    text-decoration: none;
    border-color: #c5d4f5;
}

.period-btn.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.date-range-form {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-end;
    gap: 0.55rem;
}

.date-field {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    flex: 1 1 140px;
    min-width: 140px;
}

.date-field span {
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.date-field input[type="date"] {
    min-height: 44px;
    padding: 0.45rem 0.65rem;
    border: 1px solid var(--line);
    border-radius: 10px;
    font-size: 1rem;
    font-family: inherit;
    background: #fff;
    color: var(--text);
    width: 100%;
}

.apply-btn {
    background: var(--green);
    color: #fff;
    border-color: var(--green);
    flex: 0 0 auto;
}

.apply-btn:hover {
    background: #187a50;
    color: #fff;
    border-color: #187a50;
}

/* legacy class kept if referenced */
.period-link { display: none; }

.widget-body {
    background: var(--surface);
    border: 1px solid var(--line);
    border-top: 0;
    border-radius: 0 0 var(--radius) var(--radius);
    padding: 0.75rem 1rem 1rem;
}

.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
    gap: 0.65rem;
}

.stat {
    background: var(--slate-soft);
    border-radius: 8px;
    padding: 0.75rem 0.8rem;
    min-height: 78px;
}

.stat-value {
    font-size: 1.45rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1.1;
}

.stat-label {
    margin-top: 0.25rem;
    font-size: 0.78rem;
    color: var(--muted);
    font-weight: 600;
}

.stat-hint {
    margin-top: 0.15rem;
    font-size: 0.7rem;
    color: var(--muted);
}

.tone-blue { background: var(--accent-soft); }
.tone-blue .stat-value { color: var(--accent); }
.tone-green { background: var(--green-soft); }
.tone-green .stat-value { color: var(--green); }
.tone-teal { background: var(--teal-soft); }
.tone-teal .stat-value { color: var(--teal); }
.tone-amber { background: var(--amber-soft); }
.tone-amber .stat-value { color: var(--amber); }
.tone-rose { background: var(--rose-soft); }
.tone-rose .stat-value { color: var(--rose); }
.tone-slate { background: var(--slate-soft); }
.tone-slate .stat-value { color: var(--slate); }
.tone-purple { background: var(--purple-soft); }
.tone-purple .stat-value { color: var(--purple); }

.rule {
    margin: 0 0 0.75rem;
    font-size: 0.78rem;
    color: var(--muted);
}

.panel {
    margin-top: 0.9rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--line);
}

.panel h2 {
    margin: 0 0 0.6rem;
    font-size: 0.85rem;
}

.bar-list {
    list-style: none;
    margin: 0;
    padding: 0;
    display: grid;
    gap: 0.55rem;
}

.bar-meta {
    display: flex;
    justify-content: space-between;
    font-size: 0.78rem;
    margin-bottom: 0.2rem;
}

.bar-track {
    height: 6px;
    background: var(--line);
    border-radius: 999px;
    overflow: hidden;
}

.bar-track > span {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--accent), #6f8fe0);
    border-radius: inherit;
}

.page-wrap {
    max-width: 1100px;
    margin: 0 auto;
    padding: 2rem 1.25rem 3rem;
}

.page-header {
    margin-bottom: 1.25rem;
}

.eyebrow {
    margin: 0;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    font-size: 0.72rem;
    font-weight: 700;
    color: var(--accent);
}

.page-header h1 {
    margin: 0.35rem 0 0.4rem;
    font-size: clamp(1.6rem, 3vw, 2.1rem);
    letter-spacing: -0.02em;
}

.lede {
    margin: 0;
    color: var(--muted);
    max-width: 60ch;
    line-height: 1.5;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
    box-shadow: var(--shadow);
    padding: 1.1rem 1.2rem 1.25rem;
    margin-bottom: 1rem;
}

.card h2 {
    margin: 0 0 0.85rem;
    font-size: 1.05rem;
}

.section-head {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-bottom: 0.85rem;
}

.section-head h2 { margin: 0; }

.badge {
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.2rem 0.5rem;
    border-radius: 999px;
}

.url-list {
    display: grid;
    gap: 0.65rem;
}

.url-row {
    display: grid;
    grid-template-columns: minmax(160px, 220px) 1fr;
    gap: 0.75rem;
    align-items: start;
    padding: 0.65rem 0;
    border-top: 1px solid var(--line);
}

.url-row:first-child { border-top: 0; padding-top: 0; }

.url-row .muted {
    display: block;
    color: var(--muted);
    font-size: 0.78rem;
    margin-top: 0.15rem;
}

.copyable {
    display: inline-block;
    cursor: pointer;
    word-break: break-all;
    transition: background 0.15s ease, color 0.15s ease;
}

.copyable:hover {
    background: var(--accent-soft);
    color: var(--accent);
}

.copyable.copied {
    background: var(--green-soft);
    color: var(--green);
}

.table-wrap {
    overflow-x: auto;
}

.users-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.users-table th,
.users-table td {
    text-align: left;
    padding: 0.7rem 0.55rem;
    border-bottom: 1px solid var(--line);
    vertical-align: top;
}

.users-table th {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--muted);
}

.users-table.ranking td:nth-child(n+3) {
    font-variant-numeric: tabular-nums;
}

.pill {
    display: inline-block;
    background: var(--slate-soft);
    color: var(--slate);
    border-radius: 999px;
    padding: 0.15rem 0.5rem;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
}

.links {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    font-size: 0.82rem;
}

.muted { color: var(--muted); }
.small { font-size: 0.75rem; }

.help ol {
    margin: 0 0 0.75rem;
    padding-left: 1.2rem;
    line-height: 1.55;
}

.setup, .error {
    max-width: 560px;
    margin: 3rem auto;
}

/* Admin Dashboard */
body.admin-dash {
    background: var(--bg);
}

.admin-body {
    border-radius: 0 0 var(--radius) var(--radius);
}

.admin-body > .stat-grid {
    margin-bottom: 1rem;
}

.chart-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.chart-card {
    background: #f8fafc;
    border: 1px solid var(--line);
    border-radius: 10px;
    padding: 0.75rem 0.85rem 0.9rem;
}

.chart-card.wide {
    grid-column: 1 / -1;
}

.chart-card h2 {
    margin: 0 0 0.55rem;
    font-size: 0.82rem;
    font-weight: 650;
    color: var(--slate);
}

.chart-wrap {
    position: relative;
    height: 220px;
}

.chart-wrap-sm {
    height: 200px;
    max-width: 280px;
    margin: 0 auto;
}

.admin-table-panel {
    margin-top: 0.25rem;
}

.admin-table th,
.admin-table td {
    white-space: nowrap;
    font-size: 0.82rem;
}

.admin-table td:nth-child(n+3) {
    font-variant-numeric: tabular-nums;
}

@media (max-width: 720px) {
    .widget-header {
        flex-direction: column;
    }
    .url-row {
        grid-template-columns: 1fr;
    }
    .chart-grid {
        grid-template-columns: 1fr;
    }
    .chart-card.wide {
        grid-column: auto;
    }
    .period-btn {
        flex: 1 1 calc(33.33% - 0.45rem);
        min-width: 0;
    }
    .date-range-form .apply-btn {
        width: 100%;
        min-height: 48px;
    }
}

