/* Lotto Bouse — tokens prairie + bouse */
:root {
  --background: #f6f9f4;
  --foreground: #18241d;
  --card: #ffffff;
  --card-foreground: #18241d;
  --muted: #e8efe4;
  --muted-foreground: #5a6b60;
  --border: #d5dfd0;
  --input: #c8d4c4;
  --primary: #2f8a57;
  --primary-foreground: #ffffff;
  --accent: #e6f3ec;
  --accent-foreground: #143d28;
  --bouse: #8b5e34;
  --bouse-foreground: #fff8ef;
  --grass: #c4e6d2;
  --grass-foreground: #143d28;
  --destructive: #b42318;
  --ring: #3fa36a;
  --radius: 12px;
  --font: "Plus Jakarta Sans", system-ui, sans-serif;
  --header-h: 5.5rem;
}

*, *::before, *::after { box-sizing: border-box; }
* { margin: 0; }
html {
  font-family: var(--font);
  -webkit-text-size-adjust: 100%;
  background: var(--background);
  color: var(--foreground);
}
body { min-height: 100dvh; line-height: 1.5; }
button, input { font: inherit; }
button { cursor: pointer; border: none; background: none; }
.tabular-nums { font-variant-numeric: tabular-nums; }

.material-symbols-rounded {
  font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
  line-height: 1;
  vertical-align: middle;
}

.app {
  max-width: 80rem;
  margin: 0 auto;
  padding: 1.5rem 1rem 2rem;
  min-height: 100dvh;
}
@media (min-width: 640px) { .app { padding-inline: 1.5rem; } }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.app-header {
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}
.header-inner {
  display: flex;
  align-items: center;
  gap: .85rem;
  padding: 1rem 1.1rem;
}
.header-icon {
  width: 3rem;
  height: 3rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
  background: var(--accent);
  color: var(--primary);
  font-size: 1.8rem;
}
.app-header h1 {
  font-size: clamp(1.5rem, 4vw, 2rem);
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.header-sub { color: var(--muted-foreground); font-size: .9rem; margin-top: .15rem; }

.tabs {
  display: flex;
  gap: .35rem;
  padding: .35rem;
  background: var(--muted);
  border-radius: calc(var(--radius) + 2px);
  margin-bottom: 1rem;
}
.tab {
  flex: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  padding: .65rem .8rem;
  border-radius: var(--radius);
  font-weight: 700;
  color: var(--muted-foreground);
  transition: background .15s, color .15s;
}
.tab.is-active {
  background: var(--primary);
  color: var(--primary-foreground);
}
.tab .material-symbols-rounded { font-size: 1.15rem; }

.view.is-hidden { display: none !important; }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .75rem;
}
.search-field {
  position: relative;
  display: flex;
  align-items: center;
  flex: 1 1 220px;
  max-width: 320px;
}
.search-field .material-symbols-rounded {
  position: absolute;
  left: .75rem;
  color: var(--muted-foreground);
  pointer-events: none;
}
.search-field input {
  width: 100%;
  height: 2.5rem;
  padding: 0 2.2rem 0 2.5rem;
  border: 1px solid var(--input);
  border-radius: calc(var(--radius) - 2px);
  background: var(--background);
}
.search-field input:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--ring);
}
.search-clear {
  position: absolute;
  right: .35rem;
  width: 2rem;
  height: 2rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: var(--muted-foreground);
}
.search-clear:hover { background: var(--muted); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  align-items: center;
  font-size: .82rem;
  color: var(--muted-foreground);
}
.legend-item { display: inline-flex; align-items: center; gap: .35rem; }
.swatch {
  width: .85rem;
  height: .85rem;
  border-radius: 3px;
  border: 1px solid var(--border);
}
.swatch-free { background: var(--card); }
.swatch-taken { background: var(--bouse); border-color: var(--bouse); }
.swatch-disabled { background: #c8d4cc; border-color: #a8b8ae; }
.legend-count { font-weight: 700; color: var(--foreground); }

.grid-wrap {
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
  max-height: min(70dvh, 720px);
}
.grid-table {
  border-collapse: collapse;
  text-align: center;
  font-size: 11px;
  width: max-content;
  min-width: 100%;
}
.grid-table th,
.grid-table td {
  border-bottom: 1px solid var(--border);
  border-right: 1px solid var(--border);
  min-width: 44px;
  padding: .35rem .25rem;
  transition: background .12s;
}
.grid-table thead th {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--muted);
  color: var(--muted-foreground);
  font-weight: 700;
}
.grid-table tbody th {
  position: sticky;
  left: 0;
  z-index: 10;
  background: var(--muted);
  color: var(--muted-foreground);
  font-weight: 700;
}
.grid-table thead th.corner {
  left: 0;
  z-index: 30;
}
.cell-num { font-weight: 800; display: block; }
.cell-coord { font-size: 9px; color: var(--muted-foreground); display: block; margin-top: 1px; }
.grid-cell.is-free { background: var(--card); }
.grid-cell.is-taken {
  background: var(--bouse);
  color: var(--bouse-foreground);
}
.grid-cell.is-taken .cell-coord { display: none; }
.grid-cell.is-highlight {
  outline: 2px solid var(--primary);
  outline-offset: -2px;
  z-index: 1;
}
.grid-cell.is-disabled {
  background: #e2ebe4;
  color: transparent;
}

.hint {
  display: flex;
  align-items: center;
  gap: .35rem;
  margin-top: .65rem;
  font-size: .82rem;
  color: var(--muted-foreground);
}
.hint .material-symbols-rounded { font-size: 1rem; }

/* Encodage */
.encode-layout {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  height: calc(100dvh - var(--header-h));
  min-height: 420px;
}
.assign-panel {
  order: 1;
  padding: 1rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--card);
}
.assign-panel h2 {
  font-size: 1rem;
  font-weight: 800;
  margin-bottom: .85rem;
}
.field-label {
  display: block;
  font-size: .82rem;
  font-weight: 700;
  margin-bottom: .35rem;
}
.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.input-wrap .material-symbols-rounded {
  position: absolute;
  left: .75rem;
  color: var(--muted-foreground);
}
.input-wrap input {
  width: 100%;
  height: 2.5rem;
  padding: 0 .75rem 0 2.5rem;
  border: 1px solid var(--input);
  border-radius: calc(var(--radius) - 2px);
  background: var(--background);
}
.input-wrap input:focus {
  outline: none;
  box-shadow: 0 0 0 2px var(--ring);
}
.selection-block { margin-top: .85rem; }
.selection-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: .85rem;
  margin-bottom: .4rem;
}
.link-btn {
  color: var(--primary);
  font-weight: 700;
  font-size: .82rem;
}
.link-btn:disabled { opacity: .4; cursor: not-allowed; }
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: .35rem;
  max-height: 4rem;
  overflow: auto;
  min-height: 1.5rem;
}
.chip {
  display: inline-flex;
  align-items: center;
  gap: .2rem;
  padding: .15rem .55rem;
  border-radius: 999px;
  background: var(--accent);
  font-size: .75rem;
  font-weight: 700;
}
.chip button {
  width: 1.1rem;
  height: 1.1rem;
  display: grid;
  place-items: center;
  border-radius: 999px;
  color: var(--accent-foreground);
}
.chip button:hover { background: rgba(0,0,0,.08); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .45rem;
  width: 100%;
  margin-top: .85rem;
  padding: .7rem 1rem;
  border-radius: calc(var(--radius) - 2px);
  font-weight: 800;
}
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary {
  background: var(--primary);
  color: var(--primary-foreground);
}
.btn-primary:not(:disabled):hover { filter: brightness(1.05); }
.btn-icon.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.status-msg {
  margin-top: .75rem;
  padding: .65rem .8rem;
  border-radius: calc(var(--radius) - 2px);
  font-size: .88rem;
  font-weight: 600;
}
.status-msg.is-success {
  background: var(--grass);
  color: var(--grass-foreground);
}
.status-msg.is-error {
  background: rgba(180, 35, 24, .1);
  color: var(--destructive);
}
.help-text {
  margin-top: .65rem;
  font-size: .78rem;
  color: var(--muted-foreground);
}

.encode-main {
  order: 2;
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}
.encode-toolbar { margin-bottom: .5rem; }
.encode-stats { font-size: .82rem; color: var(--muted-foreground); font-weight: 600; }

.nav-quick { margin-bottom: .65rem; }
.nav-hundreds {
  display: flex;
  gap: .35rem;
  overflow-x: auto;
  padding-bottom: .35rem;
  margin-bottom: .5rem;
}
.btn-sm {
  flex: none;
  height: 2rem;
  padding: 0 .55rem;
  border: 1px solid var(--input);
  border-radius: calc(var(--radius) - 4px);
  background: var(--background);
  font-size: .78rem;
  font-weight: 700;
}
.btn-sm:hover { background: var(--accent); }
.slider-wrap {
  display: grid;
  gap: .35rem;
  font-size: .82rem;
  color: var(--muted-foreground);
  font-weight: 600;
}
.slider-wrap input[type="range"] {
  width: 100%;
  accent-color: var(--primary);
}

.tiles-wrap {
  flex: 1;
  min-height: 0;
  padding: .75rem;
  overflow: auto;
}
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(52px, 1fr));
  gap: .35rem;
}
.tile {
  height: 3rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--input);
  border-radius: calc(var(--radius) - 4px);
  background: var(--background);
  font-size: .75rem;
  transition: background .12s, border-color .12s, color .12s;
}
.tile-num { font-weight: 800; line-height: 1.1; }
.tile-coord { font-size: 9px; color: var(--muted-foreground); line-height: 1; margin-top: 1px; }
.tile.is-free:hover { background: var(--accent); }
.tile.is-selected {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--primary-foreground);
}
.tile.is-selected .tile-coord { color: rgba(255,255,255,.8); }
.tile.is-taken {
  background: var(--muted);
  color: rgba(90, 107, 96, .55);
  text-decoration: line-through;
  cursor: not-allowed;
}
.tile.is-decade:not(.is-selected):not(.is-taken) {
  border-color: rgba(47, 138, 87, .45);
}
.tile.is-hidden { display: none; }
.tile.is-disabled {
  background: #e2ebe4;
  color: #8a9a90;
  cursor: not-allowed;
  text-decoration: none;
}

.empty-filter {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted-foreground);
}

@media (min-width: 1024px) {
  .encode-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    height: auto;
    min-height: 520px;
  }
  .assign-panel {
    order: 2;
    position: sticky;
    top: 1.5rem;
    align-self: start;
  }
  .encode-main { order: 1; }
  .tiles-wrap { height: 460px; flex: none; }
  .help-text { display: block; }
}

@media (max-width: 1023px) {
  .help-text { display: none; }
  .encode-layout {
    height: calc(100dvh - 14.5rem);
  }
}

@media (max-width: 640px) {
  .nav-quick.is-filtering { display: none; }
}

/* Header organisation + sync */
.header-inner { flex-wrap: wrap; }
.header-titles { flex: 1; min-width: 0; }
.header-actions {
  display: flex;
  align-items: center;
  gap: .45rem;
  margin-left: auto;
}
.sync-btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .45rem .7rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--background);
  font-weight: 700;
  font-size: .78rem;
}
.sync-dot {
  width: .65rem;
  height: .65rem;
  border-radius: 999px;
  flex: none;
}
.sync-dot--green { background: #2f8a57; }
.sync-dot--yellow { background: #e6962f; animation: pulseDot 1s ease infinite; }
.sync-dot--red { background: #b42318; }
@keyframes pulseDot { 50% { opacity: .45; } }

.grid-cell.is-pending { background: #f6dcae; color: #5c4a1a; }
.tile.is-pending {
  background: #f6dcae;
  border-color: #e6962f;
  cursor: wait;
}

.modal[hidden] { display: none !important; }
.modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.45);
}
.modal-panel {
  position: relative;
  width: min(420px, 100%);
  max-height: 80dvh;
  overflow: auto;
  padding: 1rem;
}
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: .85rem;
}
.modal-head h2 { font-size: 1.1rem; font-weight: 800; }
.sync-queue-list {
  list-style: none;
  padding: 0;
  display: grid;
  gap: .55rem;
  font-size: .88rem;
}
.sync-queue-list .muted { color: var(--muted-foreground); font-size: .75rem; }
.sync-ok-msg {
  display: flex;
  align-items: center;
  gap: .5rem;
  color: var(--grass-foreground);
  background: var(--grass);
  padding: .75rem;
  border-radius: calc(var(--radius) - 2px);
  font-weight: 600;
}

/* Login */
.login-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 1.5rem;
}
.login-card {
  width: min(400px, 100%);
  padding: 1.5rem;
  text-align: center;
}
.login-card h1 { margin-top: .75rem; font-size: 1.6rem; }
.login-sub { color: var(--muted-foreground); margin: .35rem 0 1rem; }
.login-form { text-align: left; display: grid; gap: .85rem; }
.login-form input {
  width: 100%;
  height: 2.5rem;
  padding: 0 .75rem;
  border: 1px solid var(--input);
  border-radius: calc(var(--radius) - 2px);
  background: var(--background);
}
.login-foot { margin-top: 1rem; font-size: .85rem; }
.login-foot a { color: var(--primary); font-weight: 700; }

/* Configuration */
.config-panel { padding: 1.25rem; }
.config-panel h2 {
  font-size: 1.05rem;
  font-weight: 800;
  margin-bottom: .85rem;
}
.config-section-title { margin-top: 1.5rem; }
.config-grid {
  display: grid;
  gap: 1rem;
}
@media (min-width: 720px) {
  .config-grid { grid-template-columns: 1fr 1fr; }
  .config-grid--dims { grid-template-columns: 120px 120px; }
}
.config-panel input[type="text"],
.config-panel input[type="number"],
.config-panel input[type="datetime-local"] {
  width: 100%;
  height: 2.5rem;
  padding: 0 .75rem;
  border: 1px solid var(--input);
  border-radius: calc(var(--radius) - 2px);
  background: var(--background);
}
.field-hint {
  display: block;
  margin-top: .35rem;
  font-size: .78rem;
  color: var(--muted-foreground);
}
.upload-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: .65rem;
}
.cfg-logo-preview {
  height: 3rem;
  width: 3rem;
  object-fit: contain;
  background: var(--primary);
  border-radius: calc(var(--radius) - 4px);
  padding: .25rem;
}
.edge-picker { margin-top: 1rem; }
.edge-preview {
  position: relative;
  width: 5rem;
  height: 5rem;
  margin: .65rem 0;
  background: var(--grass);
  border-radius: 4px;
}
.edge-preview .edge {
  position: absolute;
  background: rgba(255,255,255,.35);
  transition: background .15s;
}
.edge-preview .edge.is-active { background: #f6dcae; }
.edge-top { top: 0; left: 0; right: 0; height: 6px; }
.edge-bottom { bottom: 0; left: 0; right: 0; height: 6px; }
.edge-left { top: 0; bottom: 0; left: 0; width: 6px; }
.edge-right { top: 0; bottom: 0; right: 0; width: 6px; }
.edge-inner {
  position: absolute;
  inset: 12px;
  border: 1px dashed rgba(255,255,255,.5);
  border-radius: 2px;
}
.edge-btns { display: flex; flex-wrap: wrap; gap: .35rem; }
.edge-btn.is-active {
  background: var(--primary);
  color: var(--primary-foreground);
  border-color: var(--primary);
}
.config-actions {
  display: flex;
  flex-wrap: wrap;
  gap: .65rem;
  margin-top: 1.25rem;
}
.config-actions .btn { width: auto; flex: 1; min-width: 160px; }
.btn-secondary {
  background: var(--background);
  border: 1px solid var(--border);
  color: var(--foreground);
}

.modal--fullscreen .modal-panel--wide {
  width: min(960px, 100%);
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
}
.modal-intro {
  font-size: .88rem;
  color: var(--muted-foreground);
  margin-bottom: .75rem;
}
.disable-grid-wrap {
  flex: 1;
  min-height: 0;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.disable-table .disable-cell {
  cursor: pointer;
  user-select: none;
}
.disable-table .disable-cell.is-disabled {
  background: #c8d4cc;
  color: #5a6b60;
  text-decoration: line-through;
}
.modal-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: .85rem;
  flex-wrap: wrap;
}
.disable-count { font-size: .88rem; font-weight: 700; }
.modal-foot .btn { width: auto; margin-top: 0; min-width: 140px; }

@media (min-width: 1024px) {
  .modal--fullscreen { padding: .75rem; }
  .modal--fullscreen .modal-panel--wide {
    width: min(1100px, 100%);
    max-height: 94dvh;
  }
}
