:root {
    --bg: #0f172a;
    --card: #1e293b;
    --text: #e2e8f0;
    --muted: #94a3b8;
    --accent: #22c55e;
    --accent-hover: #16a34a;
    --danger: #f87171;
    --border: #334155;
    --tap: 44px;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

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

a, button, input, select, textarea, summary {
    font-size: 16px; /* évite le zoom auto iOS */
}

.auth-body {
    min-height: 100vh;
    min-height: 100dvh;
    display: grid;
    place-items: center;
    padding: max(1rem, env(safe-area-inset-top)) 1rem max(1rem, env(safe-area-inset-bottom));
}

.auth-card {
    width: min(420px, 100%);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.4rem;
}

h1 { margin: 0 0 .4rem; font-size: clamp(1.25rem, 4vw, 1.6rem); }
.subtitle { margin: 0 0 1.1rem; color: var(--muted); }

label { display: block; margin: .75rem 0 .35rem; font-size: .9rem; }

input[type="text"],
input[type="password"],
input[type="email"],
input[type="search"],
select,
textarea {
    width: 100%;
    min-height: var(--tap);
    padding: .7rem .8rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #0b1220;
    color: var(--text);
}

button {
    margin-top: 1.1rem;
    width: 100%;
    min-height: var(--tap);
    padding: .8rem;
    border: 0;
    border-radius: 8px;
    background: var(--accent);
    color: #052e16;
    font-weight: 700;
    cursor: pointer;
}

button:hover { background: var(--accent-hover); }

.alert {
    background: #3f1d1d;
    color: var(--danger);
    border: 1px solid #7f1d1d;
    padding: .7rem .8rem;
    border-radius: 8px;
    margin-bottom: 1rem;
}

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

.topbar {
    position: sticky;
    top: 0;
    z-index: 40;
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: .65rem 1rem;
    padding-top: max(.65rem, env(safe-area-inset-top));
}

.topbar-main {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: .75rem;
}

.brand { font-size: 1.05rem; }

.nav-toggle { position: absolute; opacity: 0; pointer-events: none; }

.nav-burger {
    width: var(--tap);
    height: var(--tap);
    display: none;
    place-items: center;
    gap: 5px;
    flex-direction: column;
    cursor: pointer;
    border-radius: 8px;
    border: 1px solid var(--border);
}

.nav-burger span {
    display: block;
    width: 18px;
    height: 2px;
    background: var(--text);
}

.topnav {
    display: flex;
    gap: .75rem 1rem;
    align-items: center;
    flex-wrap: wrap;
    margin-top: .55rem;
}

.topnav > a,
.menu summary {
    color: var(--accent);
    text-decoration: none;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
}

.who { color: var(--muted); font-size: .9rem; }

.menu { position: relative; }
.menu summary {
    list-style: none;
    cursor: pointer;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .25rem .6rem;
}
.menu summary::-webkit-details-marker { display: none; }

.menu-list {
    position: absolute;
    top: calc(100% + 4px);
    inset-inline-start: 0;
    min-width: 200px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .35rem 0;
    z-index: 30;
}

.menu-list a {
    display: block;
    padding: .7rem .9rem;
    color: var(--text);
    text-decoration: none;
}
.menu-list a:hover { background: #0b1220; color: var(--accent); }

.page { padding: 1rem; max-width: 800px; margin: 0 auto; }
.page-wide { max-width: 1100px; }

.lang-switch { display: inline-flex; gap: .4rem; }
.lang-switch a {
    color: var(--muted);
    text-decoration: none;
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .35rem .55rem;
    min-height: 36px;
    display: inline-flex;
    align-items: center;
}
.lang-switch a.active { color: var(--accent); border-color: var(--accent); }

.auth-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 1rem; gap: .5rem; }

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 1rem;
    margin: 1rem 0 1.5rem;
}
.card h2 { margin-top: 0; font-size: 1.1rem; }

.grid-form { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem 1rem; }
.grid-form textarea,
.grid-form input,
.grid-form select { width: 100%; }

.filter-bar { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin: .5rem 0 1rem; }
.filter-bar select, .filter-bar button { width: auto; margin: 0; min-height: var(--tap); }
.filter-bar select {
    flex: 1 1 180px;
    padding: .55rem .7rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: #0b1220;
    color: var(--text);
}

.check-row { display: flex; align-items: end; }
.check-row label { display: flex; gap: .45rem; align-items: center; min-height: var(--tap); }
.form-actions { grid-column: 1 / -1; display: flex; gap: .8rem; align-items: center; flex-wrap: wrap; }
.form-actions button { width: auto; margin-top: 0; padding: .7rem 1.2rem; }
.btn, .btn-link {
    color: var(--accent);
    text-decoration: none;
    min-height: var(--tap);
    display: inline-flex;
    align-items: center;
}
.alert-ok { background: #052e16; color: #86efac; border-color: #166534; }

.table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin-inline: -.25rem;
}
table.data { width: 100%; min-width: 640px; border-collapse: collapse; font-size: .92rem; }
table.data th, table.data td { border-bottom: 1px solid var(--border); padding: .65rem .45rem; text-align: start; }
.actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
form.inline { display: inline; }
button.linkish {
    width: auto;
    margin: 0;
    padding: .35rem .2rem;
    min-height: 36px;
    background: none;
    color: var(--accent);
    font-weight: 600;
}

html[dir="rtl"] body {
    font-family: "Noto Naskh Arabic", "Tahoma", system-ui, sans-serif;
}

@media (max-width: 860px) {
    .nav-burger { display: grid; }
    .topnav {
        display: none;
        flex-direction: column;
        align-items: stretch;
        gap: .15rem;
        margin-top: .7rem;
    }
    .nav-toggle:checked ~ .topnav { display: flex; }
    .topnav > a,
    .menu summary,
    .who,
    .lang-switch {
        width: 100%;
        min-height: var(--tap);
    }
    .menu-list {
        position: static;
        border: 0;
        padding-inline-start: .6rem;
    }
    .grid-form { grid-template-columns: 1fr; }
    .form-actions button,
    .filter-bar button,
    .filter-bar .btn { width: 100%; justify-content: center; }
    .page { padding: .85rem; }
    table.data { min-width: 520px; }
}

@media (max-width: 480px) {
    .auth-card { padding: 1.1rem; border-radius: 12px; }
    .who { display: none; }
}

.cal {
    display: grid;
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 4px;
}
.cal-head {
    text-align: center;
    color: var(--muted);
    font-size: .75rem;
    padding: .3rem 0;
}
.cal-cell {
    min-height: 92px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: .3rem;
}
.cal-cell.empty { background: transparent; border-color: transparent; }
.cal-cell.today { border-color: var(--accent); }
.cal-num { display: flex; justify-content: space-between; align-items: center; font-size: .8rem; margin-bottom: .2rem; }
.cal-add { color: var(--accent); text-decoration: none; font-weight: 700; padding: 0 .25rem; }
.cal-tag {
    display: block;
    font-size: .68rem;
    line-height: 1.2;
    padding: .15rem .25rem;
    border-radius: 4px;
    margin-bottom: .2rem;
    text-decoration: none;
    color: #052e16;
    background: #86efac;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.type-herbicide { background: #86efac; }
.type-pesticide, .type-insecticide { background: #fde047; }
.type-fungicide { background: #93c5fd; }
.type-acaricide { background: #fdba74; }
.type-nematicide { background: #c4b5fd; }
.type-foliar { background: #6ee7b7; }
.type-other { background: #cbd5e1; }

@media (max-width: 720px) {
    .cal { gap: 3px; }
    .cal-cell { min-height: 74px; padding: .2rem; }
    .cal-tag { font-size: .62rem; }
}
