/* Coudama Mini App — Telegram themeParams first, sane fallbacks for a plain browser. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f2f2f7);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --sub: var(--tg-theme-subtitle-text-color, var(--hint));
  --link: var(--tg-theme-link-color, #2481cc);
  --accent: var(--tg-theme-accent-text-color, var(--link));
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --sep: color-mix(in srgb, var(--hint) 22%, transparent);
  --soft: color-mix(in srgb, var(--btn) 12%, transparent);
  --radius: 16px;
  --ok: #2fb35a;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body { font: 15px/1.45 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
       padding: 12px 16px calc(24px + env(safe-area-inset-bottom)); min-height: 100vh;
       -webkit-font-smoothing: antialiased; overscroll-behavior-y: contain; }
button { font: inherit; color: inherit; }
a { color: var(--link); }
.hidden { display: none !important; }
.grow { flex: 1; min-width: 0; }

/* screen transitions */
#view { animation: in .18s ease-out; }
@keyframes in { from { opacity: 0; transform: translateY(6px); } to { opacity: 1; transform: none; } }

h1 { font-size: 24px; line-height: 1.2; margin: 6px 0 4px; letter-spacing: -.3px; }
h2 { font-size: 13px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px;
     color: var(--sub); margin: 20px 4px 8px; }
.lead { color: var(--hint); margin: 0 0 14px; }
.small { font-size: 13px; color: var(--hint); }

.card { background: var(--card); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; }
.card.pad0 { padding: 0; overflow: hidden; }
.rich { white-space: normal; }
.rich b { font-weight: 650; }

/* hero / brand */
.hero { display: flex; align-items: center; gap: 12px; margin: 4px 0 14px; }
.logo { width: 44px; height: 44px; border-radius: 13px; display: grid; place-items: center; font-size: 24px;
        background: linear-gradient(135deg, var(--btn), color-mix(in srgb, var(--btn) 55%, #8e44ff)); color: #fff; }
.hero .t { font-weight: 700; font-size: 19px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 10px; border-radius: 99px;
        background: var(--soft); color: var(--accent); font-size: 12.5px; font-weight: 600; white-space: nowrap; flex: none; }
.pill.gold { background: color-mix(in srgb, #f5b300 18%, transparent); color: #b07d00; }

/* tool tiles */
.tiles { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.tile-btn { border: 0; text-align: left; background: var(--card); border-radius: var(--radius); padding: 14px;
            min-height: 104px; display: flex; flex-direction: column; justify-content: space-between; cursor: pointer;
            transition: transform .12s; }
.tile-btn:active { transform: scale(.97); }
.tile-btn .ic { font-size: 26px; }
.tile-btn .nm { font-weight: 650; }
.tile-btn .ds { font-size: 12.5px; color: var(--hint); }
.tile-btn.wide { grid-column: span 2; flex-direction: row; align-items: center; gap: 14px; min-height: 0;
                 background: linear-gradient(135deg, var(--btn), color-mix(in srgb, var(--btn) 70%, #8e44ff)); color: var(--btn-text); }
.tile-btn.wide .ds { color: color-mix(in srgb, var(--btn-text) 80%, transparent); }
.tile-btn .badge { font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 99px; background: var(--soft); color: var(--accent); align-self: flex-start; }

/* list rows */
.row { display: flex; align-items: center; gap: 12px; padding: 13px 16px; border: 0; width: 100%; background: none;
       text-align: left; cursor: pointer; }
.row + .row { border-top: 1px solid var(--sep); }
.row .ic { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--soft); font-size: 16px; }
.row .grow { flex: 1; min-width: 0; }
.row .val { color: var(--hint); font-size: 14px; }
.row .chev { color: var(--hint); font-size: 18px; }
.row.sel .chev { color: var(--accent); }

/* buttons */
.btn { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; border: 0; border-radius: 14px;
       padding: 14px; font-weight: 650; font-size: 16px; background: var(--btn); color: var(--btn-text); cursor: pointer; }
.btn.secondary { background: var(--soft); color: var(--accent); }
.btn.ghost { background: none; color: var(--link); }
.btn.big { padding: 22px 14px; font-size: 18px; border-radius: 18px; }
.btn:disabled { opacity: .5; }
.btns { display: flex; gap: 10px; } .btns > * { flex: 1; }
.stack > * + * { margin-top: 10px; }
.fallback-main { position: sticky; bottom: 12px; margin-top: 16px; box-shadow: 0 6px 20px rgba(0,0,0,.12); }

/* segmented */
.seg { display: flex; background: var(--bg); border-radius: 11px; padding: 3px; gap: 3px; }
.seg button { flex: 1; border: 0; background: none; padding: 8px 4px; border-radius: 9px; font-size: 14px; cursor: pointer; color: var(--text); }
.seg button.on { background: var(--card); font-weight: 650; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.field { margin-top: 12px; }
.field > label { display: block; font-size: 13px; color: var(--hint); margin: 0 2px 6px; }
.input { width: 100%; padding: 12px; border-radius: 12px; border: 0; background: var(--bg); color: var(--text); font-size: 15px; }

/* page grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(98px, 1fr)); gap: 10px; }
.pg { position: relative; aspect-ratio: 3/4; border-radius: 12px; overflow: hidden; background: var(--bg);
      touch-action: manipulation; user-select: none; cursor: pointer; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.pg img, .pg canvas { position: relative; width: 100%; height: 100%; object-fit: cover; pointer-events: none; display: block; }
.pg .ph { position: absolute; inset: 0; display: grid; place-items: center; font-size: 12px; color: var(--hint); padding: 6px; text-align: center; word-break: break-all; }
.pg .n { position: absolute; left: 6px; top: 6px; background: rgba(0,0,0,.6); color: #fff; font-size: 11px; font-weight: 700; border-radius: 8px; padding: 1px 7px; }
.pg .x { position: absolute; right: 5px; top: 5px; width: 26px; height: 26px; border: 0; border-radius: 13px;
         background: rgba(0,0,0,.55); color: #fff; font-size: 13px; cursor: pointer; }
.pg .ed { position: absolute; right: 6px; bottom: 6px; background: rgba(0,0,0,.55); color: #fff; font-size: 11px; border-radius: 8px; padding: 1px 6px; }
.pg.add { display: grid; place-items: center; border: 2px dashed var(--sep); background: none; box-shadow: none; color: var(--accent); font-size: 30px; }
.ghost-drag { opacity: .35; }

/* pdf list */
.pdf-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; touch-action: manipulation; }
.pdf-item + .pdf-item { border-top: 1px solid var(--sep); }
.pdf-item .th { width: 46px; height: 60px; border-radius: 6px; background: var(--bg); overflow: hidden; flex: none; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.pdf-item .th canvas { width: 100%; height: 100%; object-fit: cover; display: block; }
.pdf-item .grow { flex: 1; min-width: 0; }
.pdf-item .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pdf-item .handle { color: var(--hint); font-size: 20px; padding: 6px; cursor: grab; touch-action: none; }
.pdf-item .x { border: 0; background: none; color: var(--danger); font-size: 18px; padding: 6px; cursor: pointer; }

/* level cards */
.opt { display: flex; gap: 12px; align-items: center; padding: 13px 14px; border-radius: 14px; background: var(--bg);
       border: 2px solid transparent; cursor: pointer; width: 100%; text-align: left; }
.opt + .opt { margin-top: 8px; }
.opt.on { border-color: var(--btn); background: var(--soft); }
.opt .ic { font-size: 22px; }

/* progress / meters */
.meter { height: 8px; border-radius: 4px; background: var(--bg); overflow: hidden; }
.meter > div { height: 100%; background: var(--btn); border-radius: 4px; transition: width .3s; }
.meter.gold > div { background: linear-gradient(90deg, #f5b300, #ff8a00); }
.status { text-align: center; padding: 28px 8px 8px; }
.status .big { font-size: 56px; }
.status .ttl { font-size: 20px; font-weight: 700; margin: 8px 0 4px; }
.spin { width: 54px; height: 54px; margin: 0 auto; border-radius: 50%; border: 5px solid var(--soft); border-top-color: var(--btn); animation: sp 1s linear infinite; }
@keyframes sp { to { transform: rotate(360deg); } }
.sizes { display: flex; justify-content: center; align-items: center; gap: 12px; margin: 14px 0; font-weight: 700; font-size: 18px; }
.sizes .after { color: var(--ok); }

/* empty / camera */
.empty { text-align: center; padding: 18px 8px 6px; }
.empty .big { font-size: 54px; }
.shot { width: 100%; max-height: 58vh; object-fit: contain; border-radius: var(--radius); background: #000; display: block; }

/* editor */
.editor-wrap { background: #000; border-radius: var(--radius); overflow: hidden; height: 58vh; }
.editor-wrap img { display: block; max-width: 100%; }
.tools { display: flex; flex-wrap: wrap; justify-content: space-around; gap: 6px 0; margin: 12px 0; }
.tools button { border: 0; background: var(--card); border-radius: 14px; padding: 10px 0; width: 23%; font-size: 12px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.tools button span { font-size: 20px; }
.tools button.danger { color: var(--danger); }
.tools button.on { background: var(--soft); box-shadow: inset 0 0 0 2px var(--btn); }

/* toast */
#toast { position: fixed; left: 16px; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 50; padding: 12px 14px;
         border-radius: 14px; background: rgba(20,20,22,.92); color: #fff; font-size: 14px; text-align: center;
         transform: translateY(160%); opacity: 0; transition: transform .25s, opacity .25s; pointer-events: none; }
#toast.on { transform: none; opacity: 1; }
#toast.err { background: color-mix(in srgb, var(--danger) 92%, #000); }

footer { margin-top: 28px; text-align: center; font-size: 12px; color: var(--hint); }
footer a { color: var(--hint); text-decoration: none; }

/* scanner steps (Ajuster / Résultat): photo fills the viewport, one compact toolbar */
.scan-step { margin: -4px -8px 0; }
.stage-wrap { position: relative; display: flex; justify-content: center; }
.stage { display: block; touch-action: none; user-select: none; -webkit-user-select: none; max-width: 100%; }
.mini { position: absolute; right: 10px; bottom: 10px; pointer-events: none; transition: opacity .15s; }
.stage-wrap.dragging .mini { opacity: 0; }
.mini canvas { display: block; max-width: 72px; max-height: 96px; border-radius: 6px; background: #fff;
               box-shadow: 0 2px 8px rgba(0,0,0,.35); border: 2px solid #fff; }
.toolbar { display: flex; justify-content: space-between; gap: 4px; margin: 6px 4px 0; }
.toolbar button { flex: 1; min-width: 0; min-height: 52px; border: 0; background: none; border-radius: 12px; padding: 4px 0;
                  font-size: 11px; color: var(--text); cursor: pointer; display: flex; flex-direction: column; align-items: center;
                  justify-content: center; gap: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.toolbar button span { font-size: 20px; line-height: 1.2; }
.toolbar button:active { background: var(--soft); }
.toolbar button.on { background: var(--soft); color: var(--accent); box-shadow: inset 0 0 0 1.5px var(--btn); }
.toolbar button.danger { color: var(--danger); }
.scan-step .hint { text-align: center; margin: 4px 8px 0; font-size: 12px; }
.result-wrap { display: flex; align-items: center; justify-content: center; }
.result-wrap canvas { display: block; width: 100%; height: 100%; object-fit: contain; border-radius: 8px;
                      box-shadow: 0 2px 12px rgba(0,0,0,.18); }
html, body { overflow-x: hidden; }

/* ===================== home v3: header + "Créer" + "Mes documents" ===================== */
:root { --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 14px rgba(0,0,0,.05); }
.home { padding-top: 2px; }
.top { display: flex; align-items: center; gap: 10px; margin: 2px 0 18px; }
.top .logo { width: 36px; height: 36px; border-radius: 11px; font-size: 19px; }
.top .brand { font-weight: 700; font-size: 18px; letter-spacing: -.2px; }
.icon-btn { width: 36px; height: 36px; border: 0; border-radius: 12px; background: var(--card); color: var(--text);
            font-size: 20px; line-height: 1; cursor: pointer; box-shadow: var(--shadow); flex: none; }
.block { margin-bottom: 22px; }
.block h2 { margin: 0 4px 10px; }
.block-head { display: flex; align-items: baseline; justify-content: space-between; margin: 0 4px 10px; }
.block-head h2 { margin: 0; }
button.link { border: 0; background: none; color: var(--link); font-size: 14px; font-weight: 600; padding: 4px 2px; cursor: pointer; }
.qa-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.qa { border: 0; background: var(--card); border-radius: 18px; padding: 16px 14px 14px; min-height: 112px; text-align: left;
      display: flex; flex-direction: column; align-items: flex-start; gap: 2px; cursor: pointer; box-shadow: var(--shadow);
      transition: transform .12s; }
.qa:active { transform: scale(.97); }
.qa-ic { width: 42px; height: 42px; border-radius: 13px; display: grid; place-items: center; font-size: 22px;
         background: var(--soft); margin-bottom: 8px; }
.qa-nm { font-weight: 650; font-size: 15px; }
.qa-ds { font-size: 12.5px; color: var(--hint); }
.a2hs { display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow); }
.a2hs .ic { font-size: 24px; }
.btn.sm { width: auto; padding: 8px 14px; font-size: 14px; border-radius: 11px; }

/* recent strip */
.strip { display: flex; gap: 12px; overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -16px; padding: 2px 16px 8px; scroll-padding: 0 16px;
         scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.dcard { flex: none; width: 116px; border: 0; background: var(--card); border-radius: 16px; padding: 8px; text-align: left;
         scroll-snap-align: start; cursor: pointer; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 6px; }
.dcard.skeleton { height: 196px; background: color-mix(in srgb, var(--card) 70%, var(--bg)); box-shadow: none; }
.dcard .nm { font-size: 12.5px; font-weight: 600; line-height: 1.25; max-height: 2.5em; overflow: hidden;
             display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; word-break: break-word; }
.dthumb { position: relative; width: 100%; aspect-ratio: 3/4; border-radius: 10px; overflow: hidden; background: var(--bg);
          display: grid; place-items: center; }
.dthumb img, .dthumb canvas { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; background: #fff; }
.dthumb .ph { font-size: 26px; opacity: .5; }
.badge { display: inline-block; align-self: flex-start; font-size: 11px; font-weight: 650; padding: 2px 8px; border-radius: 99px;
         background: var(--soft); color: var(--accent); white-space: nowrap; }
.badge.warn { background: color-mix(in srgb, var(--danger) 14%, transparent); color: var(--danger); }
.soft-empty { display: flex; align-items: center; gap: 12px; box-shadow: var(--shadow); }
.soft-empty .ic { font-size: 24px; }

.foot-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 2px 14px; margin: 26px 0 0; }
.foot-links button.link { color: var(--hint); font-weight: 500; font-size: 13px; }

/* manager */
.docs-head { display: flex; align-items: center; gap: 10px; }
.mini-seg { flex: none; }
.mini-seg button { width: 38px; padding: 6px 0; font-size: 15px; }
.docs { margin-top: 12px; }
.docs.v-list { background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.docs .doc { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; background: none; text-align: left;
             padding: 10px 12px; cursor: pointer; color: var(--text); }
.docs.v-list .doc + .doc { border-top: 1px solid var(--sep); }
.docs.v-list .dthumb { width: 48px; flex: none; border-radius: 7px; box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.docs .meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.docs .nm { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.docs .more { color: var(--hint); font-size: 20px; padding: 0 2px; }
.docs.v-grid { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 12px; }
.docs.v-grid .doc { flex-direction: column; align-items: stretch; background: var(--card); border-radius: 16px; padding: 8px;
                  box-shadow: var(--shadow); }
.docs.v-grid .nm { font-size: 13px; }
.usage { margin: 16px 4px 0; }
.usage .small { margin-top: 6px; text-align: center; }
.ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pages { display: flex; flex-direction: column; align-items: center; gap: 12px; margin-top: 12px; }
.pages .page canvas { display: block; max-width: 100%; border-radius: 6px; background: #fff; box-shadow: var(--shadow); }
.btn.ghost.danger { color: var(--danger); }

/* bottom sheet */
.sheet-bg { position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,0); transition: background .2s;
            display: flex; align-items: flex-end; }
.sheet-bg.on { background: rgba(0,0,0,.35); }
.sheet { width: 100%; max-height: 86vh; overflow-y: auto; background: var(--card); border-radius: 20px 20px 0 0;
         padding: 6px 8px calc(14px + env(safe-area-inset-bottom)); transform: translateY(100%); transition: transform .22s ease-out; }
.sheet-bg.on .sheet { transform: none; }
.grip { width: 38px; height: 5px; border-radius: 3px; background: var(--sep); margin: 4px auto 8px; }
.sheet-title { font-weight: 650; padding: 4px 12px 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sheet-meta { font-size: 13px; color: var(--hint); padding: 2px 12px 8px; }
.sheet-body { padding: 10px 8px 4px; }
.sheet-row { display: flex; align-items: center; gap: 12px; width: 100%; border: 0; background: none; color: var(--text);
             text-align: left; padding: 12px; border-radius: 12px; cursor: pointer; font-size: 15px; }
.sheet-row:active { background: var(--soft); }
.sheet-row .ic { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; background: var(--soft); font-size: 16px; flex: none; }
.sheet-row .val { color: var(--hint); font-size: 13px; }
.sheet-row .chev { color: var(--hint); font-size: 18px; }
.sheet-row.danger { color: var(--danger); }
.sheet-row.danger .ic { background: color-mix(in srgb, var(--danger) 12%, transparent); }
.sheet-row.off { opacity: .55; cursor: default; }

/* home mode switcher (js/modes.js): calm segmented control; not-yet modes greyed */
.seg { display: flex; gap: 2px; padding: 3px; margin: -6px 0 18px; border-radius: 13px; background: color-mix(in srgb, var(--hint) 14%, transparent); }
.seg-btn { flex: 1; min-width: 0; display: flex; align-items: center; justify-content: center; gap: 6px; padding: 7px 6px;
           border: 0; border-radius: 10px; background: none; color: var(--text); font-size: 14px; font-weight: 550;
           white-space: nowrap; cursor: pointer; transition: background .15s, box-shadow .15s; }
.seg-btn.on { background: var(--card); box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.seg-btn.off { color: var(--hint); }
.seg-btn.off .seg-ic { filter: grayscale(1); opacity: .6; }
.seg-ic { font-size: 15px; }
.soon-sheet { text-align: center; padding: 6px 12px 8px; }
.soon-sheet .soon-ic { font-size: 34px; margin-bottom: 4px; filter: grayscale(.3); }
.soon-sheet p { margin: 4px 0 16px; }

/* photo editor: loader, filter strip + intensity */
.loader { position: fixed; inset: 0; z-index: 1100; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; background: var(--bg); color: var(--hint); animation: in .15s ease; }
.filter-view { display: block; max-width: 100%; max-height: 100%; margin: 0 auto; object-fit: contain; border-radius: 8px; background: #fff; }
.filter-panel { margin-top: 8px; }
.filter-strip { display: flex; gap: 8px; overflow-x: auto; padding: 4px 2px 6px; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.filter-strip::-webkit-scrollbar { display: none; }
.filter-item { flex: 0 0 auto; width: 68px; border: 0; background: none; padding: 0; color: var(--text); font-size: 11.5px; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 4px; }
.filter-item canvas { width: 60px; height: 60px; object-fit: cover; border-radius: 10px; border: 2px solid transparent; background: var(--soft); }
.filter-item.on canvas { border-color: var(--btn); }
.filter-item.on span { font-weight: 650; color: var(--btn); }
.filter-strength { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--hint); padding: 2px 4px; transition: opacity .15s; }
.filter-strength.off { opacity: .35; }
.filter-strength .range { flex: 1; accent-color: var(--btn); min-height: 32px; }
.filter-strength .val { min-width: 42px; text-align: right; font-variant-numeric: tabular-nums; }
