/*
  Tricoti — Paperclips-like UI
  Objectif: interface très claire, "flat", bordures nettes, peu/pas d'animations.
  (La progression des menus/boutons est gérée par JS, ce fichier ne fait que le visuel.)
*/

:root {
  --bg: #ffffff;
  --panel: #f5f5f5;
  --panel2: #ffffff;

  --border: grey;
  --border-strong: #000000;

  --text: #000000;
  --muted: #555555;

  --btn-bg: #d3d3d3;
  --btn-bg-hover: #e5e5e5;
  --btn-bg-active: #bdbdbd;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-weight: 300;
  background: var(--bg);
  color: var(--text);
}

/* Game Over modal */
.tricoti-modal-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.35);
  z-index: 9999;
}

.tricoti-modal-overlay[hidden] {
  display: none !important;
}

.tricoti-modal {
  width: min(540px, 100%);
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 0;
  padding: 18px;
  box-shadow: 0 8px 36px rgba(0, 0, 0, 0.25);
}

.tricoti-modal__title {
  font-weight: 700;
  font-size: 18px;
  margin-bottom: 8px;
}

.tricoti-modal__message {
  margin-bottom: 10px;
  line-height: 1.45;
}

.tricoti-modal__details {
  white-space: pre-line;
  opacity: 0.95;
  font-size: 13px;
  margin-bottom: 16px;
}

.tricoti-modal__actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.muted { color: var(--muted); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
  z-index: 999;
}

.modal[hidden] {
  display: none !important;
}

.modal__card {
  width: min(520px, 100%);
}

.app-header {
  display: grid;
  /* Layout: brand | center company | actions (right) */
  grid-template-columns: auto 1fr auto;
  align-items: center;
  padding: 8px 10px;
  background: var(--bg);
  border-bottom: 1px solid var(--border-strong);
  max-width: none;
  margin: 0;
}

.header-actions {
  justify-self: end;
}

.header-company {
  justify-self: center;
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
  padding: 2px 6px;
  border: 1px solid var(--border-strong);
  background: var(--panel2);
  max-width: min(420px, 60vw);
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}

.brand__title {
  font-weight: 700;
  letter-spacing: 0.01em;
  color: var(--text);
  font-size: 18px;
}

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

.app {
  max-width: none;
  margin: 0;
  padding: 10px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 0;
  padding: 10px;
  margin-bottom: 10px;
  box-shadow: none;
  position: static;
  overflow: visible;
}

/* Paperclips-style cursor blink utility (optional usage) */
.pulsate {
  -webkit-animation: pulsate 0.5s ease-out;
  -webkit-animation-iteration-count: infinite;
  opacity: 0.0;
}

@-webkit-keyframes pulsate {
  0% { opacity: 0.0; }
  50% { opacity: 1.0; }
  100% { opacity: 0.0; }
}

.grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

@media (max-width: 900px) {
  .grid { grid-template-columns: 1fr; }
}

.row {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

/* Production row: align items so the craft button sits level with selects */
.production-row {
  align-items: flex-end;
}

/* Sell row: align sell button with select/input controls */
.sell-row {
  align-items: flex-end;
}

/* Buy wool row: align buy button with select and qty */
.buy-wool-row {
  align-items: flex-end;
}

/* Company creation row: align create button with company name input */
.company-create-row {
  align-items: flex-end;
}

/* Livestock actions row: align buttons with the quantity input */
.livestock-buy-row {
  align-items: flex-end;
}

.land-row {
  align-items: center;
}

.company-extension-row {
  align-items: flex-end;
}

.company-ops__row {
  gap: 12px;
  align-items: flex-end;
  flex-wrap: wrap;
}

.machine-buy-group {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.machine-buy-group label {
  flex: 1 1 140px;
}

.machine-buy-group button {
  white-space: nowrap;
}

label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
}

/* Label-like wrapper for non-label controls (e.g. buttons) so they align with inputs */
.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 12px;
  min-width: 0;
}

.row > .field {
  flex: 0 0 auto;
}

.field--button .field-spacer {
  visibility: hidden; /* keeps height like a label line */
}

.layout {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  flex-wrap: wrap;
}

.sidebar {
  /* Flexible sidebar: clamps between a small and max width so layout adapts to text and zoom */
  width: clamp(160px, 18%, 275px);
  flex: 0 0 clamp(160px, 18%, 275px);
  position: static;
  max-height: none;
  overflow: visible;
  min-width: 140px;
}

.content {
  flex: 1 1 auto;
  min-width: 0;
}

.home-grid {
  display: grid;
  /* Dashboard narrower, other columns expand */
  grid-template-columns: 220px 1fr 1fr;
  gap: 10px;
}

.home-grid > .card {
  margin-bottom: 0;
  max-height: none;
  overflow: visible;
}

@media (max-width: 1100px) {
  .home-grid { grid-template-columns: 1fr; }
  .home-grid > .card { max-height: none; }
}

.nav {
  display: block;
  margin-top: 6px;
}

.nav__btn {
  display: block;
  width: 100%;
  margin: 0 0 4px 0;
  padding: 4px 6px;
  border-radius: 0;
  border: 1px solid var(--border-strong);
  background: var(--btn-bg);
  color: var(--text);
  font-family: inherit;
  font-weight: 400;
  font-size: 12px;
  cursor: pointer;
  box-shadow: none;
}

.nav__btn:hover {
  background: var(--btn-bg-hover);
}

.nav__btn:active {
  background: var(--btn-bg-active);
}

.nav__btn:disabled,
.nav__btn.is-disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.nav__btn.is-active {
  background: var(--panel2);
}

@media (max-width: 900px) {
  /* On mobile, stack sidebar + content and stretch them to full width */
  .layout { flex-direction: column; align-items: stretch; }
  .sidebar { width: 100%; flex: 0 0 auto; position: static; max-height: none; min-width: 0; }
  .content { width: 100%; }
}

.input {
  min-width: 0; 
  max-width: 100%; 
}

/* Allow content and cards to shrink inside flex/grid containers */
.content { min-width: 0; flex: 1 1 0; }
.home-grid { width: 100%; }
.home-grid > .card { min-width: 0; width: 100%; box-sizing: border-box; }
.card { min-height: 0; box-sizing: border-box; width: 100%; }

/* Let labels inside rows shrink so controls can wrap neatly */
.row > label { min-width: 0; flex: 1 1 0; }

/* Ensure selects / inputs don't force containers wider than available */
.row select, .row input { max-width: 100%; }

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

/* Slightly larger titles for leaderboard columns */
.leaderboard-title {
  font-size: 14px;
  color: var(--text);
  font-weight: 200;
}

/* Larger header for the leaderboards 'Top players' label */
.leaderboard-header {
  font-size: 14px;
  color: var(--text);
  font-weight: 700;
}

.leaderboard-records {
  border: 1px dashed var(--border);
  background: var(--panel2);
  padding: 8px;
  margin: 8px 0 12px;
}

.leaderboard-records .stats {
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
}

.leaderboard-mode {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin: 6px 0 12px;
}

.btn-segment {
  border: 1px solid var(--border);
  background: var(--panel2);
  color: var(--text);
  padding: 4px 12px;
  font-size: 12px;
  font-weight: 600;
  text-transform: none;
  cursor: pointer;
  border-radius: 0;
}

.btn-segment.is-active {
  background: var(--btn-bg-active);
  color: var(--text);
  border-color: var(--border-strong);
}

.leaderboard-list li {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  background: transparent;
}

.leaderboard-list li:last-child {
  border-bottom: none;
}

.leaderboard-rank {
  width: 24px;
  font-weight: 400;
  color: var(--muted);
}

.leaderboard-name {
  display: flex;
  align-items: center;
  gap: 4px;
  flex: 1;
  min-width: 0;
  font-weight: 400;
}

.leaderboard-value {
  margin-left: auto;
  font-weight: 400;
  color: var(--text);
}

.leaderboard-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  border: 1px solid var(--border);
  display: inline-block;
  margin-right: 6px;
}

.leaderboard-dot--online { background: #0b8e3a; }
.leaderboard-dot--offline { background: #b3261e; }

.leaderboard-badge {
  border: 1px solid var(--border);
  padding: 0 6px;
  font-size: 10px;
  letter-spacing: 0.06em;
  font-weight: 500;
  background: var(--panel2);
}

h1, h2, h3 {
  color: var(--text);
  text-shadow: none;
  font-weight: 700;
}

h1 { font-size: 20px; margin-bottom: 6px; }
h2 { font-size: 16px; margin-bottom: 6px; line-height: 1.1; }
h3 { font-size: 13px; margin: 8px 0 4px; }

p { line-height: 1.25; margin: 0 0 6px 0; }

.stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

/* Dashboard stats: labels bold and values on the next line */
.stats .label { display: block; font-weight: 700; min-width: 0; }
.stats div span:not(.label) { display: block; }

.label { display: inline-block; min-width: 96px; }

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

@media (max-width: 520px) {
  .actions { grid-template-columns: 1fr; }
}

.inventory {
  display: grid;
  /* Narrower 'Laine' column, wider 'Stock' (vêtements) column */
  grid-template-columns: 120px 1fr;
  gap: 10px;
}

@media (max-width: 520px) {
  .inventory { grid-template-columns: 1fr; }
}

.inv-block {
  border: 1px solid var(--border);
  background: var(--panel2);
  padding: 8px;
  border-radius: 0;
}

.support-staff {
  border: 1px solid var(--border);
  background: var(--panel2);
  padding: 8px;
  margin: 10px 0;
}

.support-staff__grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 8px;
  margin-top: 8px;
}

.support-staff__item {
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 8px;
}

.support-staff__head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  margin-bottom: 4px;
}

.support-staff__title {
  font-weight: 400;
  font-size: 12px;
  text-transform: uppercase;
}

.support-staff__status {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.support-staff__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
}

.inv-title { font-weight: bold; margin-bottom: 6px; }

.inv-grid {
  display: grid;
  /* Show each wool type on its own line (single column) to avoid cramped two-column layout */
  grid-template-columns: 1fr;
  gap: 6px;
}

/* Keep label:value pairs on the same line in wool inventory (e.g. "Basique: 9") */
.inv-grid:not(.inv-grid--stock) > div {
  display: inline-flex;
  gap: 6px;
  align-items: baseline;
  white-space: nowrap;
}

.inv-grid--stock {
  /* Make stock columns flexible so they can shrink without causing overflow */
  grid-template-columns: 1.4fr repeat(3, minmax(0, 1fr));
  align-items: baseline;
}

/* Stock cells: label left, value right; allow label to ellipsize but keep the numeric value together */
.inv-grid--stock > div {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  min-width: 0; /* allows flex children to shrink */
}

.inv-grid--stock > div span {
  white-space: nowrap; /* keep the numeric value on one line */
}

.log {
  height: 260px;
  overflow: auto;
  padding: 8px;
  border: 1px solid var(--border-strong);
  border-radius: 0;
  background: var(--panel2);
}

.log .line { margin: 0 0 6px 0; }

.two-col {
  display: grid;
  grid-template-columns: 1fr 1.4fr;
  gap: 12px;
}

@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
}

.list {
  list-style: none;
  padding: 0;
  margin: 8px 0 0 0;
}

.list li {
  padding: 8px 10px;
  border: 1px solid var(--border);
  background: var(--panel2);
  border-radius: 0;
  margin-bottom: 8px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}

.calendar-cell {
  border: 1px solid var(--border);
  border-radius: 0;
  background: var(--panel2);
  padding: 10px;
}

.calendar-cell.good { background: #ddffdd; }
.calendar-cell.bad { background: #ffdddd; }
.calendar-cell.neutral { background: #efefef; }

.btn-link {
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0;
  font: inherit;
  text-align: left;
  text-decoration: underline;
  cursor: pointer;
  color: var(--text);
}

/* Make the leaderboards "Refresh" link match the "Top joueurs" header size */
#btnRefreshLeaderboards {
  font-size: 14px;
  font-weight: 200;
  text-decoration: underline;
  color: var(--text);
  background: transparent;
  border: 0;
  padding: 0;
  margin: 0;
}

/* Price trend indicator next to unit price */
.price-trend {
  font-weight: 700;
  margin-left: 8px;
}
.price-trend.up { color: #0a8a0a; }
.price-trend.down { color: #a00; }
.price-trend.eq { color: #666; }

.chat {
  height: 200px;
  overflow: auto;
  border: 1px solid var(--border-strong);
  padding: 8px;
  border-radius: 0;
  background: var(--panel2);
}

.chat .msg { margin: 0 0 8px 0; }

hr {
  display: block;
  margin-top: 0.05em;
  margin-bottom: 0.2em;
  margin-left: auto;
  margin-right: auto;
  border-style: inset;
  border-width: 1px;
}

/* Controls */
button,
.btn {
  background: var(--btn-bg);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  font-weight: 400;
  border: 1px solid var(--border-strong);
  border-radius: 0;
  padding: 4px 6px;
  cursor: pointer;
  box-shadow: none;
}

button:hover,
.btn:hover {
  background: var(--btn-bg-hover);
}

button:active,
.btn:active {
  background: var(--btn-bg-active);
}

button:disabled,
.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn--secondary {
  background: var(--btn-bg);
  border: 1px solid var(--border-strong);
}

.btn--secondary:hover {
  background: var(--btn-bg-hover);
}

input,
select,
textarea,
.input {
  background: var(--panel2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: 0;
  padding: 4px 6px;
  font-family: inherit;
  box-shadow: none;
  font-size: 12px;
}

input:focus,
select:focus,
textarea:focus,
.input:focus {
  outline: none;
  border-color: var(--border-strong);
}

textarea {
  min-height: 120px;
  resize: vertical;
}

@media (max-width: 900px) {
  .layout { flex-direction: column; align-items: stretch; }
  .sidebar { width: 100%; flex: 0 0 auto; min-width: 0; }
  .content { width: 100%; }
}

/* Toast notifications (in-page, auto-dismiss) */
.toast-container {
  position: fixed;
  top: 56px; /* below header */
  right: 10px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 1000;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  width: min(360px, calc(100vw - 20px));
  border: 1px solid var(--border-strong);
  background: var(--panel2);
  /* Slight transparency so toasts obstruct the game less */
  opacity: 0.92;
  backdrop-filter: blur(4px);
  padding: 8px 10px;
}

.toast__title {
  font-weight: 700;
  margin-bottom: 4px;
}

.toast__message {
  white-space: pre-wrap;
  line-height: 1.25;
}

.toast--danger { background: rgba(255,239,239,0.92); }
.toast--ok { background: rgba(239,255,239,0.92); }

/* Mobile: persistent buy-phone button */

/* Responsive adjustments for Phone view and toasts */
@media (max-width: 900px) {
  /* Ensure toasts don't overlap the bottom UI on small screens */
  .toast-container { top: 12px; right: 8px; }
}

@media (min-width: 901px) {
  .toast-container { top: 12px; right: 8px; }
}
