:root {
    --blue-deep: #003d5c;
    --blue-mid: #0077a8;
    --blue-light: #00b4d8;
    --blue-pale: #caf0f8;
    --aqua: #48cae4;
    --surface: #f0f8ff;
    --card-bg: #ffffff;
    --text: #1a2e3a;
    --text-muted: #5a7a8a;
    --border: #d0e8f2;
    --success: #2d9e6b;
    --warning: #e07b00;
    --danger: #c0392b;
    --radius: 14px;
    --shadow: 0 4px 24px rgba(0,80,120,0.10);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: 'DM Sans', sans-serif;
    background: var(--surface);
    color: var(--text);
    min-height: 100vh;
    overflow-x: hidden;
}

/* WATER BACKGROUND */
.water-bg {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: linear-gradient(160deg, #003d5c 0%, #0077a8 40%, #00b4d8 100%);
    z-index: -1;
    overflow: hidden;
}
.ripple {
    position: absolute;
    border-radius: 50%;
    border: 1px solid rgba(255,255,255,0.15);
    animation: ripple 8s infinite ease-out;
}
.r1 { width: 600px; height: 600px; top: -200px; left: -150px; animation-delay: 0s; }
.r2 { width: 900px; height: 900px; top: -300px; right: -300px; animation-delay: 2s; }
.r3 { width: 500px; height: 500px; bottom: -100px; left: 30%; animation-delay: 4s; }

@keyframes ripple {
    0% { transform: scale(0.8); opacity: 0.4; }
    50% { opacity: 0.15; }
    100% { transform: scale(1.2); opacity: 0; }
}

/* SCREENS */
.screen { min-height: 100vh; }
.screen.hidden { display: none; }
.screen.active { display: block; }

/* AUTH */
#screen-auth {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    min-height: 100vh;
}

.auth-card {
    background: white;
    border-radius: 24px;
    padding: 40px;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.25);
    animation: slideUp 0.4s ease;
}

@keyframes slideUp {
    from { opacity: 0; transform: translateY(30px); }
    to { opacity: 1; transform: translateY(0); }
}

.logo { text-align: center; margin-bottom: 28px; }
.logo-duck {
    width: 110px;
    height: 110px;
    object-fit: cover;
    border-radius: 50%;
    border: 3px solid var(--blue-light);
    box-shadow: 0 4px 20px rgba(0,180,216,0.3);
    margin-bottom: 12px;
    animation: bob 3s ease-in-out infinite;
}
@keyframes bob {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}
.logo h1 {
    font-family: 'DM Serif Display', serif;
    font-size: 2rem;
    color: var(--blue-deep);
    letter-spacing: -0.5px;
}
.tagline { color: var(--text-muted); font-size: 0.85rem; margin-top: 4px; }

.tab-row {
    display: flex;
    background: var(--surface);
    border-radius: 10px;
    padding: 4px;
    margin-bottom: 24px;
}
.tab {
    flex: 1;
    padding: 9px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    transition: all 0.2s;
}
.tab.active {
    background: white;
    color: var(--blue-deep);
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.auth-form.hidden { display: none; }

/* FIELDS */
.field { margin-bottom: 16px; }
.field label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.field input, .field select {
    width: 100%;
    padding: 11px 14px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.95rem;
    color: var(--text);
    background: white;
    transition: border-color 0.2s, box-shadow 0.2s;
    outline: none;
}
.field input:focus, .field select:focus {
    border-color: var(--blue-light);
    box-shadow: 0 0 0 3px rgba(0,180,216,0.15);
}
.field-hint { font-size: 0.75rem; color: var(--text-muted); margin-top: 4px; }
.subtle { font-weight: 400; font-size: 0.78rem; }

.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 500px) { .field-row { grid-template-columns: 1fr; } }

/* BUTTONS */
.btn-primary {
    width: 100%;
    padding: 13px;
    background: linear-gradient(135deg, var(--blue-mid), var(--blue-light));
    color: white;
    border: none;
    border-radius: 12px;
    font-family: 'DM Sans', sans-serif;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    box-shadow: 0 4px 16px rgba(0,119,168,0.3);
    margin-top: 8px;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(0,119,168,0.4); }
.btn-primary:active { transform: translateY(0); }
.btn-large { padding: 16px; font-size: 1.05rem; margin-top: 8px; }

.btn-ghost {
    background: transparent;
    border: 1.5px solid rgba(255,255,255,0.4);
    color: white;
    padding: 7px 14px;
    border-radius: 8px;
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.85rem;
    transition: background 0.2s;
}
.btn-ghost:hover { background: rgba(255,255,255,0.15); }

.btn-danger {
    background: var(--danger);
    color: white;
    border: none;
    padding: 11px 20px;
    border-radius: 10px;
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
}

/* MESSAGES */
.error-msg {
    background: #fdecea;
    color: var(--danger);
    padding: 10px 14px;
    border-radius: 8px;
    font-size: 0.875rem;
    margin-bottom: 12px;
}
.success-msg {
    color: var(--success);
    font-size: 0.875rem;
    margin-top: 10px;
    font-weight: 500;
}
.hidden { display: none !important; }

/* HEADER */
header {
    background: linear-gradient(135deg, var(--blue-deep), var(--blue-mid));
    padding: 0 24px;
    box-shadow: 0 2px 12px rgba(0,0,0,0.2);
}
.header-inner {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
}
.logo-sm {
    font-family: 'DM Serif Display', serif;
    font-size: 1.3rem;
    color: white;
    letter-spacing: -0.3px;
}
.header-right { display: flex; align-items: center; gap: 14px; }
.welcome { color: rgba(255,255,255,0.8); font-size: 0.875rem; }

/* NAV */
.app-nav {
    background: white;
    border-bottom: 1px solid var(--border);
    display: flex;
    padding: 0 24px;
    gap: 4px;
    max-width: 100%;
    overflow-x: auto;
}
.nav-btn {
    padding: 14px 20px;
    background: transparent;
    border: none;
    border-bottom: 3px solid transparent;
    cursor: pointer;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-muted);
    white-space: nowrap;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    gap: 6px;
}
.nav-btn.active {
    color: var(--blue-mid);
    border-bottom-color: var(--blue-light);
}
.nav-icon { font-size: 1rem; }

/* APP SECTIONS */
.app-section {
    max-width: 900px;
    margin: 0 auto;
    padding: 28px 20px 60px;
}
.app-section.hidden { display: none; }

.section-header { margin-bottom: 24px; }
.section-header h2 {
    font-family: 'DM Serif Display', serif;
    font-size: 1.6rem;
    color: var(--blue-deep);
}
.section-header p { color: var(--text-muted); margin-top: 4px; }

/* CARDS */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
}
.card-title {
    font-weight: 700;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.6px;
    color: var(--blue-mid);
    margin-bottom: 18px;
}

/* READINGS GRID */
.readings-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
}
.reading-item label {
    display: block;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}
.unit { font-weight: 400; text-transform: none; letter-spacing: 0; }
.reading-item input {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: 10px;
    font-family: 'DM Sans', sans-serif;
    font-size: 1rem;
    font-weight: 500;
    color: var(--text);
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}
.reading-item input:focus {
    border-color: var(--blue-light);
    box-shadow: 0 0 0 3px rgba(0,180,216,0.15);
}
.target-range { font-size: 0.72rem; color: var(--text-muted); margin-top: 5px; }

/* RESULTS */
.results-card { border-left: 4px solid var(--blue-light); animation: slideUp 0.3s ease; }

.result-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}
.result-item:last-child { border-bottom: none; }
.result-status {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    margin-top: 5px;
    flex-shrink: 0;
}
.status-ok { background: var(--success); }
.status-warn { background: var(--warning); }
.status-bad { background: var(--danger); }

.result-label { font-weight: 600; font-size: 0.9rem; color: var(--text); }
.result-value { font-size: 0.85rem; color: var(--text-muted); }
.result-action {
    font-size: 0.85rem;
    color: var(--blue-mid);
    font-weight: 500;
    margin-top: 3px;
}
.result-action.action-needed { color: var(--warning); }
.result-action.action-bad { color: var(--danger); }

.all-good {
    text-align: center;
    padding: 20px;
    color: var(--success);
    font-weight: 600;
    font-size: 1.05rem;
}

/* HISTORY */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-icon { font-size: 3rem; margin-bottom: 16px; }

.chart-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}
.chart-controls label { font-weight: 600; color: var(--text-muted); font-size: 0.85rem; }
.chart-controls select {
    padding: 7px 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    font-family: 'DM Sans', sans-serif;
    font-size: 0.9rem;
    outline: none;
}

.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
th {
    text-align: left;
    padding: 8px 12px;
    background: var(--surface);
    color: var(--text-muted);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    border-bottom: 1px solid var(--border);
}
td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
}
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--surface); }

/* SETTINGS */
.danger-zone .card-title { color: var(--danger); }
