.tool-layout {
  padding: clamp(2rem, 5vw, 4rem) clamp(1rem, 5vw, 4rem);
  max-width: 1200px;
  margin: 0 auto;
}

.tool-header h1 {
  color: var(--text);
}

.tool-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-top: 1.5rem;
}

.tool-bar .button.secondary {
  background: var(--accent);
  color: var(--white);
  border-color: transparent;
  min-height: 42px;
  padding: 0.5rem 1.1rem;
}

.tool-bar .button.secondary:hover {
  background: #4f3f2c;
}

.tool-notice {
  margin: 1.5rem 0;
  padding: 1rem 1.2rem;
  background: #fff8e6;
  border-left: 4px solid var(--accent);
  font-size: 0.9rem;
  color: var(--muted);
  line-height: 1.6;
}

.tool-notice p {
  margin: 0;
}

.tool-app {
  margin-top: 1.5rem;
}

.tool-empty {
  padding: 3rem;
  text-align: center;
  color: var(--muted);
  background: var(--panel);
  border: 2px dashed var(--line);
}

.table-config {
  margin-bottom: 1rem;
}

.table-name-input {
  display: block;
  width: 100%;
  max-width: 400px;
  margin-top: 0.35rem;
  padding: 0.6rem 0.8rem;
  font-size: 1.1rem;
  font-weight: 700;
  border: 1px solid var(--line);
  background: var(--panel);
  color: var(--text);
  font-family: 'Courier New', Courier, monospace;
}

.calc-note {
  margin: 0 0 1.2rem;
  font-size: 0.88rem;
  color: var(--muted);
  line-height: 1.6;
  max-width: 640px;
}

/* ---- Prioriza table ---- */

.ptable-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  background: var(--panel);
}

.ptable {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.ptable th,
.ptable td {
  padding: 0.55rem 0.6rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}

.ptable tbody tr:last-child td {
  border-bottom: none;
}

/* Column headers */
.col-elem {
  min-width: 130px;
}

.col-aspect {
  min-width: 200px;
  vertical-align: top;
  background: var(--band);
}

.col-total {
  min-width: 60px;
  text-align: center;
  background: var(--band);
}

.col-remove {
  width: 44px;
  background: var(--band);
}

.aspect-config {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
}

.ac-name {
  font-weight: 700;
  font-size: 0.9rem;
  padding: 0.3rem 0.4rem;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--text);
  width: 100%;
  font-family: 'Courier New', Courier, monospace;
}

.ac-fn {
  font-size: 0.75rem;
  padding: 0.25rem 0.3rem;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--muted);
  cursor: pointer;
  width: 100%;
  font-family: 'Courier New', Courier, monospace;
}

.ac-apl-label {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--muted);
}

.ac-apl {
  width: 48px;
  padding: 0.25rem 0.3rem;
  border: 1px solid var(--line);
  font-size: 0.82rem;
  text-align: center;
  color: var(--text);
  background: var(--paper);
  font-family: 'Courier New', Courier, monospace;
}

.ac-remove {
  align-self: flex-end;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 1.1rem;
  cursor: pointer;
  transition: background 0.15s;
}

.ac-remove:hover {
  background: rgba(107, 83, 54, 0.1);
}

/* Data cells */
.cell-elem {
  min-width: 120px;
}

.elem-input {
  width: 100%;
  min-width: 100px;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--line);
  font-size: 0.85rem;
  color: var(--text);
  background: var(--paper);
  font-family: 'Courier New', Courier, monospace;
}

.cell-value {
  text-align: center;
  vertical-align: middle;
}

.val-input {
  width: 64px;
  padding: 0.4rem 0.3rem;
  border: 1px solid var(--line);
  font-size: 0.85rem;
  text-align: center;
  color: var(--text);
  background: var(--paper);
  font-family: 'Courier New', Courier, monospace;
}

.cell-level {
  display: block;
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--accent);
  margin-top: 0.15rem;
}

.cell-total {
  text-align: center;
  font-weight: 800;
  font-size: 1rem;
  color: var(--text);
  background: var(--band);
}

.cell-remove {
  text-align: center;
}

.btn-remove-elem {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--accent);
  font-size: 1.2rem;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-remove-elem:hover {
  background: rgba(107, 83, 54, 0.1);
}

/* Table actions */

.ptable-actions {
  display: flex;
  gap: 0.6rem;
  margin-top: 0.8rem;
}

.button.small {
  min-height: 36px;
  padding: 0.4rem 1rem;
  font-size: 0.88rem;
  background: var(--accent);
  color: var(--white);
  border: 1px solid #4f3f2c;
  cursor: pointer;
  font-weight: 700;
  transition: background 0.2s;
  font-family: 'Courier New', Courier, monospace;
}

.button.small:hover {
  background: #4f3f2c;
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--accent);
  font-size: 1.3rem;
  cursor: pointer;
  transition: background 0.15s;
}

.btn-icon:hover {
  background: rgba(107, 83, 54, 0.1);
}

/* Results below table */

.tool-results {
  margin-top: 1.5rem;
}

.tr-summary {
  margin-bottom: 1rem;
}

.tie-badge {
  padding: 0.75rem 1rem;
  background: #fff8e6;
  border-left: 4px solid var(--accent);
  font-size: 0.9rem;
  color: var(--muted);
}

.tie-badge.no-tie {
  background: var(--band);
  border-left-color: var(--accent);
}

.tr-heading {
  font-size: 1.1rem;
  margin: 0 0 0.8rem;
}

.tr-summary {
  margin-bottom: 1rem;
}

.tr-traces {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.trace-card {
  background: var(--panel);
  border: 1px solid var(--line);
  overflow: hidden;
  transition: box-shadow 0.2s, border-color 0.2s;
}

.trace-card.trace-p1 {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(107, 83, 54, 0.12);
}

.tc-header {
  display: grid;
  grid-template-columns: 2.5rem 1fr auto;
  gap: 0.5rem;
  align-items: center;
  padding: 0.6rem 0.8rem;
  background: var(--band);
  border-bottom: 1px solid var(--line);
}

.trace-p1 .tc-header {
  background: var(--band);
  border-bottom-color: var(--accent);
}

.tc-rank {
  font-weight: 800;
  font-size: 1rem;
  color: var(--accent);
  text-align: center;
}

.tc-elem {
  font-size: 0.95rem;
  color: var(--text);
}

.tc-total {
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--text);
}

.trace-p1 .tc-total {
  color: var(--accent);
}

.tc-aspects {
  padding: 0.5rem 0.8rem;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.ta-row {
  display: grid;
  grid-template-columns: 1fr 0.6fr 1.6fr 0.8fr 0.6fr 0.6fr;
  gap: 0.3rem 0.6rem;
  align-items: center;
  font-size: 0.82rem;
  padding: 0.25rem 0;
  border-bottom: 1px solid var(--line);
}

.ta-row:last-child {
  border-bottom: none;
}

.ta-aspect {
  font-weight: 700;
  color: var(--text);
}

.ta-raw {
  color: var(--text);
  text-align: center;
  font-weight: 600;
}

.ta-fn {
  color: var(--muted);
  font-size: 0.75rem;
}

.ta-level {
  color: var(--accent);
  font-weight: 700;
  text-align: center;
}

.ta-npa {
  color: var(--muted);
  font-weight: 700;
  text-align: center;
}

.ta-contrib {
  font-weight: 800;
  color: var(--text);
  text-align: right;
}

.tc-explain {
  padding: 0.5rem 0.8rem;
  font-size: 0.82rem;
  color: var(--muted);
  border-top: 1px solid var(--line);
  background: var(--paper);
  line-height: 1.5;
}

.trace-p1 .tc-explain {
  color: var(--accent);
  font-weight: 600;
  background: var(--paper);
}

/* Responsive */

@media (max-width: 820px) {
  .ta-row {
    grid-template-columns: 1fr 1fr;
    gap: 0.2rem 0.5rem;
  }

  .ta-fn {
    grid-column: 1 / -1;
    font-size: 0.72rem;
  }
}

@media (max-width: 600px) {
  .col-aspect {
    min-width: 170px;
  }

  .val-input {
    width: 50px;
  }
}
