/* The Tactical Buddy PWA — tema alinhado com a app Flutter */
:root {
  --white: #ffffff;
  --black: #1a1a1a;
  --orange: #ff6b00;
  --gray: #f5f5f7;
  --muted: #6b7280;
  --blue-def: #1d4ed8;
  --screen: #0f172a;
  --slip: #6d28d9;
  --danger: #dc2626;
  --danger-bg: #fee2e2;
  --badge-bg: #fff3e8;
  --border: #e5e7eb;
  --shadow: 0 8px 28px rgba(26, 26, 26, 0.08);
  --modal-scrim: rgba(0, 0, 0, 0.4);
  --nav-inactive: rgba(0, 0, 0, 0.54);
  --center-grad: linear-gradient(180deg, #ffffff 0%, #fff7f0 100%);
  --court-bg: #f2e5d3;
  --toast-bg: #1a1a1a;
  --toast-fg: #ffffff;
  --radius: 12px;
  --nav-h: 64px;
  --top-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}

html[data-theme="dark"] {
  --white: #121214;
  --black: #f3f4f6;
  --orange: #ff7a1a;
  --gray: #1c1c20;
  --muted: #9ca3af;
  --danger: #f87171;
  --danger-bg: #3f1d1d;
  --badge-bg: #3a2410;
  --border: #2a2a30;
  --shadow: 0 10px 32px rgba(0, 0, 0, 0.45);
  --modal-scrim: rgba(0, 0, 0, 0.65);
  --nav-inactive: rgba(243, 244, 246, 0.55);
  --center-grad: linear-gradient(180deg, #121214 0%, #1a1510 100%);
  --court-bg: #3a2f24;
  --toast-bg: #f3f4f6;
  --toast-fg: #121214;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--black);
  background: var(--white);
  -webkit-tap-highlight-color: transparent;
}

.hidden { display: none !important; }
.view { min-height: 100vh; }
.center-view {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: var(--center-grad);
}

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--gray);
  border-top-color: var(--orange);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.muted { color: var(--muted); margin: 0; }
.error { color: var(--danger); font-size: 0.9rem; margin: 0; }
.gap { gap: 8px; }
.row { display: flex; align-items: center; }
.wrap { flex-wrap: wrap; }
.block { width: 100%; }

/* Auth / cards */
.auth-card {
  width: min(420px, calc(100% - 32px));
  margin: 24px auto;
  padding: 24px;
  background: var(--white);
  border-radius: 16px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}
.auth-card.wide { width: min(520px, calc(100% - 32px)); }
.auth-locale-field { margin-bottom: 8px; }
.auth-locale-field select { padding: 10px 12px; }
.brand { text-align: center; margin-bottom: 20px; }
.brand h1 { margin: 8px 0 4px; font-size: 1.4rem; }
.brand-mark {
  width: 64px;
  height: 64px;
  margin: 0 auto;
  border-radius: 16px;
  background: var(--orange);
  color: #fff;
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 1.4rem;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  background: var(--gray);
  padding: 4px;
  border-radius: 10px;
  margin-bottom: 16px;
}
.seg {
  border: 0;
  background: transparent;
  padding: 10px;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
}
.seg.active { background: var(--white); color: var(--black); box-shadow: var(--shadow); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-size: 0.9rem; }
.field span { color: var(--muted); font-weight: 600; }
input, textarea, select {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font: inherit;
  background: var(--white);
  color: var(--black);
}
textarea { resize: vertical; }
input:focus, textarea:focus, select:focus {
  outline: 2px solid rgba(255, 107, 0, 0.35);
  border-color: var(--orange);
}

.btn {
  border: 0;
  border-radius: 10px;
  padding: 11px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  background: var(--gray);
  color: var(--black);
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary { background: var(--orange); color: #fff; }
.btn.ghost { background: transparent; border: 1px solid var(--border); }
.btn.danger { background: var(--danger-bg); color: var(--danger); }
.btn.small { padding: 7px 10px; font-size: 0.85rem; }

/* App shell */
.app-shell {
  display: grid;
  grid-template-rows: var(--top-h) 1fr calc(var(--nav-h) + var(--safe-b));
  height: 100vh;
  max-height: 100dvh;
}
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  border-bottom: 1px solid var(--border);
  background: var(--white);
}
.topbar h1 {
  flex: 1;
  margin: 0;
  font-size: 1.05rem;
  font-weight: 650;
  text-align: center;
}
.topbar-actions { display: flex; gap: 6px; min-width: 40px; justify-content: flex-end; align-items: center; }
.icon-btn {
  border: 1px solid var(--border);
  background: var(--white);
  width: 36px;
  height: 36px;
  border-radius: 10px;
  cursor: pointer;
  font-size: 1.05rem;
  display: inline-grid;
  place-items: center;
  color: var(--black);
  padding: 0;
  line-height: 1;
}
.icon-btn:active { transform: scale(0.96); }
.theme-btn { font-size: 1.15rem; }

.main-content {
  overflow: auto;
  background: var(--white);
  -webkit-overflow-scrolling: touch;
}
.screen { padding: 16px; padding-bottom: 24px; }

.bottom-nav {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  border-top: 1px solid var(--border);
  background: var(--white);
  padding-bottom: var(--safe-b);
}
.nav-item {
  border: 0;
  background: transparent;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  font-size: 0.7rem;
  color: var(--nav-inactive);
  cursor: pointer;
}
.nav-item .nav-ico { font-size: 1.25rem; line-height: 1; }
.nav-item.active { color: var(--orange); font-weight: 700; }

/* Cards / lists */
.card {
  background: var(--gray);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 10px;
}
.card.clickable { cursor: pointer; }
.card.clickable:active { transform: scale(0.99); }
.card h3 { margin: 0 0 4px; font-size: 1rem; }
.card p { margin: 0; color: var(--muted); font-size: 0.9rem; }
.list-empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
}

.chip-row { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0; }
.chip {
  border: 1px solid var(--border);
  background: var(--white);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.85rem;
  cursor: pointer;
}
.chip.active { background: var(--orange); color: #fff; border-color: var(--orange); }

.fab {
  position: fixed;
  right: 18px;
  bottom: calc(var(--nav-h) + var(--safe-b) + 16px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  border: 0;
  background: var(--orange);
  color: #fff;
  font-size: 1.6rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  z-index: 20;
}

/* Playbook */
.playbook-meta { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.board-layout {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
  align-items: start;
}
.tools {
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.tool-btn {
  border: 1px solid var(--border);
  background: var(--white);
  border-radius: 10px;
  padding: 8px 4px;
  font-size: 0.68rem;
  font-weight: 700;
  cursor: pointer;
  text-align: center;
  line-height: 1.2;
}
.tool-btn.active { background: var(--orange); color: #fff; border-color: var(--orange); }
.board-wrap {
  width: 100%;
  background: var(--court-bg);
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid var(--border);
  touch-action: none;
  user-select: none;
}
#tactical-canvas {
  display: block;
  width: 100%;
  height: auto;
  max-height: min(70vh, 820px);
  background: var(--court-bg);
  touch-action: none;
  cursor: crosshair;
}
.steps-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
}
#timeline { flex: 1; min-width: 120px; }

/* Profile / forms */
.kv { display: grid; gap: 8px; }
.kv-row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.95rem;
}
.kv-row span:first-child { color: var(--muted); }
.section-title {
  margin: 18px 0 8px;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
}

.badge {
  display: inline-block;
  background: var(--badge-bg);
  color: var(--orange);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.75rem;
  font-weight: 700;
}

/* Sheet full-screen: header + body com scroll + footer fixo */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: var(--white);
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
  max-height: 100dvh;
  overflow: hidden;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.sheet.hidden { display: none !important; }
.sheet-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  flex: 0 0 auto;
  background: var(--white);
}
.sheet-head h3 {
  margin: 0;
  font-size: 1.1rem;
}
.sheet-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 16px;
  line-height: 1.5;
  white-space: normal;
}
.sheet-foot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  flex: 0 0 auto;
  background: var(--white);
}

/* compat com nomes antigos usados noutros sítios */
.modal { /* alias */ }
.modal-card,
.modal-head,
.modal-body,
.modal-actions { /* legado ignorado — sheet substitui */ }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + 24px);
  transform: translateX(-50%);
  background: var(--toast-bg);
  color: var(--toast-fg);
  padding: 10px 16px;
  border-radius: 999px;
  z-index: 60;
  font-size: 0.9rem;
  max-width: 90vw;
}

.theme-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0 2px;
}
.theme-toggle strong { font-size: 0.95rem; }
.theme-switch {
  position: relative;
  width: 52px;
  height: 30px;
  flex-shrink: 0;
}
.theme-switch input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}
.theme-switch span {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s ease;
}
.theme-switch span::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
  transition: transform 0.2s ease;
}
.theme-switch input:checked + span { background: var(--orange); }
.theme-switch input:checked + span::after { transform: translateX(22px); }
html[data-theme="dark"] .theme-switch span::after { background: #f3f4f6; }

.ai-text {
  display: block;
  white-space: pre-wrap;
  overflow: visible;
  overflow-wrap: break-word;
  word-break: break-word;
  line-height: 1.6;
  font-size: 1rem;
  height: auto;
  max-height: none;
  min-height: min-content;
  padding-bottom: 24px;
  color: var(--black);
}
.ai-text h4 { margin: 14px 0 8px; color: var(--black); }
.ai-text p { margin: 0 0 10px; }
.ai-text strong { color: var(--black); font-weight: 700; }

.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
}

@media (min-width: 900px) {
  .sheet-body { padding: 20px 28px 32px; max-width: 720px; width: 100%; margin: 0 auto; }
  .sheet-head, .sheet-foot { padding-left: 28px; padding-right: 28px; }
  .board-layout { grid-template-columns: 90px 1fr; }
  .tool-btn { font-size: 0.75rem; padding: 10px 6px; }
}

.hero {
  margin-bottom: 14px;
}
.hero h2 {
  margin: 0 0 6px;
  font-size: 1.35rem;
}
.grid-cards {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}
.action-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  border: 0;
  width: 100%;
  cursor: pointer;
  font: inherit;
  color: inherit;
}
.action-card strong { font-size: 1rem; }
.action-card span { color: var(--muted); font-size: 0.85rem; }
.list { display: flex; flex-direction: column; gap: 8px; }
.list-row {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  width: 100%;
  text-align: left;
  border: 0;
  background: var(--gray);
  border-radius: var(--radius);
  padding: 14px;
  font: inherit;
  cursor: pointer;
}
.list-row span { color: var(--muted); font-size: 0.9rem; }
.training-ex-list { margin-top: 4px; gap: 6px; }
.training-ex-row {
  cursor: default;
  padding: 8px 12px;
  gap: 2px;
}
.training-ex-row strong {
  font-size: 0.88rem;
  line-height: 1.25;
}
.training-ex-row span {
  font-size: 0.78rem;
  line-height: 1.35;
}
.empty, .list-empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
}

#screen-playbook.read-only .playbook-meta,
#screen-playbook.read-only .tools,
#screen-playbook.read-only #btn-add-step,
#screen-playbook.read-only #btn-undo {
  display: none;
}

#screen-playbook.read-only .board-layout {
  grid-template-columns: 1fr;
}

@media (max-width: 520px) {
  .board-layout { grid-template-columns: 1fr; }
  .tools {
    flex-direction: row;
    flex-wrap: wrap;
  }
  .tool-btn { flex: 1 1 30%; min-width: 64px; }
  .grid-cards { grid-template-columns: 1fr; }
}
