/* Guias TISS — mesma linguagem da página de vendas (site/): papel, tinta azul e verde-água,
   campos em caixas finas como na guia da ANS. */

:root {
  --paper: #f5f8fc;
  --sheet: #ffffff;
  --ink: #0f2547;
  --muted: #536583;
  --line: #c9d5e6;
  --line-strong: #9fb2cf;
  --blue: #1446a8;
  --blue-soft: #e7eefb;
  --teal: #0e8c7a;
  --teal-soft: #e2f3ef;
  --red: #b42318;
  --red-soft: #fdecea;
  --amber: #8a5a00;
  --amber-soft: #fff4d6;
  --code-bg: #0f2547;
  --code-fg: #d7e3f7;
  --font-display: "Archivo", "Arial Narrow", Arial, sans-serif;
  --font-body: "Source Sans 3", "Segoe UI", Arial, sans-serif;
  --font-mono: "IBM Plex Mono", Consolas, "Courier New", monospace;
  --radius: 6px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #0b1628; --sheet: #111f37; --ink: #e6eefb; --muted: #9fb0cc; --line: #2a3d5e;
    --line-strong: #3d5680; --blue: #7fa6ff; --blue-soft: #16294a; --teal: #3fc9ad; --teal-soft: #12352f;
    --red: #ff8a80; --red-soft: #3a1717; --amber: #ffcf70; --amber-soft: #3a2c0b;
    --code-bg: #060e1c; --code-fg: #cdd9ef;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --paper: #0b1628; --sheet: #111f37; --ink: #e6eefb; --muted: #9fb0cc; --line: #2a3d5e;
  --line-strong: #3d5680; --blue: #7fa6ff; --blue-soft: #16294a; --teal: #3fc9ad; --teal-soft: #12352f;
  --red: #ff8a80; --red-soft: #3a1717; --amber: #ffcf70; --amber-soft: #3a2c0b;
  --code-bg: #060e1c; --code-fg: #cdd9ef;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 16px;
  line-height: 1.5;
}
h1, h2, h3 { font-family: var(--font-display); font-stretch: 112%; line-height: 1.15; margin: 0; }
h1 { font-size: clamp(1.5rem, 3vw, 2rem); font-weight: 800; }
h2 { font-size: 1.15rem; font-weight: 800; }
h3 { font-size: 1rem; font-weight: 600; }
p { margin: 0; }
a { color: var(--blue); }
.mono { font-family: var(--font-mono); }
.muted { color: var(--muted); }
:focus-visible { outline: 3px solid var(--teal); outline-offset: 2px; }

/* ---------- estrutura ---------- */
.layout { display: grid; grid-template-columns: 232px minmax(0, 1fr); min-height: 100vh; }
.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column; gap: 22px;
  padding: 22px 16px; background: var(--sheet); border-right: 1px solid var(--line);
}
.brand {
  display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--ink);
  font-family: var(--font-display); font-stretch: 112%; font-weight: 800; font-size: 1.2rem;
}
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  display: block; padding: 9px 12px; border-radius: var(--radius); text-decoration: none;
  color: var(--ink); font-weight: 600;
}
.nav a:hover { background: var(--blue-soft); }
.nav a[aria-current="page"] { background: var(--blue); color: var(--sheet); }
.sidebar-note { margin-top: auto; font-size: 0.72rem; color: var(--muted); letter-spacing: 0.02em; }
.sidebar-note.warn { color: var(--red); }

.main { padding: 28px clamp(16px, 3.5vw, 44px) 64px; max-width: 1240px; width: 100%; }
.main:focus { outline: none; }

.page-head {
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between;
  gap: 12px 20px; margin-bottom: 20px;
}
.page-head .sub { color: var(--muted); margin-top: 4px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- botões ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 8px 16px; border-radius: var(--radius);
  border: 2px solid var(--blue); background: transparent; color: var(--blue);
  font: 700 0.95rem var(--font-body); cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--blue-soft); }
.btn.solid { background: var(--blue); color: var(--sheet); }
.btn.solid:hover { filter: brightness(1.08); background: var(--blue); }
.btn.teal { border-color: var(--teal); background: var(--teal); color: var(--sheet); }
.btn.danger { border-color: var(--red); color: var(--red); }
.btn.danger:hover { background: var(--red-soft); }
.btn.small { min-height: 32px; padding: 4px 10px; font-size: 0.85rem; border-width: 1.5px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.link-btn {
  background: none; border: 0; padding: 4px 6px; color: var(--blue); font: 600 0.9rem var(--font-body);
  cursor: pointer; text-decoration: underline; text-underline-offset: 2px;
}
.link-btn.danger { color: var(--red); }

/* ---------- cartões e formulários ---------- */
.card {
  background: var(--sheet); border: 1px solid var(--line); border-radius: 8px;
  padding: clamp(16px, 2.4vw, 24px);
}
.card + .card { margin-top: 16px; }
.form-section {
  margin: 22px 0 10px; padding-bottom: 6px; border-bottom: 1px solid var(--line);
  font-family: var(--font-mono); font-size: 0.74rem; letter-spacing: 0.08em; text-transform: uppercase;
  color: var(--muted);
}
.form-section:first-child { margin-top: 0; }
.grid { display: grid; gap: 12px 16px; grid-template-columns: repeat(12, minmax(0, 1fr)); }
.c2 { grid-column: span 2; } .c3 { grid-column: span 3; } .c4 { grid-column: span 4; }
.c5 { grid-column: span 5; } .c6 { grid-column: span 6; } .c8 { grid-column: span 8; } .c12 { grid-column: span 12; }

[hidden] { display: none !important; }
label.field { display: block; font-size: 0.85rem; font-weight: 600; color: var(--muted); }
label.field > input, label.field > select, label.field > textarea { display: block; margin-top: 4px; }
label.field > .hint { display: block; margin-top: 4px; }
label.field .req { color: var(--red); }
input, select, textarea {
  width: 100%; min-height: 40px; padding: 8px 10px;
  border: 1px solid var(--line-strong); border-radius: var(--radius);
  background: var(--sheet); color: var(--ink); font: 400 1rem var(--font-body);
}
textarea { min-height: 72px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--blue); outline-offset: 0; border-color: var(--blue); }
input.code, .code { font-family: var(--font-mono); }
label.check { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; min-height: 40px; }
label.check input { width: 18px; height: 18px; min-height: 0; accent-color: var(--blue); }
.hint { font-size: 0.82rem; color: var(--muted); font-weight: 400; }
.form-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 22px; }

.alert { border-radius: var(--radius); padding: 10px 14px; margin: 12px 0; border: 1px solid; }
.alert.error { background: var(--red-soft); border-color: var(--red); color: var(--red); }
.alert.warn { background: var(--amber-soft); border-color: var(--amber); color: var(--amber); }
.alert.ok { background: var(--teal-soft); border-color: var(--teal); color: var(--teal); }
.alert ul { margin: 6px 0 0; padding-left: 20px; }

/* ---------- tabelas ---------- */
.table-wrap { overflow-x: auto; background: var(--sheet); border: 1px solid var(--line); border-radius: 8px; }
table.list { width: 100%; border-collapse: collapse; font-size: 0.95rem; }
table.list th {
  text-align: left; font-family: var(--font-mono); font-weight: 500; font-size: 0.72rem;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted);
  padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.list td { padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list tr:last-child td { border-bottom: 0; }
table.list tr:hover td { background: var(--paper); }
table.list td.num, table.list th.num { text-align: right; white-space: nowrap; }
table.list td.nowrap { white-space: nowrap; }
table.list td.row-actions { white-space: nowrap; text-align: right; }
table.list input[type="checkbox"] { width: 18px; height: 18px; min-height: 0; accent-color: var(--blue); }
.empty { padding: 32px 16px; text-align: center; color: var(--muted); }

.tag {
  display: inline-block; padding: 1px 8px; border-radius: 99px; font-size: 0.78rem; font-weight: 700;
  background: var(--blue-soft); color: var(--blue); white-space: nowrap;
}
.tag.teal { background: var(--teal-soft); color: var(--teal); }
.tag.amber { background: var(--amber-soft); color: var(--amber); }
.tag.gray { background: var(--paper); color: var(--muted); border: 1px solid var(--line); }

.filters { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; align-items: flex-end; }
.filters label.field { min-width: 170px; }
.selection-bar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 14px; margin-bottom: 12px; border-radius: 8px;
  background: var(--teal-soft); border: 1px solid var(--teal); color: var(--ink);
}

/* ---------- primeiros passos ---------- */
.steps { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; }
.steps li { display: flex; align-items: center; gap: 10px; }
.steps .dot {
  width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--line-strong);
  display: inline-flex; align-items: center; justify-content: center; font-size: 0.75rem; flex: none;
}
.steps li.done .dot { background: var(--teal); border-color: var(--teal); color: var(--sheet); }
.steps li.done span:last-child { color: var(--muted); text-decoration: line-through; }

/* ---------- itens SP/SADT ---------- */
.items { display: grid; gap: 12px; }
.item {
  border: 1px solid var(--line); border-left: 4px solid var(--teal); border-radius: var(--radius);
  padding: 12px 14px; background: var(--paper);
}
.item-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.item-head strong { font-family: var(--font-mono); font-size: 0.8rem; color: var(--muted); }
.total-line {
  display: flex; justify-content: flex-end; gap: 10px; align-items: baseline;
  margin-top: 12px; font-size: 1.05rem;
}
.total-line strong { font-family: var(--font-display); font-stretch: 112%; font-size: 1.3rem; }

/* ---------- busca TUSS ---------- */
.tuss { position: relative; }
.tuss-results {
  position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px);
  max-height: 300px; overflow-y: auto; background: var(--sheet);
  border: 1px solid var(--line-strong); border-radius: var(--radius); box-shadow: 0 10px 28px rgba(15, 37, 71, 0.18);
}
.tuss-results button {
  display: flex; gap: 10px; width: 100%; text-align: left; padding: 8px 12px;
  border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--ink);
  font: 400 0.92rem var(--font-body); cursor: pointer;
}
.tuss-results button:hover, .tuss-results button:focus { background: var(--blue-soft); }
.tuss-results .code { color: var(--blue); flex: none; font-size: 0.85rem; }

/* ---------- XML ---------- */
pre.xml {
  background: var(--code-bg); color: var(--code-fg); padding: 16px; border-radius: 8px;
  overflow: auto; max-height: 420px; font: 0.8rem/1.5 var(--font-mono); margin: 12px 0 0;
}

/* ---------- aviso flutuante ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  background: var(--ink); color: var(--sheet); padding: 10px 18px; border-radius: 8px;
  font-weight: 600; opacity: 0; pointer-events: none; transition: opacity 0.2s, transform 0.2s;
  max-width: calc(100vw - 32px); z-index: 50; overflow-wrap: anywhere;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--red); }

/* ---------- celular ---------- */
@media (max-width: 860px) {
  .layout { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: sticky; top: 0; z-index: 30; height: auto; flex-direction: row; align-items: center;
    gap: 12px; padding: 10px 16px; border-right: 0; border-bottom: 1px solid var(--line); overflow: hidden;
  }
  .brand span { display: none; }
  .nav { flex-direction: row; overflow-x: auto; gap: 4px; scrollbar-width: none; }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { white-space: nowrap; padding: 7px 10px; }
  .sidebar-note { display: none; }
  .main { padding: 20px 16px 56px; }
  .c2, .c3, .c4, .c5 { grid-column: span 6; }
  .c6, .c8 { grid-column: span 12; }
}
@media (max-width: 520px) {
  .c2, .c3, .c4, .c5 { grid-column: span 12; }
  .filters label.field { min-width: 0; flex: 1 1 100%; }
}
