* { box-sizing: border-box; }

:root {
    --bg: #070b14;
    --bg-soft: #0f1728;
    --card: rgba(16, 24, 40, 0.72);
    --card-solid: #121a2b;
    --text: #e6edf8;
    --muted: #91a0ba;
    --border: #22314d;
    --primary: #5b7cff;
    --primary-2: #18c7ff;
    --success: #26d0a8;
    --danger: #ff6b7d;
    --shadow: 0 8px 20px rgba(0, 0, 0, 0.2);
}

html, body {
    min-height: 100%;
}

html {
    background: #070b14;
}

body {
    margin: 0;
    color: var(--text);
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background-color: #070b14;
    background: linear-gradient(180deg, #070b14 0%, #0a1020 100%);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    text-rendering: optimizeSpeed;
    touch-action: manipulation;
}

.container {
    max-width: 980px;
    margin: 0 auto;
    padding: 14px 14px 94px;
}

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

.topbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 14px;
    margin-bottom: 14px;
}

.eyebrow {
    margin: 0 0 6px;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    font-weight: 700;
    text-transform: uppercase;
    color: #82a2ff;
}

.brand h1 {
    margin: 0;
    font-size: 1.35rem;
    letter-spacing: -0.01em;
}

.brand p {
    margin: 4px 0 0;
    color: var(--muted);
    font-size: 0.9rem;
}

.desktop-nav { display: flex; gap: 8px; }

.logout-form {
    margin: 0;
}

.desktop-nav a {
    text-decoration: none;
    color: #cfd9ee;
    border: 1px solid #2d3f64;
    border-radius: 12px;
    background: #111b31;
    padding: 8px 12px;
    font-size: 0.85rem;
    font-weight: 600;
}

.desktop-nav .danger-link {
    color: #ffd5db;
    border-color: #653547;
    background: #26161d;
}

.desktop-nav .danger-button {
    width: auto;
    margin: 0;
    padding: 8px 12px;
}

.alert {
    border-radius: 14px;
    padding: 12px 14px;
    margin-bottom: 12px;
    font-size: 0.92rem;
}
.alert p { margin: 0; }
.error { background: rgba(113, 21, 42, 0.4); border: 1px solid #7e2f47; color: #ffd5df; }
.success { background: rgba(16, 88, 72, 0.35); border: 1px solid #1c7f6a; color: #b8f5e5; }

.auth-card {
    max-width: 420px;
    margin: 10vh auto 0;
    padding: 18px;
}

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

section.card, article.card { padding: 16px; }
body.page-profile section.card + section.card {
    margin-top: 14px;
}
h2, h3 { margin-top: 0; letter-spacing: -0.01em; }
p { color: var(--muted); }

label {
    display: block;
    font-size: 0.9rem;
    color: #d2dcf1;
    margin-bottom: 10px;
}

input, select, button {
    width: 100%;
    padding: 12px 13px;
    margin-top: 6px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--card-solid);
    color: var(--text);
    font: inherit;
}

input:focus, select:focus {
    outline: none;
    border-color: #4f78ff;
    box-shadow: 0 0 0 4px rgba(79, 120, 255, 0.18);
}

button {
    border: 0;
    cursor: pointer;
    font-weight: 700;
    color: #eef3ff;
    background: linear-gradient(135deg, var(--primary), var(--primary-2));
    transition: transform 120ms ease, filter 120ms ease;
    will-change: transform;
}

button:active {
    transform: translateY(1px) scale(0.995);
}

.grid-form, .inline-form {
    display: grid;
    gap: 10px;
    grid-template-columns: 1fr;
}

.cancel-link {
    text-decoration: none;
    text-align: center;
    border: 1px solid #30466f;
    color: #c8d7f3;
    padding: 10px 12px;
    border-radius: 12px;
    background: #121d33;
    font-size: 0.9rem;
    font-weight: 600;
}

table { width: 100%; border-collapse: collapse; margin-top: 8px; }
.table-wrap {
    border: 1px solid #22324e;
    border-radius: 12px;
    overflow: auto;
    background: #0d1525;
}
th, td {
    text-align: left;
    padding: 10px 8px;
    border-bottom: 1px solid #23324f;
    font-size: 0.87rem;
    white-space: nowrap;
}
th { color: #b7c6df; font-weight: 600; }
tbody tr:hover { background: rgba(38, 57, 94, 0.35); }
tbody tr:last-child td { border-bottom: 0; }

.actions-cell {
    min-width: 96px;
    white-space: nowrap;
    display: flex;
    align-items: center;
    gap: 6px;
}

.inline-action-form {
    display: inline;
}

.edit-log-date {
    margin: -4px 0 12px;
    font-size: 0.88rem;
    color: #9fb4d8;
}

.edit-log-date strong {
    color: #d8e6ff;
    font-weight: 600;
}

#weight-register-card input[type="date"],
#weight-register-card input[type="number"] {
    width: 100%;
    max-width: 100%;
    display: block;
}

.action-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    text-decoration: none;
    border-radius: 9px;
    width: 30px;
    height: 30px;
    padding: 0;
    font-size: 0.9rem;
    font-weight: 700;
    border: 1px solid transparent;
}

.action-link.edit {
    background: #142844;
    border-color: #2b4a78;
    color: #cce0ff;
}

button.action-link.delete {
    width: 30px;
    height: 30px;
    margin: 0;
    background: #2b1721;
    border: 1px solid #643445;
    color: #ffd7df;
    padding: 0;
    font-size: 0.9rem;
}

.stats {
    margin-top: 12px;
    display: grid;
    gap: 10px;
    grid-template-columns: 1fr;
}

.stats div {
    border: 1px solid #253a5f;
    border-radius: 14px;
    padding: 12px;
    background: linear-gradient(180deg, #101a2f 0%, #0c1424 100%);
}

.stats span {
    display: block;
    color: #9db2d3;
    margin-bottom: 5px;
    font-size: 0.82rem;
}
.stats strong { font-size: 1.24rem; letter-spacing: -0.01em; }

.stats-extra {
    display: block;
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 6px;
    line-height: 1.35;
}

.stats.insight-stats {
    grid-template-columns: repeat(auto-fit, minmax(168px, 1fr));
}

.insight-trend .insight-arrow {
    margin-right: 4px;
}

.insight-trend-down .insight-arrow { color: #2dd4bf; }
.insight-trend-up .insight-arrow { color: #f87171; }
.insight-trend-flat .insight-arrow { color: var(--muted); }

.progress-wrap {
    margin-top: 14px;
    border: 1px solid #253a5f;
    border-radius: 14px;
    padding: 12px;
    background: linear-gradient(180deg, rgba(14, 26, 48, 0.95), rgba(10, 18, 34, 0.95));
}

.email-reminder-meta {
    margin: 0 0 10px;
    color: #9fb4d8;
    font-size: 0.85rem;
}

.email-reminder-meta strong {
    color: #cfe0ff;
}

.email-reminder-form {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.reminder-modern {
    padding: 12px;
    border: 1px solid #253a5f;
    border-radius: 14px;
    background: linear-gradient(180deg, rgba(14, 26, 48, 0.95), rgba(10, 18, 34, 0.95));
    overflow: hidden;
}

.reminder-switch-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 14px;
}

.reminder-label {
    margin: 0;
    color: #d8e6ff !important;
    font-weight: 700;
    font-size: 0.95rem;
}

.reminder-sub {
    margin: 2px 0 0;
    color: #9fb4d8 !important;
    font-size: 0.84rem;
}

.switch {
    position: relative;
    display: inline-flex;
    width: 52px;
    height: 30px;
    flex: 0 0 auto;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
    margin: 0;
}

.slider {
    position: absolute;
    inset: 0;
    cursor: pointer;
    border-radius: 999px;
    background: #1f2d48;
    border: 1px solid #30466f;
    transition: background 0.2s ease, border-color 0.2s ease;
}

.slider::before {
    content: "";
    position: absolute;
    left: 4px;
    top: 4px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #d6e4ff;
    transition: transform 0.2s ease;
}

.switch input:checked + .slider {
    background: linear-gradient(135deg, #4f78ff, #22d3ee);
    border-color: #4f78ff;
}

.switch input:checked + .slider::before {
    transform: translateX(22px);
    background: #ffffff;
}

.email-reminder-time-label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    color: #d2dcf1;
    font-size: 0.9rem;
    width: 100%;
    min-width: 0;
}

.email-reminder-time-label input[type="time"] {
    width: 100%;
    max-width: none;
    min-width: 0;
    padding: 8px 10px;
    border-radius: 10px;
    border: 1px solid #30466f;
    background: #0f1a2d;
    color: #e2e9ff;
    box-sizing: border-box;
}

.reminder-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.reminder-actions button {
    width: auto;
    min-width: 200px;
}

.reminder-status {
    font-size: 0.82rem;
    color: #9fb4d8;
}

.reminder-status.ok {
    color: #34d399;
}

.reminder-status.error {
    color: #fca5a5;
}

.btn-secondary {
    width: 100%;
    background: #1a2744;
    border: 1px solid #30466f;
    color: #e2e9ff;
}

.email-reminder-hint {
    display: block;
    margin-top: 10px;
    color: #7d8fab;
    font-size: 0.72rem;
    line-height: 1.4;
}

.email-reminder-hint code {
    font-size: 0.7rem;
    color: #a8c4ff;
}

.mini-stats {
    display: grid;
    gap: 8px;
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.mini-stats div {
    background: #0f1a2d;
    border: 1px solid #24395e;
    border-radius: 10px;
    padding: 10px;
}

.mini-stats span {
    display: block;
    font-size: 0.74rem;
    color: #91a7ca;
    margin-bottom: 4px;
}

.mini-stats strong {
    font-size: 0.95rem;
}

.progress-label {
    margin: 11px 0 6px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    color: #b4c5e3;
}

.progress-track {
    height: 11px;
    border-radius: 999px;
    background: #13233f;
    overflow: hidden;
    border: 1px solid #24395f;
}

.progress-fill {
    height: 100%;
    border-radius: inherit;
    background: linear-gradient(90deg, #5b7cff, #22d3ee);
    transition: width 220ms linear;
}

.mobile-tabbar {
    position: fixed;
    left: 10px;
    right: 10px;
    bottom: 8px;
    z-index: 40;
    padding: 8px;
    gap: 8px;
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    border-radius: 18px;
    border: 1px solid #273a60;
    background: rgba(11, 17, 31, 0.94);
    box-shadow: 0 6px 14px rgba(0, 0, 0, 0.28);
}

.mobile-tabbar.has-admin {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

.mobile-tabbar a {
    text-decoration: none;
    color: #9eb0d1;
    border-radius: 12px;
    padding: 10px 4px;
    text-align: center;
    font-size: 1.05rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 44px;
}

.mobile-logout-form {
    margin: 0;
}

.mobile-tabbar-button {
    width: 100%;
    min-height: 44px;
    margin: 0;
    padding: 10px 4px;
    border: 0;
    border-radius: 12px;
    background: transparent;
    color: #9eb0d1;
    font-size: 1.05rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.mobile-tabbar a.active {
    color: #ecf3ff;
    background: linear-gradient(135deg, #283f6b, #13395d);
}

.tab-icon {
    line-height: 1;
}

@media (max-width: 899px) {
    body {
        background: linear-gradient(180deg, #080f1c 0%, #0b1324 100%);
    }
    #weight-register-card {
        scroll-margin-bottom: calc(88px + env(safe-area-inset-bottom, 0px));
    }

    #weight-register-card .inline-form label {
        width: 100%;
    }

    #weight-register-card input[type="date"],
    #weight-register-card input[type="number"] {
        min-height: 48px;
    }

    #weight-register-card input[type="date"] {
        -webkit-appearance: none;
        appearance: none;
    }
}

@media (min-width: 900px) {
    .container { padding: 20px 18px 24px; }
    .mobile-tabbar { display: none; }
    .grid { grid-template-columns: minmax(0, 1.6fr) minmax(320px, 1fr); }
    .grid-form { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .grid-form button { grid-column: span 2; }
    .inline-form { grid-template-columns: 1fr auto; align-items: end; }
    .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .stats.insight-stats {
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    }
    .history-card { grid-column: 1 / -1; }
    .register-card .inline-form { grid-template-columns: 1fr; }
    .register-card button { width: 100%; }
}

@media (max-width: 899px) {
    .desktop-nav { display: none; }
}

@media (max-width: 640px) {
    th, td {
        padding: 8px 6px;
        font-size: 0.82rem;
    }
    .actions-cell {
        min-width: 78px;
    }
    .reminder-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .reminder-actions button {
        width: 100%;
        min-width: 0;
    }
    .email-reminder-time-label input[type="time"] {
        width: 100%;
        max-width: none;
    }
    .reminder-status {
        display: block;
        text-align: left;
    }
    .admin-actions {
        flex-direction: column;
        align-items: stretch;
        gap: 8px;
    }
    .admin-actions button {
        width: 100%;
        min-width: 0;
    }
    .admin-status {
        display: block;
        text-align: left;
    }
}

@media (display-mode: standalone) {
    .container { padding-top: calc(env(safe-area-inset-top, 0px) + 12px); }
    .mobile-tabbar { bottom: calc(env(safe-area-inset-bottom, 0px) + 8px); }
}

body.standalone .container {
    padding-top: calc(env(safe-area-inset-top, 0px) + 12px);
}

/* —— Tipografia e layout —— */
.page-title {
    font-size: 1.28rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin: 0 0 12px;
}

.admin-card p {
    margin-bottom: 0;
}

.admin-stack {
    display: grid;
    gap: 14px;
}

.admin-actions {
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.admin-actions button {
    width: auto;
    min-width: 220px;
}

.admin-status {
    font-size: 0.82rem;
    color: var(--muted);
}

.admin-status.ok {
    color: #34d399;
}

.admin-status.error {
    color: #fca5a5;
}

.topbar {
    flex-wrap: wrap;
    gap: 10px;
}

.topbar-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    justify-content: flex-end;
}

button.theme-toggle {
    width: auto;
    margin: 0;
    padding: 8px 12px;
    font-size: 0.85rem;
    font-weight: 600;
    line-height: 1.2;
    border-radius: 12px;
    border: 1px solid #2d3f64;
    background: #111b31;
    color: #cfd9ee;
    cursor: pointer;
    flex-shrink: 0;
    transition: border-color 0.15s ease, filter 0.15s ease;
}

button.theme-toggle:hover,
button.theme-toggle:focus-visible {
    border-color: #4f78ff;
    outline: none;
    filter: brightness(1.05);
}

/* Dashboard — espaço entre blocos dentro do mesmo cartão */
.dashboard-hero {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.dashboard-hero > .page-title {
    margin-bottom: 0;
}

.dashboard-hero .chart-card,
.dashboard-hero .progress-wrap {
    margin: 0;
}

/* Gráfico */
.chart-card {
    margin: 0 0 14px;
    padding: 10px 4px 4px;
    border-radius: 14px;
    border: 1px solid var(--border);
    background: rgba(10, 18, 34, 0.5);
}

.chart-title {
    margin: 0 0 6px 8px;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.chart-inner {
    width: 100%;
    overflow: hidden;
}

.weight-chart {
    display: block;
    width: 100%;
    height: auto;
    max-height: 150px;
}

.weight-point {
    fill: #18c7ff;
    stroke: #0b1220;
    stroke-width: 1.5;
    opacity: 0.7;
    transition: r 120ms ease, opacity 120ms ease;
}

.weight-point:hover {
    r: 5.5;
    opacity: 1;
}

/* Estados vazios */
.empty-state {
    text-align: center;
    padding: 18px 12px;
    border-radius: 14px;
    border: 1px dashed var(--border);
    background: rgba(12, 20, 36, 0.45);
    margin: 10px 0;
}

.empty-state-soft {
    border-style: solid;
    background: rgba(15, 26, 45, 0.35);
}

.empty-state-inline {
    margin: 0;
}

.empty-state p {
    margin: 6px 0 0;
    max-width: 28rem;
    margin-left: auto;
    margin-right: auto;
}

.empty-icon {
    font-size: 1.75rem;
    display: block;
    margin-bottom: 6px;
}

.btn-link {
    display: inline-block;
    margin-top: 10px;
    padding: 8px 14px;
    border-radius: 10px;
    background: linear-gradient(135deg, #3d5a9e, #1e3a6b);
    color: #eef3ff !important;
    text-decoration: none;
    font-weight: 600;
    font-size: 0.88rem;
}

.btn-link:hover {
    filter: brightness(1.06);
}

.history-card h3 {
    margin-top: 0;
}

/* Tema claro */
html[data-theme="light"] {
    color-scheme: light;
    --bg: #f1f4fb;
    --bg-soft: #e8edf7;
    --card: rgba(255, 255, 255, 0.92);
    --card-solid: #ffffff;
    --text: #152032;
    --muted: #5a6b85;
    --border: #c9d4ea;
    --shadow: 0 14px 40px rgba(20, 40, 80, 0.12);
}

html[data-theme="light"] {
    background: #eef2fb;
}

html[data-theme="light"] body {
    background-color: #eef2fb;
    background: linear-gradient(180deg, #eef2fb 0%, #e4eaf7 100%);
}

/* Prefer motion efficiency and low-end smoothness */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation: none !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

html[data-theme="light"] .card,
html[data-theme="light"] .topbar {
    box-shadow: var(--shadow);
}

html[data-theme="light"] .desktop-nav a {
    background: #fff;
    border-color: var(--border);
    color: #1a2744;
}

html[data-theme="light"] .mobile-tabbar-button {
    color: #64748b;
}

html[data-theme="light"] .theme-toggle {
    background: #fff;
}

html[data-theme="light"] .mobile-tabbar {
    background: rgba(255, 255, 255, 0.96);
    border-color: #c5d2eb;
}

html[data-theme="light"] .mobile-tabbar a {
    color: #64748b;
}

html[data-theme="light"] .mobile-tabbar a.active {
    color: #1e293b;
    background: linear-gradient(135deg, #e2e8f0, #f1f5f9);
}

html[data-theme="light"] button.theme-toggle {
    background: #fff;
    border-color: var(--border);
    color: #1a2744;
}

html[data-theme="light"] .stats div,
html[data-theme="light"] .stats.insight-stats div {
    background: linear-gradient(180deg, #ffffff 0%, #f1f5f9 100%);
    border-color: var(--border);
}

html[data-theme="light"] .stats span {
    color: var(--muted);
}

html[data-theme="light"] .chart-card {
    background: #fff;
    border-color: var(--border);
}

html[data-theme="light"] .weight-point {
    stroke: #ffffff;
}

html[data-theme="light"] .empty-state,
html[data-theme="light"] .empty-state-soft {
    background: rgba(255, 255, 255, 0.85);
    border-color: var(--border);
}

html[data-theme="light"] .progress-wrap {
    background: linear-gradient(180deg, #ffffff, #f8fafc);
    border-color: var(--border);
}

html[data-theme="light"] .progress-label {
    color: var(--muted);
}

html[data-theme="light"] .mini-stats div {
    background: #f8fafc;
    border-color: var(--border);
}

html[data-theme="light"] .mini-stats span {
    color: var(--muted);
}

html[data-theme="light"] .table-wrap {
    background: #fff;
    border-color: var(--border);
}

html[data-theme="light"] th {
    color: var(--muted);
}

html[data-theme="light"] td {
    border-bottom-color: #e2e8f0;
}

html[data-theme="light"] tbody tr:hover {
    background: rgba(15, 23, 42, 0.04);
}

html[data-theme="light"] label,
html[data-theme="light"] .reminder-label,
html[data-theme="light"] .reminder-sub,
html[data-theme="light"] .email-reminder-time-label {
    color: #334155;
}

html[data-theme="light"] .email-reminder-time-label input[type="time"] {
    background: #fff;
    border-color: var(--border);
    color: var(--text);
}

html[data-theme="light"] .reminder-modern {
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
    border-color: var(--border);
}

html[data-theme="light"] .slider {
    background: #dbeafe;
    border-color: #bfdbfe;
}

html[data-theme="light"] .cancel-link {
    background: #f1f5f9;
    border-color: var(--border);
    color: #334155;
}

html[data-theme="light"] .action-link.edit {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #1d4ed8;
}

html[data-theme="light"] button.action-link.delete {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #b91c1c;
}

html[data-theme="light"] .eyebrow {
    color: #4f46e5;
}

html[data-theme="light"] .error {
    background: rgba(254, 226, 226, 0.85);
    border-color: #f87171;
    color: #991b1b;
}

html[data-theme="light"] .success {
    background: rgba(209, 250, 229, 0.85);
    border-color: #34d399;
    color: #065f46;
}
