:root {
    --bg-main: #e8f4fd;
    --bg-secondary: #f0f8ff;
    --card-bg: #ffffff;
    --card-shadow: 0 4px 20px rgba(14, 100, 168, 0.12);
    --card-shadow-hover: 0 8px 32px rgba(14, 100, 168, 0.2);
    --input-bg: #eaf4fc;
    --input-shadow-inset: inset 3px 3px 8px rgba(14, 100, 168, 0.13), inset -3px -3px 8px rgba(255, 255, 255, 0.95);
    --input-focus-shadow: 0 0 0 3px rgba(14, 100, 168, 0.18), inset 3px 3px 8px rgba(14, 100, 168, 0.13);
    --input-outer-shadow: 2px 2px 6px rgba(14, 100, 168, 0.10), -2px -2px 6px rgba(255, 255, 255, 0.85);
    --accent: #0e64a8;
    --accent-light: #38a8f5;
    --accent-mid: #1a8cd8;
    --text-primary: #0d2f4a;
    --text-secondary: #5b8fb0;
    --text-muted: #9bbfd8;
    --border: rgba(14, 100, 168, 0.12);
    --nav-bg: rgba(255, 255, 255, 0.85);
    --header-bg: rgba(255, 255, 255, 0.9);
    --card-radius: 18px;
    --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);

    /* Parameter colors */
    --color-ok: #16a34a;
    --color-warn: #d97706;
    --color-danger: #dc2626;
    --color-info: #0284c7;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Outfit', sans-serif;
    background: linear-gradient(160deg, #cde9f7 0%, #e8f4fd 50%, #d0eafb 100%);
    background-attachment: fixed;
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
}

#app {
    max-width: 500px;
    margin: 0 auto;
    padding-bottom: 100px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ── HEADER ── */
.glass-header {
    padding: 16px 20px;
    background: var(--header-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 12px rgba(14, 100, 168, 0.08);
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo h1 {
    font-size: 1.45rem;
    font-weight: 700;
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.icon-primary {
    color: var(--accent);
    filter: drop-shadow(0 2px 4px rgba(14, 100, 168, 0.25));
}

/* ── NAV ── */
.glass-nav {
    position: fixed;
    bottom: 16px;
    left: 16px;
    right: 16px;
    max-width: 468px;
    margin: 0 auto;
    height: 66px;
    background: var(--nav-bg);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border: 1px solid rgba(14, 100, 168, 0.15);
    border-radius: 22px;
    display: flex;
    justify-content: space-around;
    align-items: center;
    padding: 0 8px;
    box-shadow: 0 4px 24px rgba(14, 100, 168, 0.15);
    z-index: 1000;
}

.nav-item {
    background: none;
    border: none;
    color: var(--text-muted);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    cursor: pointer;
    transition: var(--transition);
    padding: 8px 12px;
    border-radius: 14px;
}

.nav-item i {
    width: 22px;
    height: 22px;
}

.nav-item span {
    font-size: 0.68rem;
    font-weight: 500;
}

.nav-item.active {
    color: var(--accent);
    background: rgba(14, 100, 168, 0.08);
}

.nav-item:active {
    transform: scale(0.9);
}

/* ── MAIN ── */
#main-content {
    flex: 1;
    padding: 20px 16px;
}

/* ── CARDS ── */
.glass-card {
    background: var(--card-bg);
    border-radius: var(--card-radius);
    padding: 20px;
    margin-bottom: 16px;
    box-shadow: var(--card-shadow);
    border: 1px solid var(--border);
    transition: var(--transition);
}

.glass-card:hover {
    box-shadow: var(--card-shadow-hover);
}

/* ── LOADER ── */
.loader-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 60vh;
    gap: 15px;
    color: var(--text-secondary);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(14, 100, 168, 0.15);
    border-top: 3px solid var(--accent);
    border-radius: 50%;
    animation: spin 0.9s linear infinite;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* ── FORM ── */
.section-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.section-title i {
    color: var(--accent);
}

.form-group {
    margin-bottom: 16px;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 7px;
    margin-left: 4px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.form-input {
    width: 100%;
    background: var(--input-bg);
    border: 1.5px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: var(--transition);
    box-shadow: var(--input-shadow-inset), var(--input-outer-shadow);
    -webkit-appearance: none;
    appearance: none;
}

.form-input:focus {
    border-color: var(--accent-light);
    box-shadow: var(--input-focus-shadow);
    background: #fff;
}

.form-input option {
    color: var(--text-primary);
    background: #fff;
}

textarea.form-input {
    resize: none;
}

.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.form-divider {
    height: 1px;
    background: var(--border);
    margin: 18px 0;
}

.form-section-label {
    font-size: 0.78rem;
    font-weight: 700;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 14px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.btn-primary {
    width: 100%;
    background: linear-gradient(135deg, var(--accent), var(--accent-mid));
    color: #fff;
    border: none;
    border-radius: 14px;
    padding: 14px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin-top: 10px;
    box-shadow: 0 4px 16px rgba(14, 100, 168, 0.3);
    letter-spacing: 0.3px;
}

.btn-primary:not(:disabled):hover {
    filter: brightness(1.08);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(14, 100, 168, 0.4);
}

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    opacity: 0.55;
    cursor: not-allowed;
}

/* ── HISTORY ── */
.page-title {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 16px;
    padding-left: 4px;
}

/* Client row */
.client-row {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    margin-bottom: 10px;
    overflow: hidden;
    box-shadow: var(--card-shadow);
}

.client-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 14px 16px;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.client-header:hover {
    background: rgba(14, 100, 168, 0.04);
}

.client-header:active {
    background: rgba(14, 100, 168, 0.08);
}

.client-header-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.client-avatar {
    width: 38px;
    height: 38px;
    background: linear-gradient(135deg, var(--accent), var(--accent-light));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 0.95rem;
    color: #fff;
    flex-shrink: 0;
}

.client-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--text-primary);
}

.chevron-icon {
    color: var(--text-muted);
    transition: transform 0.25s;
    width: 18px;
    height: 18px;
}

.client-row.open .chevron-icon {
    transform: rotate(180deg);
}

/* year/month dropdown */
.years-container {
    display: none;
}

.client-row.open .years-container {
    display: block;
}

.year-row {
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.year-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 11px 16px 11px 24px;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.year-header:hover {
    background: rgba(14, 100, 168, 0.05);
}

.year-label {
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--accent);
}

.months-container {
    display: none;
}

.year-row.open .months-container {
    display: block;
}

.month-row {
    border-top: 1px solid var(--border);
    background: var(--bg-main);
}

.month-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 16px 10px 36px;
    cursor: pointer;
    transition: var(--transition);
    user-select: none;
}

.month-header:hover {
    background: rgba(14, 100, 168, 0.05);
}

.month-label {
    font-size: 0.82rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-transform: capitalize;
}

.samples-container {
    display: none;
    padding: 10px 12px;
}

.month-row.open .samples-container {
    display: block;
}

/* ── SAMPLE CARD ── */
.sample-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 14px;
    margin-bottom: 10px;
    box-shadow: var(--card-shadow);
}

.sample-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 6px;
}

.sample-name {
    font-weight: 700;
    font-size: 0.95rem;
    color: var(--accent);
}

.sample-code {
    font-size: 0.72rem;
    background: rgba(14, 100, 168, 0.1);
    color: var(--accent);
    border-radius: 6px;
    padding: 2px 7px;
    font-weight: 600;
}

.sample-meta {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 8px;
}

.sample-desc {
    font-size: 0.92rem;
    font-weight: 700;
    color: var(--text-primary);
    background: var(--bg-secondary);
    border-radius: 10px;
    padding: 8px 10px;
    margin-bottom: 10px;
    line-height: 1.4;
}

/* Parameter badges */
.params-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 7px;
}

.param-chip {
    border-radius: 10px;
    padding: 7px 5px;
    text-align: center;
    border: 1.5px solid transparent;
    background: var(--bg-secondary);
}

.param-chip .param-icon {
    font-size: 0.95rem;
    display: block;
    margin-bottom: 2px;
}

.param-chip .param-label {
    font-size: 0.58rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: block;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.param-chip .param-value {
    font-size: 0.82rem;
    font-weight: 700;
    display: block;
}

.param-ok {
    border-color: #86efac;
    background: #f0fdf4;
}

.param-warn {
    border-color: #fcd34d;
    background: #fffbeb;
}

.param-danger {
    border-color: #fca5a5;
    background: #fef2f2;
}

.param-info {
    border-color: #7dd3fc;
    background: #f0f9ff;
}

.param-none {
    border-color: var(--border);
}

/* Value is always bold dark — no conflicting color from ok/warn/danger */
.param-chip .param-value {
    font-size: 0.82rem;
    font-weight: 800;
    display: block;
    color: var(--text-primary);
}

/* Per-param chip: tinted background, icon + label in param color */
.param-chip.ph-chip {
    background: #fffbeb;
    border-color: #fde68a;
}

.param-chip.ph-chip .param-icon-wrap,
.param-chip.ph-chip .param-label {
    color: #d97706;
}

.param-chip.temp-chip {
    background: #fff1f2;
    border-color: #fecdd3;
}

.param-chip.temp-chip .param-icon-wrap,
.param-chip.temp-chip .param-label {
    color: #ef4444;
}

.param-chip.cloro-chip {
    background: #f0f9ff;
    border-color: #bae6fd;
}

.param-chip.cloro-chip .param-icon-wrap,
.param-chip.cloro-chip .param-label {
    color: #0ea5e9;
}

.param-chip.hierro-chip {
    background: #f9fafb;
    border-color: #e5e7eb;
}

.param-chip.hierro-chip .param-icon-wrap,
.param-chip.hierro-chip .param-label {
    color: #6b7280;
}

.param-icon-wrap {
    display: flex;
    justify-content: center;
    margin-bottom: 3px;
}

.param-icon-wrap svg {
    width: 16px;
    height: 16px;
    stroke-width: 2;
}

/* ── CALENDAR ── */
.calendar-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 6px;
}

.cal-day-name {
    text-align: center;
    font-size: 0.7rem;
    color: var(--text-muted);
    font-weight: 700;
    padding-bottom: 4px;
}

.cal-day {
    aspect-ratio: unset;
    min-height: 52px;
    background: var(--card-bg);
    border-radius: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    padding: 4px 2px 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
    border: 1.5px solid transparent;
    font-weight: 500;
    color: var(--text-primary);
    overflow: hidden;
}

.cal-day:hover {
    background: rgba(14, 100, 168, 0.06);
}

.cal-day.has-data {
    border-color: var(--accent-light);
    background: rgba(14, 100, 168, 0.05);
    color: var(--accent);
    font-weight: 700;
}

.cal-day.selected {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

.day-dots {
    display: flex;
    gap: 2px;
    justify-content: center;
    margin-top: 2px;
}

.day-dot {
    width: 4px;
    height: 4px;
    background: var(--accent);
    border-radius: 50%;
}

.day-client-name {
    font-size: 0.62rem;
    font-weight: 800;
    color: var(--accent);
    text-align: center;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1;
    padding: 2px 1px;
    margin-top: 1px;
    background: rgba(14, 100, 168, 0.05);
    border-radius: 4px;
}

.cal-day.selected .day-client-name {
    color: rgba(255, 255, 255, 0.85);
}

.cal-arrow {
    background: rgba(14, 100, 168, 0.08);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    width: 36px;
    height: 36px;
    font-size: 1rem;
    color: var(--accent);
    cursor: pointer;
    transition: var(--transition);
    display: flex;
    align-items: center;
    justify-content: center;
}

.cal-arrow:hover {
    background: rgba(14, 100, 168, 0.15);
}

.cal-day.selected .day-dot {
    background: rgba(255, 255, 255, 0.7);
}

/* ── CARD ACTIONS (edit/delete) ── */
.card-actions {
    display: flex;
    gap: 8px;
    margin-top: 12px;
    padding-top: 10px;
    border-top: 1px solid var(--border);
}

.btn-icon {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 5px;
    padding: 7px 0;
    border-radius: 10px;
    border: 1.5px solid var(--border);
    background: var(--bg-secondary);
    font-size: 0.78rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
    font-family: inherit;
    color: var(--text-secondary);
}

.btn-icon i {
    width: 14px;
    height: 14px;
}

.btn-icon.edit:hover {
    background: #eff6ff;
    border-color: #93c5fd;
    color: #2563eb;
}

.btn-icon.delete:hover {
    background: #fef2f2;
    border-color: #fca5a5;
    color: #dc2626;
}

/* ── EDIT MODAL ── */
.edit-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(13, 47, 74, 0.5);
    backdrop-filter: blur(4px);
    z-index: 2000;
    display: flex;
    align-items: flex-end;
    padding: 16px;
}

.edit-modal-card {
    background: var(--card-bg);
    border-radius: 20px 20px 16px 16px;
    width: 100%;
    max-width: 468px;
    margin: 0 auto;
    padding: 20px;
    max-height: 88vh;
    overflow-y: auto;
    box-shadow: 0 -8px 40px rgba(14, 100, 168, 0.2);
    animation: slideUp 0.25s ease;
}

@keyframes slideUp {
    from {
        transform: translateY(60px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.edit-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
}

.close-btn {
    background: var(--bg-secondary);
    border: 1.5px solid var(--border);
    border-radius: 10px;
    width: 34px;
    height: 34px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text-secondary);
    transition: var(--transition);
}

.close-btn:hover {
    background: #fef2f2;
    color: #dc2626;
    border-color: #fca5a5;
}

/* ── DELETE CONFIRMATION MODAL ── */
.delete-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(13, 47, 74, 0.6);
    backdrop-filter: blur(5px);
    z-index: 3000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.delete-modal-card {
    background: var(--card-bg);
    border-radius: 20px;
    width: 100%;
    max-width: 320px;
    padding: 24px;
    text-align: center;
    box-shadow: 0 10px 40px rgba(220, 38, 38, 0.2);
    animation: scaleUp 0.2s ease-out;
}

@keyframes scaleUp {
    from {
        transform: scale(0.9);
        opacity: 0;
    }

    to {
        transform: scale(1);
        opacity: 1;
    }
}

.delete-modal-card i {
    color: #dc2626;
    margin-bottom: 16px;
    background: #fef2f2;
    padding: 12px;
    border-radius: 50%;
}

.delete-modal-card h3 {
    font-size: 1.15rem;
    margin-bottom: 10px;
    color: var(--text-primary);
}

.delete-modal-card p {
    font-size: 0.88rem;
    color: var(--text-secondary);
    margin-bottom: 24px;
    line-height: 1.4;
}

.delete-actions {
    display: flex;
    gap: 12px;
}

.btn-cancel {
    flex: 1;
    padding: 12px;
    border-radius: 12px;
    border: 1.5px solid var(--border);
    background: var(--bg-secondary);
    font-weight: 700;
    cursor: pointer;
}

.btn-confirm-delete {
    flex: 1;
    padding: 12px;
    border-radius: 12px;
    background: #dc2626;
    color: #fff;
    border: none;
    font-weight: 700;
    cursor: pointer;
}

/* ── MISC ── */
.hidden {
    display: none !important;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text-muted);
}

.empty-state i {
    width: 40px;
    height: 40px;
    margin-bottom: 12px;
    opacity: 0.5;
}

@media (max-width: 380px) {
    .form-row {
        grid-template-columns: 1fr;
    }

    .params-grid {
        grid-template-columns: repeat(2, 1fr);
    }
}