/* =========================================================================
   SRS — Layout Cartão Equilibrado (6º BBM)
   ========================================================================= */
:root {
  --red: #CE2029;
  --burg: #7A1E24;
  --yellow: #FFB000;
  --char: #1A1A1A;
  --cream: #F5F2E9;
  --paper: #FFFDF8;
  --line: #E4D5C3;
  --muted: #706762;
  --green: #1C7C54;
  --shadow: 0 12px 30px rgba(64,27,20,.09);
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; scroll-behavior: smooth; }
body {
  margin: 0;
  background: linear-gradient(180deg, #F8F5EF, var(--cream));
  color: var(--char);
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.ic { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
a { color: var(--burg); font-weight: 600; }
code { background: #F4EBE0; border: 1px solid var(--line); border-radius: 6px; padding: 1px 5px; font-size: .9em; color: var(--burg); }
button, input, select, textarea { font: inherit; }

/* ------------------------------ Header ------------------------------ */
header.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  color: #fff;
  background: linear-gradient(115deg, var(--burg), #9E171E 70%, var(--red));
  border-bottom: 3px solid var(--yellow);
  box-shadow: 0 8px 22px rgba(58,10,15,.2);
}
.head {
  max-width: 1240px;
  margin: auto;
  min-height: 92px;
  padding: max(10px, env(safe-area-inset-top)) 16px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
}
.brand { display: flex; align-items: center; gap: 13px; min-width: 0; }
.brand img {
  width: 58px;
  height: 66px;
  object-fit: contain;
  flex: none;
  filter: drop-shadow(0 4px 6px rgba(0,0,0,.22));
}
.brand h1 {
  margin: 0;
  color: #fff;
  font-size: clamp(19px, 3.6vw, 28px);
  line-height: 1.05;
  font-weight: 900;
  letter-spacing: -.55px;
}
.brand p {
  margin: 4px 0 0;
  color: #F5E9E5;
  font-size: 13px;
  font-weight: 650;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.header-actions { display: flex; align-items: center; gap: 8px; flex: none; }

.icon-btn {
  position: relative;
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  border-radius: 15px;
  border: 1.5px solid rgba(255,255,255,.78);
  color: #fff;
  background: rgba(58,9,12,.26);
  cursor: pointer;
  transition: background .15s, transform .05s;
}
.icon-btn:hover { background: rgba(58,9,12,.45); }
.icon-btn:active { transform: translateY(1px); }
.icon-btn svg { width: 22px; height: 22px; }

.dot {
  position: absolute;
  top: 7px;
  right: 7px;
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--yellow);
  border: 1.5px solid #fff;
}
.dot.on { background: #36D399; }

.pill {
  font-size: 11px;
  font-weight: 800;
  padding: 4px 10px;
  border-radius: 99px;
  letter-spacing: .3px;
  text-transform: uppercase;
}
.pill-offline { background: rgba(0,0,0,.32); color: var(--yellow); border: 1px solid rgba(255,176,0,.6); }

/* ------------------------------ Layout ------------------------------ */
.layout {
  max-width: 1240px;
  margin: 0 auto;
  padding: 20px 14px 36px;
  display: grid;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr);
}
.col { display: flex; flex-direction: column; min-width: 0; }
@media (min-width: 960px) {
  .layout { grid-template-columns: minmax(0, 1.05fr) minmax(0, .95fr); padding: 24px 18px 42px; gap: 20px; align-items: start; }
  .col-preview { position: sticky; top: 112px; }
  .btn.gen-mobile { display: none; }
}
@media (max-width: 959px) { .btn.gen-desktop { display: none; } }
@media (max-width: 520px) {
  .brand img { width: 46px; height: 54px; }
  .brand p { max-width: 180px; font-size: 12px; }
}

/* ------------------------------ Modo (Switch) ------------------------------ */
.mode-switch {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 6px;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 15px;
}
.mode-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 11px 10px;
  background: transparent;
  color: var(--muted);
  border: 1.5px solid transparent;
  border-radius: 15px;
  cursor: pointer;
  transition: all .15s;
}
.mode-btn:hover { background: #FAF3E8; color: var(--char); }
.mode-btn .mode-title { font-weight: 900; font-size: 15px; letter-spacing: -.2px; }
.mode-btn .mode-sub { font-size: 11px; font-weight: 800; letter-spacing: .5px; text-transform: uppercase; opacity: .85; }
.mode-btn[aria-checked='true'] {
  background: linear-gradient(100deg, var(--red), #A71620);
  color: #fff;
  box-shadow: 0 6px 15px rgba(206,32,41,.22);
}

/* ------------------------------ Cartões e Blocos ------------------------------ */
.settings-card, .report-card, .unit-card {
  padding: 17px;
  border: 1px solid var(--line);
  border-radius: 22px;
  background: var(--paper);
  box-shadow: var(--shadow);
  margin-bottom: 15px;
}
.unit-card { padding: 0; overflow: hidden; }
.card-accent { border-color: rgba(206,32,41,.38); }

.block {
  border: 1px solid #E5D7C7;
  border-radius: 17px;
  background: #FFFDF9;
  margin-bottom: 12px;
}
.mb-0 { margin-bottom: 0; }

.block-head {
  padding: 12px 13px;
  border-bottom: 1px solid #E9DCCE;
  background: linear-gradient(90deg, #FFF8F1, #FFFDF9);
  border-radius: 17px 17px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.block-head h3 {
  margin: 0;
  color: var(--burg);
  font-size: 15px;
  font-weight: 900;
}
.block-head h3 small { font-weight: 700; color: var(--muted); }
.block-body {
  padding: 13px;
  display: flex;
  flex-direction: column;
  gap: 13px;
}
.inner-block { margin-bottom: 0; }

.summary-head { cursor: pointer; list-style: none; border-radius: 0; border-bottom: 0; }
.summary-head::-webkit-details-marker { display: none; }
.unit-card[open] > .summary-head { border-bottom: 1px solid #E9DCCE; }
.summary-info {
  margin-left: auto;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-align: right;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
}
.chev {
  width: 10px;
  height: 10px;
  flex: none;
  border: solid var(--burg);
  border-width: 0 2.5px 2.5px 0;
  transform: rotate(45deg);
  transition: transform .18s;
  margin-right: 3px;
}
.unit-card[open] > .summary-head .chev { transform: rotate(225deg); margin-top: 4px; }

.hint { margin: 0; font-size: 12.5px; color: var(--muted); font-weight: 500; }
.link {
  background: none;
  border: 0;
  padding: 0;
  color: var(--burg);
  font-weight: 800;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.sync-pill { font-size: 11.5px; font-weight: 750; color: var(--green); }
.sync-pill.local { color: var(--muted); }

/* ------------------------------ Campos e Inputs ------------------------------ */
.grid-2 { display: grid; gap: 12px; grid-template-columns: minmax(0, 1fr); }
@media (min-width: 560px) { .grid-2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); } }
.field { min-width: 0; margin: 0; }
.field label {
  display: block;
  margin: 0 0 6px;
  color: #4E403B;
  font-size: 12px;
  font-weight: 850;
}
.field label small { font-weight: 650; color: var(--muted); }

input, select, textarea {
  width: 100%;
  min-height: 49px;
  padding: 11px 13px;
  border: 1px solid #DCCBBB;
  border-radius: 15px;
  background: #FFFEFB;
  color: var(--char);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
textarea { min-height: 92px; resize: vertical; line-height: 1.48; }
input::placeholder, textarea::placeholder { color: #9A8D84; }
input:focus, select:focus, textarea:focus {
  border-color: var(--red);
  box-shadow: 0 0 0 3px rgba(206,32,41,.11);
}
input[readonly] {
  color: var(--muted);
  background: #F9F4EC;
  border-style: dashed;
  cursor: default;
}
select {
  appearance: none;
  padding-right: 36px;
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' fill='none' stroke='%237A1E24' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
.invalid {
  border-color: var(--red) !important;
  background: #FFF6F5 !important;
  box-shadow: 0 0 0 3px rgba(206,32,41,.18) !important;
}

.input-btn { display: flex; gap: 8px; align-items: stretch; }
.input-btn input { flex: 1; min-width: 0; }
.mini-search { min-height: 36px !important; padding: 6px 11px !important; width: min(210px, 100%) !important; font-size: 13px; border-radius: 11px !important; }

/* Chips de integrantes */
.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  max-height: 185px;
  overflow-y: auto;
  padding: 2px;
}
.chip { position: relative; }
.chip input { position: absolute; opacity: 0; inset: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; min-height: 0; }
.chip span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  min-height: 36px;
  background: #FAF3E8;
  border: 1px solid #E2D2C0;
  border-radius: 99px;
  color: #4E403B;
  font-size: 12.5px;
  font-weight: 700;
  transition: all .15s;
  user-select: none;
}
.chip input:checked + span {
  background: var(--burg);
  border-color: var(--burg);
  color: #fff;
}
.chip input:focus-visible + span { box-shadow: 0 0 0 3px rgba(206,32,41,.22); }
.chip input:disabled { cursor: not-allowed; }
.chip input:disabled + span { opacity: .42; }
.chips-empty { font-size: 13px; color: var(--muted); }

/* ------------------------------ Botões (.btn) ------------------------------ */
.btn {
  min-height: 49px;
  border: 0;
  border-radius: 15px;
  padding: 11px 17px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-weight: 850;
  font-size: 14.5px;
  cursor: pointer;
  white-space: nowrap;
  transition: transform .05s, filter .15s, background .15s;
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-sm { min-height: 38px; padding: 8px 13px; font-size: 13px; border-radius: 12px; }

.primary {
  color: #fff;
  background: linear-gradient(100deg, var(--red), #A71620);
  box-shadow: 0 8px 17px rgba(206,32,41,.18);
}
.primary:hover:not(:disabled) { filter: brightness(1.06); }

.secondary {
  color: #40322f;
  background: #F1E7DA;
  border: 1px solid #E0D0BE;
}
.secondary:hover { background: #E9DCCB; }

.success { color: #fff; background: var(--green); }
.success:hover { filter: brightness(1.07); }

.danger { color: var(--red); background: #FFF0ED; border: 1px solid #F0C5BC; }
.danger:hover { background: #FFE4DE; }

.outline { color: var(--burg); background: #FFFDFC; border: 1px solid rgba(122,30,36,.28); }
.outline:hover { background: #FFF4F0; }

.gen-btn { width: 100%; }
.btn.loading .gen-label::after {
  content: '';
  display: inline-block;
  width: 13px;
  height: 13px;
  margin-left: 10px;
  border: 2px solid rgba(255,255,255,.35);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .7s linear infinite;
  vertical-align: -2px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ------------------------------ Preview / Report Card ------------------------------ */
.report-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
}
.report-heading { margin: 0; color: var(--burg); font-size: 20px; font-weight: 900; letter-spacing: -.3px; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.badge {
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .4px;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 99px;
  color: var(--burg);
  background: #FFF3D6;
  border: 1px solid #F0CA73;
  white-space: nowrap;
}
.badge-warn { color: var(--red); background: #FFF0ED; border-color: #F0C5BC; }
.badge-muted { color: var(--muted); background: #F4EDE4; border-color: var(--line); }

.preview-card > .gen-btn { margin-bottom: 12px; }
.output {
  display: block;
  width: 100%;
  min-height: 420px;
  height: 55vh;
  max-height: 68vh;
  padding: 16px;
  border: 1px solid #DFD0BF;
  border-radius: 17px;
  background: #FBF7F0;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font-family: Consolas, "SFMono-Regular", ui-monospace, monospace;
  font-size: 13.5px;
  line-height: 1.46;
  color: var(--char);
}
@media (max-width: 959px) { .output { height: 460px; } }

.actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 13px; }
.actions #btnCopiar { grid-column: 1 / -1; }
@media (max-width: 420px) { .actions { grid-template-columns: 1fr; } }

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 10px 12px;
  font-size: 12.5px;
  font-weight: 650;
  color: #5A4A44;
  background: #FFF7EC;
  border: 1px dashed #DFC9AE;
  border-radius: 14px;
}
.avisos {
  list-style: none;
  margin: 0 0 12px;
  padding: 10px 12px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--burg);
  background: #FFF6E0;
  border: 1px solid #F0CA73;
  border-radius: 14px;
}
.avisos li + li { margin-top: 4px; }
.preview-card.flash { animation: flash .9s ease-out; }
@keyframes flash { 0% { box-shadow: 0 0 0 4px rgba(28,124,84,.45); } 100% { box-shadow: var(--shadow); } }

.app-footer {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  text-align: center;
  color: var(--muted);
  font-size: 11.5px;
  padding: 6px 16px 26px;
}
.app-footer strong { color: var(--burg); letter-spacing: 1px; font-weight: 900; }

/* ------------------------------ Modais (.modal-overlay / .modal-sheet) ------------------------------ */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: grid;
  place-items: center;
  padding: 14px;
  background: rgba(23,14,12,.58);
  backdrop-filter: blur(3px);
}
.modal-sheet {
  width: min(600px, 100%);
  max-height: calc(100dvh - 28px);
  display: flex;
  flex-direction: column;
  border: 1px solid #DCCBBB;
  border-radius: 24px 24px 18px 18px;
  background: #FFFDF9;
  box-shadow: 0 24px 70px rgba(0,0,0,.28);
  overflow: hidden;
  margin: 0;
}
.modal-sheet-sm { width: min(480px, 100%); }
.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 18px;
  background: #FFF7F1;
  border-bottom: 1px solid #E7D9C9;
  color: var(--burg);
}
.modal-head h3 { margin: 0; font-size: 17px; font-weight: 900; color: var(--burg); }
.modal-sub { margin: 2px 0 0; font-size: 12px; font-weight: 700; color: var(--muted); }
.modal-close {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: 1px solid #E5D6C5;
  background: #FFFDF9;
  color: var(--burg);
  display: grid;
  place-items: center;
  cursor: pointer;
}
.modal-close:hover { background: #FFF0ED; color: var(--red); }

.tabs {
  display: flex;
  gap: 6px;
  padding: 8px 16px 0;
  background: #FFF9F3;
  border-bottom: 1px solid #E7D9C9;
}
.tab {
  background: none;
  border: 0;
  border-bottom: 3px solid transparent;
  color: var(--muted);
  font-weight: 800;
  padding: 10px 14px;
  cursor: pointer;
  margin-bottom: -1px;
}
.tab:hover { color: var(--char); }
.tab[aria-selected='true'] { color: var(--burg); border-bottom-color: var(--red); }
.count {
  font-size: 11px;
  background: #EFE4D6;
  border-radius: 99px;
  padding: 2px 8px;
  margin-left: 5px;
  color: #4E403B;
}
.tab[aria-selected='true'] .count { background: #FCE1DF; color: var(--red); }

.modal-body {
  padding: 16px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 13px;
}
.modal-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: #FFF9F3;
  border-top: 1px solid #E7D9C9;
}

.tabpanel { display: flex; flex-direction: column; gap: 12px; }
.add-row { display: flex; gap: 8px; }
.add-row input { flex: 1; min-width: 0; }
.rows {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 280px;
  overflow-y: auto;
}
.rows li { display: flex; gap: 8px; align-items: center; }
.rows input { flex: 1; min-width: 0; min-height: 42px; padding: 8px 12px; }
.remove {
  width: 42px;
  height: 42px;
  flex: none;
  border-radius: 12px;
  border: 1px solid #F0C6BD;
  color: var(--red);
  background: #FFF2EF;
  display: grid;
  place-items: center;
  cursor: pointer;
}
.remove:hover { background: #FFE2DC; }
.empty { color: var(--muted); font-size: 13px; padding: 12px; text-align: center; border: 1px dashed #DDCDBD; border-radius: 14px; }

.import { border: 1px solid #E5D7C7; border-radius: 15px; padding: 0 13px; background: #FFFEFB; }
.import summary { cursor: pointer; padding: 11px 0; font-size: 13px; font-weight: 800; color: var(--burg); }
.import textarea { font-size: 13px; font-family: Consolas, "SFMono-Regular", monospace; }
.import-actions { display: flex; gap: 8px; flex-wrap: wrap; padding: 10px 0 12px; }
.share-bar { display: flex; gap: 8px; flex-wrap: wrap; padding-top: 4px; border-top: 1px solid #E9DCCE; }
.share-bar .btn { flex: 1; min-width: 180px; }

/* ------------------------------ Toasts ------------------------------ */
.toasts {
  position: fixed;
  left: 50%;
  bottom: max(20px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100vw - 24px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 12px 16px;
  font-size: 14px;
  font-weight: 650;
  border-radius: 14px;
  color: #fff;
  background: var(--char);
  box-shadow: 0 10px 25px rgba(0,0,0,.23);
  border-left: 4px solid var(--yellow);
  animation: toast-in .2s ease-out;
}
.toast.ok { border-left-color: #36D399; }
.toast.err { border-left-color: var(--red); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

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