/*
 * Shared admin widget styles — prediction config, calibration results,
 * AI provider summaries, and any future structured admin displays.
 *
 * Design tokens: GitHub-inspired neutral palette.
 */

/* ------------------------------------------------------------------ */
/*  Base widget container                                              */
/* ------------------------------------------------------------------ */

.tw-widget {
  max-width: 900px;
  font-size: 13px;
}

/* Django admin paints the whole form-row red (via `color` on `.errors` —
   which children inherit — and via `.errors input/textarea/select` for
   border colour) whenever the JSONField has any ValidationError. Our widget
   surfaces errors per-panel (tw-accordion-item-error), so undo the
   bleed-through inside the widget subtree. */
.errors .tw-widget,
.errors .tw-widget label,
.errors .tw-widget .tw-label,
.errors .tw-widget legend,
.errors .tw-widget .help {
  color: #1f2328;
}

.errors .tw-widget .help {
  color: #57606a;
}

.errors .tw-widget input,
.errors .tw-widget textarea,
.errors .tw-widget select {
  color: #1f2328;
  border-color: #d0d7de;
}

/* ------------------------------------------------------------------ */
/*  Fieldset / section                                                 */
/* ------------------------------------------------------------------ */

.tw-section {
  border: 1px solid #d0d7de;
  border-radius: 6px;
  margin: 0 0 10px 0;
  padding: 10px 14px;
  background: #fafbfc;
}

.tw-section legend {
  color: #1f2328;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 6px;
}

/* Inner group — lighter border, used inside accordion bodies */
.tw-group {
  border: 1px solid #e4e8ec;
  border-radius: 4px;
  margin: 0 0 10px 0;
  padding: 8px 12px 10px;
  background: #fafbfc;
}

.tw-group:last-child {
  margin-bottom: 0;
}

.tw-group legend {
  color: #1f2328;
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 6px;
}

/* ------------------------------------------------------------------ */
/*  Field rows                                                         */
/* ------------------------------------------------------------------ */

.tw-field {
  margin-bottom: 6px;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.tw-field:last-child {
  margin-bottom: 0;
}

.tw-field label,
.tw-label {
  min-width: 200px;
  color: #1f2328;
  font-weight: 500;
  font-size: 13px;
}

/* Monospace read-only value badge */
.tw-value {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  color: #24292f;
  padding: 2px 8px;
  background: #fff;
  border: 1px solid #d0d7de;
  border-radius: 4px;
}

/* ------------------------------------------------------------------ */
/*  Inputs                                                             */
/* ------------------------------------------------------------------ */

.tw-field input[type="number"],
.tw-field input[type="text"] {
  width: 140px;
  padding: 4px 8px;
  border: 1px solid #d0d7de;
  border-radius: 4px;
  font-size: 13px;
}

.tw-field input[type="checkbox"] {
  margin: 0;
}

/* Textarea variant — stacks label above */
.tw-field-textarea {
  align-items: flex-start;
  flex-direction: column;
}

.tw-field-textarea label {
  margin-bottom: 4px;
}

.tw-field textarea {
  width: 100%;
  box-sizing: border-box;
  min-height: 80px;
  padding: 6px 8px;
  border: 1px solid #d0d7de;
  border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

/* ------------------------------------------------------------------ */
/*  Help text                                                          */
/* ------------------------------------------------------------------ */

.tw-field .help {
  display: block;
  color: #57606a;
  font-size: 11px;
  line-height: 1.4;
  flex: 1;
}

.tw-field-textarea .help {
  margin-top: 4px;
}

/* ------------------------------------------------------------------ */
/*  Data table                                                         */
/* ------------------------------------------------------------------ */

.tw-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.tw-table th {
  text-align: left;
  padding: 5px 10px;
  background: #f6f8fa;
  border: 1px solid #d0d7de;
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.tw-table td {
  padding: 4px 10px;
  border: 1px solid #e4e8ec;
}

.tw-table tr:nth-child(even) {
  background: #f6f8fa;
}

/* ------------------------------------------------------------------ */
/*  Accordion / collapsible sections (prediction config)               */
/* ------------------------------------------------------------------ */

.tw-accordion-item {
  border: 1px solid #d0d7de;
  border-radius: 6px;
  margin: 0 0 8px 0;
  padding: 0;
  background: #fff;
  overflow: hidden;
}

.tw-accordion-item-error {
  border-color: #cf222e;
}

.tw-accordion-item-error > .tw-accordion-header .tw-accordion-toggle {
  background: #ffebe9;
}

.tw-accordion-item-error > .tw-accordion-header .toggle-label {
  color: #cf222e;
}

.tw-accordion-header {
  margin: 0;
  padding: 0;
  background: transparent;
  border: none;
}

.tw-accordion-toggle {
  display: flex;
  align-items: center;
  width: 100%;
  box-sizing: border-box;
  text-align: left;
  cursor: pointer;
  padding: 10px 14px;
  margin: 0;
  border: none;
  background: #f6f8fa;
  color: #1f2328 !important;
  font: 600 14px/1.3 -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  user-select: none;
  transition: background-color 0.15s ease;
}

.tw-accordion-toggle:hover {
  background: #eef1f4;
}

.tw-accordion-toggle:focus {
  outline: 2px solid #0969da;
  outline-offset: -2px;
}

.tw-accordion-toggle[aria-expanded="true"] {
  background: #eef1f4;
  border-bottom: 1px solid #d0d7de;
}

.tw-accordion-toggle .toggle-label {
  color: #1f2328;
}

.tw-toggle-indicator {
  display: inline-block;
  width: 0;
  height: 0;
  margin-right: 10px;
  border-top: 5px solid transparent;
  border-bottom: 5px solid transparent;
  border-left: 6px solid #57606a;
  transition: transform 0.15s ease;
}

.tw-accordion-toggle[aria-expanded="true"] .tw-toggle-indicator {
  transform: rotate(90deg);
}

.tw-accordion-body {
  padding: 12px 14px;
  background: #fff;
}

/* ------------------------------------------------------------------ */
/*  Pre-formatted code / JSON block                                    */
/* ------------------------------------------------------------------ */

.tw-pre {
  margin-top: 8px;
  padding: 10px;
  background: #f8f8f8;
  border: 1px solid #ddd;
  border-radius: 4px;
  max-height: 400px;
  overflow: auto;
  font-size: 12px;
}

/* ------------------------------------------------------------------ */
/*  Django GIS OpenLayers widget (django.contrib.gis.admin)            */
/* ------------------------------------------------------------------ */
/*
 * Unfold's form chrome wraps each field in a flex container that
 * collapses the inline <style width:600px;height:400px> rules the
 * widget emits. Force the dimensions back so the OpenLayers canvas
 * actually has a box to draw into. Selectors target the *_map div
 * inside any *_div_map wrapper, which is the only place the widget
 * uses this id suffix scheme.
 */
[id$="_div_map"] {
  display: block !important;
  width: 100%;
  max-width: 600px;
}

[id$="_div_map"] > [id$="_map"] {
  display: block !important;
  width: 100% !important;
  max-width: 600px;
  height: 400px !important;
  border: 1px solid var(--color-base-300, #d1d5db);
  border-radius: 6px;
  overflow: hidden;
}

[id$="_div_map"] .clear_features {
  display: inline-block;
  margin-top: 6px;
  font-size: 12px;
}

[id$="_div_map"] textarea.vSerializedField {
  display: none;
}

/* ------------------------------------------------------------------ */
/*  Dark mode overrides (django-unfold toggles `html.dark`)            */
/* ------------------------------------------------------------------ */

html.dark .tw-widget,
html.dark .tw-widget label,
html.dark .tw-widget .tw-label,
html.dark .tw-widget legend,
html.dark .errors .tw-widget,
html.dark .errors .tw-widget label,
html.dark .errors .tw-widget .tw-label,
html.dark .errors .tw-widget legend {
  color: rgb(var(--color-base-200));
}

html.dark .tw-widget .help,
html.dark .errors .tw-widget .help,
html.dark .tw-field .help {
  color: rgb(var(--color-base-400));
}

html.dark .tw-section,
html.dark .tw-group {
  background: rgb(var(--color-base-900));
  border-color: rgb(var(--color-base-700));
}

html.dark .tw-value {
  background: rgb(var(--color-base-800));
  border-color: rgb(var(--color-base-700));
  color: rgb(var(--color-base-100));
}

html.dark .tw-field input[type="number"],
html.dark .tw-field input[type="text"],
html.dark .tw-field textarea,
html.dark .errors .tw-widget input,
html.dark .errors .tw-widget textarea,
html.dark .errors .tw-widget select {
  background: rgb(var(--color-base-800));
  border-color: rgb(var(--color-base-700));
  color: rgb(var(--color-base-100));
}

html.dark .tw-table th {
  background: rgb(var(--color-base-800));
  border-color: rgb(var(--color-base-700));
  color: rgb(var(--color-base-200));
}

html.dark .tw-table td {
  border-color: rgb(var(--color-base-700));
  color: rgb(var(--color-base-200));
}

html.dark .tw-table tr:nth-child(even) {
  background: rgb(var(--color-base-900));
}

html.dark .tw-accordion-item {
  background: rgb(var(--color-base-900));
  border-color: rgb(var(--color-base-700));
}

html.dark .tw-accordion-toggle {
  background: rgb(var(--color-base-800));
  color: rgb(var(--color-base-100)) !important;
}

html.dark .tw-accordion-toggle:hover,
html.dark .tw-accordion-toggle[aria-expanded="true"] {
  background: rgb(var(--color-base-700));
}

html.dark .tw-accordion-toggle[aria-expanded="true"] {
  border-bottom-color: rgb(var(--color-base-700));
}

html.dark .tw-accordion-toggle .toggle-label {
  color: rgb(var(--color-base-100));
}

html.dark .tw-toggle-indicator {
  border-left-color: rgb(var(--color-base-400));
}

html.dark .tw-accordion-body {
  background: rgb(var(--color-base-900));
}

html.dark .tw-accordion-item-error {
  border-color: rgb(220 38 38);
}

html.dark .tw-accordion-item-error > .tw-accordion-header .tw-accordion-toggle {
  background: rgb(127 29 29 / 0.3);
}

html.dark .tw-accordion-item-error > .tw-accordion-header .toggle-label {
  color: rgb(248 113 113);
}

html.dark .tw-pre {
  background: rgb(var(--color-base-800));
  border-color: rgb(var(--color-base-700));
  color: rgb(var(--color-base-100));
}
