:root {
  --navy: #12355b;
  --blue: #1f6feb;
  --bg: #f2f4f7;
  --card: #ffffff;
  --text: #17202b;
  --muted: #667085;
  --line: #e2e6ec;
  --mine: #d9ebff;
  --ok: #17803d;
  --warn: #b25e09;
  --bad: #c62828;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  overscroll-behavior: none;
}

#app {
  height: 100dvh;
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

/* ---------- Barre du haut ---------- */

.bar {
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: calc(env(safe-area-inset-top) + 10px) 12px 10px;
  min-height: 56px;
  flex: none;
}

.bar h1 {
  font-size: 18px;
  margin: 0;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar h1 small {
  display: block;
  font-size: 12px;
  font-weight: 400;
  opacity: 0.75;
}

.bar button {
  background: rgba(255, 255, 255, 0.14);
  border: 0;
  color: #fff;
  border-radius: 10px;
  padding: 9px 12px;
  min-height: 40px;
  font-size: 14px;
  white-space: nowrap;
}

.tabs {
  display: flex;
  background: var(--card);
  border-bottom: 1px solid var(--line);
  flex: none;
}

.tabs button {
  flex: 1;
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  padding: 12px 6px;
  font-weight: 600;
  color: var(--muted);
}

.tabs button.on {
  color: var(--blue);
  border-bottom-color: var(--blue);
}

.scroll {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
}

/* ---------- Boutons, champs ---------- */

.btn {
  background: var(--blue);
  color: #fff;
  border: 0;
  border-radius: 12px;
  padding: 14px 18px;
  font-weight: 600;
  min-height: 50px;
  width: 100%;
}

.btn.ghost {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--line);
}

.btn.small {
  width: auto;
  min-height: 38px;
  padding: 8px 12px;
  font-size: 14px;
  border-radius: 10px;
}

.btn:disabled {
  opacity: 0.5;
}

.field {
  width: 100%;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 13px 14px;
  min-height: 50px;
}

.field:focus {
  outline: 2px solid var(--blue);
  outline-offset: -1px;
}

.err {
  color: var(--bad);
  font-weight: 600;
  min-height: 1.4em;
  margin: 8px 0;
}

.muted {
  color: var(--muted);
  font-size: 14px;
}

/* ---------- Connexion ---------- */

.login {
  flex: 1;
  overflow-y: auto;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.login .logo {
  width: 84px;
  height: 84px;
  border-radius: 20px;
  margin: 12px auto 4px;
}

.login h2 {
  text-align: center;
  margin: 4px 0 14px;
}

.person {
  display: flex;
  align-items: center;
  gap: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  font-size: 19px;
  font-weight: 600;
  text-align: left;
  width: 100%;
}

.avatar {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: var(--navy);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 700;
  flex: none;
}

.code-input {
  text-align: center;
  font-size: 26px;
  letter-spacing: 0.3em;
}

/* ---------- Liste des chantiers ---------- */

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px;
  margin-bottom: 9px;
  width: 100%;
  text-align: left;
}

.row .body {
  flex: 1;
  min-width: 0;
}

.row .title {
  font-weight: 700;
  font-size: 17px;
}

.row .sub {
  color: var(--muted);
  font-size: 14px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.badge {
  background: var(--bad);
  color: #fff;
  border-radius: 999px;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
}

.tag {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  border-radius: 999px;
  padding: 2px 9px;
  background: #eef1f5;
  color: var(--muted);
}

.tag.ok {
  background: #e3f5e9;
  color: var(--ok);
}

.tag.warn {
  background: #fdf0dc;
  color: var(--warn);
}

.tag.bad {
  background: #fde7e7;
  color: var(--bad);
}

/* ---------- Conversation ---------- */

.chat {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.day {
  align-self: center;
  font-size: 12px;
  color: var(--muted);
  background: #e6e9ee;
  border-radius: 999px;
  padding: 3px 12px;
  margin: 8px 0 4px;
}

.msg {
  max-width: 84%;
  align-self: flex-start;
  background: var(--card);
  border-radius: 16px 16px 16px 4px;
  padding: 8px 12px;
  box-shadow: 0 1px 1px rgba(16, 24, 40, 0.07);
  overflow-wrap: anywhere;
}

.msg.mine {
  align-self: flex-end;
  background: var(--mine);
  border-radius: 16px 16px 4px 16px;
}

.msg .who {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--navy);
}

.msg .txt {
  white-space: pre-wrap;
}

.msg .orig {
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px dashed #c3ccd8;
  color: var(--muted);
  font-size: 14.5px;
  white-space: pre-wrap;
}

.msg .meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 10px;
  margin-top: 3px;
  font-size: 12px;
  color: var(--muted);
}

.msg .meta button {
  background: none;
  border: 0;
  padding: 4px 0;
  color: var(--blue);
  font-size: 12.5px;
}

.bon-card {
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(18, 53, 91, 0.07);
  border-radius: 12px;
  padding: 10px;
  margin: 4px 0;
  color: inherit;
  text-decoration: none;
  font-weight: 600;
}

.bon-card .ico {
  font-size: 26px;
}

.bon-card small {
  display: block;
  font-weight: 400;
  color: var(--muted);
}

.composer {
  flex: none;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 8px);
}

.composer textarea {
  flex: 1;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 11px 14px;
  max-height: 130px;
  min-height: 46px;
  background: var(--bg);
}

.composer textarea:focus {
  outline: 2px solid var(--blue);
  outline-offset: -1px;
}

.round {
  flex: none;
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 0;
  background: var(--blue);
  color: #fff;
  font-size: 20px;
  display: grid;
  place-items: center;
}

.round.alt {
  background: var(--navy);
}

.round:disabled {
  opacity: 0.4;
}

/* ---------- Scan de bon ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  max-width: 760px;
  margin: 0 auto;
}

.thumbs {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.thumb {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 10px;
  overflow: hidden;
  background: #cfd6df;
}

.thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.thumb span {
  position: absolute;
  left: 6px;
  bottom: 6px;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 12px;
  border-radius: 6px;
  padding: 1px 7px;
}

.thumb button {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: 0;
  background: rgba(0, 0, 0, 0.6);
  color: #fff;
  font-size: 16px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.pair {
  display: flex;
  gap: 10px;
}

.pair > * {
  flex: 1;
}

/* ---------- Gestion ---------- */

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 14px;
}

.panel h3 {
  margin: 0 0 10px;
}

.line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 9px 0;
  border-top: 1px solid var(--line);
}

.line .grow {
  flex: 1;
  min-width: 140px;
}

.line.off .grow {
  opacity: 0.5;
}

.result {
  background: var(--bg);
  border-radius: 10px;
  padding: 10px;
  margin-top: 10px;
  font-size: 14.5px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 84px);
  transform: translateX(-50%);
  background: #1d2733;
  color: #fff;
  border-radius: 999px;
  padding: 10px 18px;
  z-index: 20;
  font-weight: 600;
  max-width: 90vw;
  text-align: center;
}

@media (min-width: 760px) {
  #app,
  .sheet {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
  }
}
