/* Borehole Data Management System — visual design
   Palette pulled from the Waterlift Solar logo. */

:root {
    --navy:        #1a1a6c;
    --navy-dark:   #12124d;
    --orange:      #f2600c;
    --orange-dark: #d34f04;
    --sky:         #29abe2;
    --sky-dark:    #1c8ebd;

    --bg:          #f4f7fb;
    --surface:     #ffffff;
    --text:        #1f2933;
    --muted:       #64748b;
    --border:      #e2e8f0;

    --error-bg:    #fdecea;
    --error-text:  #7a1f16;
    --error-border:#f3b7ae;
    --success-bg:  #e8f7ee;
    --success-text:#175a34;
    --success-border:#a9e4c1;

    --radius:      8px;
    --shadow:      0 1px 3px rgba(18, 18, 77, 0.08), 0 1px 2px rgba(18, 18, 77, 0.06);
    --shadow-lg:   0 8px 24px rgba(18, 18, 77, 0.12);
}

* {
    box-sizing: border-box;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    color: var(--text);
    margin: 0;
    background: var(--bg);
    line-height: 1.5;
}

a {
    color: var(--sky-dark);
}

/* ---------- Header ---------- */

.site-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.6rem 1.5rem;
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 10;
    flex-wrap: wrap;
}

.brand {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    text-decoration: none;
}

.brand img {
    height: 40px;
    width: auto;
    display: block;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.brand-text strong {
    color: var(--navy);
    font-size: 1.05rem;
}

.brand-text span {
    color: var(--muted);
    font-size: 0.75rem;
}

.site-nav {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.site-nav a {
    text-decoration: none;
    color: var(--navy);
    font-weight: 600;
    font-size: 0.92rem;
    padding: 0.45rem 0.85rem;
    border-radius: var(--radius);
}

.site-nav a:hover {
    background: var(--bg);
}

.site-nav a.active {
    background: var(--navy);
    color: #fff;
}

.site-nav a.logout {
    color: var(--muted);
}

.site-nav a.logout:hover {
    color: var(--error-text);
    background: var(--error-bg);
}

main {
    max-width: 1080px;
    margin: 0 auto;
    padding: 1.75rem 1.5rem 3rem;
}

h1 {
    font-size: 1.4rem;
    color: var(--navy);
    margin: 0 0 1rem;
}

/* ---------- Buttons ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.55rem 1.1rem;
    border-radius: var(--radius);
    border: none;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    line-height: 1;
}

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

.btn-primary:hover {
    background: var(--orange-dark);
}

.btn-primary:disabled {
    background: #f2a074;
    cursor: not-allowed;
}

.btn-secondary {
    background: var(--surface);
    color: var(--navy);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--bg);
}

.spinner {
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.5);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: none;
}

.btn-primary.is-loading .spinner {
    display: inline-block;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ---------- Cards / panels ---------- */

.panel {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
}

/* ---------- Alerts / flash ---------- */

.alert {
    padding: 0.75rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1.25rem;
    border: 1px solid transparent;
    font-size: 0.92rem;
}

.alert ul {
    margin: 0;
    padding-left: 1.2rem;
}

.alert-error {
    background: var(--error-bg);
    color: var(--error-text);
    border-color: var(--error-border);
}

.alert-success {
    background: var(--success-bg);
    color: var(--success-text);
    border-color: var(--success-border);
}

/* ---------- Forms ---------- */

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem 1.25rem;
}

.form-field {
    display: flex;
    flex-direction: column;
}

.form-field.full {
    grid-column: 1 / -1;
}

label {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--navy);
    margin-bottom: 0.3rem;
}

label .req {
    color: var(--orange);
}

input[type="text"],
input[type="number"],
input[type="password"],
input[type="file"] {
    padding: 0.55rem 0.7rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.95rem;
    background: var(--surface);
    color: var(--text);
    width: 100%;
}

input:focus {
    outline: 2px solid var(--sky);
    outline-offset: 1px;
    border-color: var(--sky);
}

.form-actions {
    margin-top: 1.25rem;
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.hint {
    color: var(--muted);
    font-size: 0.8rem;
    margin-top: 0.3rem;
}

/* Dropzone */

.dropzone {
    border: 2px dashed var(--border);
    border-radius: var(--radius);
    background: var(--bg);
    padding: 1.5rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.15s, background 0.15s;
}

.dropzone:hover,
.dropzone.is-dragover {
    border-color: var(--sky);
    background: #eaf6fd;
}

.dropzone .dz-icon {
    font-size: 1.6rem;
    display: block;
    margin-bottom: 0.4rem;
}

.dropzone .dz-main {
    font-weight: 600;
    color: var(--navy);
}

.dropzone .dz-sub {
    color: var(--muted);
    font-size: 0.82rem;
    margin-top: 0.2rem;
}

.dropzone input[type="file"] {
    display: none;
}

.dz-file-preview {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-top: 0.75rem;
    padding: 0.6rem 0.8rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.88rem;
}

.dz-file-preview.is-visible {
    display: flex;
}

.dz-file-preview .dz-file-name {
    font-weight: 600;
    color: var(--text);
    word-break: break-all;
}

.dz-file-preview .dz-file-size {
    color: var(--muted);
    white-space: nowrap;
}

/* ---------- Filters ---------- */

.filters {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 0.75rem 1rem;
    margin-bottom: 1.25rem;
    padding: 1rem 1.25rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.filters .form-field {
    margin: 0;
}

.filters label {
    margin-bottom: 0.25rem;
}

.result-count {
    color: var(--muted);
    font-size: 0.88rem;
    margin: 0 0 0.75rem;
}

/* ---------- Table ---------- */

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.scroll-hint {
    display: none;
    color: var(--muted);
    font-size: 0.78rem;
    margin: 0 0 0.5rem;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 760px;
}

th, td {
    text-align: left;
    padding: 0.65rem 0.85rem;
    border-bottom: 1px solid var(--border);
    font-size: 0.9rem;
}

thead th {
    background: var(--navy);
    color: #fff;
    position: sticky;
    top: 0;
    user-select: none;
    white-space: nowrap;
}

th.sortable {
    cursor: pointer;
}

th.sortable:hover {
    background: var(--navy-dark);
}

th.sortable .sort-arrow {
    display: inline-block;
    margin-left: 0.3rem;
    opacity: 0.5;
    font-size: 0.75rem;
}

th.sortable.sorted-asc .sort-arrow,
th.sortable.sorted-desc .sort-arrow {
    opacity: 1;
}

tbody tr:nth-child(even) {
    background: #fafbfd;
}

tbody tr:hover {
    background: #eef6fc;
}

td.filesize {
    color: var(--muted);
    font-size: 0.8rem;
    white-space: nowrap;
}

.truncate {
    display: inline-block;
    max-width: 220px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    vertical-align: bottom;
}

.file-cell {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    white-space: nowrap;
}

.truncate-filename {
    max-width: 180px;
}

tr[data-no-match-row] td {
    text-align: center;
    color: var(--muted);
    padding: 1.5rem;
}

.pdf-link {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-weight: 600;
    text-decoration: none;
}

.pdf-newtab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    height: 28px;
    border-radius: 4px;
    color: var(--muted);
    text-decoration: none;
    font-size: 0.85rem;
    flex-shrink: 0;
}

.pdf-newtab:hover {
    background: var(--bg);
    color: var(--navy);
}

/* ---------- Pagination ---------- */

.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    margin-top: 1.25rem;
}

.pagination .btn {
    padding: 0.4rem 0.9rem;
    font-size: 0.85rem;
}

.pagination .btn.is-disabled {
    opacity: 0.45;
    pointer-events: none;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 34px;
    height: 34px;
    padding: 0 0.5rem;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--navy);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
}

.page-link:hover {
    background: var(--bg);
}

.page-link.active {
    background: var(--navy);
    border-color: var(--navy);
    color: #fff;
    cursor: default;
}

.page-ellipsis {
    color: var(--muted);
    padding: 0 0.15rem;
}

/* ---------- PDF preview modal ---------- */

.icon-btn {
    width: 32px;
    height: 32px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--navy);
    cursor: pointer;
    font-size: 0.95rem;
    line-height: 1;
    flex-shrink: 0;
}

.icon-btn:hover {
    background: var(--bg);
}

.pdf-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(18, 18, 77, 0.6);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    z-index: 100;
}

.pdf-modal-overlay[hidden] {
    display: none;
}

.pdf-modal {
    width: 100%;
    max-width: 920px;
    height: 88vh;
    height: 88dvh; /* accounts for mobile browser chrome; ignored where unsupported, falls back to vh above */
    background: var(--surface);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.pdf-modal-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 0.5rem 1rem;
    padding: 0.75rem 1rem 0.75rem 1.25rem;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.pdf-modal-header h2 {
    flex: 1 1 auto;
    min-width: 0; /* lets a flex item actually shrink below its content width so ellipsis can kick in */
    font-size: 1rem;
    margin: 0;
    color: var(--navy);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pdf-modal-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    flex-shrink: 0;
}

.pdf-modal-actions .btn {
    padding: 0.4rem 0.8rem;
    font-size: 0.85rem;
}

.pdf-modal-body {
    flex: 1;
    background: #525659;
}

.pdf-modal-body iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

@media (max-width: 640px) {
    .pdf-modal-overlay {
        padding: 0;
    }

    .pdf-modal {
        max-width: none;
        height: 100vh;
        height: 100dvh;
        border-radius: 0;
    }
}

.empty-state {
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--muted);
}

.empty-state .es-icon {
    font-size: 2.2rem;
    display: block;
    margin-bottom: 0.5rem;
}

.empty-state .btn {
    margin-top: 1rem;
}

/* ---------- Login page ---------- */

.login-page {
    min-height: 100vh;
    min-height: 100dvh; /* accounts for mobile browser chrome; ignored where unsupported, falls back to 100vh above */
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, var(--navy) 0%, var(--navy-dark) 55%, #0d0d3d 100%);
    padding: 1.5rem;
}

.login-card {
    width: 100%;
    max-width: 380px;
    background: var(--surface);
    border-radius: 12px;
    box-shadow: var(--shadow-lg);
    padding: 2rem 1.75rem;
    text-align: center;
}

.login-card img {
    height: 64px;
    width: auto;
    margin-bottom: 1rem;
}

.login-card h1 {
    font-size: 1.2rem;
    margin-bottom: 0.25rem;
}

.login-card p.subtitle {
    color: var(--muted);
    font-size: 0.85rem;
    margin: 0 0 1.25rem;
}

.login-card form {
    text-align: left;
}

.login-card .btn {
    width: 100%;
    justify-content: center;
    margin-top: 0.75rem;
}

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
    .form-grid {
        grid-template-columns: 1fr;
    }

    .site-header {
        padding: 0.6rem 1rem;
    }

    main {
        padding: 1.25rem 1rem 2.5rem;
    }

    .filters {
        flex-direction: column;
        align-items: stretch;
    }

    .scroll-hint {
        display: block;
    }
}

@media (max-width: 420px) {
    .brand-text span {
        display: none; /* drop the "Waterlift Solar" subtitle — logo + title alone still identify the app */
    }

    .site-nav {
        gap: 0.15rem;
    }

    .site-nav a {
        padding: 0.4rem 0.55rem;
        font-size: 0.85rem;
    }

    .login-card {
        padding: 1.5rem 1.25rem;
    }

    .pdf-modal-header {
        padding: 0.65rem 0.75rem 0.65rem 1rem;
    }

    .pdf-modal-actions .btn span {
        display: none; /* icon-only "Open in new tab" once space is this tight */
    }
}
