:root {
  --bg: #f6f3ee;
  --bg-soft: #efe9e1;
  --surface: #ffffff;
  --text: #23201b;
  --muted: #756f66;
  --border: #e6e0d6;
  --accent: #c65a30;
  --accent-strong: #a8461f;
  --accent-2: #2c6e49;
  --danger: #b3261e;
  --warn: #ad7a1e;
  --shadow-sm: 0 1px 2px rgba(30, 25, 15, 0.06), 0 1px 1px rgba(30, 25, 15, 0.04);
  --shadow-md: 0 6px 20px rgba(30, 25, 15, 0.08), 0 2px 6px rgba(30, 25, 15, 0.05);
  --shadow-lift: 0 12px 28px rgba(30, 25, 15, 0.12), 0 4px 10px rgba(30, 25, 15, 0.06);
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171512;
    --bg-soft: #1f1c18;
    --surface: #24211c;
    --text: #f0ebe2;
    --muted: #a89f93;
    --border: #38332c;
    --accent: #e88a5c;
    --accent-strong: #f2a179;
    --accent-2: #74c491;
    --danger: #e2726a;
    --warn: #e0b357;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.4);
    --shadow-lift: 0 14px 32px rgba(0, 0, 0, 0.5);
  }
}

* { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background:
    radial-gradient(1200px 500px at 15% -10%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 60%),
    radial-gradient(900px 400px at 100% 0%, color-mix(in srgb, var(--accent-2) 8%, transparent), transparent 55%),
    var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

::selection { background: color-mix(in srgb, var(--accent) 35%, transparent); }

/* scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border) transparent; }
*::-webkit-scrollbar { height: 10px; width: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border); border-radius: 999px; }
*::-webkit-scrollbar-track { background: transparent; }

header {
  padding: 1.5rem 1.5rem 0;
  position: sticky;
  top: 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px) saturate(1.4);
  -webkit-backdrop-filter: blur(10px) saturate(1.4);
  z-index: 10;
  border-bottom: 1px solid var(--border);
}

.header-inner { display: flex; flex-direction: column; gap: 0.15rem; margin-bottom: 1rem; }

.header-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

.header-user { display: flex; align-items: center; gap: 0.5rem; font-size: 0.85rem; color: var(--muted); }

.user-dot {
  display: inline-block;
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  flex-shrink: 0;
}

.btn-logout {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.35rem 0.7rem;
  border-radius: 7px;
  cursor: pointer;
  font-size: 0.8rem;
  transition: color 0.12s ease, border-color 0.12s ease;
}
.btn-logout:hover { color: var(--danger); border-color: var(--danger); }

h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 750;
  letter-spacing: -0.01em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.header-emoji { display: inline-block; animation: wiggle 3.5s ease-in-out infinite; }
@keyframes wiggle {
  0%, 92%, 100% { transform: rotate(0deg); }
  94% { transform: rotate(-8deg); }
  96% { transform: rotate(8deg); }
  98% { transform: rotate(-4deg); }
}

.header-sub { margin: 0; font-size: 0.88rem; color: var(--muted); }

#tabs { display: flex; gap: 0.3rem; overflow-x: auto; scrollbar-width: none; }
#tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  background: none;
  border: none;
  padding: 0.65rem 1.05rem;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
  border-radius: 8px 8px 0 0;
  white-space: nowrap;
  position: relative;
  transition: color 0.15s ease, background 0.15s ease;
}
.tab-btn:hover { color: var(--text); background: color-mix(in srgb, var(--accent) 8%, transparent); }
.tab-btn.active { color: var(--accent); }
.tab-btn.active::after {
  content: "";
  position: absolute;
  left: 0.4rem; right: 0.4rem; bottom: -1px;
  height: 2.5px;
  background: var(--accent);
  border-radius: 999px 999px 0 0;
}

main { padding: 1.5rem 1.5rem 3.5rem; max-width: 1400px; margin: 0 auto; }

.tab-panel { display: none; animation: fadeIn 0.25s ease; }
.tab-panel.active { display: block; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 0.9rem;
}

.totals { font-size: 0.9rem; color: var(--muted); }
.totals strong { color: var(--text); }

.btn-add {
  background: linear-gradient(155deg, var(--accent), var(--accent-strong));
  color: white;
  border: none;
  padding: 0.55rem 1rem;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.btn-add:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }
.btn-add:active { transform: translateY(0); }

.table-scroll {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  max-width: 100%;
}

table.editable { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 0.88rem; }

table.editable thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  text-align: left;
  padding: 0.6rem 0.7rem;
  background: var(--bg-soft);
  border-bottom: 1px solid var(--border);
  font-weight: 650;
  color: var(--muted);
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  overflow: hidden;
}

.th-label {
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

table.editable tbody tr { transition: background 0.1s ease; }
table.editable tbody tr:hover { background: color-mix(in srgb, var(--accent) 4%, transparent); }

table.editable td {
  border-bottom: 1px solid var(--border);
  padding: 0;
  overflow: hidden;
  vertical-align: top;
}

table.editable tfoot td {
  font-weight: 700;
  background: var(--bg-soft);
  padding: 0.6rem 0.7rem;
  position: sticky;
  bottom: 0;
}

table.editable input[type="text"],
table.editable input[type="number"],
table.editable select,
table.editable textarea {
  width: 100%;
  border: none;
  background: transparent;
  padding: 0.55rem 0.7rem;
  font-size: 0.88rem;
  color: var(--text);
  font-family: inherit;
}
table.editable textarea { resize: none; overflow: hidden; display: block; }

table.editable input:focus,
table.editable select:focus,
table.editable textarea:focus {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
  background: var(--surface);
  position: relative;
  z-index: 1;
}

td.readonly { color: var(--muted); padding: 0.55rem 0.7rem; }

td.cell-flash { background: color-mix(in srgb, var(--accent-2) 25%, transparent); transition: background 1.2s ease; }

td.checkbox-cell { text-align: center; }
td.checkbox-cell input { width: auto; margin: 0 auto; display: block; cursor: pointer; }

/* colonnes redimensionnables */
table.editable th { position: relative; }
.col-resize-handle {
  position: absolute;
  top: 0; right: 0; bottom: 0;
  width: 8px;
  cursor: col-resize;
  user-select: none;
  touch-action: none;
  z-index: 3;
}
.col-resize-handle::after {
  content: "";
  position: absolute;
  top: 15%; bottom: 15%; right: 3px;
  width: 2px;
  background: var(--border);
  border-radius: 999px;
  transition: background 0.12s ease;
}
.col-resize-handle:hover::after,
.col-resize-handle.resizing::after { background: var(--accent); }

.rank-cell { display: flex; flex-direction: column; align-items: center; padding: 0.3rem 0.4rem; gap: 2px; }
.rank-cell button {
  background: var(--surface); border: 1px solid var(--border); border-radius: 5px;
  cursor: pointer; color: var(--text); width: 1.7rem; height: 1.45rem; line-height: 1;
  font-size: 0.75rem; transition: background 0.12s ease, border-color 0.12s ease;
}
.rank-cell button:hover:not(:disabled) { background: var(--bg-soft); border-color: var(--accent); }
.rank-cell button:disabled { opacity: 0.3; cursor: default; }

.btn-del {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 1rem;
  padding: 0.4rem 0.6rem;
  border-radius: 6px;
  transition: background 0.12s ease;
}
.btn-del:hover { background: color-mix(in srgb, var(--danger) 12%, transparent); }

.badge {
  display: inline-block;
  padding: 0.2rem 0.6rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.01em;
}
.badge.ok { background: color-mix(in srgb, var(--accent-2) 20%, transparent); color: var(--accent-2); }
.badge.no { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.badge.warn { background: color-mix(in srgb, var(--warn) 20%, transparent); color: var(--warn); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1.1rem;
  margin-top: 1.4rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 1.1rem 1.1rem;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.card:hover { transform: translateY(-3px); box-shadow: var(--shadow-lift); }

.card-photo {
  width: 100%;
  height: 170px;
  object-fit: cover;
  border-radius: 10px;
  margin-bottom: 0.7rem;
  background: var(--bg-soft);
  display: block;
}
.card-photo-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-size: 0.8rem;
  border: 1px dashed var(--border);
}

.card h3 { margin: 0 0 0.5rem; font-size: 1.05rem; font-weight: 700; }
.card .badges { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-bottom: 0.6rem; }
.card dl { margin: 0; font-size: 0.85rem; }
.card dt { color: var(--muted); margin-top: 0.4rem; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.02em; }
.card dd { margin: 0.05rem 0 0; }

.card-fields { margin-top: 0.8rem; border-top: 1px solid var(--border); padding-top: 0.7rem; }
.card-field { margin-bottom: 0.6rem; }
.card-field label { display: block; font-size: 0.73rem; color: var(--muted); margin-bottom: 0.2rem; text-transform: uppercase; letter-spacing: 0.02em; }
.card-field input,
.card-field textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg-soft);
  color: var(--text);
  padding: 0.42rem 0.55rem;
  font-size: 0.85rem;
  font-family: inherit;
  transition: border-color 0.12s ease, background 0.12s ease;
}
.card-field textarea { resize: none; overflow: hidden; display: block; }
.card-field input:hover, .card-field textarea:hover { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.card-field input:focus,
.card-field textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }
.card-field.cell-flash input,
.card-field.cell-flash textarea { background: color-mix(in srgb, var(--accent-2) 20%, transparent); transition: background 1.2s ease; }

.card-link {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  margin-top: 0.7rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent);
  text-decoration: none;
}
.card-link:hover { text-decoration: underline; }

#toast {
  position: fixed;
  bottom: 1.4rem;
  left: 50%;
  transform: translateX(-50%) translateY(1rem);
  background: var(--text);
  color: var(--bg);
  padding: 0.6rem 1.1rem;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  box-shadow: var(--shadow-lift);
  opacity: 0;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 640px) {
  header { padding: 1.1rem 1rem 0; }
  main { padding: 1rem 1rem 3rem; }
  h1 { font-size: 1.25rem; }
  .header-sub { font-size: 0.8rem; }
  .tab-btn { padding: 0.55rem 0.8rem; font-size: 0.88rem; }
  .cards { grid-template-columns: 1fr; }
  .panel-head { align-items: stretch; }
  .btn-add { width: 100%; text-align: center; }
}

.history-list { display: flex; flex-direction: column; gap: 0.5rem; }
.history-entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  font-size: 0.85rem;
  box-shadow: var(--shadow-sm);
  position: relative;
}
.history-entry .history-del { position: absolute; top: 0.3rem; right: 0.3rem; }
.history-entry .history-meta { color: var(--muted); font-size: 0.75rem; margin-top: 0.25rem; }
.history-entry .history-user { font-weight: 700; color: var(--accent); }
.history-empty { color: var(--muted); font-size: 0.9rem; padding: 1rem 0; }

.user-add-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.9rem;
}
.user-add-form input[type="text"],
.user-add-form input[type="password"] {
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg-soft);
  color: var(--text);
  padding: 0.5rem 0.65rem;
  font-size: 0.88rem;
  font-family: inherit;
  flex: 1 1 160px;
}
.user-admin-check { display: flex; align-items: center; gap: 0.35rem; font-size: 0.85rem; color: var(--muted); }

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 0.7rem;
  max-height: 62vh;
  overflow-y: auto;
  padding: 0.3rem 0.2rem 1rem;
  margin-bottom: 0.9rem;
}
.chat-bubble {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--chat-color, var(--accent));
  border-radius: 10px;
  padding: 0.6rem 0.85rem;
  font-size: 0.9rem;
  box-shadow: var(--shadow-sm);
  max-width: 640px;
}
.chat-bubble .chat-head { display: flex; align-items: baseline; gap: 0.5rem; margin-bottom: 0.2rem; }
.chat-bubble .chat-author { font-weight: 700; color: var(--chat-color, var(--accent)); font-size: 0.85rem; }
.chat-bubble .chat-time { font-size: 0.72rem; color: var(--muted); }
.chat-bubble .chat-content { white-space: pre-wrap; word-break: break-word; }
.chat-bubble .btn-del { float: right; margin: -0.3rem -0.4rem 0 0; }
.chat-empty { color: var(--muted); font-size: 0.9rem; padding: 1rem 0; }

.chat-form { display: flex; gap: 0.6rem; align-items: flex-end; }
.chat-form textarea {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  color: var(--text);
  padding: 0.6rem 0.8rem;
  font-size: 0.9rem;
  font-family: inherit;
  resize: none;
  overflow: hidden;
  min-height: 2.6rem;
  box-shadow: var(--shadow-sm);
}
.chat-form textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.account-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1.1rem;
  max-width: 900px;
}
.account-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.2rem 1.3rem;
  box-shadow: var(--shadow-sm);
}
.account-card h3 { margin: 0 0 0.3rem; font-size: 1rem; }
.account-card .header-sub { margin-bottom: 0.9rem; }

.color-picker { display: flex; flex-wrap: wrap; gap: 0.55rem; }
.color-swatch {
  width: 2.1rem;
  height: 2.1rem;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  position: relative;
  transition: transform 0.12s ease;
}
.color-swatch:hover:not(:disabled) { transform: scale(1.1); }
.color-swatch.selected { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--text); }
.color-swatch:disabled { cursor: not-allowed; opacity: 0.25; }
.color-swatch.selected::after { content: "✓"; position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: white; font-size: 0.9rem; text-shadow: 0 1px 2px rgba(0,0,0,0.4); }

.password-form .login-field { margin-bottom: 0.8rem; }

.proposal-card { margin-bottom: 1rem; max-width: none; }
.proposal-form { display: flex; flex-wrap: wrap; gap: 0.6rem; }
.proposal-form input {
  flex: 1 1 200px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--bg-soft);
  color: var(--text);
  padding: 0.5rem 0.65rem;
  font-size: 0.88rem;
  font-family: inherit;
}

.proposals-list { display: flex; flex-direction: column; gap: 0.6rem; margin-bottom: 1.2rem; }
.proposal-entry {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--warn);
  border-radius: 10px;
  padding: 0.7rem 0.9rem;
  font-size: 0.85rem;
  display: flex;
  align-items: flex-start;
  gap: 0.8rem;
  flex-wrap: wrap;
}
.proposal-entry .proposal-body { flex: 1 1 260px; min-width: 0; }
.proposal-entry .proposal-meta { color: var(--muted); font-size: 0.75rem; margin-top: 0.2rem; }
.proposal-entry .proposal-actions { display: flex; gap: 0.4rem; flex-shrink: 0; align-self: center; }
.proposal-photo {
  width: 110px;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  flex-shrink: 0;
}
.proposal-details {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 0.15rem 1rem;
  margin-top: 0.4rem;
  font-size: 0.8rem;
  color: var(--text);
}
.proposal-details strong { color: var(--muted); font-weight: 600; }
.btn-accept {
  background: var(--accent-2);
  color: white;
  border: none;
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
  font-weight: 600;
}
.btn-accept:hover { opacity: 0.9; }
.btn-reject {
  background: none;
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.4rem 0.8rem;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.82rem;
}
.btn-reject:hover { color: var(--danger); border-color: var(--danger); }

.login-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow-lift);
  padding: 2.2rem 2rem;
  width: 100%;
  max-width: 340px;
  text-align: center;
}
.login-emoji { font-size: 2.5rem; margin-bottom: 0.3rem; }
.login-card h1 { font-size: 1.3rem; margin: 0 0 0.3rem; }
.login-card .header-sub { margin-bottom: 1.3rem; }

.login-field { display: block; text-align: left; margin-bottom: 1rem; }
.login-field span { display: block; font-size: 0.78rem; color: var(--muted); margin-bottom: 0.25rem; text-transform: uppercase; letter-spacing: 0.02em; }
.login-field input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-soft);
  color: var(--text);
  padding: 0.55rem 0.7rem;
  font-size: 0.95rem;
  font-family: inherit;
}
.login-field input:focus { outline: 2px solid var(--accent); outline-offset: -1px; background: var(--surface); }

.login-submit { width: 100%; padding: 0.65rem; font-size: 0.95rem; margin-top: 0.4rem; }

.login-error {
  background: color-mix(in srgb, var(--danger) 15%, transparent);
  color: var(--danger);
  border-radius: 8px;
  padding: 0.5rem 0.7rem;
  font-size: 0.85rem;
  margin-bottom: 1rem;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}
