/* SolTrack — design système : carnet de sondage terrain */

:root {
    --stone-50: #EDEAE2;
    --paper: #F8F6F0;
    --stone-900: #2A2621;
    --text-muted: #746C5E;

    --clay: #B5583A;
    --ochre: #C89A3D;
    --sand: #D9C48C;
    --slate: #6E7570;
    --basalt: #34302B;
    --water: #3D7D82;
    --danger: #A23B2E;
    --success: #4C7A4E;

    --line: #DCD6C7;
    --line-dark: #C7C0AE;

    --radius: 8px;
    --radius-lg: 14px;
    --shadow: 0 1px 2px rgba(42, 38, 33, 0.06), 0 4px 14px rgba(42, 38, 33, 0.06);

    --font-display: 'Archivo Expanded', 'Arial Narrow', sans-serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-mono: 'IBM Plex Mono', 'SF Mono', monospace;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
    margin: 0;
    font-family: var(--font-body);
    background: var(--stone-50);
    color: var(--stone-900);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
    font-family: var(--font-display);
    font-weight: 800;
    letter-spacing: -0.01em;
    margin: 0 0 0.25rem;
    color: var(--stone-900);
}
h1 { font-size: 1.75rem; }
h3 { font-size: 1.05rem; font-weight: 600; }
h4 { font-size: 0.85rem; font-weight: 600; }

p { margin: 0 0 0.5rem; }
a { color: inherit; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.text-sm { font-size: 0.83rem; }
.text-muted { color: var(--text-muted); }
.eyebrow {
    font-family: var(--font-mono);
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--clay);
    margin: 0 0 0.15rem;
}

*:focus-visible {
    outline: 2px solid var(--water);
    outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
    * { animation: none !important; transition: none !important; }
}

/* ---------- Core strip motif (signature) ---------- */
.core-strip {
    display: flex;
    width: 84px;
    height: 10px;
    border-radius: 3px;
    overflow: hidden;
    box-shadow: var(--shadow);
}
.core-strip span { flex: 1; }
.core-strip-sm { width: 46px; height: 8px; }

/* ---------- Login page ---------- */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background:
        radial-gradient(ellipse 900px 500px at 20% -10%, #E9E2CE 0%, transparent 60%),
        var(--stone-50);
    padding: 1.5rem;
}
.login-container { width: 100%; max-width: 380px; }
.login-brand { text-align: center; margin-bottom: 1.75rem; }
.login-brand .core-strip { margin: 0 auto 1rem; width: 120px; height: 12px; }
.logo { font-size: 2rem; margin-bottom: 0.15rem; }
.tagline { color: var(--text-muted); font-size: 0.9rem; }
.login-box {
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    padding: 1.75rem;
}
.login-footer { margin-top: 1.5rem; padding-top: 1rem; border-top: 1px dashed var(--line-dark); font-size: 0.82rem; color: var(--text-muted); }
.login-footer ul { margin: 0.4rem 0 0; padding-left: 1.1rem; }
.alert { padding: 0.7rem 0.9rem; border-radius: var(--radius); margin-bottom: 1rem; font-size: 0.88rem; }
.alert-error { background: #F3DEDA; color: #7A2C21; border: 1px solid #E3B6AC; }

/* ---------- App shell ---------- */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.85rem 1.5rem;
    background: var(--paper);
    border-bottom: 1px solid var(--line);
    position: sticky;
    top: 0;
    z-index: 20;
}
.topbar-brand { display: flex; align-items: center; gap: 0.6rem; }
.brand-name { font-family: var(--font-display); font-weight: 800; font-size: 1.15rem; }
.topbar-user { display: flex; align-items: center; gap: 0.75rem; }
.user-name { font-size: 0.88rem; font-weight: 500; }
.role-pill {
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    padding: 0.2rem 0.55rem;
    border-radius: 20px;
    font-weight: 600;
}
.role-sondeur { background: #E8D9CD; color: #8A3F22; }
.role-ingenieur { background: #D8E2DD; color: #2E5C4E; }
.role-admin { background: #E8D9DD; color: #8A2C4E; }

.content { max-width: 1080px; margin: 0 auto; padding: 1.75rem 1.5rem 4rem; width: 100%; }

/* ---------- Page head ---------- */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; flex-wrap: wrap; }
.back-link { display: inline-block; font-size: 0.85rem; color: var(--text-muted); text-decoration: none; margin-bottom: 0.75rem; }
.back-link:hover { color: var(--clay); }

/* ---------- Buttons ---------- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 600;
    padding: 0.65rem 1.1rem;
    border-radius: var(--radius);
    border: 1px solid transparent;
    cursor: pointer;
    text-decoration: none;
    transition: transform 0.08s ease, background 0.15s ease, border-color 0.15s ease;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--clay); color: #fff; }
.btn-primary:hover { background: #A24A2E; }
.btn-primary:disabled { background: var(--line-dark); color: var(--text-muted); cursor: not-allowed; }
.btn-outline { background: transparent; color: var(--stone-900); border-color: var(--line-dark); }
.btn-outline:hover { border-color: var(--clay); color: var(--clay); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { color: var(--stone-900); }
.btn-sm { padding: 0.4rem 0.7rem; font-size: 0.82rem; }
.btn-block { width: 100%; }
.flex { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: 0.5rem; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 1.1rem; }
label { display: block; font-size: 0.83rem; font-weight: 600; margin-bottom: 0.35rem; color: var(--stone-900); }
input[type="text"], input[type="password"], input[type="email"], input[type="number"],
input[type="date"], input[type="file"], select, textarea {
    width: 100%;
    padding: 0.65rem 0.75rem;
    border: 1px solid var(--line-dark);
    border-radius: var(--radius);
    background: #fff;
    font-family: var(--font-body);
    font-size: 0.92rem;
    color: var(--stone-900);
}
input:focus, select:focus, textarea:focus { border-color: var(--water); outline: none; box-shadow: 0 0 0 3px rgba(61,125,130,0.15); }
textarea { resize: vertical; min-height: 60px; }

.type-toggle { display: flex; gap: 0.6rem; }
.type-option {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    padding: 0.65rem;
    border: 1px solid var(--line-dark);
    border-radius: var(--radius);
    cursor: pointer;
    font-weight: 500;
    font-size: 0.88rem;
    margin: 0;
}
.type-option input { width: auto; margin: 0; }
.type-option:has(input:checked) { border-color: var(--clay); background: #FBF0EA; color: var(--clay); font-weight: 600; }

.checkbox-row { display: flex; align-items: center; gap: 0.5rem; }
.checkbox-row input { width: auto; }
.checkbox-row label { margin: 0; font-weight: 500; }

/* ---------- GPS capture ---------- */
.gps-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.85rem 1rem;
    border: 1px dashed var(--line-dark);
    border-radius: var(--radius);
    background: #F2EFE6;
    margin-bottom: 0.5rem;
    flex-wrap: wrap;
}
.gps-status { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; }
.gps-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--text-muted); flex-shrink: 0; }
.gps-dot.active { background: var(--success); box-shadow: 0 0 0 3px rgba(76,122,78,0.2); }
.gps-dot.error { background: var(--danger); }
.gps-dot.pending { background: var(--ochre); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: 0.4; } }

/* ---------- Cards ---------- */
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-lg); box-shadow: var(--shadow); overflow: hidden; }
.card-header { padding: 1rem 1.25rem; border-bottom: 1px solid var(--line); }
.card-body { padding: 1.25rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; }
@media (max-width: 800px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Project grid ---------- */
.project-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 1rem; }
.project-card {
    display: block;
    background: var(--paper);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    text-decoration: none;
    color: inherit;
    box-shadow: var(--shadow);
    transition: border-color 0.15s ease, transform 0.1s ease;
}
.project-card:hover { border-color: var(--clay); transform: translateY(-2px); }
.project-card-head { display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.25rem; }
.project-card-client { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 0.5rem; }
.project-card-foot { display: flex; justify-content: space-between; margin-top: 1rem; padding-top: 0.75rem; border-top: 1px solid var(--line); }

.status-dot { width: 9px; height: 9px; border-radius: 50%; display: inline-block; flex-shrink: 0; }
.status-en_cours { background: var(--ochre); }
.status-termine { background: var(--success); }

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

/* ---------- Meta strip ---------- */
.meta-strip { display: flex; gap: 2rem; flex-wrap: wrap; padding: 1rem 1.25rem; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-lg); }
.meta-strip > div { display: flex; flex-direction: column; gap: 0.15rem; font-size: 0.88rem; }
.meta-strip .text-muted { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }

/* ---------- Tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.table th {
    text-align: left;
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0.7rem 1rem;
    border-bottom: 1px solid var(--line);
}
.table td { padding: 0.7rem 1rem; border-bottom: 1px solid var(--line); }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: #F2EFE6; }
.table tbody tr.row-active { background: #FBF0EA; }
.table-compact th, .table-compact td { padding: 0.45rem 0.6rem; }

/* ---------- Dynamic rows (measurements) ---------- */
.dynamic-rows { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.75rem; }
.dynamic-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 0.5rem; align-items: center; }
.dynamic-row .remove-row { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1rem; padding: 0.4rem; }
.dynamic-row .remove-row:hover { color: var(--danger); }

/* ---------- Layer blocks (batch soil layer entry) ---------- */
.layer-block {
    border: 1px solid var(--line-dark);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    background: #FBFAF6;
    position: relative;
}
.layer-block-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.75rem; }
.layer-block-title { font-family: var(--font-mono); font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--clay); font-weight: 600; }
.layer-block .remove-row { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 1rem; }
.layer-block .remove-row:hover { color: var(--danger); }
.layer-block-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.75rem; }
.layer-block-grid .full { grid-column: 1 / -1; }

/* ---------- Existing layer cards (read) ---------- */
.layer-card { border: 1px solid var(--line); border-radius: var(--radius); padding: 0.85rem 1rem; margin-bottom: 0.7rem; }
.layer-card-head { display: flex; align-items: center; gap: 0.55rem; margin-bottom: 0.4rem; flex-wrap: wrap; }
.nature-chip { width: 12px; height: 12px; border-radius: 3px; flex-shrink: 0; }
.water-chip { font-size: 0.85rem; }

/* ---------- Core log (signature element) ---------- */
.core-log {
    display: flex;
    flex-direction: column;
    border-radius: var(--radius);
    overflow: hidden;
    border: 1px solid var(--line-dark);
    min-height: 120px;
}
.core-log-empty { padding: 2rem 1rem; text-align: center; color: var(--text-muted); font-size: 0.85rem; background: #F2EFE6; }
.core-log-segment {
    position: relative;
    padding: 0.4rem 0.7rem;
    display: flex;
    flex-direction: column;
    justify-content: center;
    color: #fff;
    border-bottom: 1px solid rgba(255,255,255,0.25);
}
.core-log-segment:last-of-type { border-bottom: none; }
.core-log-depth { font-size: 0.7rem; opacity: 0.9; }
.core-log-nature { font-size: 0.85rem; font-weight: 600; }
.core-log-bottom { text-align: right; padding: 0.3rem 0.7rem; color: var(--text-muted); background: var(--paper); }

/* ---------- Penetrometer chart ---------- */
.pen-chart { display: flex; align-items: flex-end; gap: 0.5rem; height: 260px; padding: 1rem 0.5rem 0; border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
.pen-bar-wrap { display: flex; flex-direction: column; align-items: center; gap: 0.4rem; min-width: 28px; }
.pen-bar { width: 24px; background: var(--clay); border-radius: 4px 4px 0 0; display: flex; align-items: flex-start; justify-content: center; }
.pen-bar-value { font-family: var(--font-mono); font-size: 0.65rem; color: #fff; margin-top: 3px; }
.pen-bar-label { font-size: 0.65rem; color: var(--text-muted); writing-mode: vertical-rl; }

/* ---------- Photo box ---------- */
.photo-box { aspect-ratio: 4/3; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #F2EFE6; display: flex; align-items: center; justify-content: center; }
.photo-box img { width: 100%; height: 100%; object-fit: cover; }
.photo-empty { color: var(--text-muted); font-size: 0.85rem; }

/* ---------- Modal ---------- */
.modal { display: none; position: fixed; inset: 0; background: rgba(42,38,33,0.5); align-items: center; justify-content: center; z-index: 100; padding: 1rem; }
.modal.open { display: flex; }
.modal-content { background: var(--paper); border-radius: var(--radius-lg); width: 100%; max-width: 460px; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 50px rgba(0,0,0,0.25); }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--line); }
.modal-body { padding: 1.25rem; }
.modal-footer { display: flex; justify-content: flex-end; gap: 0.6rem; padding: 1rem 1.25rem; border-top: 1px solid var(--line); }

/* ---------- Section label ---------- */
.section-label { font-family: var(--font-mono); font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-muted); margin-bottom: 0.75rem; }

/* ---------- Report / print ---------- */
.report-toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1.5rem; }
.report { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-lg); padding: 2.5rem; max-width: 780px; margin: 0 auto; }
.report-head { text-align: center; margin-bottom: 2rem; }
.report-head .core-strip { margin: 0 auto 1rem; }
.report-info { width: 100%; border-collapse: collapse; margin-bottom: 2rem; }
.report-info td { padding: 0.5rem 0.75rem; border-bottom: 1px solid var(--line); font-size: 0.9rem; }
.report-info td:first-child { color: var(--text-muted); width: 40%; }
.report-point { margin-bottom: 2rem; padding-top: 1.5rem; border-top: 1px dashed var(--line-dark); }
.report-table { width: 100%; border-collapse: collapse; margin-top: 0.75rem; font-size: 0.85rem; }
.report-table th { text-align: left; padding: 0.5rem 0.6rem; background: #F2EFE6; font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-muted); }
.report-table td { padding: 0.5rem 0.6rem; border-bottom: 1px solid var(--line); }
.report-photo { max-width: 260px; border-radius: var(--radius); margin: 0.75rem 0; display: block; }

@media print {
    .no-print, .topbar { display: none !important; }
    body { background: #fff; }
    .content { padding: 0; max-width: none; }
    .report { border: none; box-shadow: none; padding: 0; }
}

/* ---------- Responsive ---------- */
@media (max-width: 640px) {
    .content { padding: 1.25rem 1rem 3rem; }
    .topbar { padding: 0.75rem 1rem; }
    .user-name { display: none; }
    .layer-block-grid { grid-template-columns: 1fr; }
    .meta-strip { gap: 1rem; }
    .table th, .table td { padding: 0.55rem 0.6rem; font-size: 0.82rem; }
    h1 { font-size: 1.4rem; }
}

/* ---------- Point metadata panel (GPS, critère d'arrêt, historique) ---------- */
.point-meta { margin-bottom: 1.25rem; padding-bottom: 1.25rem; border-bottom: 1px dashed var(--line-dark); }
.point-meta-row { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; }
@media (max-width: 800px) { .point-meta-row { grid-template-columns: 1fr; } }
.point-meta-field p { margin-bottom: 0.5rem; }
.section-divider { border: none; border-top: 1px dashed var(--line-dark); margin: 1.5rem 0; }

.stop-toggle { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.stop-chip {
    display: inline-block; padding: 0.15rem 0.55rem; border-radius: 20px;
    font-size: 0.72rem; font-weight: 600; letter-spacing: 0.02em;
}
.stop-refus { background: #F3DEDA; color: #7A2C21; }
.stop-arret_volontaire { background: #E8E1CE; color: #6B5424; }

.edit-history { margin-top: 1rem; }
.edit-history summary { cursor: pointer; user-select: none; }
.history-list { list-style: none; margin: 0.75rem 0 0; padding: 0; display: flex; flex-direction: column; gap: 0.5rem; }
.history-list li { padding: 0.5rem 0.75rem; border-left: 2px solid var(--line-dark); background: #F2EFE6; border-radius: 0 var(--radius) var(--radius) 0; }

/* ---------- Multi-photo gallery ---------- */
.photo-gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 0.5rem; }
.photo-thumb { position: relative; aspect-ratio: 1; border-radius: var(--radius); overflow: hidden; border: 1px solid var(--line); }
.photo-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photo-thumb-remove {
    position: absolute; top: 4px; right: 4px; width: 20px; height: 20px; border-radius: 50%;
    background: rgba(42,38,33,0.7); color: #fff; border: none; cursor: pointer; font-size: 0.7rem; line-height: 1;
}

/* ---------- Validation errors ---------- */
.input-error { border-color: var(--danger) !important; box-shadow: 0 0 0 3px rgba(162,59,46,0.12) !important; }

/* ---------- Report modal ---------- */
.report-point-list { max-height: 220px; overflow-y: auto; border: 1px solid var(--line); border-radius: var(--radius); padding: 0.75rem; }

/* ---------- Pagination ---------- */
.pagination { display: flex; align-items: center; justify-content: center; gap: 1rem; margin-top: 1.5rem; }
.pagination-inline { padding: 0.85rem 1.25rem; border-top: 1px solid var(--line); margin-top: 0; }
.btn-disabled { opacity: 0.4; pointer-events: none; }

/* ---------- Bulle de description du sol (cascade de catégories) ---------- */
.soil-bubble {
    margin-top: 0.5rem;
    padding: 0.6rem 0.85rem;
    background: #EFEADA;
    border-left: 3px solid var(--ochre);
    border-radius: 0 var(--radius) var(--radius) 0;
    font-size: 0.82rem;
    color: var(--stone-900);
}

.project-card-dossier { font-size: 0.78rem; color: var(--clay); margin-bottom: 0.15rem; }

/* ---------- Ligne de mesure auto-enregistrée ---------- */
.dynamic-row.row-saved {
    background: #EEF3EC;
    border: 1px solid #C9DAC6;
    border-radius: var(--radius);
    padding: 0.45rem 0.6rem;
    display: flex;
    align-items: center;
    gap: 1rem;
}
.saved-check { margin-left: auto; font-size: 0.75rem; color: var(--success); font-weight: 600; }

/* ---------- Admin page ---------- */
.admin-users-container { margin-top: 1rem; }
.users-table-wrapper { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-lg); overflow: hidden; }
.users-table { width: 100%; border-collapse: collapse; }
.users-table th {
    text-align: left;
    font-family: var(--font-mono);
    font-size: 0.68rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-muted);
    padding: 0.85rem 1rem;
    border-bottom: 1px solid var(--line);
    background: #F2EFE6;
}
.users-table td { padding: 0.85rem 1rem; border-bottom: 1px solid var(--line); }
.users-table tbody tr:last-child td { border-bottom: none; }
.users-table tbody tr:hover { background: #F2EFE6; }
.text-center { text-align: center; }
.text-error { color: var(--danger); }
