:root {
    --bg: #f6f5f3;
    --surface: #ffffff;
    --text: #22201c;
    --muted: #6f6a62;
    --line: #e4e1dc;
    --primary: #d9480f;
    --primary-dark: #b33a0b;
    --green: #2b8a3e;
    --green-bg: #e6f4ea;
    --blue: #1c6bd1;
    --blue-bg: #e7f0fc;
    --amber: #b06000;
    --amber-bg: #fff3dc;
    --red: #c92a2a;
    --red-bg: #fde8e8;
    --grey-bg: #efedea;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(0, 0, 0, .05);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.45;
    color: var(--text);
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); }
a { color: var(--primary-dark); }
h1 { font-size: 1.6rem; margin: .2em 0 .6em; }
h2 { font-size: 1.15rem; margin: 0 0 .6em; display: flex; align-items: center; gap: .5em; flex-wrap: wrap; }
h3 { font-size: 1rem; margin: 1em 0 .5em; }
code, .mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .9em; }
pre { white-space: pre-wrap; word-break: break-word; max-height: 400px; overflow: auto; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.red { color: var(--red); }
.warn { color: var(--amber); font-weight: 600; }
.nowrap { white-space: nowrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
[hidden] { display: none !important; }

/* En-tête */
.topbar {
    display: flex; align-items: center; gap: 1.5rem; flex-wrap: wrap;
    background: var(--surface); border-bottom: 1px solid var(--line); padding: .6rem 1.5rem;
    position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 800; font-size: 1.15rem; text-decoration: none; color: var(--text); letter-spacing: -.01em; }
.brand span { color: var(--primary); }
.nav { display: flex; gap: .2rem; flex-wrap: wrap; }
.nav a { text-decoration: none; color: var(--muted); padding: .35rem .65rem; border-radius: 6px; }
.nav a:hover { background: var(--grey-bg); color: var(--text); }
.nav a.active { background: var(--grey-bg); color: var(--text); font-weight: 600; }
.topbar-right { margin-left: auto; display: flex; align-items: center; gap: .8rem; }
.mode-form select { font-weight: 600; border-radius: 999px; padding: .25rem .8rem; border: 1px solid transparent; }
.mode-grey select { background: var(--grey-bg); }
.mode-blue select { background: var(--blue-bg); color: var(--blue); }
.mode-amber select { background: var(--amber-bg); color: var(--amber); }
.mode-green select { background: var(--green-bg); color: var(--green); }

.container { max-width: 1180px; margin: 0 auto; padding: 1.2rem 1.5rem 3rem; }
.narrow { max-width: 680px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 1rem; flex-wrap: wrap; margin-bottom: .8rem; }
.page-head h1 { margin-bottom: .2em; }
.crumbs { margin: 0; color: var(--muted); font-size: .9rem; }
.crumbs a { color: var(--muted); }
.section-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; flex-wrap: wrap; margin-bottom: .4rem; }
.section-head h2 { margin: 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.actions form { margin: 0; }
.inline { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.row-between { justify-content: space-between; padding: .6rem 0; border-bottom: 1px solid var(--line); }
.row-between:last-child { border-bottom: 0; }

/* Cartes et grilles */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.1rem 1.25rem; margin-bottom: 1rem; box-shadow: var(--shadow); }
.card-flush { padding: 0; overflow-x: auto; }
.card-todo { border-color: #f5c38b; background: #fffaf2; }
.card-todo ul { margin: 0; padding-left: 1.2rem; }
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); }
.grid > .card { margin-bottom: 0; }
.grid + .card, .card + .grid { margin-top: 1rem; }
.big { font-size: 1.3rem; margin: .2em 0; }
.list { margin: 0; padding-left: 1.1rem; }
.list li { margin-bottom: .3rem; }

/* Statistiques */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: .6rem; margin: 0; }
.stats div { background: var(--bg); border-radius: 8px; padding: .5rem .7rem; }
.stats dt { color: var(--muted); font-size: .8rem; }
.stats dd { margin: 0; font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.stats-inline { margin-top: 1rem; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-all; }

/* Badges */
.badge { display: inline-block; font-size: .78rem; font-weight: 600; padding: .1rem .5rem; border-radius: 999px; white-space: nowrap; vertical-align: middle; }
.badge-grey { background: var(--grey-bg); color: var(--muted); }
.badge-blue { background: var(--blue-bg); color: var(--blue); }
.badge-green { background: var(--green-bg); color: var(--green); }
.badge-amber { background: var(--amber-bg); color: var(--amber); }
.badge-red { background: var(--red-bg); color: var(--red); }
.net { font-weight: 700; font-size: .85rem; }
.net-instagram { color: #c13584; }
.net-facebook { color: #1877f2; }

/* Messages */
.flash { padding: .7rem 1rem; border-radius: 8px; margin-bottom: .8rem; border: 1px solid transparent; }
.flash-success { background: var(--green-bg); border-color: #b7dfc1; }
.flash-error { background: var(--red-bg); border-color: #f3b9b9; }
.flash-warning { background: var(--amber-bg); border-color: #f5d199; }
.problems { background: var(--amber-bg); border-radius: 8px; padding: .6rem .9rem; margin-top: .8rem; font-size: .9rem; }
.problems ul { margin: .3rem 0 0; padding-left: 1.1rem; }

/* Tableaux */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .55rem .7rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.table thead th { font-size: .8rem; color: var(--muted); font-weight: 600; background: #faf9f7; }
.table tfoot th { background: #faf9f7; }
.table tr:last-child td { border-bottom: 0; }
.table tr.inactive td { opacity: .55; }
.table .num { text-align: right; }
.cell-thumb { width: 56px; }
.cell-thumb img { width: 48px; height: 60px; object-fit: cover; border-radius: 6px; display: block; }

/* Formulaires */
.form label { display: block; margin-bottom: .8rem; font-weight: 600; font-size: .9rem; }
.form label.check, label.check { font-weight: 400; display: flex; gap: .5rem; align-items: baseline; margin-bottom: .5rem; }
input[type=text], input[type=search], input[type=password], input[type=number], input[type=email], input[type=datetime-local], select, textarea {
    width: 100%; font: inherit; font-weight: 400; padding: .5rem .65rem; border: 1px solid #d6d2cc; border-radius: 8px; background: #fff; color: var(--text); margin-top: .25rem;
}
.inline input, .inline select { width: auto; flex: 1; margin-top: 0; }
textarea { resize: vertical; }
textarea[readonly] { background: #f7f6f4; color: var(--muted); }
input:focus, select:focus, textarea:focus { outline: 2px solid #f8b58a; border-color: var(--primary); }
fieldset.toggles { border: 1px solid var(--line); border-radius: 8px; padding: .6rem .9rem; margin: 0; }
fieldset.toggles legend { font-weight: 600; font-size: .9rem; padding: 0 .3rem; }
.radios label { margin-bottom: .4rem; }
.filters { display: flex; gap: .6rem; align-items: center; margin-bottom: .8rem; flex-wrap: wrap; }
.filters select { width: auto; margin: 0; }
.filters form { margin: 0; }
.counter { display: block; text-align: right; font-size: .8rem; color: var(--muted); font-weight: 400; margin-top: .2rem; }
.counter.over { color: var(--red); font-weight: 700; }
.secret code { font-size: 1.1rem; letter-spacing: .05em; background: var(--grey-bg); padding: .3rem .6rem; border-radius: 6px; }

/* Boutons */
.btn {
    display: inline-flex; align-items: center; gap: .3rem; font: inherit; font-weight: 600; font-size: .9rem; text-decoration: none; cursor: pointer;
    padding: .45rem .9rem; border-radius: 8px; border: 1px solid #d6d2cc; background: #fff; color: var(--text);
}
.btn:hover { background: #f4f2ef; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { color: var(--red); border-color: #f0c2c2; }
.btn-danger:hover { background: var(--red-bg); }
.btn-small { padding: .25rem .6rem; font-size: .82rem; }
button.link { background: none; border: 0; color: var(--muted); cursor: pointer; font: inherit; padding: 0; text-decoration: underline; }

/* Onglets */
.tabs { display: flex; gap: .2rem; background: var(--grey-bg); padding: .2rem; border-radius: 9px; }
.tabs a { text-decoration: none; color: var(--muted); padding: .3rem .8rem; border-radius: 7px; font-size: .9rem; }
.tabs a.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: var(--shadow); }
.pager { display: flex; gap: .5rem; }

/* Sélecteur de recette */
.recipe-picker { margin: .25rem 0 .9rem; position: relative; }
.recipe-selected { display: flex; align-items: center; gap: .8rem; border: 1px solid var(--line); border-radius: 8px; padding: .5rem; }
.recipe-selected img { width: 64px; height: 48px; object-fit: cover; border-radius: 6px; background: var(--grey-bg); }
.recipe-selected div { flex: 1; display: flex; flex-direction: column; }
.recipe-results { list-style: none; margin: .2rem 0 0; padding: 0; border: 1px solid var(--line); border-radius: 8px; background: #fff; max-height: 320px; overflow: auto; position: absolute; left: 0; right: 0; z-index: 5; box-shadow: 0 6px 16px rgba(0, 0, 0, .08); }
.recipe-results:empty { display: none; }
.recipe-results li { display: flex; gap: .6rem; align-items: center; padding: .4rem .6rem; cursor: pointer; font-weight: 400; }
.recipe-results li:hover, .recipe-results li.active { background: var(--grey-bg); }
.recipe-results img { width: 44px; height: 33px; object-fit: cover; border-radius: 4px; }

.keyword-test { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
.keyword-test input { flex: 1; margin: 0; min-width: 200px; }

/* Carrousel */
.carousel { list-style: none; padding: 0; margin: .6rem 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: .9rem; }
.carousel-item { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: #fff; display: flex; flex-direction: column; }
.carousel-item img { width: 100%; aspect-ratio: 4 / 5; object-fit: cover; display: block; background: var(--grey-bg); }
.carousel-meta { display: flex; gap: .4rem; align-items: center; padding: .4rem .5rem 0; }
.carousel-actions { display: flex; gap: .3rem; padding: .4rem .5rem .5rem; flex-wrap: wrap; }
.carousel-warning { margin: .3rem .5rem 0; font-size: .78rem; color: var(--amber); font-weight: 600; }
.carousel-actions form { margin: 0; }

/* Aperçus */
.preview summary { cursor: pointer; font-weight: 600; margin-top: .8rem; }
.bubble { background: #f1f0ee; border-radius: 14px; padding: .55rem .8rem; margin-bottom: .5rem; font-size: .92rem; white-space: normal; word-break: break-word; }
.bubble:empty { display: none; }
.bubble-public { background: #fff; border: 1px solid var(--line); }

/* Fenêtres */
.dialog { border: 0; border-radius: 14px; padding: 1.2rem; width: min(440px, 94vw); box-shadow: 0 20px 50px rgba(0, 0, 0, .25); }
.dialog-wide { width: min(1100px, 96vw); }
.dialog::backdrop { background: rgba(30, 25, 20, .45); }
.dialog-head { display: flex; align-items: center; gap: 1rem; margin-bottom: .6rem; flex-wrap: wrap; }
.dialog-head h2 { margin: 0; }
.dialog-head .actions { margin-left: auto; }
.photo-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: .8rem; max-height: 70vh; overflow: auto; padding: .2rem; }
.photo-card { border: 2px solid transparent; border-radius: 10px; overflow: hidden; background: #fff; box-shadow: 0 0 0 1px var(--line); cursor: pointer; text-align: left; padding: 0; font: inherit; display: flex; flex-direction: column; }
.photo-card:hover { box-shadow: 0 0 0 2px var(--primary); }
.photo-card.added { border-color: var(--green); cursor: default; }
.photo-card img { width: 100%; aspect-ratio: 1; object-fit: cover; display: block; background: var(--grey-bg); }
.photo-card .meta { padding: .35rem .5rem .5rem; font-size: .8rem; }
.photo-card .likes { font-weight: 700; }
.photo-card .state { font-size: .78rem; font-weight: 700; color: var(--green); }

.crop-viewport { width: 100%; max-width: 380px; aspect-ratio: 4 / 5; margin: 0 auto; overflow: hidden; position: relative; border-radius: 8px; background: #222; cursor: grab; touch-action: none; }
.crop-viewport:active { cursor: grabbing; }
.crop-viewport img { position: absolute; top: 0; left: 0; transform-origin: 0 0; max-width: none; user-select: none; -webkit-user-drag: none; }
.crop-zoom { display: flex; gap: .6rem; align-items: center; margin: .8rem 0 .2rem; font-weight: 600; }
.crop-zoom input { flex: 1; }

/* Import */
.import-list { display: grid; gap: 1rem; }
.import-item { display: flex; gap: 1rem; margin: 0; }
.import-item > img { width: 120px; height: 150px; object-fit: cover; border-radius: 8px; flex-shrink: 0; background: var(--grey-bg); }
.import-body { flex: 1; min-width: 0; }
.import-body p { margin: 0 0 .5rem; }

/* Pages publiques */
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 1rem; }
.login-card { width: min(380px, 100%); }
.login-card .brand { display: block; text-align: center; font-size: 1.5rem; margin-bottom: 1rem; }
.login-card label { display: block; font-weight: 600; font-size: .9rem; margin-bottom: .8rem; }
.login-card .btn { width: 100%; justify-content: center; margin-top: .4rem; }
.public-page .container { padding-top: 2rem; }

@media (max-width: 700px) {
    .topbar { padding: .6rem 1rem; gap: .6rem; }
    .container { padding: 1rem; }
    .import-item { flex-direction: column; }
}
