/* 
   AguaSup - Modern responsive Design System (Dark/Light mode)
   Based on the Technical Inspections layout styling.
   Includes styling for groundwater template and river flow analysis (Aforo).
*/

:root {
    /* Color Palette - Light Mode Default */
    --bg-color: #f8fafc;
    --bg-header: #0f172a;
    --card-bg: #ffffff;
    --text-color: #0f172a;
    --text-secondary: #475569;
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --secondary-color: #0284c7;
    --accent-color: #0d9488;
    --accent-hover: #0f766e;
    --border-color: #e2e8f0;
    --shadow-color: rgba(15, 23, 42, 0.08);
    --shadow-hover: rgba(15, 23, 42, 0.15);
    --danger-color: #ef4444;
    --danger-hover: #dc2626;
    --success-color: #10b981;
    --success-hover: #059669;
    
    /* Layout Constants */
    --font-sans: 'Outfit', 'Plus Jakarta Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --header-height: 70px;
    --border-radius-lg: 16px;
    --border-radius-md: 10px;
    --border-radius-sm: 6px;
    --transition-speed: 0.3s;
}

/* Dark Mode Overrides */
[data-theme="dark"] {
    --bg-color: #0b0f19;
    --bg-header: #111827;
    --card-bg: #1e293b;
    --text-color: #f1f5f9;
    --text-secondary: #94a3b8;
    --primary-color: #3b82f6;
    --primary-hover: #60a5fa;
    --secondary-color: #38bdf8;
    --border-color: #334155;
    --shadow-color: rgba(0, 0, 0, 0.25);
    --shadow-hover: rgba(0, 0, 0, 0.4);
}

/* Universal Reset */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    -webkit-tap-highlight-color: transparent;
}

html, body {
    font-family: var(--font-sans);
    background-color: var(--bg-color);
    color: var(--text-color);
    width: 100%;
    height: 100%;
    overflow-x: hidden;
    transition: background-color var(--transition-speed), color var(--transition-speed);
}

body {
    display: flex;
    flex-direction: column;
}

/* Scrollbar styling */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: transparent;
}
::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: var(--border-radius-sm);
}

/* App Layout Container */
.app-container {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100vh;
    overflow: hidden;
}

/* App Header styling */
.app-header {
    height: var(--header-height);
    background-color: var(--bg-header);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    z-index: 100;
    flex-shrink: 0;
}

.header-logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.header-svg-icon {
    width: 32px;
    height: 32px;
    color: var(--primary-color);
}

.header-text h1 {
    font-size: 1.1rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: #ffffff;
    line-height: 1.2;
}

.header-text p {
    font-size: 0.72rem;
    color: #38bdf8;
    font-weight: 500;
}

/* Theme Toggle Button */
.icon-btn {
    background: transparent;
    border: none;
    cursor: pointer;
    color: #ffffff;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.2s;
}

.icon-btn:hover {
    background-color: rgba(255, 255, 255, 0.1);
}

.icon-btn svg {
    width: 22px;
    height: 22px;
}

.sun-icon { display: block; }
.moon-icon { display: none; }

[data-theme="dark"] .sun-icon { display: none; }
[data-theme="dark"] .moon-icon { display: block; }

/* Main Content Wrapper */
.app-main {
    flex: 1;
    overflow-y: auto;
    position: relative;
    width: 100%;
}

/* Screens System */
.app-screen {
    display: none;
    opacity: 0;
    transition: opacity 0.2s ease-in-out;
    padding: 20px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.app-screen.active {
    display: block;
    opacity: 1;
}

/* Headings & Screen Headers */
.screen-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    gap: 12px;
}

.screen-header h2 {
    font-size: 1.4rem;
    font-weight: 700;
    color: var(--text-color);
}

/* Buttons Design System */
.btn {
    font-family: var(--font-sans);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 10px 18px;
    border-radius: var(--border-radius-md);
    border: none;
    cursor: pointer;
    transition: all 0.2s ease;
    height: 42px;
}

.btn-sm {
    height: 34px;
    font-size: 0.8rem;
    padding: 6px 12px;
    border-radius: var(--border-radius-sm);
}

.btn-lg {
    height: 52px;
    font-size: 1rem;
    padding: 14px 24px;
    border-radius: var(--border-radius-lg);
}

.btn-block {
    display: flex;
    width: 100%;
}

.btn-primary {
    background-color: var(--primary-color);
    color: #ffffff;
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-hover);
    transform: translateY(-1px);
}

.btn-accent {
    background-color: var(--accent-color);
    color: #ffffff;
}

.btn-accent:hover:not(:disabled) {
    background-color: var(--accent-hover);
    transform: translateY(-1px);
}

.btn-success {
    background-color: var(--success-color);
    color: #ffffff;
}

.btn-success:hover:not(:disabled) {
    background-color: var(--success-hover);
    transform: translateY(-1px);
}

.btn-outline {
    background-color: transparent;
    border: 1.5px solid var(--border-color);
    color: var(--text-color);
}

.btn-outline:hover:not(:disabled) {
    background-color: var(--border-color);
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
    transform: none !important;
}

.btn-danger-text {
    color: var(--danger-color);
    border-color: rgba(239, 68, 68, 0.3);
}

.btn-danger-text:hover {
    background-color: rgba(239, 68, 68, 0.1) !important;
    border-color: var(--danger-color);
}

.btn-back {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: transparent;
    border: none;
    color: var(--primary-color);
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    font-family: var(--font-sans);
    padding: 6px 0;
}

.back-icon, .btn-icon {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
}

/* Search Bar styling */
.search-bar-container {
    margin-bottom: 20px;
}

.search-input-wrapper {
    position: relative;
    width: 100%;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    width: 20px;
    height: 20px;
    color: var(--text-secondary);
}

.search-input-wrapper input {
    width: 100%;
    height: 48px;
    background-color: var(--card-bg);
    border: 1.5px solid var(--border-color);
    border-radius: var(--border-radius-md);
    padding: 0 16px 0 46px;
    font-size: 0.95rem;
    font-family: var(--font-sans);
    color: var(--text-color);
    box-shadow: 0 2px 4px var(--shadow-color);
    transition: all 0.2s;
}

.search-input-wrapper input:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 211, 0.15);
}

/* Inspections List & Cards */
.list-container {
    min-height: 250px;
}

.inspections-list {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.list-empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 40px 20px;
    text-align: center;
    background-color: var(--card-bg);
    border-radius: var(--border-radius-lg);
    border: 2px dashed var(--border-color);
}

.empty-icon {
    width: 48px;
    height: 48px;
    color: var(--text-secondary);
    margin-bottom: 12px;
    opacity: 0.7;
}

.empty-subtext {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 4px;
}

/* Inspection Card */
.inspection-card {
    background-color: var(--card-bg);
    border-radius: var(--border-radius-lg);
    border: 1.5px solid var(--border-color);
    padding: 18px;
    box-shadow: 0 4px 6px -1px var(--shadow-color);
    display: flex;
    flex-direction: column;
    gap: 12px;
    position: relative;
    transition: transform 0.2s, box-shadow 0.2s;
}

.inspection-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 8px 12px var(--shadow-hover);
}

.card-header-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.card-title-group h3 {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-color);
}

.card-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

.card-date-badge {
    background-color: rgba(37, 99, 211, 0.1);
    color: var(--primary-color);
    font-size: 0.75rem;
    font-weight: 700;
    padding: 4px 10px;
    border-radius: 50px;
}

[data-theme="dark"] .card-date-badge {
    background-color: rgba(59, 130, 246, 0.2);
    color: #60a5fa;
}

.card-details-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    padding: 10px 0;
}

.detail-item {
    font-size: 0.85rem;
}

.detail-item strong {
    color: var(--text-secondary);
    font-weight: 500;
}

.detail-item span {
    display: block;
    font-weight: 600;
    margin-top: 1px;
}

.card-actions-row {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 4px;
}

/* Backup tools bar */
.backup-tools {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 30px;
    padding-top: 20px;
    border-top: 1.5px solid var(--border-color);
    gap: 12px;
}

/* Settings/Signature Cards */
.settings-card {
    background-color: var(--card-bg);
    border-radius: var(--border-radius-lg);
    border: 1.5px solid var(--border-color);
    padding: 20px;
    box-shadow: 0 4px 6px -1px var(--shadow-color);
    margin-top: 24px;
}

.settings-card h3, .settings-card h4 {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 12px;
    color: var(--text-color);
}

.section-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
    line-height: 1.4;
    margin-bottom: 16px;
}

.signature-setting-wrapper {
    display: flex;
    align-items: center;
    gap: 18px;
    flex-wrap: wrap;
}

.signature-preview-box {
    width: 180px;
    height: 90px;
    border: 1.5px dashed var(--border-color);
    border-radius: var(--border-radius-md);
    background-color: var(--bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.preview-placeholder {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
    padding: 10px;
}

.signature-actions {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Form Design & Elements */
.form-steps-nav {
    display: flex;
    overflow-x: auto;
    background-color: var(--card-bg);
    border: 1px solid var(--border-color);
    padding: 6px;
    border-radius: var(--border-radius-md);
    margin-bottom: 20px;
    gap: 4px;
}

.step-tab {
    font-family: var(--font-sans);
    background: transparent;
    border: none;
    padding: 8px 14px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
    flex: 1;
    text-align: center;
}

.step-tab.active {
    background-color: var(--primary-color);
    color: #ffffff;
}

.form-step-content {
    display: none;
    background-color: var(--card-bg);
    border: 1.5px solid var(--border-color);
    border-radius: var(--border-radius-lg);
    padding: 20px;
    box-shadow: 0 4px 6px -1px var(--shadow-color);
    animation: fadeIn 0.2s ease-in-out;
}

.form-step-content.active {
    display: block;
}

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

.step-title {
    font-size: 1.1rem;
    font-weight: 700;
    margin-bottom: 16px;
    color: var(--primary-color);
    border-bottom: 1.5px solid var(--border-color);
    padding-bottom: 6px;
}

.mt-4 { margin-top: 24px; }

/* Grid Layouts */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}

@media (max-width: 500px) {
    .grid-2 {
        grid-template-columns: 1fr;
        gap: 12px;
    }
}

/* Form Groups, Labels, Inputs */
.form-group {
    margin-bottom: 18px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

label, .label-span {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-color);
}

.input-hint {
    font-size: 0.78rem;
    color: var(--text-secondary);
    margin-top: 2px;
}

input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea {
    font-family: var(--font-sans);
    height: 44px;
    border: 1.5px solid var(--border-color);
    border-radius: var(--border-radius-md);
    padding: 0 12px;
    font-size: 0.9rem;
    color: var(--text-color);
    background-color: var(--card-bg);
    transition: border-color 0.2s, box-shadow 0.2s;
    width: 100%;
}

textarea {
    height: auto;
    padding: 12px;
    resize: vertical;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 211, 0.1);
}

input.invalid, select.invalid, textarea.invalid {
    border-color: var(--danger-color);
    background-color: rgba(239, 68, 68, 0.03);
}

/* Combined Groups */
.input-combined-group {
    display: flex;
    gap: 8px;
    width: 100%;
}
.input-combined-group select {
    width: 140px;
    flex-shrink: 0;
}
.input-combined-group input {
    flex: 1;
}

/* Unit Inputs */
.input-unit {
    position: relative;
    display: flex;
    align-items: center;
}
.input-unit input {
    padding-right: 70px;
}
.input-unit .unit {
    position: absolute;
    right: 12px;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--text-secondary);
}

/* Radio Toggle Options */
.radio-toggle-group {
    display: flex;
    gap: 12px;
    margin-top: 4px;
}

.radio-label {
    flex: 1;
    cursor: pointer;
    position: relative;
}

.radio-label input {
    opacity: 0;
    position: absolute;
}

.radio-label span {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 44px;
    background-color: var(--bg-color);
    border: 1.5px solid var(--border-color);
    border-radius: var(--border-radius-md);
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.radio-label input:checked + span {
    background-color: rgba(37, 99, 211, 0.1);
    border-color: var(--primary-color);
    color: var(--primary-color);
}

[data-theme="dark"] .radio-label input:checked + span {
    background-color: rgba(59, 130, 246, 0.15);
    color: #60a5fa;
}

/* Chips / Radios styled as chips */
.material-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 4px;
}

.chip {
    cursor: pointer;
}

.chip input {
    display: none;
}

.chip span {
    display: inline-block;
    padding: 8px 16px;
    background-color: var(--bg-color);
    border: 1.5px solid var(--border-color);
    border-radius: 50px;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    transition: all 0.2s;
}

.chip input:checked + span {
    background-color: rgba(37, 99, 211, 0.1);
    border-color: var(--primary-color);
    color: var(--primary-color);
    font-weight: 600;
}

[data-theme="dark"] .chip input:checked + span {
    background-color: rgba(59, 130, 246, 0.2);
}

/* GPS Section styles */
.gps-capture-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}
.gps-capture-header .step-title {
    margin-bottom: 0;
    border-bottom: none;
    padding-bottom: 0;
}

.gps-status-box {
    font-size: 0.82rem;
    padding: 10px 14px;
    border-radius: var(--border-radius-md);
    margin-bottom: 16px;
    line-height: 1.4;
    font-weight: 500;
}

/* Photo Upload Previews */
.photo-uploader-box {
    margin-bottom: 16px;
}

.photos-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
    gap: 12px;
    margin-top: 14px;
}

.photo-preview-card-wrapper {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.photo-preview-card {
    position: relative;
    aspect-ratio: 1;
    border-radius: var(--border-radius-md);
    overflow: hidden;
    border: 1.5px solid var(--border-color);
    box-shadow: 0 2px 4px var(--shadow-color);
}

.photo-preview-card img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.btn-remove-photo {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 26px;
    height: 26px;
    border-radius: 50%;
    background-color: rgba(0, 0, 0, 0.6);
    color: #ffffff;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.2s;
}

.btn-remove-photo:hover {
    background-color: rgba(239, 68, 68, 0.9);
}

.btn-remove-photo svg {
    width: 16px;
    height: 16px;
}

/* Navigation Footer */
.step-navigation-footer {
    display: flex;
    justify-content: space-between;
    margin-top: 24px;
    gap: 12px;
}

.step-navigation-footer button {
    flex: 1;
}

/* Modal overlays */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background-color: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 16px;
}

.modal-content {
    background-color: var(--card-bg);
    border-radius: var(--border-radius-lg);
    width: 100%;
    max-width: 560px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.15);
    border: 1.5px solid var(--border-color);
    overflow: hidden;
}

.modal-header {
    height: 60px;
    padding: 0 20px;
    border-bottom: 1.5px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text-color);
}

.modal-body-scroll {
    padding: 20px;
    overflow-y: auto;
    flex: 1;
}

.danger-zone {
    border-color: rgba(239, 68, 68, 0.3);
    background-color: rgba(239, 68, 68, 0.02);
}

.form-actions-top {
    display: flex;
    gap: 8px;
}

/* Credits Footer style */
.app-credits-footer {
    text-align: center;
    padding: 24px 0 12px 0;
    font-size: 0.8rem;
    color: var(--text-secondary);
    border-top: 1.5px solid var(--border-color);
    margin-top: 32px;
    opacity: 0.7;
}
.app-credits-footer strong {
    color: var(--text-color);
    font-weight: 600;
}

/* --- PRINT RULES --- */
.print-only {
    display: none;
}

@media print {
    body * {
        visibility: hidden;
    }
    
    .print-only, .print-only * {
        visibility: visible;
    }
    
    .print-only {
        display: block !important;
        position: absolute;
        left: 0;
        top: 0;
        width: 100%;
        color: #000000 !important;
        background-color: #ffffff !important;
    }

    /* Print Template structures */
    .print-header {
        text-align: center;
        border-bottom: 2px solid #000000;
        padding-bottom: 12px;
        margin-bottom: 20px;
    }

    .print-header h1 {
        font-size: 16pt;
        font-weight: bold;
        margin-bottom: 4px;
        color: #000000;
    }

    .print-header p {
        font-size: 9.5pt;
        color: #333333;
    }

    .print-section-title {
        font-size: 10pt;
        font-weight: bold;
        background-color: #f2f2f2 !important;
        border: 1px solid #000000;
        padding: 6px 10px;
        margin-top: 20px;
        margin-bottom: 10px;
        text-transform: uppercase;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .print-table {
        width: 100%;
        border-collapse: collapse;
        margin-bottom: 16px;
    }

    .print-table td {
        border: 1px solid #000000;
        padding: 6px 8px;
        font-size: 9pt;
        color: #000000;
    }

    .print-table td.label {
        font-weight: bold;
        background-color: #fafafa !important;
        width: 25%;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .print-check-list {
        display: flex;
        flex-wrap: wrap;
        gap: 14px;
    }

    .print-check-item {
        display: flex;
        align-items: center;
        gap: 6px;
        font-size: 9pt;
    }

    .print-box {
        display: inline-flex;
        width: 13px;
        height: 13px;
        border: 1.5px solid #000000;
        align-items: center;
        justify-content: center;
        font-size: 8pt;
        font-weight: bold;
    }

    .print-observations {
        font-size: 9.5pt;
        line-height: 1.5;
        border: 1px solid #000000;
        padding: 12px;
        min-height: 100px;
        white-space: pre-wrap;
        color: #000000;
    }

    /* Print Photos */
    .print-photo-page {
        page-break-before: always;
        break-before: page;
        display: flex;
        flex-direction: column;
    }

    .print-photo-container {
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        border: 1px solid #000000;
        padding: 14px;
        margin-top: 10px;
        height: auto;
    }

    .print-photo-container img {
        max-width: 100%;
        max-height: 45vh;
        object-fit: contain;
    }

    .print-photo-caption {
        font-size: 9pt;
        margin-top: 10px;
        font-style: italic;
        text-align: center;
    }

    /* Signatures Print styling */
    .print-signatures-single {
        margin-top: 40px;
        display: flex;
        justify-content: center;
        page-break-inside: avoid;
        break-inside: avoid;
    }

    .signature-block {
        text-align: center;
        width: 280px;
        display: flex;
        flex-direction: column;
        align-items: center;
    }

    .print-signature-img-wrapper {
        height: 210px;
        margin-bottom: -63px;
        z-index: 10;
        display: flex;
        justify-content: center;
        align-items: center;
    }

    .print-signature-img-wrapper img {
        max-height: 100%;
        max-width: 600px;
        object-fit: contain;
    }

    .signature-block .line {
        border-top: 1px dashed #000000;
        width: 100%;
        margin-bottom: 8px;
    }

    .signature-block p {
        font-size: 8.5pt !important;
        margin: 2px 0 !important;
        line-height: 1.2 !important;
        color: #000000 !important;
    }
}
