:root {
    --bg: #f6f8fb;
    --bg-soft: #eef2f7;
    --surface: #ffffff;
    --surface-muted: #f8fafc;
    --border: #e5e7eb;
    --border-strong: #d1d5db;
    --text: #0f172a;
    --text-secondary: #334155;
    --text-muted: #64748b;
    --headline: #1e293b;
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #3b82f6;
    --accent-pink: #ec4899;
    --accent-green: #10b981;
    --success: #059669;
    --success-bg: #ecfdf5;
    --error: #dc2626;
    --error-bg: #fef2f2;
    --warning: #ea580c;
    --warning-bg: #fff7ed;
    --radius: 20px;
    --radius-sm: 12px;
    --radius-lg: 24px;
    --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
    --shadow-sm: 0 4px 14px rgba(15, 23, 42, 0.06);
    --shadow-hover: 0 16px 40px rgba(15, 23, 42, 0.1);
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    --gradient-btn: linear-gradient(135deg, #3b82f6 0%, #6366f1 50%, #8b5cf6 100%);
    --gradient-soft: linear-gradient(135deg, rgba(59, 130, 246, 0.08) 0%, rgba(236, 72, 153, 0.06) 100%);
    --touch-min: 44px;
}

*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    min-height: 100vh;
    font-family: var(--font);
    font-size: 16px;
    line-height: 1.55;
    color: var(--text-secondary);
    background: var(--bg);
    background-image:
        radial-gradient(ellipse 90% 60% at 50% -10%, rgba(59, 130, 246, 0.07), transparent 55%),
        radial-gradient(ellipse 70% 50% at 100% 0%, rgba(236, 72, 153, 0.05), transparent 50%),
        radial-gradient(ellipse 60% 40% at 0% 100%, rgba(16, 185, 129, 0.04), transparent 45%);
}

.container {
    width: 100%;
    max-width: 980px;
    margin: 0 auto;
    padding: 0 1.125rem;
}

/* —— Header —— */
.site-header {
    border-bottom: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.82);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    position: sticky;
    top: 0;
    z-index: 20;
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 60px;
    gap: 1rem;
}

.logo {
    font-weight: 700;
    font-size: 1.125rem;
    letter-spacing: -0.02em;
    color: var(--headline);
    text-decoration: none;
    background: linear-gradient(135deg, #1e40af, #7c3aed);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.main-content {
    padding: 1.75rem 0 3.5rem;
}

.site-footer {
    padding: 1.75rem 0 2rem;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.site-footer small {
    opacity: 0.85;
}

/* —— Typography —— */
.page-title {
    margin: 0 0 0.35rem;
    font-size: clamp(1.75rem, 5vw, 2.125rem);
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--headline);
    line-height: 1.2;
}

.page-subtitle {
    margin: 0 0 2rem;
    color: var(--text-muted);
    font-size: 1rem;
}

.section {
    margin-bottom: 2.25rem;
}

.section-title {
    margin: 0 0 1.125rem;
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

/* —— Grid —— */
.grid {
    display: grid;
    gap: 1.125rem;
}

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

@media (min-width: 640px) {
    .grid-2 {
        grid-template-columns: repeat(2, 1fr);
        gap: 1.25rem;
    }
}

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

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

@media (min-width: 640px) {
    .grid-3 {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (min-width: 960px) {
    .grid-3 {
        grid-template-columns: repeat(3, 1fr);
    }
}

/* —— Cards —— */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.375rem 1.5rem;
    box-shadow: var(--shadow);
    transition: box-shadow 0.2s ease, transform 0.2s ease;
}

@media (hover: hover) {
    .card:hover {
        box-shadow: var(--shadow-hover);
    }
}

.card h3 {
    margin: 0 0 1.125rem;
    font-size: 1.125rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--headline);
}

.date-cell {
    color: var(--text-muted);
    font-size: 0.875rem;
    font-variant-numeric: tabular-nums;
}

.entry-card--start {
    background: linear-gradient(135deg, rgba(16, 185, 129, 0.06) 0%, rgba(59, 130, 246, 0.05) 100%);
    border-color: rgba(16, 185, 129, 0.2);
}

.card-hint {
    margin: -0.5rem 0 1rem;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.card-hint strong {
    color: var(--headline);
}

.day-label {
    font-weight: 700;
    color: var(--headline);
}

.row-start {
    background: rgba(16, 185, 129, 0.06) !important;
}

.row-start:hover {
    background: rgba(16, 185, 129, 0.1) !important;
}

.row-start .day-label {
    color: var(--success);
}

.entry-card {
    background: var(--gradient-soft);
    border-color: rgba(59, 130, 246, 0.12);
}

.entry-card--pet {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.08) 0%, rgba(139, 92, 246, 0.05) 100%);
    border-color: rgba(245, 158, 11, 0.18);
}

.entry-card h3 {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.profile-subtitle {
    display: inline-block;
    margin-left: 0.35rem;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--text-muted);
    letter-spacing: 0;
}

/* —— Stat cards —— */
.stat-card {
    position: relative;
    overflow: hidden;
    padding-top: 1.5rem;
}

.stat-card::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    border-radius: var(--radius) var(--radius) 0 0;
    background: var(--gradient-btn);
}

.stat-card--rauno::before {
    background: linear-gradient(90deg, #2563eb, #3b82f6);
}

.stat-card--kleiri::before {
    background: linear-gradient(90deg, #db2777, #ec4899);
}

.stat-card h3 {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.stat-card--rauno h3::before,
.stat-card--kleiri h3::before {
    content: "";
    width: 10px;
    height: 10px;
    border-radius: 50%;
    flex-shrink: 0;
}

.stat-card--rauno h3::before {
    background: #2563eb;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.2);
}

.stat-card--kleiri h3::before {
    background: #ec4899;
    box-shadow: 0 0 0 3px rgba(236, 72, 153, 0.2);
}

.stat-card--mupi::before {
    background: linear-gradient(90deg, #f59e0b, #fb923c);
}

.stat-card--mupi h3::before {
    content: "🐾";
    width: auto;
    height: auto;
    border-radius: 0;
    background: none;
    box-shadow: none;
    font-size: 0.875rem;
    line-height: 1;
}

.stat-card--pet {
    max-width: 520px;
}

.section--pet {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border);
}

.chart-card--pet {
    margin-top: 1.125rem;
}

.chart-card__title {
    margin: 0 0 1rem;
    font-size: 1rem;
    font-weight: 700;
    color: var(--headline);
}

.table-card--pet {
    margin-top: 1.125rem;
}

.stat-list {
    margin: 0;
}

.stat-row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 1rem;
    padding: 0.65rem 0;
    border-bottom: 1px solid var(--border);
}

.stat-row:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.stat-row dt {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 500;
}

.stat-row dd {
    margin: 0;
    font-weight: 600;
    color: var(--headline);
    text-align: right;
}

.stat-highlight {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--primary);
}

.positive {
    color: var(--success) !important;
}

.negative {
    color: var(--error) !important;
}

.btn-secondary {
    background: #f8fafc;
    color: #475569;
    border: 1.5px solid #e2e8f0;
    box-shadow: none;
}

.btn-secondary:hover {
    background: #f1f5f9;
    color: #334155;
    border-color: #cbd5e1;
}

.user-goals {
    margin-top: 1.125rem;
    padding-top: 1rem;
    border-top: 1px dashed var(--border);
}

.user-goals__readonly {
    background: #f1f5f9;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 0.75rem 0.875rem;
    margin-bottom: 0.75rem;
}

.user-goals__line {
    margin: 0;
    padding: 0.25rem 0;
    font-size: 0.9rem;
    color: #64748b;
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
}

.user-goals__line + .user-goals__line {
    margin-top: 0.15rem;
}

.user-goals__label {
    font-weight: 600;
}

.user-goals__value {
    color: #475569;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.user-goals__toggle {
    width: 100%;
}

.user-goals__form {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 0.875rem;
}

.user-goals__form .form-row {
    margin-bottom: 0.75rem;
}

.user-goals__form input[type="number"] {
    background: #fff;
}

.user-goals__actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.user-goals__actions .btn-primary,
.user-goals__actions .btn-ghost {
    flex: 1 1 auto;
    min-width: 7rem;
}

.table-row-collapsed {
    display: none;
}

body.table-history-expanded .table-row-collapsed {
    display: table-row;
}

.pet-table-row-collapsed {
    display: none;
}

.table-card--pet.is-expanded .pet-table-row-collapsed {
    display: table-row;
}

.table-more-wrap {
    padding: 0.875rem 1rem 1rem;
    text-align: center;
    border-top: 1px solid var(--border);
    background: var(--surface-muted);
}

.table-more-wrap .btn-secondary {
    min-width: 10rem;
    max-width: 100%;
}

@media (min-width: 480px) {
    .user-goals__toggle {
        width: auto;
    }
}

.form-goals .form-row {
    margin-bottom: 1rem;
}

.form-goals .btn-primary {
    width: 100%;
    margin-top: 0.25rem;
}

.stat-row--goal dd {
    font-weight: 700;
}

.weekly-details {
    margin-top: 1.125rem;
    padding-top: 1rem;
    border-top: 1px dashed var(--border);
    font-size: 0.9rem;
}

.weekly-details summary {
    cursor: pointer;
    color: var(--primary);
    font-weight: 600;
    list-style: none;
    min-height: var(--touch-min);
    display: flex;
    align-items: center;
}

.weekly-details summary::-webkit-details-marker {
    display: none;
}

.weekly-details summary::after {
    content: " ›";
    margin-left: 0.25rem;
    transition: transform 0.15s;
}

.weekly-details[open] summary::after {
    transform: rotate(90deg);
    display: inline-block;
}

.weekly-list {
    margin: 0.75rem 0 0;
    padding: 0;
    list-style: none;
}

.weekly-list li {
    display: flex;
    justify-content: space-between;
    padding: 0.4rem 0;
    color: var(--text-secondary);
}

.weekly-list strong {
    color: var(--headline);
}

/* —— Login —— */
body:has(.login-wrap) .main-content {
    display: flex;
    flex-direction: column;
    justify-content: center;
    min-height: calc(100vh - 80px);
    padding-top: 2rem;
    padding-bottom: 2rem;
}

body:has(.login-wrap) .site-footer {
    border-top: none;
    padding-top: 0;
}

.login-wrap {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 0.5rem 0;
}

.login-card {
    width: 100%;
    max-width: 400px;
    text-align: center;
    padding: 2rem 1.75rem 1.75rem;
    border-radius: var(--radius-lg);
}

.login-card-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 1rem;
    background: var(--gradient-btn);
    border-radius: 18px;
    box-shadow: 0 8px 20px rgba(59, 130, 246, 0.3);
    position: relative;
}

.login-card-icon::before,
.login-card-icon::after {
    content: "";
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(255, 255, 255, 0.95);
    border-radius: 2px;
}

.login-card-icon::before {
    top: 14px;
    width: 22px;
    height: 3px;
}

.login-card-icon::after {
    bottom: 14px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
}

.login-card h1 {
    margin: 0 0 0.35rem;
    font-size: 1.75rem;
    font-weight: 700;
    letter-spacing: -0.03em;
    color: var(--headline);
    background: linear-gradient(135deg, #1e40af 0%, #7c3aed 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.login-card .text-muted {
    margin-bottom: 1.75rem;
}

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

/* —— Forms —— */
.form label {
    display: block;
    margin-bottom: 0.4rem;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
}

.form input[type="password"],
.form input[type="number"] {
    width: 100%;
    min-height: var(--touch-min);
    padding: 0.75rem 1rem;
    margin-bottom: 0;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--surface);
    color: var(--headline);
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.15s, box-shadow 0.15s;
    -webkit-appearance: none;
    appearance: none;
}

.form input::placeholder {
    color: #94a3b8;
}

.form input:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.15);
}

.form-inline .form-row {
    margin-bottom: 1.125rem;
}

.form-inline .btn-primary {
    width: 100%;
}

@media (min-width: 480px) {
    .form-inline .btn-primary {
        width: auto;
        min-width: 8rem;
    }
}

.login-card .form input[type="password"] {
    margin-bottom: 1.25rem;
}

/* —— Buttons —— */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: var(--touch-min);
    padding: 0.65rem 1.25rem;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.12s ease, box-shadow 0.15s ease, opacity 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--gradient-btn);
    color: #fff;
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.35);
}

.btn-primary:hover {
    box-shadow: 0 6px 20px rgba(59, 130, 246, 0.45);
    opacity: 0.95;
}

.btn-ghost {
    background: var(--surface);
    color: var(--text-secondary);
    border: 1.5px solid var(--border);
    box-shadow: var(--shadow-sm);
}

.btn-ghost:hover {
    color: var(--headline);
    border-color: var(--border-strong);
    background: var(--surface-muted);
}

.btn-block {
    width: 100%;
}

.btn-sm {
    min-height: 38px;
    padding: 0.4rem 0.85rem;
    font-size: 0.8125rem;
    border-radius: 10px;
}

/* —— Chart —— */
.chart-card {
    padding: 1.25rem 1rem 1.5rem;
    border-radius: var(--radius-lg);
}

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

@media (min-width: 640px) {
    .chart-card {
        padding: 1.5rem 1.25rem 1.75rem;
    }

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

/* —— Table —— */
.table-card {
    padding: 0;
    overflow: hidden;
    border-radius: var(--radius-lg);
}

.table-scroll {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: thin;
    scrollbar-color: var(--border-strong) transparent;
}

.data-table {
    width: 100%;
    min-width: 520px;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.data-table th,
.data-table td {
    padding: 0.875rem 1.125rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}

.data-table thead th {
    background: var(--surface-muted);
    color: var(--text-muted);
    font-weight: 700;
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    position: sticky;
    top: 0;
    z-index: 1;
}

.data-table tbody tr:nth-child(even) {
    background: rgba(248, 250, 252, 0.8);
}

.data-table tbody tr:hover {
    background: rgba(59, 130, 246, 0.06);
}

.data-table tbody td {
    color: var(--text-secondary);
    font-variant-numeric: tabular-nums;
}

.data-table tbody td:first-child {
    font-weight: 600;
    color: var(--headline);
}

.row-today {
    background: rgba(37, 99, 235, 0.07) !important;
}

.row-today:hover {
    background: rgba(37, 99, 235, 0.1) !important;
}

.badge {
    display: inline-block;
    margin-left: 0.4rem;
    padding: 0.15rem 0.5rem;
    font-size: 0.65rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    background: var(--gradient-btn);
    color: #fff;
    border-radius: 999px;
    vertical-align: middle;
}

.empty-cell {
    text-align: center;
    color: var(--text-muted);
    padding: 2.5rem 1.5rem !important;
    white-space: normal;
    min-width: auto;
}

.actions-cell {
    text-align: right;
}

/* —— Alerts —— */
.alert {
    padding: 0.875rem 1.125rem;
    border-radius: var(--radius-sm);
    margin-bottom: 1.25rem;
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.45;
}

.alert-success {
    background: var(--success-bg);
    border: 1px solid #a7f3d0;
    color: #047857;
}

.alert-error {
    background: var(--error-bg);
    border: 1px solid #fecaca;
    color: #b91c1c;
}

/* —— Edit section —— */
#edit-section {
    scroll-margin-top: 5rem;
}

#edit-section .card {
    border-style: dashed;
    border-color: var(--border-strong);
    background: var(--surface-muted);
}

/* —— Mobile polish —— */
@media (max-width: 639px) {
    .main-content {
        padding-top: 1.25rem;
    }

    .card {
        padding: 1.25rem 1.125rem;
        border-radius: var(--radius);
    }

    .page-subtitle {
        margin-bottom: 1.5rem;
    }

    .data-table th,
    .data-table td {
        padding: 0.75rem 0.875rem;
    }

    .stat-highlight {
        font-size: 1.2rem;
    }
}

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        transition-duration: 0.01ms !important;
    }

    .goal-progress__fill {
        transition: none;
    }

    .goal-progress__fill::after {
        animation: none;
    }
}

/* —— Goal progress bar (kindel stiil) —— */
.goal-progress {
    margin-top: 18px;
    padding: 16px;
    border: 1px solid #e5e7eb;
    border-radius: 20px;
    background: linear-gradient(180deg, #ffffff 0%, #f8fafc 100%);
}

.goal-progress__top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 10px;
    color: #334155;
    font-weight: 700;
}

.goal-progress__top strong {
    font-size: 1.35rem;
    color: #0f172a;
}

.goal-progress__bar {
    position: relative;
    display: block;
    width: 100%;
    height: 22px;
    overflow: hidden;
    border-radius: 999px;
    background: #e5e7eb;
    box-shadow: inset 0 2px 5px rgba(15, 23, 42, 0.12);
}

.goal-progress__fill {
    display: block;
    height: 100%;
    min-width: 0;
    border-radius: inherit;
    background: linear-gradient(90deg, #2563eb, #38bdf8);
    box-shadow: 0 8px 18px rgba(37, 99, 235, 0.28);
    transition: width 900ms ease;
    position: relative;
    overflow: hidden;
}

.goal-progress__fill[style*="width: 0"],
.goal-progress__fill[style*="width:0"] {
    min-width: 0 !important;
}

.goal-progress__fill:not([style*="width: 0"]):not([style*="width:0"]) {
    min-width: 8px;
}

.goal-progress__fill::after {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(110deg, transparent 0%, rgba(255, 255, 255, 0.35) 45%, transparent 70%);
    transform: translateX(-100%);
    animation: progressShine 2.2s ease-in-out infinite;
}

.goal-progress--rauno .goal-progress__fill {
    background: linear-gradient(90deg, #2563eb, #38bdf8);
}

.goal-progress--kleiri .goal-progress__fill {
    background: linear-gradient(90deg, #ec4899, #a855f7);
    box-shadow: 0 8px 18px rgba(236, 72, 153, 0.24);
}

.goal-progress--mupi .goal-progress__fill {
    background: linear-gradient(90deg, #f59e0b, #fb923c);
    box-shadow: 0 8px 18px rgba(245, 158, 11, 0.22);
}

.goal-progress__meta {
    margin-top: 10px;
    color: #64748b;
    font-size: 0.95rem;
    font-weight: 600;
}

.goal-progress.is-complete {
    border-color: rgba(34, 197, 94, 0.35);
    background: linear-gradient(180deg, #f0fdf4 0%, #ffffff 100%);
}

.goal-progress.is-complete .goal-progress__fill {
    background: linear-gradient(90deg, #16a34a, #22c55e) !important;
    box-shadow: 0 8px 18px rgba(34, 197, 94, 0.25);
}

.goal-progress.is-complete .goal-progress__meta {
    color: #15803d;
}

.goal-progress--placeholder {
    text-align: center;
    background: linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
    border-style: dashed;
}

.goal-progress--placeholder .goal-progress__meta {
    margin-top: 0;
    color: #94a3b8;
}

@keyframes progressShine {
    0% {
        transform: translateX(-100%);
    }
    55%,
    100% {
        transform: translateX(100%);
    }
}

@media (max-width: 639px) {
    .goal-progress__bar {
        height: 20px;
    }

    .goal-progress__top strong {
        font-size: 1.25rem;
    }
}
