:root {
  --bg: #fff8ec;
  --ink: #3d2c1e;
  --muted: #8a7461;
  --card: #ffffff;
  --line: #f0e2cc;
  --yellow: #ffb703;
  --orange: #fb8500;
  --pink: #ff6b8b;
  --green: #2a9d8f;
  --blue: #3a86ff;
  --red: #e63946;
  --radius: 18px;
  --shadow: 0 6px 24px rgba(108, 74, 46, .10);
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* ================= LOGIN ================= */
.login {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  overflow: hidden;
  background: linear-gradient(180deg, #8ecae6 0%, #bde0fe 55%, #ffe5b4 100%);
  padding: 16px;
}
.sky { position: absolute; inset: 0; pointer-events: none; }
.sun {
  position: absolute; top: 7%; right: 10%;
  width: 110px; height: 110px; border-radius: 50%;
  background: radial-gradient(circle, #ffe066 55%, #ffd23f 100%);
  box-shadow: 0 0 60px 20px rgba(255, 214, 10, .55);
  animation: pulse 4s ease-in-out infinite;
}
.cloud {
  position: absolute; background: #fff; border-radius: 100px; opacity: .9;
  width: 140px; height: 44px;
}
.cloud::before, .cloud::after {
  content: ""; position: absolute; background: #fff; border-radius: 50%;
}
.cloud::before { width: 64px; height: 64px; top: -30px; left: 22px; }
.cloud::after  { width: 48px; height: 48px; top: -20px; left: 70px; }
.c1 { top: 16%; left: -160px; animation: drift 38s linear infinite; }
.c2 { top: 38%; left: -160px; transform: scale(.7); animation: drift 52s linear infinite 8s; }
.c3 { top: 64%; left: -160px; transform: scale(1.2); animation: drift 45s linear infinite 20s; }

@keyframes drift { to { left: 110%; } }
@keyframes pulse { 50% { transform: scale(1.06); } }

.tape {
  position: absolute; left: -10%; width: 120%;
  background: repeating-linear-gradient(-45deg, #ffd60a 0 26px, #222 26px 52px);
  color: #fff; font-weight: 900; letter-spacing: .25em; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-align: center;
  padding: 8px 0; text-shadow: 0 1px 2px #000;
  box-shadow: 0 4px 12px rgba(0,0,0,.2);
}
.tape-top { top: 6%; transform: rotate(-4deg); }
.tape-bottom { bottom: 6%; transform: rotate(3deg); }

.login-card {
  position: relative; z-index: 1;
  width: min(380px, 100%);
  background: rgba(255,255,255,.92);
  border-radius: 28px;
  padding: 28px 24px 22px;
  text-align: center;
  box-shadow: 0 20px 60px rgba(61, 44, 30, .25);
  border: 4px dashed var(--yellow);
}
.lock { width: 110px; height: 120px; margin-top: -78px; filter: drop-shadow(0 8px 10px rgba(0,0,0,.15)); }
.lock .eye { animation: blink 5s infinite; transform-origin: center; transform-box: fill-box; }
@keyframes blink { 0%, 94%, 100% { transform: scaleY(1); } 96% { transform: scaleY(.1); } }
.lock.shake { animation: shake .5s; }
.lock.sad .mouth { d: path("M48 110q12 -10 24 0"); }
.lock.happy .shackle { transform: translateY(-14px) rotate(-12deg); transform-origin: 85px 58px; transition: transform .4s; }
@keyframes shake {
  20% { transform: translateX(-12px) rotate(-6deg); }
  40% { transform: translateX(10px) rotate(5deg); }
  60% { transform: translateX(-8px) rotate(-3deg); }
  80% { transform: translateX(6px); }
}
.login h1 { margin: 6px 0 4px; font-size: 1.7rem; letter-spacing: -.01em; }
.login-sub { margin: 0 0 18px; color: var(--muted); line-height: 1.45; }
#login-form, #recover-form { display: grid; gap: 10px; }
#rc-submit {
  padding: 13px; border: 0; border-radius: 14px; background: var(--green); color: #fff; font-weight: 700;
}
#rc-submit:disabled { opacity: .6; cursor: wait; }
.link-btn { background: none; border: 0; color: var(--muted); text-decoration: underline; font-size: .88rem; padding: 6px; margin-top: 6px; }
.link-btn:hover { color: var(--ink); }
.login-small { margin: 0; font-size: .82rem; color: var(--muted); }
#login-form input, #recover-form input {
  width: 100%; padding: 13px 16px; border-radius: 14px;
  border: 2px solid var(--line); background: #fffdf8; text-align: center;
  font-size: 1rem;
}
#login-form input:focus, #recover-form input:focus { outline: none; border-color: var(--orange); }
#login-btn {
  padding: 13px; border: 0; border-radius: 14px;
  background: var(--orange); color: #fff; font-weight: 700;
  box-shadow: 0 4px 0 #c96a00; transition: transform .08s;
}
#login-btn:active { transform: translateY(3px); box-shadow: 0 1px 0 #c96a00; }
#login-btn:disabled { opacity: .6; cursor: wait; }
.login-msg { min-height: 1.4em; margin: 12px 0 0; font-weight: 600; color: var(--pink); }

/* ================= APP ================= */
.app { min-height: 100vh; }
.topbar {
  position: sticky; top: 0; z-index: 5;
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 16px; background: rgba(255,248,236,.92);
  backdrop-filter: blur(6px); border-bottom: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 10px;
  background: none; border: 0; font-weight: 800; font-size: 1.1rem; color: var(--ink);
}
.brand-dot { width: 14px; height: 14px; border-radius: 50%; background: linear-gradient(135deg, var(--yellow), var(--pink)); }
main { max-width: 860px; margin: 0 auto; padding: 20px 16px 80px; }
h2 { margin: 6px 0 16px; font-size: 1.5rem; }
.hello { font-size: 1.15rem; color: var(--muted); margin: 8px 0 20px; }

.big-buttons { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); }
.big {
  display: flex; flex-direction: column; align-items: flex-start; gap: 6px;
  padding: 24px 20px; border: 0; border-radius: 24px; color: #fff; text-align: left;
  box-shadow: var(--shadow); transition: transform .15s, box-shadow .15s;
  min-height: 170px;
}
.big:hover { transform: translateY(-3px); box-shadow: 0 12px 30px rgba(108,74,46,.18); }
.big-ico { font-size: 2.2rem; }
.big-title { font-size: 1.2rem; font-weight: 800; }
.big-sub { opacity: .9; font-size: .95rem; }
.b-work { background: linear-gradient(135deg, #fb8500, #ffb703); }
.b-pay { background: linear-gradient(135deg, #2a9d8f, #52c7b8); }
.b-state { background: linear-gradient(135deg, #ff6b8b, #c77dff); }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); border: 1px solid var(--line); }
.form { display: grid; gap: 16px; padding: 20px; }
.form label { display: grid; gap: 6px; font-weight: 600; font-size: .95rem; }
.form input, .form textarea {
  width: 100%; padding: 11px 13px; border: 2px solid var(--line); border-radius: 12px;
  background: #fffdf8; font-weight: 400;
}
.form input:focus, .form textarea:focus { outline: none; border-color: var(--orange); }
.form textarea { resize: vertical; }
.opt { color: var(--muted); font-weight: 400; }
.two { display: grid; gap: 16px; grid-template-columns: 1fr 1fr; }
@media (max-width: 520px) { .two { grid-template-columns: 1fr; } }
.hint { margin: 0; color: var(--muted); font-size: .92rem; min-height: 1.2em; }
.hint.warn { color: var(--orange); }
.actions { display: flex; justify-content: flex-end; gap: 10px; flex-wrap: wrap; }
.primary, .ghost, .danger, .mini {
  border-radius: 12px; padding: 10px 18px; font-weight: 700; border: 2px solid transparent;
}
.primary { background: var(--orange); color: #fff; }
.primary:hover { background: #e07600; }
.ghost { background: transparent; border-color: var(--line); color: var(--ink); }
.ghost:hover { background: #fff; }
.mini { padding: 5px 10px; font-size: .82rem; background: #fff7e6; border-color: var(--line); color: var(--ink); }
.mini.del { color: var(--red); }
.mini:hover { border-color: var(--orange); }

/* État */
.due { padding: 22px; text-align: center; background: linear-gradient(135deg, #fff3d6, #ffe0ea); }
.due-label { margin: 0; color: var(--muted); font-weight: 600; }
.due-amount { margin: 6px 0 2px; font-size: clamp(2.2rem, 8vw, 3.2rem); font-weight: 900; letter-spacing: -.02em; }
.due-amount.neg { color: var(--green); }
.due-ttc { margin: 0; color: var(--muted); }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(3, 1fr); margin: 14px 0 22px; }
@media (max-width: 560px) { .stats { grid-template-columns: 1fr; } }
.stat { padding: 14px 16px; display: grid; gap: 4px; }
.stat span { color: var(--muted); font-size: .88rem; }
.stat strong { font-size: 1.25rem; }

.tabs { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.tab { border: 2px solid var(--line); background: #fff; border-radius: 999px; padding: 8px 16px; font-weight: 700; color: var(--muted); }
.tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.week { margin-bottom: 16px; overflow: hidden; }
.week-head {
  display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 12px 16px; background: #fff7e6; border-bottom: 1px solid var(--line); font-weight: 700;
}
.week-head .wsum { color: var(--muted); font-weight: 600; }
.badge { display: inline-block; font-size: .75rem; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #ffe0ea; color: #c9184a; margin-left: 6px; vertical-align: middle; }
.row { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row-main { display: grid; gap: 3px; min-width: 0; }
.row-date { font-weight: 700; }
.row-note { color: var(--muted); font-size: .92rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.row-right { display: grid; justify-items: end; gap: 6px; align-content: start; }
.row-amount { font-weight: 800; font-size: 1.05rem; }
.row-btns { display: flex; gap: 6px; }
.row a { color: var(--blue); overflow-wrap: anywhere; font-size: .9rem; }
.empty { text-align: center; color: var(--muted); padding: 30px 16px; }

.top-actions { display: flex; gap: 8px; }
@media (max-width: 480px) { .hide-sm { display: none; } }

/* Calendrier */
.cal { padding: 14px; margin-bottom: 16px; }
.cal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.cal-head .mini { font-size: 1.2rem; padding: 4px 14px; }
.cal-title { font-size: 1.15rem; }
.cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 6px; }
.cal-dow { margin-bottom: 6px; }
.cal-dow span { text-align: center; font-size: .78rem; font-weight: 700; color: var(--muted); text-transform: uppercase; }
.cal-cell {
  height: clamp(50px, 12vw, 74px); border-radius: 12px; border: 2px solid transparent;
  background: #fbf3e4; padding: 4px 6px; display: flex; flex-direction: column; justify-content: space-between;
  color: var(--ink); font: inherit; text-align: left;
}
.cal-cell.out { background: transparent; }
.cal-num { font-size: .8rem; font-weight: 600; opacity: .75; }
.cal-hours { font-size: clamp(.9rem, 3.6vw, 1.35rem); font-weight: 900; text-align: center; line-height: 1; padding-bottom: 4px; }
.cal-cell.worked { color: #fff; cursor: pointer; transition: transform .1s; }
.cal-cell.worked:hover { transform: scale(1.05); }
.cal-cell.worked .cal-num { opacity: .9; }
.cal-cell.paid, .dot.paid { background: #2a9d8f; }
.cal-cell.partial, .dot.partial { background: #f8961e; }
.cal-cell.unpaid, .dot.unpaid { background: #e63946; }
.cal-cell.today { border-color: var(--ink); }
.cal-cell.sel { box-shadow: 0 0 0 3px #fff, 0 0 0 6px var(--ink); }
.cal-foot { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 8px; margin-top: 12px; font-size: .88rem; color: var(--muted); }
.legend { display: flex; align-items: center; gap: 6px; }
.dot { display: inline-block; width: 12px; height: 12px; border-radius: 4px; margin-left: 6px; }
.pill { font-size: .8rem; padding: 2px 10px; border-radius: 999px; color: #fff; }
.pill.paid { background: #2a9d8f; }
.pill.partial { background: #f8961e; }
.pill.unpaid { background: #e63946; }

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%) translateY(120px);
  background: var(--ink); color: #fff; padding: 12px 20px; border-radius: 999px;
  font-weight: 600; transition: transform .25s; z-index: 50; max-width: calc(100% - 32px);
}
.toast.show { transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--red); }
