/* Shared components: buttons, fields, badges, cards, tables, tabs, dialogs, drawers, toast. */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 36px;
  padding: 8px 13px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font-size: 12px;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: var(--recess); border-color: #cdd8c8; }
.btn.primary { background: var(--green); border-color: var(--green); color: #fff; box-shadow: 0 2px 3px #142d2310; }
.btn.primary:hover { background: var(--green-dark); border-color: var(--green-dark); }
.btn.quiet { background: transparent; border-color: transparent; color: var(--ink-3); }
.btn.quiet:hover { background: var(--recess); color: var(--ink); }
.btn.danger { color: var(--red); }
.btn.small { min-height: 30px; padding: 5px 10px; font-size: 11px; }
.btn:disabled { opacity: 0.4; cursor: default; }
.btn .icon { width: 15px; height: 15px; }
.icon-btn {
  min-width: 36px;
  height: 36px;
  border: 0;
  background: transparent;
  border-radius: var(--radius);
  color: #81877f;
  cursor: pointer;
  display: inline-grid;
  place-items: center;
}
.icon-btn:hover { background: #f3f4f0; color: var(--ink); }

/* Fields */
.field { display: grid; gap: 8px; font-size: 12px; }
.field > span { font-weight: 500; }
.field .hint { font-size: 11px; color: var(--ink-3); font-weight: 400; }
input[type="text"], input[type="search"], textarea, select {
  min-height: 36px;
  padding: 7px 11px;
  border: 1px solid var(--rule);
  border-radius: var(--radius);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: 12px;
}
input::placeholder, textarea::placeholder { color: var(--ink-3); }
textarea { resize: vertical; min-height: 96px; line-height: 1.5; }
select {
  appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23596854' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  cursor: pointer;
}
input[type="checkbox"] { accent-color: var(--green); width: 15px; height: 15px; }
.search { width: 260px; max-width: 100%; }
.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--rule);
}
.toolbar .search { flex: 1; min-width: 180px; }

/* Badges and tags */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 4px 8px;
  border-radius: 5px;
  background: var(--recess);
  color: var(--ink-3);
  font-size: 10px;
  font-weight: 500;
  white-space: nowrap;
}
.badge.red { background: var(--red-soft); color: var(--red); }
.badge.amber { background: var(--amber-soft); color: var(--amber); }
.badge.green { background: var(--green-soft); color: var(--green); }
.badge.blue { background: var(--blue-soft); color: var(--blue); }
.tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 8px;
  border-radius: 5px;
  font-size: 10px;
  font-weight: 500;
  color: var(--ink-2);
  background: color-mix(in srgb, var(--cat, var(--ink-3)) 9%, #fff);
  border: 1px solid color-mix(in srgb, var(--cat, var(--ink-3)) 28%, #fff);
  white-space: nowrap;
}
.tag::before { content: ''; width: 8px; height: 8px; border-radius: 2px; background: var(--cat, var(--ink-3)); }
.tag.latency { --cat: var(--cat-latency); }
.tag.user_experience { --cat: var(--cat-user_experience); }
.tag.accuracy { --cat: var(--cat-accuracy); }
.tag.reliability { --cat: var(--cat-reliability); }
.tag.security { --cat: var(--cat-security); }
.tag.trace_quality { --cat: var(--cat-trace_quality); }
.chip {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 5px;
  background: var(--recess);
  color: #6d7b64;
  font-size: 10px;
  white-space: nowrap;
}
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.severity { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; color: var(--ink-2); white-space: nowrap; }
.severity-glyph.severity-high { color: var(--red); }
.severity-glyph.severity-medium { color: var(--amber); }
.severity-glyph.severity-low { color: var(--green); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; }

/* Cards */
.card {
  background: var(--paper);
  border: 1px solid var(--rule);
  border-radius: var(--radius-l);
  box-shadow: var(--shadow-card);
  overflow: hidden;
}
.card + .card { margin-top: 20px; }
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--rule);
}
.card-header p { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.card-body { padding: 22px; }
.card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 20px;
  border-top: 1px solid var(--rule);
  background: #fcfdfb;
  font-size: 11px;
  color: var(--ink-3);
}

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  padding: 10px 20px;
  background: #f5f7f1;
  font-size: 10px;
  font-weight: 500;
  color: var(--ink-3);
  text-align: left;
  white-space: nowrap;
}
th .sort {
  padding: 0;
  border: 0;
  background: none;
  font: inherit;
  color: inherit;
  cursor: pointer;
  display: inline-flex;
  gap: 4px;
  align-items: center;
}
th .sort:hover, th .sort.active { color: var(--ink); }
.sort-arrow { font-size: 11px; color: #9aa396; opacity: 0.5; }
th .sort:hover .sort-arrow, th .sort.active .sort-arrow { color: var(--green); opacity: 1; }
td {
  padding: 14px 20px;
  border-top: 1px solid var(--row-line);
  font-size: 12px;
  color: var(--ink-2);
  vertical-align: middle;
}
tbody tr:first-child td { border-top: 0; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: #f5f8ef; }
td .title { color: var(--ink); font-weight: 500; }
td .sub { display: block; font-size: 10px; color: var(--ink-3); margin-top: 2px; }
td .bar-cell { display: inline-flex; align-items: center; gap: 8px; }
.meter { height: 4px; border-radius: 3px; background: var(--bar-track); overflow: hidden; }
.meter > i { display: block; height: 100%; background: var(--bar); border-radius: 3px; }
.meter.amber > i { background: var(--severity-medium); }
.meter.stacked { display: flex; }
.meter.stacked > i { border-radius: 0; }
.meter.stacked > i.high { background: var(--severity-high); }
.meter.stacked > i.medium { background: var(--severity-medium); }
.meter.stacked > i.low { background: var(--severity-low); }
.meter.stacked > i.input { background: var(--bar-input); }
.meter.stacked > i.output { background: var(--bar-output); }
.agent-cell { display: inline-flex; align-items: center; gap: 10px; }
.agent-cell .tile {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: #edf2e6;
  color: #718363;
  display: grid;
  place-items: center;
}
.agent-cell a { color: var(--ink); font-weight: 500; text-decoration: none; }
.agent-cell a:hover { text-decoration: underline; }

/* Empty and loading states */
.empty {
  padding: 46px 22px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 14px;
}
.empty .tile {
  width: 48px;
  height: 48px;
  border-radius: 14px;
  background: var(--green-soft);
  color: var(--green);
  display: grid;
  place-items: center;
}
.empty h3 { font-size: 15px; font-weight: 500; }
.empty p { font-size: 12px; color: var(--ink-3); max-width: 400px; }
.empty .btn { margin-top: 6px; }
.loading { padding: 40px; text-align: center; color: var(--ink-3); font-size: 12px; }
.error-banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 12px 16px;
  border-radius: var(--radius);
  background: var(--red-soft);
  color: var(--red);
  font-size: 12px;
}

/* Tabs */
.tabs { display: flex; gap: 24px; border-bottom: 1px solid var(--rule); }
.tabs button {
  padding: 12px 2px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink-3);
  cursor: pointer;
}
.tabs button.active { color: var(--green-dark); border-bottom-color: var(--green); }
.tab-panel { padding-top: 18px; }

/* Definition lists */
.facts {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 14px 20px;
  padding: 16px 20px;
  border-radius: 10px;
  background: #f4f4f2;
}
.facts dt { font-size: 10px; color: var(--ink-3); margin-bottom: 3px; }
.facts dd { margin: 0; font-size: 12px; color: var(--ink); }
.facts dd .badge { vertical-align: middle; }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: 6px 14px; font-size: 12px; }
.kv dt { color: var(--ink-3); }
.kv dd { margin: 0; color: var(--ink); }

/* Dialogs and drawers */
dialog { color: inherit; }
dialog::backdrop { background: #20332845; backdrop-filter: blur(5px); }
.dialog {
  width: min(640px, calc(100vw - 36px));
  max-height: calc(100vh - 48px);
  padding: 0;
  border: 1px solid #dbe3d3;
  border-radius: 15px;
  background: var(--canvas);
  box-shadow: 0 20px 100px #142e2950;
  display: flex;
  flex-direction: column;
}
.dialog:not([open]), .drawer:not([open]) { display: none; }
.dialog-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 24px;
  border-bottom: 1px solid var(--rule);
}
.dialog-header h2 { font-size: 23px; letter-spacing: -0.6px; }
.dialog-body { padding: 24px; display: grid; gap: 20px; overflow: auto; }
.dialog-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 24px;
  border-top: 1px solid var(--rule);
  background: #f4f6f0;
  font-size: 11px;
  color: var(--ink-3);
}
.dialog-footer .actions { display: flex; gap: 10px; margin-left: auto; }
.drawer {
  position: fixed;
  inset: 0 0 0 auto;
  margin: 0;
  width: min(940px, calc(100vw - 24px));
  max-width: none;
  height: 100vh;
  max-height: none;
  padding: 0;
  border: 0;
  border-left: 1px solid var(--rule);
  border-radius: 16px 0 0 16px;
  background: var(--paper);
  box-shadow: var(--shadow-drawer);
  display: flex;
  flex-direction: column;
  animation: slide-in 0.22s ease-out;
}
.drawer::backdrop { background: #28362e24; backdrop-filter: none; }
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } to { transform: none; opacity: 1; } }
.drawer-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  padding: 20px 26px;
  border-bottom: 1px solid var(--rule);
}
.drawer-header h2 { font-size: 23px; font-weight: 600; letter-spacing: -0.6px; margin-top: 2px; }
.drawer-header .badges { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.drawer-body { flex: 1; overflow: auto; padding: 24px 28px 32px; display: flex; flex-direction: column; gap: 24px; }
.section h3 { margin-bottom: 8px; }
.section p { color: var(--ink-2); }
.section ul { margin: 0; padding-left: 18px; color: var(--ink-2); }
.section li + li { margin-top: 4px; }
.callout { padding: 16px 18px; border-radius: 10px; background: var(--green-soft); }
.callout h3 { margin-bottom: 6px; }
.callout p { color: var(--ink-2); }
.callout.finding { background: var(--fault-soft); }
.callout.finding a { color: var(--ink); font-weight: 500; text-decoration: none; }
.callout.finding a:hover { text-decoration: underline; }
.code-box {
  position: relative;
  padding: 14px 16px;
  border-radius: 10px;
  background: var(--recess-2);
  border: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.6;
  overflow: auto;
}
.code-box .btn { position: absolute; top: 8px; right: 8px; }
details.fold > summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 8px; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary::before { content: '›'; color: var(--ink-3); transition: transform 0.15s; }
details.fold[open] > summary::before { transform: rotate(90deg); }

/* Toast */
#toast {
  position: fixed;
  left: calc(50% + var(--sidebar-width) / 2);
  bottom: 25px;
  transform: translate(-50%, 20px);
  padding: 12px 18px;
  border-radius: 10px;
  background: var(--tooltip);
  color: #fff;
  font-size: 12px;
  box-shadow: 0 12px 30px #233d2c30;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 20;
}
#toast.visible { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 760px) {
  #toast { left: 50%; }
  .drawer { width: 100vw; border-radius: 0; }
  td, th { padding-left: 12px; padding-right: 12px; }
}

/* Inspectors page and setup dialog */
.status-strip { display: flex; align-items: center; gap: 16px; padding: 20px 22px; }
.status-icon { width: 40px; height: 40px; border-radius: 10px; background: var(--recess); color: var(--ink-3); display: grid; place-items: center; flex: none; }
.status-strip.active .status-icon { background: var(--green-soft); color: var(--green); }
.status-strip h3 { font-size: 14px; font-weight: 600; }
.meter.progress { margin-top: 10px; max-width: 360px; }
.inspector-list { list-style: none; margin: 0; padding: 0; }
.inspector-list li { display: flex; align-items: center; gap: 16px; padding: 16px 22px; border-top: 1px solid var(--row-line); }
.inspector-list li:first-child { border-top: 0; }
.inspector-list p { margin-top: 2px; }
.choices { display: grid; gap: 8px; margin: 0; padding: 0; border: 0; }
.choices legend { padding: 0; margin-bottom: 8px; font-size: 12px; font-weight: 500; }
.choice { display: flex; gap: 12px; align-items: flex-start; padding: 12px 14px; border: 1px solid var(--rule); border-radius: var(--radius); background: var(--paper); cursor: pointer; }
.choice:has(input:checked) { background: #f3f7e8; border-color: #a7bd89; }
.choice input { margin-top: 2px; }
.choice > span { display: flex; flex-direction: column; gap: 2px; }
.setup-form { display: contents; }

/* Quiet, predictable column proportions for the existing desktop tables. */
.table-title { text-decoration: none; display: block; line-height: 1.5; overflow-wrap: anywhere; }
.table-title:hover { color: var(--green); text-decoration: underline; text-underline-offset: 3px; }
.traces-table, .issues-table { table-layout: fixed; }
.traces-table th, .traces-table td, .issues-table th, .issues-table td { padding: 12px 14px; }
/* Column widths account for the sidebar, including smaller laptop displays. */
.traces-table th:first-child { width: 32%; }
.traces-table th:nth-child(2) { width: 15%; }
.traces-table th:nth-child(3) { width: 16%; }
.traces-table th:nth-child(4) { width: 15%; }
.traces-table th:nth-child(5) { width: 9%; }
.traces-table th:nth-child(6) { width: 13%; }
.traces-table :is(th, td):nth-child(4), .traces-table :is(th, td):nth-child(5) { text-align: right; }
.traces-table td { height: 82px; padding-top: 16px; padding-bottom: 16px; }
.traces-table th { padding-top: 15px; padding-bottom: 15px; }
.traces-table .table-title { font-size: 13px; line-height: 1.5; }
.trace-id { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 100%; }
.traces-table .trace-id { font-size: 10px; margin-top: 5px; opacity: .8; }
.traces-table .chips { min-width: 0; }
.traces-table .chip { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; border: 1px solid var(--rule); }
.traces-table .badge { max-width: 100%; white-space: normal; }
.traces-table .trace-usage .sub { font-size: 11px; margin-top: 4px; overflow-wrap: anywhere; }
.usage-heading { display: inline-flex; flex-wrap: wrap; justify-content: flex-end; align-items: center; gap: 3px; }
.traces-card .toolbar > * { min-width: 0; }
.traces-card .toolbar select[name="agent"] { max-width: 240px; flex-shrink: 1; }
.issues-table th:first-child { width: 35%; }
.issues-table th:nth-child(2) { width: 16%; }
.issues-table th:nth-child(3) { width: 14%; }
.issues-table th:nth-child(4) { width: 8%; }
.issues-table th:nth-child(5) { width: 15%; }
.issues-table th:nth-child(6) { width: 12%; }
.issues-table :is(th, td):nth-child(4) { text-align: right; }
.issues-table .tag { white-space: normal; }
.issues-table .tag::before { flex: none; }
.btn, .icon-btn { transition: background .15s, border-color .15s, color .15s; }
.inspection-progress { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); padding: 0 22px 20px; gap: 12px; }
.inspection-progress > div { border-left: 1px solid var(--rule); padding-left: 16px; }
.inspection-progress > div:first-child { border-left: 0; padding-left: 0; }
.inspection-progress dt { color: var(--ink-3); font-size: 12px; }
.inspection-progress dd { margin: 3px 0 0; color: var(--ink); font-size: 23px; font-weight: 500; }
.inspector-list p { max-width: 85ch; font-size: 12px !important; line-height: 1.6; margin-top: 4px; }
.status-strip .secondary { font-size: 12px; }
.status-strip .grow { min-width: 0; }
.activity-spinner { width: 13px; height: 13px; border: 2px solid var(--rule-2); border-top-color: var(--green); border-radius: 50%; animation: activity-spin 1s linear infinite; }
@keyframes activity-spin { to { transform: rotate(360deg); } }
.analysis-agent { padding: 16px; border: 1px solid var(--rule); border-radius: 9px; }
.analysis-agent h3 { margin-bottom: 12px; }
.analysis-agent .inspection-progress { padding: 0; grid-template-columns: repeat(3, minmax(0, 1fr)); }
.analysis-agent .inspection-progress dd { font-size: 20px; }
.analysis-note { color: var(--ink-2); font-size: 12px; line-height: 1.6; }
@media (min-width: 761px) and (max-width: 1200px) {
  .traces-table th, .traces-table td, .issues-table th, .issues-table td { padding: 11px 8px; }
  .traces-table th, .issues-table th { white-space: normal; }
  .traces-table .nowrap, .issues-table .nowrap { white-space: normal; }
  .issues-table .severity { white-space: normal; }
}
.traces-table .table-title { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.grouping-status { display:flex; align-items:center; justify-content:space-between; gap:16px; }
.grouping-status h3 { margin:0; }
.grouping-status a { color:var(--green); text-decoration:none; }
.grouping-track { display:flex; align-items:center; gap:12px; font-size:12px; color:var(--ink-3); padding:8px 0; }
.grouping-track .completed { color:var(--green); }
.grouping-track .track-line { height:2px; background:var(--rule); flex:1; }
.grouping-results { display:flex; align-items:baseline; gap:10px; margin-top:12px; color:var(--ink-3); font-size:12px; }
.grouping-results strong { font-size:28px; font-weight:500; color:var(--ink); }
