/* ===== Tools (/tool, /tool/{slug}) ===== */
[x-cloak] { display: none !important; }

.tool-card-sub { margin: 0 0 0.5rem; font-size: 0.85rem; font-weight: 600; color: var(--primary-color, #059669); }

.tool-legal { margin: 0.35rem 0 0; font-size: 0.9rem; opacity: 0.9; }

.tool-app {
  border: 1px solid #e2e8f0;
  border-radius: 0.75rem;
  background: #fff;
  box-shadow: 0 2px 10px rgba(15, 23, 42, 0.04);
  margin-bottom: 2rem;
}
.tool-app-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.75rem 1rem 0;
  border-bottom: 1px solid #e2e8f0;
}
.tool-tabs { display: flex; gap: 0.25rem; list-style: none; margin: 0; padding: 0; }
.tool-tabs button {
  border: 0;
  background: none;
  padding: 0.6rem 1rem;
  font-weight: 600;
  color: #64748b;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
}
.tool-tabs button[aria-selected="true"] { color: var(--primary-color, #059669); border-bottom-color: var(--primary-color, #059669); }
.tool-saved { font-size: 0.85rem; color: var(--primary-color, #059669); opacity: 0; transition: opacity 0.2s; }
.tool-saved.is-on { opacity: 1; }
.tool-pane { padding: 1rem; }

.tool-label { display: block; font-size: 0.85rem; font-weight: 600; color: #334155; margin-bottom: 0.3rem; }
.tool-section-title { font-size: 1rem; font-weight: 700; color: #0f172a; margin: 0 0 0.6rem; }

/* Editable data table */
.tool-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.tool-table th {
  background: #f1f5f9;
  color: #0f172a;
  font-weight: 600;
  padding: 0.5rem;
  border: 1px solid #e2e8f0;
  white-space: nowrap;
}
.tool-table td { border: 1px solid #e2e8f0; padding: 0; vertical-align: middle; }
.tool-table td.tool-num { text-align: center; color: #94a3b8; font-size: 0.82rem; width: 44px; }
.tool-table input {
  width: 100%;
  border: 0;
  padding: 0.45rem 0.55rem;
  background: transparent;
  min-width: 90px;
}
.tool-table input:focus { outline: 2px solid var(--primary-color, #059669); outline-offset: -2px; background: #f0fdf4; }
.tool-table input.tool-money { text-align: right; font-variant-numeric: tabular-nums; }
.tool-table tfoot td { padding: 0.5rem 0.6rem; font-weight: 600; background: #f8fafc; }
.tool-table tfoot td.tool-money { text-align: right; font-variant-numeric: tabular-nums; }
.tool-sort, .tool-remove {
  border: 0;
  background: none;
  color: #64748b;
  padding: 0 0.25rem;
  line-height: 1;
}
.tool-sort:hover { color: var(--primary-color, #059669); }
.tool-remove { width: 100%; padding: 0.45rem 0; font-size: 1.1rem; }
.tool-remove:hover:not(:disabled) { color: #dc2626; }
.tool-remove:disabled { opacity: 0.3; }

.tool-line {
  border: 1px solid #e2e8f0;
  border-left: 4px solid var(--primary-color, #059669);
  border-radius: 0.5rem;
  background: #f8fafc;
  padding: 1rem;
  margin-bottom: 1rem;
}
.tool-summary {
  border-radius: 0.5rem;
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  padding: 1rem;
  margin-bottom: 1rem;
}
.tool-summary-label { font-size: 0.85rem; color: #475569; }
.tool-summary-value { font-weight: 700; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.tool-note { font-size: 0.82rem; color: #64748b; }

/* ===== A4 form preview ===== */
.a4-wrapper { overflow-x: auto; background: #e2e8f0; padding: 1.25rem; border-radius: 0.5rem; }
.a4-page {
  width: 210mm;
  min-height: 297mm;
  margin: 0 auto;
  padding: 15mm 12mm;
  background: #fff;
  color: #000;
  box-shadow: 0 4px 16px rgba(15, 23, 42, 0.15);
  font-family: 'Times New Roman', Times, serif;
  font-size: 13px;
  line-height: 1.45;
}
.form-head { display: flex; justify-content: space-between; gap: 8mm; margin-bottom: 6mm; }
.form-head-left { flex: 1; }
.form-head-left b { font-weight: 700; }
.form-head-right { text-align: center; width: 70mm; flex: none; }
.form-code { font-weight: 700; font-size: 14px; }
.form-legal { font-style: italic; font-size: 12px; }
.form-title { text-align: center; font-weight: 700; font-size: 17px; text-transform: uppercase; margin: 2mm 0 2mm; }
.form-sub { text-align: center; margin-bottom: 1mm; }
.form-unit { text-align: right; font-style: italic; font-size: 12px; margin: 2mm 0; }
.form-table { width: 100%; border-collapse: collapse; margin-top: 3mm; }
.form-table th, .form-table td { border: 1px solid #000; padding: 1.5mm 2mm; vertical-align: top; }
.form-table th { text-align: center; font-weight: 700; vertical-align: middle; }
.form-table .form-col { text-align: center; font-weight: 700; padding: 0.5mm; }
.form-table td { height: 7mm; }
.form-table .r { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.form-table .c { text-align: center; }
.form-table .b { font-weight: 700; }
.form-table .i { font-style: italic; }
.form-table tfoot td, .form-table .form-total td { font-weight: 700; }
.form-table tr { page-break-inside: avoid; break-inside: avoid; }
.form-sign { width: 85mm; margin: 6mm 0 0 auto; text-align: center; page-break-inside: avoid; break-inside: avoid; }
.form-sign-title { font-weight: 700; margin-top: 1mm; }
.form-sign-note { font-style: italic; font-size: 12px; }
.form-sign-space { height: 25mm; }

/* ===== Print: only the form inside #printArea ===== */
@page { size: A4 portrait; margin: 12mm 10mm; }

@media print {
  /* Along the chain of ancestors of #printArea, hide every other sibling … */
  *:has(#printArea) > *:not(:has(#printArea)):not(#printArea) { display: none !important; }
  /* … and flatten the ancestors themselves (this also beats x-show's inline display:none). */
  *:has(#printArea) {
    display: block !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    box-shadow: none !important;
    background: #fff !important;
    max-width: none !important;
    width: auto !important;
  }
  .a4-wrapper { background: none; padding: 0; overflow: visible; }
  .a4-page { width: auto; min-height: 0; padding: 0; margin: 0; box-shadow: none; }
  .form-table thead { display: table-header-group; }
  .form-table tfoot { display: table-row-group; } /* print totals once, at the end */
}

/* ===== Chart maker (/tool/tao-bieu-do-*) ===== */
.tool-card-icon { font-size: 1.6rem; line-height: 1; margin-bottom: 0.5rem; }
.tool-group-title { font-size: 1.15rem; font-weight: 700; color: #0f172a; margin: 1.75rem 0 0; }

.chart-controls { border-right: 1px solid #e2e8f0; }
.chart-panel { border: 0; border-bottom: 1px solid #e2e8f0; border-radius: 0; margin: 0; padding: 0; background: none; box-shadow: none; cursor: auto; width: auto; }
.chart-panel:last-child { border-bottom: 0; }
.chart-panel > summary {
  cursor: pointer;
  list-style: none;
  padding: 0.75rem 1rem;
  font-weight: 700;
  color: #0f172a;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.chart-panel > summary::-webkit-details-marker { display: none; }
.chart-panel > summary::after { content: '▾'; color: #94a3b8; transition: transform 0.15s; }
.chart-panel:not([open]) > summary::after { transform: rotate(-90deg); }
.chart-panel-body { padding: 0 1rem 1rem; }

.chart-table { font-size: 0.88rem; }
.chart-table input { min-width: 70px; }
.chart-table input[type="date"] { min-width: 128px; padding-right: 0.25rem; }
.chart-table td:has(> input[type="text"]:not(.tool-money)) { min-width: 130px; }
.chart-table th { white-space: normal; }
.chart-move-col, .chart-del-col { width: 32px; }
.chart-move { border: 0; background: none; color: #94a3b8; width: 100%; padding: 0.4rem 0; }
.chart-move:hover:not(:disabled) { color: var(--primary-color, #059669); }
.chart-move:disabled { opacity: 0.25; }
.chart-series-th { padding: 0.25rem !important; min-width: 150px; }
.chart-series-head { display: flex; align-items: center; gap: 0.25rem; }
.chart-series-head .chart-series-name {
  flex: 1;
  min-width: 60px;
  border: 1px solid transparent;
  border-radius: 0.3rem;
  background: #fff;
  padding: 0.2rem 0.35rem;
  font-weight: 600;
}
.chart-series-head .chart-series-name:focus { outline: 2px solid var(--primary-color, #059669); }
.chart-x { border: 0; background: none; color: #94a3b8; font-size: 1.05rem; line-height: 1; padding: 0 0.15rem; }
.chart-x:hover { color: #dc2626; }

.chart-color {
  width: 28px;
  height: 28px;
  padding: 0;
  border: 1px solid #cbd5e1;
  border-radius: 0.35rem;
  background: none;
  cursor: pointer;
  flex: none;
}
.tool-table input.chart-color { width: 28px; min-width: 28px; padding: 0; margin: 0.2rem auto; display: block; }
.chart-color::-webkit-color-swatch-wrapper { padding: 2px; }
.chart-color::-webkit-color-swatch { border: 0; border-radius: 0.25rem; }
.chart-color:disabled { opacity: 0.4; cursor: not-allowed; }
.chart-check { margin: 0; }

.chart-groups { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.9rem; margin-top: 0.6rem; }
.chart-group-chip { display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.88rem; cursor: pointer; }
.chart-band { display: flex; align-items: center; gap: 0.35rem; font-size: 0.8rem; color: #475569; margin-bottom: 0.25rem; }

.chart-textarea { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 0.85rem; }
.chart-import-box { margin-top: 0.6rem; padding: 0.75rem; border: 1px dashed #cbd5e1; border-radius: 0.5rem; background: #f8fafc; }

.chart-toggles { display: flex; flex-wrap: wrap; align-items: center; gap: 0.35rem 1.1rem; }
.chart-toggles .form-check { margin: 0; font-size: 0.9rem; }
.chart-inline-select { width: auto; display: inline-block; }

.chart-preview-col { background: #f8fafc; border-radius: 0 0.75rem 0.75rem 0; }
.chart-preview { padding: 1rem; position: sticky; top: 0.5rem; }
.chart-preview-bar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 0.5rem; }
.chart-box {
  position: relative;
  width: 100%;
  max-height: 78vh;
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  overflow: hidden;
}
.chart-box.is-transparent {
  background-color: #fff;
  background-image: linear-gradient(45deg, #f1f5f9 25%, transparent 25%), linear-gradient(-45deg, #f1f5f9 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f1f5f9 75%), linear-gradient(-45deg, transparent 75%, #f1f5f9 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}
.chart-box canvas { position: absolute; inset: 0; width: 100% !important; height: 100% !important; }
.chart-notice { text-align: center; margin: 0.6rem 0 0; font-size: 0.9rem; color: var(--primary-color, #059669); font-weight: 600; }

.chart-stats { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.5rem; margin-top: 0.75rem; }
.chart-stats div { background: #fff; border: 1px solid #e2e8f0; border-radius: 0.5rem; padding: 0.45rem 0.6rem; }
.chart-stats span { display: block; font-size: 0.75rem; color: #64748b; }
.chart-stats b { font-variant-numeric: tabular-nums; }

/* Guide + related links under each chart tool */
.tool-guide { max-width: 52rem; margin: 0 auto 2rem; line-height: 1.7; }
.tool-guide h2 { font-size: 1.3rem; font-weight: 700; margin: 1.75rem 0 0.6rem; color: #0f172a; }
.tool-guide h3 { font-size: 1.05rem; font-weight: 700; margin: 1.2rem 0 0.4rem; }
.tool-guide ul, .tool-guide ol { padding-left: 1.3rem; }
.tool-guide li { margin-bottom: 0.3rem; }
.chart-related { margin: 0 0 2.5rem; }
.chart-related-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 0.6rem; }
.chart-related-item {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.6rem 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.6rem;
  background: #fff;
  color: #0f172a;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.92rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.chart-related-item:hover { border-color: var(--primary-color, #059669); box-shadow: 0 2px 8px rgba(5, 150, 105, 0.12); color: var(--primary-color, #059669); }
.chart-related-icon { font-size: 1.25rem; }

@media (max-width: 991.98px) {
  .chart-controls { border-right: 0; border-bottom: 1px solid #e2e8f0; }
  .chart-preview-col { border-radius: 0 0 0.75rem 0.75rem; }
  .chart-preview { position: static; }
}
@media (max-width: 575.98px) {
  .chart-stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
