/* Diabetes Rekisteri – Mobile-first styles */

:root {
    --bg-deep: #0f172a;
    --bg-card: rgba(255, 255, 255, 0.05);
    --bg-card-hover: rgba(255, 255, 255, 0.08);
    --border: rgba(255, 255, 255, 0.08);
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --text-dim: #64748b;
    --accent: #38bdf8;
    --accent-2: #14b8a6;
    --success: #22c55e;
    --warning: #fbbf24;
    --danger: #ef4444;
    --radius: 16px;
    --radius-sm: 12px;
    --nav-height: 72px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --font: 'DM Sans', system-ui, -apple-system, sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    -webkit-text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font);
    background: var(--bg-deep);
    background-image:
        radial-gradient(ellipse at 20% 0%, rgba(56, 189, 248, 0.12) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 100%, rgba(20, 184, 166, 0.1) 0%, transparent 50%);
    color: var(--text);
    min-height: 100dvh;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

.app {
    display: flex;
    flex-direction: column;
    min-height: 100dvh;
    max-width: 600px;
    margin: 0 auto;
}

.top-bar {
    position: sticky;
    top: 0;
    z-index: 100;
    background: rgba(15, 23, 42, 0.85);
    backdrop-filter: blur(16px);
    -webkit-backdrop-filter: blur(16px);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
    padding-top: max(0.75rem, env(safe-area-inset-top));
}

.top-bar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.brand-icon { font-size: 1.4rem; }
.brand-text { font-weight: 600; font-size: 1rem; }

.back-link {
    color: var(--accent);
    text-decoration: none;
    font-size: 1.25rem;
    padding: 0.25rem 0.5rem;
}

.main-content {
    flex: 1;
    padding: 1rem 1rem calc(var(--nav-height) + var(--safe-bottom) + 1rem);
}

.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 600px;
    display: flex;
    background: rgba(15, 23, 42, 0.92);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-top: 1px solid var(--border);
    padding-bottom: var(--safe-bottom);
    z-index: 100;
}

.nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.15rem;
    padding: 0.6rem 0.25rem;
    text-decoration: none;
    color: var(--text-dim);
    font-size: 0.65rem;
    font-weight: 500;
    transition: color 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.nav-item.active { color: var(--accent); }
.nav-icon { font-size: 1.25rem; }

.page-header { margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.6rem; font-weight: 700; letter-spacing: -0.02em; }
.page-sub { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.25rem; }

.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: 1.5rem;
}

.login-container { width: 100%; max-width: 360px; }

.login-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 2rem 1.5rem;
    text-align: center;
    backdrop-filter: blur(20px);
}

.login-icon { font-size: 2.5rem; margin-bottom: 0.75rem; }
.login-card h1 { font-size: 1.4rem; font-weight: 700; }
.login-sub { color: var(--text-muted); font-size: 0.9rem; margin: 0.5rem 0 1.5rem; }

.pin-display { display: flex; justify-content: center; gap: 1rem; margin-bottom: 1.5rem; }

.pin-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid var(--text-dim);
    transition: all 0.2s;
}

.pin-dot.filled {
    background: var(--accent);
    border-color: var(--accent);
    transform: scale(1.1);
}

.pin-pad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.75rem; }

.pin-key {
    aspect-ratio: 1.4;
    border: none;
    border-radius: var(--radius);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text);
    font-size: 1.4rem;
    font-weight: 500;
    font-family: var(--font);
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
    -webkit-tap-highlight-color: transparent;
}

.pin-key:active { transform: scale(0.95); background: rgba(255,255,255,.12); }
.pin-key.empty { visibility: hidden; pointer-events: none; }

.menu-grid {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.menu-card {
    display: flex;
    flex-direction: column;
    padding: 1.25rem 1.5rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    text-decoration: none;
    color: var(--text);
    transition: background 0.2s, transform 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.menu-card:active { transform: scale(0.98); }

.menu-card-primary {
    background: linear-gradient(135deg, rgba(56,189,248,.2), rgba(20,184,166,.15));
    border-color: rgba(56,189,248,.25);
}

.menu-icon { font-size: 1.75rem; margin-bottom: 0.5rem; }
.menu-title { font-size: 1.1rem; font-weight: 600; }
.menu-desc { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.15rem; }

.quick-stat-card {
    background: linear-gradient(135deg, rgba(56,189,248,.15), rgba(20,184,166,.1));
    border: 1px solid rgba(56,189,248,.2);
    border-radius: var(--radius);
    padding: 1.25rem 1.5rem;
    text-align: center;
}

.quick-stats-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1.25rem;
}

@media (max-width: 400px) {
    .quick-stats-row { grid-template-columns: 1fr; }
}

.quick-stats-row .quick-stat-value { font-size: 1.6rem; }
.quick-stats-row .quick-stat-card { padding: 1rem; }

.quick-stat-label {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.quick-stat-value { font-size: 2.5rem; font-weight: 700; line-height: 1.2; margin: 0.25rem 0; }
.quick-stat-value .unit { font-size: 1rem; font-weight: 500; color: var(--text-muted); }
.quick-stat-time { font-size: 0.85rem; color: var(--text-dim); }

.glucose-low, .glucose-high { color: var(--danger); }
.glucose-elevated { color: var(--warning); }
.glucose-normal { color: var(--success); }

.bp-normal { color: var(--success); }
.bp-warning { color: #86efac; }
.bp-elevated { color: var(--warning); }
.bp-high, .bp-crisis { color: var(--danger); }

.info-strip {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background: var(--bg-card);
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    color: var(--text-muted);
}

.form-section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
    margin-bottom: 1rem;
}

.section-title {
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-size: 0.75rem;
}

.section-hint {
    font-size: 0.85rem;
    color: var(--text-dim);
    margin: -0.5rem 0 1rem;
}

.type-picker-section {
    margin-bottom: 1rem;
}

.type-picker-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.65rem;
}

.type-picker-card {
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.type-picker-card input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.type-picker-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    padding: 1rem 0.5rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    background: rgba(0, 0, 0, 0.2);
    transition: all 0.2s;
    text-align: center;
}

.type-picker-icon {
    font-size: 1.75rem;
    line-height: 1;
}

.type-picker-label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-muted);
}

.type-picker-card input:checked + .type-picker-inner {
    border-color: var(--accent);
    background: rgba(56, 189, 248, 0.12);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.1);
}

.type-picker-card input:checked + .type-picker-inner .type-picker-label {
    color: var(--accent);
}

.type-picker-card:active .type-picker-inner {
    transform: scale(0.97);
}

.type-hint {
    text-align: center;
    padding: 2rem 1rem;
    color: var(--text-dim);
}

.type-hint-icon {
    font-size: 1.5rem;
    display: block;
    margin-bottom: 0.5rem;
}

.type-hint p {
    font-size: 0.9rem;
}

.type-section.hidden {
    display: none;
}

.field-label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-muted);
    margin-bottom: 0.4rem;
}

.field-input, .field-textarea {
    width: 100%;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    background: rgba(0, 0, 0, 0.25);
    color: var(--text);
    font-size: 1rem;
    font-family: var(--font);
    margin-bottom: 1rem;
    transition: border-color 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
}

.field-input:focus, .field-textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.field-input-lg { font-size: 1.5rem; font-weight: 600; text-align: center; }
.field-textarea { resize: vertical; min-height: 80px; }

.datetime-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.field-group .field-input { margin-bottom: 0; }

.meal-chips { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.chip { cursor: pointer; -webkit-tap-highlight-color: transparent; }
.chip input { display: none; }

.chip span {
    display: block;
    padding: 0.5rem 0.85rem;
    border-radius: 999px;
    border: 1px solid var(--border);
    background: rgba(0,0,0,.2);
    font-size: 0.85rem;
    font-weight: 500;
    transition: all 0.2s;
}

.chip input:checked + span {
    background: rgba(56,189,248,.2);
    border-color: var(--accent);
    color: var(--accent);
}

.toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
    margin-bottom: 0.75rem;
    cursor: pointer;
    font-weight: 500;
}

.toggle-row input { display: none; }

.toggle-switch {
    width: 48px;
    height: 28px;
    background: rgba(255,255,255,.1);
    border-radius: 999px;
    position: relative;
    transition: background 0.2s;
    flex-shrink: 0;
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 22px;
    height: 22px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.2s;
}

.toggle-row input:checked + .toggle-switch { background: var(--accent); }
.toggle-row input:checked + .toggle-switch::after { transform: translateX(20px); }
.toggle-fields.hidden { display: none; }

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.85rem 1.5rem;
    border: none;
    border-radius: var(--radius-sm);
    font-family: var(--font);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.15s;
    -webkit-tap-highlight-color: transparent;
}

.btn:active { transform: scale(0.98); }
.btn-primary { background: linear-gradient(135deg, var(--accent), #0ea5e9); color: var(--bg-deep); }
.btn-ghost { background: transparent; color: var(--text-muted); border: 1px solid var(--border); }
.btn-danger { background: rgba(239, 68, 68, 0.15); color: #fca5a5; border: 1px solid rgba(239, 68, 68, 0.3); }
.btn-block { width: 100%; margin-top: 0.75rem; }
.btn-sm { padding: 0.5rem 1rem; font-size: 0.85rem; }

.alert { padding: 0.75rem 1rem; border-radius: var(--radius-sm); font-size: 0.9rem; margin-bottom: 1rem; }
.alert-error { background: rgba(239, 68, 68, 0.12); border: 1px solid rgba(239, 68, 68, 0.25); color: #fca5a5; }
.alert-success { background: rgba(34, 197, 94, 0.12); border: 1px solid rgba(34, 197, 94, 0.25); color: #86efac; }
.hidden { display: none !important; }

.filter-bar {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1.25rem;
}

.filter-row { margin-bottom: 0.75rem; }
.filter-row:last-of-type { margin-bottom: 0.5rem; }
.filter-dates { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }

.entry-list { display: flex; flex-direction: column; gap: 0.75rem; }

.entry-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.25rem;
}

.entry-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.entry-time { font-size: 0.8rem; color: var(--text-dim); }
.entry-actions { display: flex; gap: 0.25rem; }

.action-btn {
    background: none;
    border: none;
    font-size: 1rem;
    cursor: pointer;
    padding: 0.25rem;
    text-decoration: none;
    opacity: 0.7;
}

.meal-badge {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    background: rgba(56,189,248,.15);
    color: var(--accent);
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
}

.entry-notes { margin-top: 0.4rem; font-size: 0.9rem; color: var(--text-muted); }
.entry-glucose { display: flex; align-items: baseline; gap: 0.25rem; margin-top: 0.5rem; }
.glucose-num { font-size: 1.5rem; font-weight: 700; }
.glucose-unit { font-size: 0.8rem; color: var(--text-muted); }

.entry-bp { display: flex; align-items: baseline; gap: 0.25rem; margin-top: 0.5rem; }
.bp-num { font-size: 1.5rem; font-weight: 700; }
.bp-unit { font-size: 0.8rem; color: var(--text-muted); }

.entry-exercise { margin-top: 0.5rem; }
.exercise-duration {
    display: inline-block;
    padding: 0.2rem 0.6rem;
    background: rgba(20,184,166,.15);
    color: var(--accent-2);
    border-radius: 999px;
    font-size: 0.85rem;
    font-weight: 600;
}

.entry-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    margin-bottom: 0.5rem;
}

.type-badge {
    font-size: 0.7rem;
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    background: rgba(255,255,255,.06);
    color: var(--text-muted);
}

.type-meal { background: rgba(56,189,248,.12); color: var(--accent); }
.type-glucose { background: rgba(34,197,94,.12); color: var(--success); }
.type-bp { background: rgba(244,114,182,.12); color: #f472b6; }
.type-exercise { background: rgba(20,184,166,.12); color: var(--accent-2); }

.empty-state, .loading-state { text-align: center; padding: 3rem 1rem; color: var(--text-muted); }
.empty-icon { font-size: 2.5rem; display: block; margin-bottom: 0.75rem; }

.modal {
    position: fixed;
    inset: 0;
    z-index: 200;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1.5rem;
}

.modal.hidden { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(4px); }

.modal-content {
    position: relative;
    background: #1e293b;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.5rem;
    max-width: 340px;
    width: 100%;
    text-align: center;
}

.modal-content h3 { margin-bottom: 0.5rem; }
.modal-content p { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1.25rem; }
.modal-actions { display: flex; gap: 0.75rem; }
.modal-actions .btn { flex: 1; margin-top: 0; }

.stats-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.stats-tabs {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.25rem;
}

.stats-tab {
    flex: 1;
    min-width: max-content;
    padding: 0.65rem 0.85rem;
    border: 1px solid var(--border);
    border-radius: 999px;
    background: var(--bg-card);
    color: var(--text-muted);
    font-family: var(--font);
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    -webkit-tap-highlight-color: transparent;
}

.stats-tab.active {
    background: rgba(56,189,248,.15);
    border-color: rgba(56,189,248,.3);
    color: var(--accent);
}

.stat-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    text-align: center;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    margin-bottom: 0.25rem;
}

.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-value-sm { font-size: 1.1rem; }
.stat-unit { font-size: 0.75rem; font-weight: 500; color: var(--text-muted); }

.trend-banner {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    border: 1px solid var(--border);
}

.trend-rising { background: rgba(251,191,36,.1); border-color: rgba(251,191,36,.25); }
.trend-falling { background: rgba(34,197,94,.1); border-color: rgba(34,197,94,.25); }
.trend-stable { background: rgba(56,189,248,.1); border-color: rgba(56,189,248,.25); }

.trend-icon { font-size: 1.75rem; }
.trend-banner p { font-size: 0.85rem; color: var(--text-muted); margin-top: 0.15rem; }

.chart-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
}

.chart-title { font-size: 0.85rem; font-weight: 600; color: var(--text-muted); margin-bottom: 0.75rem; }
.chart-wrap { position: relative; height: 220px; }
.chart-wrap-sm { height: 200px; }
.chart-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.chart-card-half { margin-bottom: 0; }
.no-data { text-align: center; color: var(--text-dim); padding: 2rem 0; font-size: 0.85rem; }

.settings-section { margin-bottom: 1.5rem; }
.settings-form .field-input { margin-bottom: 0.75rem; }

.info-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1.25rem;
}

.text-muted { color: var(--text-muted); font-size: 0.9rem; margin-top: 0.25rem; }

@media (min-width: 480px) {
    .menu-grid { display: grid; grid-template-columns: 1fr 1fr; }
    .menu-card-primary { grid-column: 1 / -1; }
    .stats-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 400px) {
    .chart-row { grid-template-columns: 1fr; }
    .chart-card-half { margin-bottom: 1rem; }
}

input[type="date"], input[type="time"], input[type="month"] { color-scheme: dark; }
