:root {
    --bg: #f5f6f8;
    --surface: #ffffff;
    --text: #1a1d23;
    --text-muted: #6b7280;
    --border: #e7e9ec;
    --accent: #16a34a;
    --accent-soft: #dcfce7;
    --danger: #dc2626;
    --radius: 16px;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
}

@media (prefers-color-scheme: dark) {
    :root:not([data-theme="light"]) {
        --bg: #121317;
        --surface: #1c1f26;
        --text: #f1f2f4;
        --text-muted: #9aa0ab;
        --border: #2a2e37;
        --accent: #22c55e;
        --accent-soft: #14321f;
        --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
    }
}

:root[data-theme="dark"] {
    --bg: #121317;
    --surface: #1c1f26;
    --text: #f1f2f4;
    --text-muted: #9aa0ab;
    --border: #2a2e37;
    --accent: #22c55e;
    --accent-soft: #14321f;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

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

.app {
    max-width: 640px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    padding-bottom: 84px;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    position: sticky;
    top: 0;
    background: var(--bg);
    z-index: 10;
}

.topbar-brand {
    font-weight: 700;
    font-size: 18px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.brand-icon { font-size: 22px; }

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.icon-link {
    color: var(--text-muted);
    display: flex;
    padding: 6px;
    border-radius: 8px;
}

.content {
    flex: 1;
    padding: 4px 20px 24px;
}

.page-title {
    font-size: 26px;
    margin: 8px 0 2px;
}

.page-sub {
    color: var(--text-muted);
    margin: 0 0 20px;
    font-size: 14px;
}

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 18px;
    margin-bottom: 18px;
}

.card-title {
    font-size: 15px;
    font-weight: 700;
    margin: 0 0 12px;
    color: var(--text);
}

.card-title-row {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    margin-bottom: 12px;
}

.card-title-row .card-title { margin: 0; }

.link-small { font-size: 13px; font-weight: 600; }

.stat-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
    margin-bottom: 18px;
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    text-align: center;
}

.stat-icon { font-size: 24px; margin-bottom: 6px; }
.stat-value { font-size: 22px; font-weight: 800; line-height: 1.1; }
.stat-value-sm { font-size: 15px; font-weight: 700; }
.stat-label { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

.mini-chart {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    height: 110px;
}

.mini-bar-col {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-end;
    height: 100%;
    gap: 6px;
    font-size: 11px;
    color: var(--text-muted);
}

.mini-bar {
    width: 100%;
    max-width: 28px;
    min-height: 4px;
    background: var(--accent);
    border-radius: 6px 6px 2px 2px;
}

.exercise-list { display: flex; flex-direction: column; gap: 10px; }

.exercise-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 12px;
    border-radius: 12px;
    background: var(--bg);
    border: 1px solid var(--border);
}

a.exercise-row { color: var(--text); }

.exercise-icon {
    font-size: 22px;
    width: 38px;
    height: 38px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent-soft);
    border-radius: 10px;
    flex-shrink: 0;
}

.exercise-info { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.exercise-name { font-weight: 600; font-size: 14px; }
.exercise-meta { font-size: 12px; color: var(--text-muted); }
.exercise-arrow { font-size: 20px; color: var(--accent); font-weight: 700; }

.icon-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 16px;
    cursor: pointer;
    padding: 6px 8px;
    border-radius: 8px;
}

.icon-btn:hover { background: var(--border); color: var(--danger); }

.empty-hint, .empty-hint-sm {
    color: var(--text-muted);
    font-size: 14px;
}

.fab {
    position: fixed;
    right: 20px;
    bottom: 96px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 400;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
    max-width: 600px;
    margin: 0 auto;
}

.bottomnav {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--surface);
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: space-around;
    padding: 8px 4px calc(8px + env(safe-area-inset-bottom));
    max-width: 640px;
    margin: 0 auto;
}

.bottomnav a {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    color: var(--text-muted);
    font-size: 11px;
    padding: 4px 8px;
    border-radius: 10px;
    flex: 1;
}

.bottomnav a.active { color: var(--accent); }

.bottomnav a.navplus svg {
    background: var(--accent);
    color: #fff;
    border-radius: 50%;
    padding: 3px;
    box-sizing: content-box;
}

.bottomnav a.navplus.active svg { background: var(--accent); }

/* Forms */
label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-size: 13px;
    color: var(--text-muted);
    font-weight: 600;
}

input, select, button, textarea {
    font-family: inherit;
    font-size: 14px;
}

input[type="text"], input[type="number"], input[type="password"], input[type="date"], select, textarea {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 12px;
    color: var(--text);
}

input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 1px; }

button {
    cursor: pointer;
    border: none;
    border-radius: 10px;
    padding: 10px 16px;
    font-weight: 700;
    background: var(--accent);
    color: #fff;
}

button:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary { width: 100%; padding: 12px; font-size: 15px; }

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

.inline-form select, .inline-form input { flex: 1; min-width: 90px; }
.inline-form-wrap { gap: 10px; }
.icon-select { max-width: 70px; flex: 0 0 70px; }

.add-details { margin-top: 12px; }
.add-details summary {
    cursor: pointer;
    color: var(--accent);
    font-weight: 700;
    font-size: 13px;
    list-style: none;
}
.add-details summary::-webkit-details-marker { display: none; }
.add-details form { margin-top: 10px; }

.date-form { margin-bottom: 16px; }
.date-form input { width: 100%; }

.date-shortcuts {
    display: flex;
    gap: 8px;
    margin-top: 8px;
}

.date-shortcuts a {
    flex: 1;
    text-align: center;
    padding: 8px 0;
    border-radius: 10px;
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
}

.date-shortcuts a.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.template-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(84px, 1fr));
    gap: 10px;
    margin-bottom: 16px;
}

.template-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    background: var(--bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 12px 6px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
}

.template-btn.is-planned { border-color: var(--accent); }
.template-btn.is-active { background: var(--accent); color: #fff; }
.template-icon { font-size: 24px; }

.log-form { border-top: 1px solid var(--border); padding-top: 16px; }
.log-form-selected { font-size: 13px; font-weight: 600; margin-bottom: 12px; color: var(--accent); }
.log-form-row { display: flex; gap: 12px; margin-bottom: 16px; }
.log-form-row label { flex: 1; }
.log-form-row input { width: 100%; }

.period-switch {
    display: flex;
    gap: 6px;
    margin-bottom: 18px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 4px;
}

.period-switch a {
    flex: 1;
    text-align: center;
    padding: 8px 0;
    border-radius: 9px;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
}

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

.error {
    background: #fee2e2;
    color: var(--danger);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 13px;
    margin-bottom: 14px;
}

.success {
    background: var(--accent-soft);
    color: var(--accent);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 13px;
    margin-bottom: 14px;
}

.stack-form {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

/* Auth pages */
.authpage {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
}

.auth-box {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 20px;
    box-shadow: var(--shadow);
    padding: 32px 28px;
    width: 100%;
    max-width: 360px;
    text-align: center;
}

.auth-icon {
    font-size: 40px;
    margin-bottom: 8px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
}
.auth-box h1 { margin: 0 0 4px; font-size: 22px; }
.auth-sub { color: var(--text-muted); font-size: 13px; margin: 0 0 20px; }
.auth-box form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.auth-box button { margin-top: 4px; padding: 12px; font-size: 15px; }
