/* Change — web app. Thème clair par défaut, thème sombre via .theme-dark sur <html>. */

@font-face { font-family: "Fredoka"; font-weight: 600; font-display: swap; src: url(fonts/Fredoka-SemiBold.woff2) format("woff2"); }
@font-face { font-family: "Fredoka"; font-weight: 500; font-display: swap; src: url(fonts/Fredoka-Medium.woff2) format("woff2"); }
@font-face { font-family: "Nunito"; font-weight: 600; font-display: swap; src: url(fonts/Nunito-SemiBold.woff2) format("woff2"); }
@font-face { font-family: "Nunito"; font-weight: 800; font-display: swap; src: url(fonts/Nunito-ExtraBold.woff2) format("woff2"); }

:root {
  --bg: #EEF3F0;            /* papier fiduciaire */
  --key: #FFFFFF;
  --key-op: #DCE6E2;
  --key-pressed: #C8D5D0;
  --line: rgba(18, 38, 43, .13);
  --text: #12262B;
  --muted: #5B7174;
  --accent: #96670A;        /* ocre, lisible sur fond clair */
  --equals: #E9B949;        /* dorure */
  --equals-pressed: #D4A436;
  --on-equals: #12262B;
  --clear: #C2553A;
  --card: #12262B;          /* la ligne de saisie : un « billet » encre */
  --on-card: #EEF3F0;
  --on-card-muted: #9DB3B1;
  --card-lines: #E6EDE8;
  --card-lines-alpha: .18;
  --caret: #E9B949;
  --ring: rgba(18, 38, 43, .35);
  --grip: rgba(18, 38, 43, .2);
  --scrim: rgba(18, 38, 43, .45);
  --num: "Fredoka", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --txt: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

.theme-dark {
  --bg: #12262B;            /* encre bleu-vert */
  --key: #19323A;
  --key-op: #224149;
  --key-pressed: #2B4D56;
  --line: rgba(230, 237, 232, .15);
  --text: #E6EDE8;
  --muted: #8FA7A6;
  --accent: #E9B949;
  --equals: #E9B949;
  --equals-pressed: #C99A2E;
  --on-equals: #12262B;
  --clear: #E58A6B;
  --card: #E6EDE8;          /* la ligne de saisie : un « billet » clair */
  --on-card: #12262B;
  --on-card-muted: #4A6669;
  --card-lines: #12262B;
  --card-lines-alpha: .14;
  --caret: #C99A2E;
  --ring: rgba(230, 237, 232, .5);
  --grip: rgba(230, 237, 232, .25);
  --scrim: rgba(0, 0, 0, .55);
  color-scheme: dark;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: var(--txt);
  font-weight: 600;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}

body {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
}

button:focus { outline: none; }
button:focus-visible, .row:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

svg { stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------------ Cadre */

#app {
  position: fixed;
  top: 0; right: 0; bottom: 0; left: 0;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  max-width: 480px;
  margin: 0 auto;
}

.hdr { display: flex; align-items: center; padding: 10px 8px 8px 22px; flex: none; }
.tc { flex: 1; min-width: 0; }
.title { font-family: var(--num); font-weight: 600; font-size: 30px; line-height: 1; color: var(--text); }

.status {
  display: flex; align-items: center; margin-top: 6px; max-width: 100%;
  font-size: 12.5px; color: var(--muted); text-align: left;
}
.status span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status .dot { width: 7px; height: 7px; border-radius: 4px; background: var(--muted); margin-right: 7px; flex: none; }
.status.offline { color: var(--clear); }
.status.offline .dot { background: var(--clear); }
.status.loading .dot { background: var(--equals); }

.ib {
  width: 48px; height: 48px; border-radius: 24px; flex: none;
  display: flex; align-items: center; justify-content: center; color: var(--text);
}
.ib:active { background: var(--key-pressed); }
#refreshBtn.spin svg { animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.content { flex: 1; display: flex; flex-direction: column; min-height: 0; }

/* ------------------------------------------------------------------ Lignes de devises */

.rows { flex: 1 1 0; display: flex; flex-direction: column; padding: 4px 10px 6px; min-height: 0; }

.row {
  flex: 1 1 0; min-height: 0; margin: 2px 0; position: relative;
  display: flex; align-items: center; padding: 0 14px 0 12px; border-radius: 20px;
  cursor: pointer; overflow: hidden;
}
.row.div::after {
  content: ""; position: absolute; left: 12px; right: 12px; bottom: 0; height: 1px; background: var(--line);
}
.row.active { background: var(--card); cursor: default; }
.row .g { position: absolute; top: 0; left: 0; pointer-events: none; }
.row.copied { animation: flash .5s ease-out; }
@keyframes flash { from { box-shadow: inset 0 0 0 2px var(--equals); } to { box-shadow: inset 0 0 0 2px transparent; } }

.pick {
  position: relative; display: flex; align-items: center; max-width: 50%; min-width: 0;
  padding: 6px 8px 6px 0; text-align: left; border-radius: 14px;
}
.badge {
  width: 42px; height: 42px; border-radius: 50%; flex: none; margin-right: 12px;
  border: 1.2px solid var(--ring); color: var(--text);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--txt); font-weight: 800; line-height: 1; white-space: nowrap;
}
.active .badge { background: var(--on-card); border-color: var(--on-card); color: var(--card); }
.names { min-width: 0; display: block; }
.code { font-weight: 800; font-size: 17px; line-height: 1; color: var(--text); display: flex; align-items: center; }
.code svg { width: 16px; height: 16px; margin-left: 2px; stroke-width: 2.6; opacity: .75; flex: none; }
.name {
  display: block; margin-top: 4px; font-size: 12.5px; line-height: 1.15; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.active .code { color: var(--on-card); }
.active .name, .active .sub { color: var(--on-card-muted); }

.right {
  position: relative; flex: 1; min-width: 0; height: 100%;
  display: flex; flex-direction: column; align-items: flex-end; justify-content: center; padding: 8px 0;
}
.val {
  flex: 1; min-height: 0; width: 100%;
  display: flex; align-items: center; justify-content: flex-end;
  font-family: var(--num); font-weight: 600; line-height: 1; white-space: nowrap; color: var(--text);
  overflow: hidden;
}
.val .num { display: inline-block; }
.val .op { font-weight: 500; font-size: .82em; position: relative; top: -.03em; }
.active .val { color: var(--on-card); }
.caret { display: none; width: 2.5px; height: .78em; background: var(--caret); margin-left: 5px; flex: none; animation: blink 1.06s steps(1) infinite; }
.active .caret { display: inline-block; }
@keyframes blink { 50% { opacity: 0; } }
.sub { font-size: 12px; line-height: 1.2; color: var(--muted); margin-bottom: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; }
.row.short .sub { display: none; }
.row.tight .name { display: none; }

/* ------------------------------------------------------------------ Clavier */

.kp { flex: .86 1 0; display: flex; padding: 6px 9px 10px; min-height: 0; }
.kl { flex: 3; display: flex; flex-direction: column; }
.kr { flex: 1; display: flex; flex-direction: column; }
.krow { flex: 1; display: flex; min-height: 0; }
.kcell { flex: 1; display: flex; min-height: 0; }
.kcell.two { flex: 2; }

.k {
  flex: 1; margin: 3px; border-radius: 16px; min-width: 0; min-height: 0;
  background: var(--key); color: var(--text);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--num); font-weight: 500; font-size: 28px; line-height: 1;
  transition: background-color .08s;
}
.k:active, .k.pressed { background: var(--key-pressed); }
.k.op { background: var(--key-op); color: var(--accent); font-size: 32px; }
.k.op:active, .k.op.pressed { background: var(--key-pressed); }
.k.eq { background: var(--equals); color: var(--on-equals); font-size: 34px; }
.k.eq:active, .k.eq.pressed { background: var(--equals-pressed); }
.k.c { font-family: var(--txt); font-weight: 800; color: var(--clear); font-size: 22px; }
.k.t { font-size: 22px; }

@media (max-height: 640px) {
  .k { font-size: 24px; }
  .k.op, .k.eq { font-size: 28px; }
  .k.t, .k.c { font-size: 19px; }
  .hdr { padding-top: 6px; padding-bottom: 4px; }
  .title { font-size: 26px; }
}

/* Paysage sur téléphone : lignes à gauche, clavier à droite */
@media (orientation: landscape) and (max-height: 560px) {
  #app { max-width: 920px; }
  .content { flex-direction: row; }
  .rows { flex: 1.1 1 0; }
  .kp { flex: 1 1 0; padding-top: 4px; }
  .hdr { padding-top: 4px; padding-bottom: 2px; }
  .title { font-size: 24px; }
  .k { font-size: 22px; }
  .k.op, .k.eq { font-size: 26px; }
  .k.t, .k.c { font-size: 18px; }
}

/* ------------------------------------------------------------------ Choix d'une devise */

.picker {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 20;
  background: var(--bg); display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  animation: rise .22s ease-out;
}
.picker[hidden], .sheet[hidden], .scrim[hidden] { display: none; }
.picker > * { width: 100%; max-width: 480px; margin-left: auto; margin-right: auto; }
.ph { display: flex; align-items: center; padding: 12px 8px 6px 20px; }
.ph .title { flex: 1; font-size: 25px; }
.search {
  display: flex; align-items: center; height: 48px; border-radius: 16px; background: var(--key);
  margin: 4px 16px 8px; padding: 0 12px 0 12px; color: var(--muted); width: auto;
}
.search svg { flex: none; margin-right: 8px; }
.search input {
  flex: 1; min-width: 0; height: 100%; border: 0; outline: 0; background: transparent;
  font: 600 16px/1 var(--txt); color: var(--text);
  -webkit-user-select: text; user-select: text; -webkit-appearance: none; appearance: none;
}
.search input::placeholder { color: var(--muted); opacity: 1; }
.search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.plist { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding: 0 8px 16px; }
.sec { padding: 18px 12px 6px; color: var(--muted); font-weight: 800; font-size: 13px; }
.empty { padding: 24px 12px; color: var(--muted); font-size: 15px; line-height: 1.4; }
.it {
  display: flex; align-items: center; width: 100%; min-height: 60px; padding: 10px 12px;
  border-radius: 16px; text-align: left;
}
.it:active { background: var(--key-pressed); }
.it .badge { width: 38px; height: 38px; margin-right: 14px; }
.it .c2 { flex: 1; min-width: 0; }
.it .code { font-size: 16px; }
.it .name { font-size: 13px; margin-top: 3px; }
.it .tag { font-size: 12px; color: var(--muted); margin-left: 8px; }
.it .chk { color: var(--accent); margin-left: 8px; flex: none; }

/* ------------------------------------------------------------------ Réglages */

.scrim {
  position: fixed; top: 0; right: 0; bottom: 0; left: 0; z-index: 30; background: var(--scrim);
  animation: fade .2s ease-out;
}
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 31;
  width: 100%; max-width: 480px; margin: 0 auto; max-height: 92%;
  overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain;
  background: var(--bg); border-radius: 28px 28px 0 0;
  padding: 14px 22px calc(20px + env(safe-area-inset-bottom));
  animation: rise .24s ease-out;
}
.grip { width: 36px; height: 4px; border-radius: 2px; background: var(--grip); margin: 0 auto 14px; }
.sheet .title { font-size: 28px; }
.lab { font-weight: 800; font-size: 13px; color: var(--muted); margin: 22px 0 10px; }
.seg { display: flex; }
.seg button {
  flex: 1; height: 52px; border-radius: 16px; background: var(--key); color: var(--text);
  font-weight: 800; font-size: 16px; margin-left: 8px;
}
.seg button:first-child { margin-left: 0; }
.seg button:active { background: var(--key-pressed); }
.seg button.on { background: var(--equals); color: var(--on-equals); }
.seg.n button { font-family: var(--num); font-weight: 600; font-size: 22px; }
.stat { font-size: 15px; line-height: 1.45; color: var(--text); white-space: pre-line; }
.btn {
  display: flex; align-items: center; justify-content: center; width: 100%; min-height: 48px; margin-top: 12px;
  border-radius: 16px; border: 1.5px solid var(--accent); color: var(--accent); font-weight: 800; font-size: 15px;
}
.btn:active { background: var(--key-pressed); }
.btn[disabled] { opacity: .6; }
.btn.f { background: var(--equals); border-color: var(--equals); color: var(--on-equals); margin-top: 22px; }
.btn.f:active { background: var(--equals-pressed); }
.note { font-size: 13px; line-height: 1.45; color: var(--muted); margin-top: 8px; }
.note.first { margin-top: 18px; }
.note:empty { display: none; }
.ver { text-align: center; font-size: 12px; color: var(--muted); margin-top: 14px; }

/* ------------------------------------------------------------------ Message bref */

.toast {
  position: fixed; left: 50%; bottom: calc(24px + env(safe-area-inset-bottom)); z-index: 40;
  max-width: 88%; padding: 12px 18px; border-radius: 16px;
  background: var(--text); color: var(--bg); font-size: 14px; line-height: 1.3; text-align: center;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@keyframes rise { from { transform: translateY(24px); opacity: .6; } to { transform: none; opacity: 1; } }
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .caret { animation: none; }
  #refreshBtn.spin svg { animation-duration: 2.5s; }
  .picker, .sheet, .scrim, .row.copied { animation: none; }
}
