:root {
    --bg: #f4f6f8;
    --card: #ffffff;
    --border: #d9e0e7;
    --head: #1f4e79;
    --head-text: #ffffff;
    --text: #1f2933;
    --muted: #6b7785;
    --link: #0b57d0;
    --stripe: #f9fbfd;
    --summary: #eef5fb;
    --goal: #fef6e7;
    --warn-bg: #fff5f5;
    --warn-border: #d64545;
    --warn-text: #9b1c1c;
    --success-bg: #dff3e3;
    --success-text: #1c6b2a;
    --error-bg: #fde7e9;
    --error-text: #a12b2b;
    --warning-bg: #fff8e6;
    --warning-text: #8a6d00;

    --bg-1: #0f172a;
    --bg-2: #1e293b;
    --login-card: rgba(15, 23, 42, 0.82);
    --login-border: rgba(255, 255, 255, 0.12);
    --login-text: #f8fafc;
    --login-muted: #cbd5e1;
    --input-bg: rgba(255, 255, 255, 0.08);
    --input-border: rgba(255, 255, 255, 0.16);
    --accent: #3b82f6;
    --accent-hover: #2563eb;
    --shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
    --code-bg: #0f1720;
    --code-text: #d7e0ea;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
}

body {
    padding: 24px;
    font-family: Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

a {
    color: var(--link);
    text-decoration: none;
    font-weight: 600;
}

a:hover {
    text-decoration: underline;
}

.container {
    max-width: 1900px;
    margin: 0 auto;
}

.page {
    max-width: 1450px;
    margin: 0 auto;
    padding: 24px;
}

.card,
.header-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 20px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.04);
    margin-bottom: 20px;
}

.header-card h1 {
    margin: 0 0 6px 0;
    font-size: 2rem;
}

h1,
h2,
h3 {
    margin-top: 0;
}

.section-title {
    margin: 0 0 14px 0;
    font-size: 1.2rem;
}

.subtitle,
.muted,
.empty {
    color: var(--muted);
}

.subtitle {
    margin-bottom: 18px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.nav-links,
.day-nav,
.week-nav,
.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

.nav-links a.active {
    color: #1f4e79;
    text-decoration: underline;
}

.button-link {
    display: inline-block;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 9px 12px;
    background: #fff;
    color: var(--link);
    font-weight: 600;
}

.button-link:hover {
    text-decoration: none;
    background: #f8fafc;
}

.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 16px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.toolbar form {
    display: flex;
    gap: 10px;
    align-items: end;
    flex-wrap: wrap;
}

.toolbar-form {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 12px;
    align-items: end;
}

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

.grid,
.small-grid,
.metrics-grid,
.metric-list,
.stats-grid,
.compare-grid {
    display: grid;
    gap: 14px;
}

.grid,
.small-grid {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.metrics-grid,
.metric-list {
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 10px 14px;
}

.stats-grid {
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    margin-bottom: 10px;
}

.compare-grid {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

.two-col {
    display: grid;
    grid-template-columns: minmax(0, 1.15fr) minmax(0, 0.85fr);
    gap: 20px;
}

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

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

label {
    font-size: 13px;
    color: var(--muted);
    font-weight: 600;
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="email"],
select,
textarea,
button {
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 14px;
    background: #fff;
    font-family: inherit;
}

input,
select {
    width: 100%;
}

textarea {
    min-height: 90px;
    resize: vertical;
}

button {
    cursor: pointer;
    font-weight: 700;
    color: #fff;
    background: #1f4e79;
    border: 0;
}

button:hover {
    background: #163b5c;
}

.button-primary {
    background: #0b57d0;
    border: 1px solid #0b57d0;
}

.inline-check {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
}

.inline-check input[type="checkbox"] {
    width: auto;
    margin: 0;
}

.check-group {
    display: flex;
    flex-wrap: wrap;
    gap: 16px;
    align-items: center;
}

.table-wrap {
    max-height: 800px;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

.month-view .table-wrap {
    max-height: none;
    overflow-x: auto;
    overflow-y: visible;
}

table,
.goal-category-table {
    width: 100%;
    border-collapse: collapse;
}

th,
td,
.goal-category-table th,
.goal-category-table td {
    border: 1px solid var(--border);
    padding: 10px 12px;
    vertical-align: middle;
    white-space: nowrap;
}

th:first-child,
td:first-child {
    text-align: left;
    font-weight: 600;
}

thead th {
    position: sticky;
    top: 0;
    z-index: 20;
    background: var(--head);
    color: var(--head-text);
    font-size: 14px;
}

thead th a {
    color: var(--head-text);
    text-decoration: none;
    font-weight: 700;
}

thead th a:hover {
    color: #dbeafe;
    text-decoration: underline;
}

thead th a:visited {
    color: var(--head-text);
}

thead th:first-child {
    left: 0;
    z-index: 30;
}

tbody td:first-child {
    position: sticky;
    left: 0;
    background: #fff;
    z-index: 10;
}

table tbody tr:nth-child(even) td:first-child {
    background: var(--stripe);
}

table tbody tr.summary-row td:first-child {
    background: var(--summary) !important;
}

table tbody tr.goal-row td:first-child {
    background: var(--goal) !important;
}

tbody tr:nth-child(even) td {
    background: var(--stripe);
}

.summary-row td {
    background: var(--summary) !important;
    font-weight: 700;
}

.goal-row td {
    background: var(--goal) !important;
    font-weight: 700;
}

.highlight-row {
    background: var(--summary) !important;
    font-weight: 600;
}

.section-gap td {
    border-bottom: none;
    padding: 8px 0;
    background: transparent !important;
}

.num {
    text-align: right !important;
}

.day-link {
    color: inherit;
    display: block;
}

.day-head {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.day-date,
.activity-type,
.small,
.goal-sub,
small.help {
    font-size: 12px;
    color: var(--muted);
}

.activity-name {
    font-weight: 600;
}

.badge,
.goal-pill,
.sport-badge,
.category-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 9px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    white-space: nowrap;
}

.badge-new {
    background: var(--error-bg);
    color: var(--error-text);
}

.badge-assigned,
.goal-good,
.badge-active {
    background: #d1e7dd;
    color: #1c6b2a;
}

.badge-ignored,
.goal-mid {
    background: #fff3cd;
    color: #8a6d00;
}

.goal-low,
.badge-inactive {
    background: #f8d7da;
    color: #842029;
}

.goal-positive {
    color: #1c6b2a;
    font-weight: 700;
}

.goal-negative {
    color: #9b1c1c;
    font-weight: 700;
}

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

.warn-box,
.warning {
    background: var(--warning-bg);
    color: var(--warning-text);
    border-radius: 12px;
    padding: 12px 14px;
    margin-bottom: 18px;
    font-weight: 600;
}

.warn-box {
    border: 2px solid var(--warn-border);
    background: var(--warn-bg);
    color: var(--warn-text);
    font-weight: 700;
}

.message,
.msg {
    background: var(--success-bg);
    color: var(--success-text);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 16px;
    font-weight: 600;
}

.error,
.err,
.error-box {
    background: var(--error-bg);
    color: var(--error-text);
    border-radius: 10px;
    padding: 12px 14px;
    margin-bottom: 16px;
    font-weight: 600;
}

.stat {
    background: #f8fafc;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px;
}

.stat .label,
.stat-label {
    color: var(--muted);
    font-size: 13px;
    margin-bottom: 8px;
    font-weight: 600;
}

.stat .value,
.stat-value,
.compare-value {
    font-size: 24px;
    font-weight: 700;
}

.metric {
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    background: #fff;
}

.metric strong {
    display: block;
    margin-bottom: 6px;
    color: var(--muted);
    font-size: 0.92rem;
}

.category-label {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
}

.category-dot,
.color-dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 999px;
    flex: 0 0 12px;
    margin-right: 8px;
    vertical-align: middle;
}

.goal-category-table th {
    background: var(--head);
    color: var(--head-text);
}

.goal-category-table tbody tr:nth-child(even) {
    background: #f9fbfd;
}

.actions,
.save-row {
    margin-top: 20px;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}

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

.inline-actions {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.mapping-grid,
.rule-grid,
.category-grid,
.chart-grid,
.charts-grid {
    display: grid;
    gap: 18px;
}

.mapping-grid,
.rule-grid,
.category-grid {
    grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
}

.chart-grid {
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.charts-grid {
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
}

.mapping-card,
.rule-card,
.category-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 18px;
}

.mapping-card.new {
    border: 2px solid #d64545;
}

.mapping-card.ignored,
.category-card.inactive {
    border: 2px solid #999999;
}

.section-card {
    border-top: 6px solid #1f4e79;
}

.head-row,
.mapping-head,
.category-head {
    display: flex;
    justify-content: space-between;
    align-items: start;
    gap: 14px;
    margin-bottom: 14px;
}

.mapping-key,
.rule-key,
.mapping-title,
.category-title {
    font-size: 20px;
    font-weight: 700;
}

.mapping-meta,
.rule-meta,
.category-meta,
.stats {
    color: var(--muted);
    font-size: 13px;
}

.status-new-text {
    color: #d64545;
    font-weight: 700;
}

.chart-section {
    margin-bottom: 32px;
}

.chart-box,
.chart-card {
    position: relative;
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
}

.chart-card {
    height: 320px;
}

.chart-box {
    height: 360px;
}

.chart-box canvas {
    width: 100% !important;
    height: calc(100% - 28px) !important;
}

.chart-title {
    margin: 0 0 8px;
    font-size: 16px;
    font-weight: 700;
    color: var(--text);
}

.chart-card canvas {
    width: 100% !important;
    height: calc(100% - 30px) !important;
}

.compare-box,
.compare-card {
    background: #f9fbfd;
    border: 1px solid #d9e0e7;
    border-radius: 12px;
    padding: 16px;
    min-height: 100%;
}

.compare-box h3,
.compare-card h3 {
    margin: 0 0 10px 0;
    font-size: 1rem;
    color: #1f4e79;
}

.compare-value {
    font-size: 1.5rem;
    line-height: 1.2;
    margin-bottom: 6px;
}

.compare-label {
    font-size: 0.9rem;
    color: #6b7785;
    margin-bottom: 10px;
}

.compare-diff {
    display: inline-block;
    padding: 4px 8px;
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 700;
}

.compare-diff.positive {
    background: #dff3e3;
    color: #1c6b2a;
}

.compare-diff.negative {
    background: #fde7e9;
    color: #a12b2b;
}

.compare-diff.neutral {
    background: #eef5fb;
    color: #1f4e79;
}

#map {
    width: 100%;
    height: 460px;
    border-radius: 12px;
    border: 1px solid var(--border);
    overflow: hidden;
}

pre.json {
    margin: 0;
    padding: 16px;
    border-radius: 12px;
    background: var(--code-bg);
    color: var(--code-text);
    overflow: auto;
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 0.88rem;
    line-height: 1.45;
}

.toggle-summary {
    cursor: pointer;
    font-weight: 700;
}

.toggle-content {
    margin-top: 12px;
}

.mb-16 {
    margin-bottom: 16px;
}

.mb-18 {
    margin-bottom: 18px;
}

.mt-12 {
    margin-top: 12px;
}

tr.status-ok>td {
    background-color: #dff3e3 !important;
}

tr.status-error>td {
    background-color: #fde7e9 !important;
}

tr.status-warning>td {
    background-color: #fff5e6 !important;
}

.status-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    margin-left: 6px;
    border-radius: 50%;
    vertical-align: middle;
}

.status-dot.status-error {
    background-color: #d64545;
}

.status-dot.status-warning {
    background-color: #f0ad4e;
}

.status-dot.status-ok {
    background-color: #1c6b2a;
}

/* Login */
body.login-page {
    min-height: 100vh;
    padding: 0;
    background:
        radial-gradient(circle at top left, rgba(59, 130, 246, 0.28), transparent 38%),
        radial-gradient(circle at bottom right, rgba(37, 99, 235, 0.20), transparent 32%),
        linear-gradient(135deg, var(--bg-1), var(--bg-2));
    color: var(--login-text);
}

.login-wrapper {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.login-card {
    width: 100%;
    max-width: 430px;
    padding: 34px 30px 28px;
    border-radius: 22px;
    background: var(--login-card);
    border: 1px solid var(--login-border);
    box-shadow: var(--shadow);
    backdrop-filter: blur(10px);
}

.logo {
    width: 70px;
    height: 70px;
    margin: 0 auto 18px;
    border-radius: 20px;
    display: grid;
    place-items: center;
    font-size: 34px;
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.22), rgba(37, 99, 235, 0.44));
    border: 1px solid rgba(96, 165, 250, 0.32);
}

.login-card h1 {
    margin: 0 0 10px;
    text-align: center;
    font-size: 30px;
    color: var(--login-text);
}

.login-card .subtitle {
    margin: 0 0 22px;
    text-align: center;
    color: var(--login-muted);
    line-height: 1.5;
}

.form-group {
    margin-bottom: 16px;
}

.login-card label {
    display: block;
    margin-bottom: 8px;
    color: #e2e8f0;
    font-weight: 700;
}

.input-wrapper {
    position: relative;
}

.login-card input[type="text"],
.login-card input[type="password"] {
    width: 100%;
    padding: 12px 14px;
    border-radius: 12px;
    border: 1px solid var(--input-border);
    background: var(--input-bg);
    color: var(--login-text);
    font-size: 15px;
    outline: none;
}

.login-card input[type="text"]::placeholder,
.login-card input[type="password"]::placeholder {
    color: #94a3b8;
}

.login-card input[type="text"]:focus,
.login-card input[type="password"]:focus {
    border-color: rgba(96, 165, 250, 0.65);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.18);
}

.login-card .actions {
    margin-top: 20px;
    justify-content: stretch;
}

.login-card button {
    width: 100%;
    padding: 12px 16px;
    border: none;
    border-radius: 12px;
    background: linear-gradient(135deg, var(--accent), var(--accent-hover));
    color: #fff;
    font-size: 15px;
    font-weight: 700;
    box-shadow: 0 12px 24px rgba(37, 99, 235, 0.24);
    transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.login-card button:hover {
    transform: translateY(-1px);
    box-shadow: 0 14px 28px rgba(37, 99, 235, 0.32);
}

.login-card button:active {
    transform: translateY(0);
}

.footer-note {
    margin-top: 20px;
    text-align: center;
    font-size: 13px;
    color: #94a3b8;
}

/* Responsive */
@media (max-width: 1200px) {
    .charts-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }

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

    .chart-box {
        height: 320px;
    }

    .chart-card {
        height: 300px;
    }
}

@media (max-width: 1100px) {
    .two-col {
        grid-template-columns: 1fr;
    }

    .mapping-grid,
    .rule-grid,
    .category-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 900px) {
    body {
        padding: 12px;
    }

    .page {
        padding: 14px;
    }

    .card,
    .header-card {
        padding: 14px;
    }

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

    .stat-value,
    .compare-value {
        font-size: 20px;
    }

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

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

@media (max-width: 700px) {
    .topbar {
        flex-direction: column;
        align-items: stretch;
    }

    .nav-links,
    .day-nav,
    .week-nav,
    .header-actions,
    .actions,
    .save-row,
    .save-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }

    .nav-links a,
    .actions button,
    .save-row button,
    .save-actions button {
        display: block;
        width: 100%;
        text-align: center;
    }

    .button-link {
        text-align: center;
    }

    .header-card h1 {
        font-size: 1.5rem;
    }

    .stats-grid,
    .metrics-grid,
    .metric-list,
    .grid,
    .small-grid,
    .compare-grid {
        grid-template-columns: 1fr;
    }

    .stat .value,
    .stat-value,
    .compare-value {
        font-size: 20px;
    }

    .head-row,
    .mapping-head,
    .category-head {
        flex-direction: column;
        align-items: flex-start;
    }

    .mapping-key,
    .rule-key,
    .mapping-title,
    .category-title {
        font-size: 18px;
    }

    .table-wrap {
        max-height: 75vh;
        overflow: auto;
        -webkit-overflow-scrolling: touch;
    }

    table {
        font-size: 13px;
    }

    th,
    td {
        padding: 8px 10px;
        white-space: normal;
    }

    thead th {
        top: 0;
    }

    thead th:first-child {
        position: sticky;
        left: 0;
        z-index: 30;
        background: var(--head);
    }

    tbody td:first-child {
        position: sticky;
        left: 0;
        z-index: 10;
        background: #fff;
    }

    table tbody tr:nth-child(even) td:first-child {
        background: var(--stripe);
    }

    table tbody tr.summary-row td:first-child {
        background: var(--summary) !important;
    }

    table tbody tr.goal-row td:first-child {
        background: var(--goal) !important;
    }

    #map {
        height: 240px;
    }

    .chart-card {
        padding: 12px;
    }

    .chart-card canvas {
        max-height: 260px;
    }

    .chart-grid,
    .charts-grid {
        grid-template-columns: 1fr;
    }

    .month-view th,
    .month-view td {
        white-space: nowrap;
    }

    .stat {
        padding: 12px;
    }

    .stat .label,
    .stat-label {
        margin-bottom: 6px;
    }
}

@media (max-width: 520px) {
    body {
        padding: 8px;
    }

    .card,
    .header-card {
        padding: 12px;
        border-radius: 12px;
    }

    .section-title {
        font-size: 1.05rem;
    }

    .login-card {
        padding: 28px 22px 24px;
        border-radius: 18px;
    }

    .login-card h1 {
        font-size: 26px;
    }

    .login-card .subtitle {
        font-size: 14px;
    }
}