/* =========================================================
   ALGEMENE RESET & BASIS
========================================================= */

* { 
    box-sizing: border-box; 
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: #f3f4f6;
    color: #1f2937;
    margin: auto;
    padding: 12px;
    max-width: 520px;
    padding-top: max(12px, env(safe-area-inset-top));
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    
    /* VOORKOMT SELECTEREN EN LONG-PRESS */
    user-select: none;
    -webkit-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    -webkit-touch-callout: none; 
    touch-action: pan-y; /* Staat verticaal scrollen toe, blokkeert in-/uitzoomen */
    
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior-y: none; 
}

/* Zorg dat je in de invoervelden WEL tekst kunt selecteren */
input, textarea { 
    user-select: text !important; 
    -webkit-user-select: text !important; 
}

/* =========================================================
   LAYOUT & KAARTEN
========================================================= */

.card {
    background: #fff;
    padding: 16px;
    border-radius: 16px;
    margin-bottom: 12px;
    box-shadow: 0 3px 8px rgba(0,0,0,.07);
}

h2 { 
    font-size: 1.08rem; 
    color: #374151; 
    margin: 0 0 12px; 
}

.secret-title { 
    cursor: pointer; 
    color: #4f46e5; 
}

/* =========================================================
   FORMULIEREN & INPUTS
========================================================= */

.input-form { display: flex; flex-direction: column; gap: 8px; }
.row-inputs, .btn-group { display: flex; gap: 8px; }

input {
    min-width: 0;
    padding: 12px;
    font-size: 1rem;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    flex: 1;
    background: #fff;
    color: #1f2937;
    outline: none;
    transition: border-color 0.15s, box-shadow 0.15s;
}

input:focus {
    border-color: #4f46e5;
    box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1);
}

button {
    background: #4f46e5;
    color: white;
    border: 0;
    padding: 11px 13px;
    border-radius: 10px;
    font-size: .95rem;
    font-weight: 650;
    cursor: pointer;
    font-family: inherit;
    transition: opacity 0.15s;
}

button:active { opacity: 0.7; }
button:disabled { opacity: .5; cursor: not-allowed; }

.btn-group button { flex: 1; }
.cancel-btn { background: #9ca3af; display: none; }

/* =========================================================
   RESULTATEN & STATISTIEKEN
========================================================= */

.total-stat {
    text-align: center;
    padding: 12px;
    background: #f9fafb;
    border-radius: 10px;
    font-size: 1.15rem;
    font-weight: bold;
}

.positive { color: #dc2626; }
.negative { color: #059669; }

/* =========================================================
   GRAFIEK
========================================================= */

.chart-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 12px;
}

.chart-header h2 { margin: 0; }

#predictionButton {
    flex: none;
    background: #f0fdf4;
    color: #15803d;
    border: 1px solid #bbf7d0;
    padding: 7px 9px;
    border-radius: 8px;
    font-size: .72rem;
    white-space: nowrap;
}

#predictionButton.active { background: #dcfce7; color: #166534; }
#predictionButton:disabled { background: #f3f4f6; color: #9ca3af; border-color: #e5e7eb; }

.prediction-hint {
    font-size: .72rem;
    color: #6b7280;
    text-align: right;
    margin-bottom: 8px;
    line-height: 1.4;
}

.prediction-hint.warn { color: #b45309; }
.chart-wrap { position: relative; height: 260px; width: 100%; }

.small-note { font-size: .76rem; color: #6b7280; line-height: 1.45; margin-top: 8px; }

/* =========================================================
   TABEL
========================================================= */

.table-container {
    max-height: 270px;
    overflow-y: auto;
    border: 1px solid #e5e7eb;
    border-radius: 10px;
    margin-top: 10px;
}

table { width: 100%; border-collapse: collapse; font-size: .82rem; }

th { 
    background: #f9fafb; 
    padding: 8px; 
    text-align: left; 
    position: sticky; 
    top: 0; 
    z-index: 10;
}

td { padding: 8px; border-top: 1px solid #eee; }
.empty-state { text-align: center; padding: 20px; color: #9ca3af; }

/* =========================================================
   FOUTMELDINGEN & STATUS
========================================================= */

.error-msg {
    background: #fee2e2;
    color: #991b1b;
    padding: 10px;
    border-radius: 8px;
    margin-bottom: 10px;
    display: none;
    font-size: .9rem;
}

.sync-status {
    font-size: .68rem;
    color: #9ca3af;
    text-align: right;
    margin-top: 4px;
}

.sync-status.ok { color: #059669; }
.sync-status.offline { color: #b45309; }

/* =========================================================
   BACKUP TOOLS
========================================================= */

.backup-tools {
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid #f0f0f0;
    display: flex;
    justify-content: flex-end;
    gap: 6px;
}

.backup-button, .restore-button {
    flex: none;
    padding: 7px 9px;
    border-radius: 7px;
    font-size: .72rem;
}

.backup-button { background: #f5f3ff; color: #6d5bd0; border: 1px solid #ddd8ff; }
.restore-button { background: #f9fafb; color: #6b7280; border: 1px solid #e5e7eb; }
#backupFile { display: none; }

/* =========================================================
   AUTH / LOGIN SCHERM
========================================================= */

#authScreen {
    position: fixed;
    inset: 0;
    background: #f3f4f6;
    z-index: 1000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding: 16px;
    overflow-y: auto;
}

#appScreen { display: none; }

.auth-card {
    background: #fff;
    padding: 24px;
    border-radius: 20px;
    box-shadow: 0 8px 24px rgba(0,0,0,.08);
    width: 100%;
    max-width: 420px;
    margin: auto;
}

.auth-title { font-size: 1.4rem; font-weight: 700; text-align: center; margin: 0 0 6px; color: #4f46e5; }
.auth-subtitle { text-align: center; color: #6b7280; font-size: .85rem; margin: 0 0 20px; }

.auth-error {
    background: #fee2e2;
    color: #991b1b;
    padding: 10px;
    border-radius: 8px;
    text-align: center;
    font-size: .85rem;
    margin-bottom: 12px;
    display: none;
}

.back-link {
    background: transparent;
    color: #6b7280;
    padding: 8px;
    font-size: .85rem;
    text-align: center;
    display: block;
    margin: 8px auto 0;
    border: 0;
}

.auth-action-btn {
    width: 100%;
    background: #eef2ff;
    color: #4f46e5;
    border: 2px dashed #c7d2fe;
    padding: 12px;
    border-radius: 12px;
    font-weight: 600;
    margin-top: 4px;
}

.auth-action-btn:active { background: #e0e7ff; }

/* =========================================================
   GEBRUIKERSLIJST (LOGIN)
========================================================= */

.user-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin-bottom: 16px;
    max-height: 280px;
    overflow-y: auto;
}

.user-item {
    background: #f9fafb;
    border: 2px solid #e5e7eb;
    padding: 14px;
    border-radius: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: all .15s;
}

.user-item:active, .user-item:focus { border-color: #4f46e5; background: #eef2ff; }

.user-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #4f46e5;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.user-name { font-weight: 600; font-size: 1rem; flex: 1; }

/* =========================================================
   PINCODE INVOER (KEYPAD)
========================================================= */

.pin-display { display: flex; justify-content: center; gap: 10px; margin: 16px 0 20px; }

.pin-dot {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid #c7d2fe;
    background: #fff;
    transition: all .15s;
}

.pin-dot.filled { background: #4f46e5; border-color: #4f46e5; transform: scale(1.1); }
.pin-dot.error { background: #dc2626; border-color: #dc2626; animation: shake .4s; }

@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }

.keypad button {
    background: #f3f4f6;
    color: #1f2937;
    padding: 16px 0;
    font-size: 1.3rem;
    font-weight: 600;
    border-radius: 12px;
}

.keypad button:active { background: #e5e7eb; }
.keypad .keypad-empty { background: transparent; cursor: default; }

/* =========================================================
   DIALOGEN (PINCODE WIJZIGEN, ETC)
========================================================= */

.pin-input {
    width: 100%;
    padding: 14px;
    border: 2px solid #e5e7eb;
    border-radius: 12px;
    font-size: 1.6rem;
    letter-spacing: 10px;
    text-align: center;
    font-family: inherit;
    background: #fff;
    color: #1f2937;
    -webkit-user-select: text;
    user-select: text;
    -webkit-appearance: none;
    appearance: none;
    outline: none;
    touch-action: manipulation;
}

.pin-input:focus { border-color: #4f46e5; box-shadow: 0 0 0 3px rgba(79,70,229,.1); }

.field-label { display: block; font-size: .78rem; color: #6b7280; margin-bottom: 4px; font-weight: 600; }
.field-wrap { margin-bottom: 12px; }

.text-input {
    width: 100%;
    padding: 12px;
    border: 2px solid #e5e7eb;
    border-radius: 10px;
    font-size: 1rem;
    -webkit-user-select: text;
    user-select: text;
    -webkit-appearance: none;
    appearance: none;
    outline: none;
}

.text-input:focus { border-color: #4f46e5; box-shadow: 0 0 0 3px rgba(79,70,229,.1); }

/* =========================================================
   USER BAR (INGELOGD SCHERM)
========================================================= */

.user-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 10px 14px;
    background: #fff;
    border-radius: 14px;
    margin-bottom: 12px;
    box-shadow: 0 3px 8px rgba(0,0,0,.07);
}

.user-bar-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }

.user-bar-avatar {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: #4f46e5;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    flex-shrink: 0;
}

.user-bar-name {
    font-weight: 600;
    font-size: .95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-bar-actions { display: flex; gap: 6px; flex-shrink: 0; }

.user-bar-actions button {
    padding: 7px 10px;
    font-size: .72rem;
    background: #f3f4f6;
    color: #4b5563;
}

.user-bar-actions .logout-btn { background: #fee2e2; color: #991b1b; }