/* ==========================================================================
   Calculatrice Un-chef.fr — dans la lignée de Kairos, Agenda et Contacts
   Fond nacré, cartes blanches, bleu marine et or, police Jakarta.
   ========================================================================== */

@font-face { font-family: "Jakarta"; src: url("fonts/jakarta.woff2") format("woff2"); font-weight: 200 800; font-display: swap; }

:root {
  --bg: #F7F5F0;
  --surface: #FFFFFF;
  --surface-2: #F4F6FA;
  --navy: #12306B;
  --navy-2: #21468F;
  --gold: #C39A4F;
  --gold-soft: #E6C98A;
  --gold-ink: #8A6424;
  --ink: #0E1B35;
  --ink-2: #33405C;
  --muted: #667089;
  --line: rgba(14, 27, 53, .09);
  --line-2: rgba(14, 27, 53, .14);
  --danger: #C92A2A;
  --shadow: 0 1px 2px rgba(14, 27, 53, .05), 0 10px 26px -14px rgba(14, 27, 53, .22);
  --shadow-lg: 0 2px 6px rgba(14, 27, 53, .06), 0 26px 50px -22px rgba(14, 27, 53, .32);
  font-size: 16px;
}

* { box-sizing: border-box; }
html, body {
  height: 100%; margin: 0; background: var(--bg); color: var(--ink);
  font-family: "Jakarta", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior: none; user-select: none; -webkit-user-select: none;
}
body::before {
  content: ""; position: fixed; inset: 0; pointer-events: none; z-index: 0;
  background:
    radial-gradient(800px 480px at 0% -10%, rgba(195, 154, 79, .14), transparent 60%),
    radial-gradient(800px 520px at 100% -5%, rgba(33, 70, 143, .10), transparent 60%);
}
button, input, select { font-family: inherit; }

.app {
  position: relative; z-index: 1; max-width: 900px; margin: 0 auto; min-height: 100vh;
  display: flex; flex-direction: column;
  padding: calc(16px + env(safe-area-inset-top)) 18px calc(20px + env(safe-area-inset-bottom));
}

/* ── En-tête ───────────────────────────────────────────── */
.brand { display: flex; align-items: center; gap: 12px; margin: 2px 2px 14px; }
.brand img { width: 40px; height: 40px; border-radius: 12px; box-shadow: 0 6px 16px -8px rgba(10, 28, 71, .6); }
.brand b { display: block; font-size: 17px; font-weight: 800; letter-spacing: .14em; color: var(--ink); }
.brand small { display: block; font-size: 12.5px; color: var(--muted); font-weight: 600; }

/* ── Onglets ───────────────────────────────────────────── */
.tabs {
  display: flex; gap: 3px; margin-bottom: 14px; background: #ECEEF3; border-radius: 14px; padding: 4px;
  overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; scroll-snap-type: x proximity;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto; border: none; background: none; color: var(--muted); font-size: .84rem; font-weight: 700; white-space: nowrap;
  padding: 10px 12px; border-radius: 11px; cursor: pointer; transition: background .15s, color .15s, box-shadow .15s;
  scroll-snap-align: center; touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.tab.active { background: var(--surface); color: var(--navy); box-shadow: 0 1px 3px rgba(14, 27, 53, .14); }

/* ── Panneaux ──────────────────────────────────────────── */
.panel { display: none; flex: 1; flex-direction: column; }
.panel.active { display: flex; }

/* ── Calculatrice : écran bleu marine ──────────────────── */
.display {
  position: relative; overflow: hidden;
  background: linear-gradient(135deg, var(--navy-2), #0A1C47); color: #fff;
  border-radius: 22px; padding: 16px 20px 20px; margin-bottom: 14px;
  min-height: 220px; max-height: 40vh; display: flex; flex-direction: column; box-shadow: var(--shadow-lg);
}
.display::after {
  content: ""; position: absolute; right: -60px; top: -60px; width: 180px; height: 180px; border-radius: 50%;
  border: 2px solid rgba(230, 201, 138, .35); pointer-events: none;
}
.display-history {
  flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding-bottom: 8px; scrollbar-width: thin;
  scrollbar-color: rgba(255, 255, 255, .25) transparent;
}
.history-line {
  display: block; width: 100%; text-align: right; opacity: .6; border: none; border-bottom: 1px solid rgba(255, 255, 255, .1);
  padding: 0 0 8px; background: none; color: inherit; font: inherit; cursor: pointer; flex-shrink: 0;
  -webkit-tap-highlight-color: transparent; transition: opacity .15s;
}
.history-line:active { opacity: 1; }
.history-line:first-child { margin-top: auto; }
.history-line .h-expr { font-size: .82rem; color: rgba(255, 255, 255, .65); }
.history-line .h-result { font-size: 1.3rem; font-weight: 500; font-variant-numeric: tabular-nums; }
.display-current { text-align: right; padding-top: 4px; flex-shrink: 0; }
.display-expr { font-size: .95rem; color: var(--gold-soft); min-height: 1.2em; word-break: break-all; }
.display-main { font-size: 2.7rem; font-weight: 700; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: clip; font-variant-numeric: tabular-nums; transition: font-size .12s ease; }
.display-main[data-size="m"] { font-size: 2.25rem; }
.display-main[data-size="s"] { font-size: 1.8rem; }
.display-main[data-size="xs"] { font-size: 1.4rem; }

/* ── Clavier ───────────────────────────────────────────── */
.keypad { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); grid-auto-rows: 1fr; gap: 10px; max-height: 420px; }
.key {
  border: 1px solid var(--line); border-radius: 16px; background: var(--surface); color: var(--ink);
  font-size: 1.25rem; font-weight: 700; cursor: pointer; box-shadow: var(--shadow);
  transition: transform .14s cubic-bezier(.2, .8, .2, 1), background .14s, box-shadow .14s;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none;
  will-change: transform;
}
.key.pressed, .key:active { transform: scale(.94); background: var(--surface-2); box-shadow: none; transition-duration: .04s; }
.key-wide { grid-column: span 2; }
.key-fn { background: var(--surface-2); color: var(--ink-2); font-size: 1.1rem; }
.key-op { background: #EAF1FC; color: var(--navy); font-size: 1.5rem; border-color: rgba(33, 70, 143, .15); }
.key-eq {
  background: linear-gradient(135deg, #E6C98A, var(--gold)); color: #0A1C47; font-size: 1.6rem; border: none;
  box-shadow: 0 10px 22px -12px rgba(169, 124, 53, .9);
}
.key-eq:active, .key-eq.pressed { background: var(--gold-soft); }
.key-op.pressed { background: #DCE7F9; }

/* ── Cartes TVA / Marge / Déplacement ──────────────────── */
.card {
  background: var(--surface); border: 1px solid var(--line); border-radius: 22px; padding: 20px;
  display: flex; flex-direction: column; gap: 14px; box-shadow: var(--shadow);
}
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: .78rem; color: var(--muted); font-weight: 700; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-row-3 { grid-template-columns: 1fr 1fr 1fr; }
.field input, .field select {
  background: var(--surface); border: 1px solid var(--line-2); border-radius: 12px; padding: 12px;
  color: var(--ink); font-size: 1.05rem; font-weight: 600; font-variant-numeric: tabular-nums; width: 100%;
}
.field input::placeholder { color: #9AA3B5; font-weight: 500; }
.field input:focus, .field select:focus { outline: none; border-color: var(--navy-2); box-shadow: 0 0 0 4px rgba(33, 70, 143, .12); }
.field select {
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23667089'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center; padding-right: 32px;
}
.or-divider { text-align: center; font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .1em; font-weight: 700; margin: -6px 0; }
.result-box {
  border-top: 1px solid var(--line); padding-top: 14px; margin-top: 2px;
  display: flex; flex-direction: column; gap: 9px;
}
.result-line { display: flex; justify-content: space-between; align-items: baseline; font-size: .9rem; color: var(--muted); font-weight: 600; }
.result-line strong { color: var(--ink); font-size: 1.05rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.result-line.result-highlight { background: #FBF6EA; border: 1px solid #EEDFBF; border-radius: 12px; padding: 10px 12px; }
.result-line.result-highlight strong { color: var(--gold-ink); font-size: 1.35rem; }
.reset-btn {
  border: 1px solid var(--line-2); background: var(--surface); color: var(--ink-2); padding: 11px;
  border-radius: 12px; font-size: .88rem; font-weight: 700; cursor: pointer; margin-top: 2px;
}
.reset-btn:active { background: var(--surface-2); }

/* ── Devises ───────────────────────────────────────────── */
.devise { display: flex; align-items: center; gap: 12px; padding: 10px 12px 10px 10px; border: 1px solid var(--line-2); border-radius: 16px; background: var(--surface); transition: border-color .15s, box-shadow .15s; }
.devise:focus-within { border-color: var(--navy-2); box-shadow: 0 0 0 4px rgba(33, 70, 143, .12); }
.devise label { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; font-weight: 700; font-size: .9rem; color: var(--ink); cursor: text; }
.devise label small { display: block; font-size: .7rem; color: var(--muted); font-weight: 700; letter-spacing: .08em; margin-top: 1px; }
.devise .sigle {
  flex: none; width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-weight: 800; font-size: 1.05rem;
  background: linear-gradient(135deg, var(--navy-2), #0A1C47); color: var(--gold-soft);
}
.devise input {
  width: 46%; min-width: 0; border: none; background: none; text-align: right; font-family: inherit; color: var(--ink);
  font-size: 1.35rem; font-weight: 800; font-variant-numeric: tabular-nums; padding: 4px 0; outline: none;
}
.devise input::placeholder { color: #B6BCCB; font-weight: 600; }
.taux { background: #FBF6EA; border: 1px solid #EEDFBF; border-radius: 14px; padding: 12px 14px; display: flex; flex-direction: column; gap: 8px; }
.taux-lignes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.taux-lignes div { display: flex; flex-direction: column; gap: 2px; }
.taux-lignes span { font-size: .72rem; color: var(--muted); font-weight: 700; }
.taux-lignes strong { font-size: 1rem; color: var(--gold-ink); font-weight: 800; font-variant-numeric: tabular-nums; }
.taux-pied { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.taux-pied small { font-size: .74rem; color: var(--muted); font-weight: 600; }
.taux-maj { border: 1px solid #E3CFA3; background: #fff; color: var(--gold-ink); font-weight: 700; font-size: .78rem; padding: 7px 11px; border-radius: 10px; cursor: pointer; font-family: inherit; }
.taux-maj.turning { opacity: .6; }

/* ── Hors connexion ────────────────────────────────────── */
.offline-badge { display: none; text-align: center; font-size: .74rem; color: var(--muted); padding: 10px 4px 0; }
.offline-badge.show { display: block; }

@media (max-width: 360px) {
  .display-main { font-size: 2.1rem; }
  .key { font-size: 1.1rem; }
  .field-row-3 { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 700px) {
  html, body { font-size: 19px; }
  .display { min-height: 280px; padding: 22px 26px 26px; }
  .display-main { font-size: 3.6rem; }
  .history-line .h-result { font-size: 1.7rem; }
  .key { font-size: 1.6rem; border-radius: 18px; }
  .key-fn { font-size: 1.3rem; }
  .key-op { font-size: 1.9rem; }
  .key-eq { font-size: 2rem; }
  .keypad { gap: 14px; max-height: 520px; }
  .tab { font-size: 1rem; padding: 12px; }
  .devise input { font-size: 1.6rem; }
  .display-main[data-size="m"] { font-size: 3rem; }
  .display-main[data-size="s"] { font-size: 2.4rem; }
  .display-main[data-size="xs"] { font-size: 1.9rem; }
  .card { padding: 30px 34px; gap: 20px; }
  .field label { font-size: 1rem; }
  .field input, .field select { font-size: 1.25rem; padding: 15px 16px; border-radius: 14px; }
}
