/* Tracking SW admin theme.
   Layout: signage-blue sidebar (full height) + white top bar + content; EU plates and tachograph
   pictograms as the fleet's own vocabulary. Maps Django admin variables onto our tokens (light + dark). */

html[data-theme="light"], :root {
  --tsw-bg: #eef1f4;
  --tsw-surface: #ffffff;
  --tsw-surface-2: #f5f7f9;
  --tsw-ink: #142030;
  --tsw-muted: #5a6779;
  --tsw-line: #d8dee5;
  --tsw-accent: #1c4f9c;
  --tsw-accent-hover: #163f7d;
  --tsw-accent-soft: #e3ecf8;
  --tsw-accent-ink: #ffffff;
  --tsw-side: #0f2440;
  --tsw-side-ink: #d5e0ef;
  --tsw-side-muted: #8ea3bf;
  --tsw-side-active: #1c4f9c;
  --tsw-side-hover: rgba(255, 255, 255, .07);
  --tsw-ok: #1d7f47;
  --tsw-ok-soft: #e1f2e8;
  --tsw-warn: #b96f00;
  --tsw-warn-soft: #fbefd9;
  --tsw-crit: #c22a2a;
  --tsw-crit-soft: #fbe3e3;
  --tsw-plate-bg: #ffffff;
  --tsw-plate-fg: #111111;
  --tsw-plate-band: #003399;
  --tsw-plate-line: #2b2b2b;
  --tsw-font-display: "Barlow Semi Condensed", "Arial Narrow", "Roboto Condensed", sans-serif;
  --tsw-font-body: "Barlow", "Segoe UI", system-ui, sans-serif;
  --tsw-font-data: "IBM Plex Mono", ui-monospace, "SFMono-Regular", Menlo, monospace;

  /* Django admin variables */
  --primary: var(--tsw-accent);
  --secondary: var(--tsw-accent);
  --accent: var(--tsw-accent);
  --primary-fg: #ffffff;
  --body-fg: var(--tsw-ink);
  --body-bg: var(--tsw-bg);
  --body-quiet-color: var(--tsw-muted);
  --body-medium-color: var(--tsw-ink);
  --body-loud-color: var(--tsw-ink);
  --header-color: var(--tsw-ink);
  --header-branding-color: var(--tsw-ink);
  --header-bg: var(--tsw-surface);
  --header-link-color: var(--tsw-accent);
  --breadcrumbs-fg: var(--tsw-muted);
  --breadcrumbs-link-fg: var(--tsw-accent);
  --breadcrumbs-bg: transparent;
  --link-fg: var(--tsw-accent);
  --link-hover-color: var(--tsw-accent-hover);
  --link-selected-fg: var(--tsw-accent);
  --hairline-color: var(--tsw-line);
  --border-color: var(--tsw-line);
  --error-fg: var(--tsw-crit);
  --message-success-bg: var(--tsw-ok-soft);
  --message-warning-bg: var(--tsw-warn-soft);
  --message-error-bg: var(--tsw-crit-soft);
  --message-info-bg: var(--tsw-accent-soft);
  --darkened-bg: var(--tsw-surface-2);
  --selected-bg: var(--tsw-accent-soft);
  --selected-row: var(--tsw-accent-soft);
  --button-fg: #ffffff;
  --button-bg: var(--tsw-accent);
  --button-hover-bg: var(--tsw-accent-hover);
  --default-button-bg: var(--tsw-accent);
  --default-button-hover-bg: var(--tsw-accent-hover);
  --close-button-bg: var(--tsw-muted);
  --close-button-hover-bg: var(--tsw-ink);
  --delete-button-bg: var(--tsw-crit);
  --delete-button-hover-bg: #a11f1f;
  --object-tools-fg: var(--tsw-accent);
  --object-tools-bg: var(--tsw-surface);
  --object-tools-hover-bg: var(--tsw-accent-soft);
  --font-family-primary: var(--tsw-font-body);
  --font-family-monospace: var(--tsw-font-data);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --tsw-bg: #0d1219; --tsw-surface: #141b24; --tsw-surface-2: #19222d; --tsw-ink: #e5eaf0;
    --tsw-muted: #96a3b3; --tsw-line: #29343f; --tsw-accent: #7aa3e6; --tsw-accent-hover: #9cbcef;
    --tsw-accent-soft: #1b2a40; --tsw-accent-ink: #0d1219;
    --tsw-side: #0a1626; --tsw-side-ink: #d5e0ef; --tsw-side-muted: #7f93ad; --tsw-side-active: #24497f;
    --tsw-ok: #46c27f; --tsw-ok-soft: #12291d; --tsw-warn: #f0a83a; --tsw-warn-soft: #2d2212;
    --tsw-crit: #f06262; --tsw-crit-soft: #321718;
    --primary-fg: #0d1219; --button-fg: #0d1219; --delete-button-hover-bg: #ff7b7b;
    color-scheme: dark;
  }
}
html[data-theme="dark"] {
  --tsw-bg: #0d1219; --tsw-surface: #141b24; --tsw-surface-2: #19222d; --tsw-ink: #e5eaf0;
  --tsw-muted: #96a3b3; --tsw-line: #29343f; --tsw-accent: #7aa3e6; --tsw-accent-hover: #9cbcef;
  --tsw-accent-soft: #1b2a40; --tsw-accent-ink: #0d1219;
  --tsw-side: #0a1626; --tsw-side-ink: #d5e0ef; --tsw-side-muted: #7f93ad; --tsw-side-active: #24497f;
  --tsw-ok: #46c27f; --tsw-ok-soft: #12291d; --tsw-warn: #f0a83a; --tsw-warn-soft: #2d2212;
  --tsw-crit: #f06262; --tsw-crit-soft: #321718;
  --primary-fg: #0d1219; --button-fg: #0d1219; --delete-button-hover-bg: #ff7b7b;
  color-scheme: dark;
}

/* ---------- Base ---------- */
body { background: var(--tsw-bg); color: var(--tsw-ink); font-family: var(--tsw-font-body); font-size: 15px; }
h1, h2, h3, #content h1, #content h2 { font-family: var(--tsw-font-display); font-weight: 700; letter-spacing: .01em; text-wrap: balance; }
#content h1 { font-size: 30px; line-height: 1.1; margin: 0 0 4px; color: var(--tsw-ink); }
#content h2 { font-size: 19px; }
.tsw-num { font-family: var(--tsw-font-data); font-variant-numeric: tabular-nums; }
a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--tsw-accent); outline-offset: 2px; }

/* ---------- Layout: sidebar + topbar + content ---------- */
#container:has(#tsw-sidebar) {
  background: linear-gradient(to right, var(--tsw-side) 236px, var(--tsw-bg) 236px);
  display: grid; grid-template-columns: 236px minmax(0, 1fr); grid-template-rows: auto auto 1fr auto;
  min-width: 0; min-height: 100vh; height: auto;
}
#container:has(#tsw-sidebar) > .main { display: contents; }
#container:has(#tsw-sidebar) > #header,
#container:has(#tsw-sidebar) > nav,
#container:has(#tsw-sidebar) #content-start,
#container:has(#tsw-sidebar) > #footer { grid-column: 2; min-width: 0; }
#tsw-sidebar { grid-column: 1; grid-row: 1 / -1; }

#header {
  background: var(--tsw-surface); color: var(--tsw-ink); border-bottom: 1px solid var(--tsw-line);
  padding: 12px max(28px, env(safe-area-inset-right, 0px)) 12px 28px; gap: 14px; align-items: center;
}
#header #branding { flex: 1; min-width: 0; }
#user-tools { color: var(--tsw-muted); font-size: 13px; text-transform: none; letter-spacing: 0; font-weight: 400; }
#user-tools a { color: var(--tsw-accent); border-bottom: 0; text-decoration: none; }
#user-tools a:hover { text-decoration: underline; color: var(--tsw-accent); }
#user-tools strong { color: var(--tsw-ink); font-weight: 600; }
#user-tools button { color: var(--tsw-accent); }
.theme-toggle svg { fill: var(--tsw-accent); color: var(--tsw-accent); }

/* User menu */
.tsw-user { position: relative; display: flex; align-items: center; }
#user-tools .tsw-user-btn {
  display: inline-flex; align-items: center; gap: 8px; padding: 4px 8px 4px 4px; border-radius: 22px; border: 0;
  background: transparent; color: var(--tsw-ink); font: 500 14px var(--tsw-font-body); cursor: pointer;
}
#user-tools .tsw-user-btn:hover, #user-tools .tsw-user-btn[aria-expanded="true"] { background: var(--tsw-surface-2); box-shadow: inset 0 0 0 1px var(--tsw-line); }
.tsw-chevron { width: 16px; height: 16px; stroke: var(--tsw-muted); fill: none; stroke-width: 2; }
.tsw-avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--tsw-side-active); color: #fff; display: grid; place-items: center;
  font: 700 13px var(--tsw-font-display); letter-spacing: .04em; flex: none;
}
.tsw-avatar.big { width: 40px; height: 40px; font-size: 16px; }
.tsw-user-menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 50; width: 270px; padding: 6px;
  background: var(--tsw-surface); border: 1px solid var(--tsw-line); border-radius: 12px; box-shadow: 0 12px 32px rgba(0, 0, 0, .22);
  display: flex; flex-direction: column; gap: 2px; text-align: left;
}
.tsw-user-menu[hidden] { display: none; }
.tsw-user-head { display: flex; align-items: center; gap: 10px; padding: 8px 8px 10px; border-bottom: 1px solid var(--tsw-line); margin-bottom: 4px; }
.tsw-user-head b { display: block; color: var(--tsw-ink); font-size: 14px; }
.tsw-user-head small { display: block; color: var(--tsw-muted); font-size: 12px; overflow-wrap: anywhere; }
#container#container .tsw-user-menu a, #user-tools .tsw-logout {
  display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 7px; color: var(--tsw-ink);
  font: 500 14px var(--tsw-font-body); text-decoration: none; border: 0; background: transparent; width: 100%; cursor: pointer; text-align: left;
}
#container#container .tsw-user-menu a:hover, #user-tools .tsw-logout:hover { background: var(--tsw-surface-2); }
.tsw-user-menu svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.8; flex: none; }
.tsw-user-menu form { margin: 0; border-top: 1px solid var(--tsw-line); padding-top: 4px; margin-top: 4px; }
#user-tools .tsw-logout { color: var(--tsw-crit); }
.tsw-theme { padding: 8px; display: flex; flex-direction: column; gap: 6px; }
.tsw-theme > span { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--tsw-muted); }
.tsw-seg { display: grid; grid-template-columns: repeat(3, 1fr); background: var(--tsw-surface-2); border-radius: 8px; padding: 3px; gap: 3px; }
#user-tools .tsw-seg button {
  display: inline-flex; align-items: center; justify-content: center; gap: 5px; padding: 6px 4px; border: 0; border-radius: 6px;
  background: transparent; color: var(--tsw-muted); font: 500 12px var(--tsw-font-body); cursor: pointer;
}
#user-tools .tsw-seg button svg { width: 14px; height: 14px; }
#user-tools .tsw-seg button[aria-pressed="true"] { background: var(--tsw-surface); color: var(--tsw-ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .15); }

.tsw-search { width: 100%; display: flex; align-items: center; gap: 8px; max-width: 440px; background: var(--tsw-surface-2); border: 1px solid var(--tsw-line); border-radius: 8px; padding: 6px 10px; color: var(--tsw-muted); }
.tsw-search svg { width: 16px; height: 16px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; }
.tsw-search input { all: unset; flex: 1; min-width: 0; color: var(--tsw-ink); font-size: 14px; }
.tsw-search select { all: unset; font-size: 12px; color: var(--tsw-muted); cursor: pointer; padding-left: 8px; border-left: 1px solid var(--tsw-line); }

nav[aria-label] > .breadcrumbs, div.breadcrumbs {
  background: transparent; color: var(--tsw-muted); padding: 14px 28px 0; font-size: 13px; border: 0;
}
div.breadcrumbs a { color: var(--tsw-accent); }
#content { padding: 14px 28px 40px; }
#content-start { min-width: 0; }
#footer { padding: 0; }

/* Theme links never underlined (beats the admin's a:not(#header a, ...) rule). */
#container#container a:is(.tsw-brand, .tsw-stat, .tsw-plate, .tsw-btn, .tsw-file),
#container#container :is(.tsw-nav, .tsw-panel-head, .tsw-page-head) a { text-decoration: none; }
#container#container .tsw-panel-head a:hover { text-decoration: underline; }
#container a.tsw-plate { color: var(--tsw-plate-fg); }
#container a.tsw-brand { color: var(--tsw-side-ink); }
#container .tsw-nav a { color: var(--tsw-side-ink); }
#container .tsw-nav a[aria-current="page"], #container .tsw-nav a:hover { color: #fff; }
#container a.tsw-stat { color: var(--tsw-ink); }
#container a.tsw-btn { color: var(--tsw-accent-ink); }
#container a.tsw-btn.ghost { color: var(--tsw-accent); }
#container a.tsw-file { color: var(--tsw-ink); }

/* Login */
body.login { background: var(--tsw-bg); }
.login #container { border-radius: 12px; border: 1px solid var(--tsw-line); overflow: hidden; background: var(--tsw-surface); }
.login #header { background: var(--tsw-side); color: #fff; border: 0; padding: 18px 24px; }
.login #header .tsw-brand-plain b { font-family: var(--tsw-font-display); font-size: 24px; letter-spacing: .02em; color: #fff; }
.login #content { padding: 20px 24px 24px; background: var(--tsw-surface); }
.login .submit-row { border: 0; padding: 8px 0 0; background: transparent; }
.login .submit-row input { width: 100%; padding: 10px; }

/* Sidebar */
#tsw-sidebar {
  background: var(--tsw-side); color: var(--tsw-side-ink); display: flex; flex-direction: column; gap: 20px;
  padding: 18px 0; position: sticky; top: 0; height: 100vh; overflow-y: auto;
}
.tsw-brand { display: flex; align-items: center; gap: 10px; padding: 0 20px; color: var(--tsw-side-ink); text-decoration: none; }
.tsw-brand:hover { text-decoration: none; color: #fff; }
.tsw-brand-mark { width: 30px; height: 30px; border-radius: 7px; background: var(--tsw-side-active); display: grid; place-items: center; flex: none; }
.tsw-brand-mark svg { width: 18px; height: 18px; stroke: #fff; fill: none; stroke-width: 2; }
.tsw-brand b { display: block; font-family: var(--tsw-font-display); font-size: 20px; letter-spacing: .02em; line-height: 1.1; }
.tsw-brand small { display: block; font-size: 11px; color: var(--tsw-side-muted); letter-spacing: .08em; text-transform: uppercase; }
.tsw-nav { display: flex; flex-direction: column; gap: 2px; padding: 0 10px; }
.tsw-nav-label { font-size: 11px; letter-spacing: .1em; text-transform: uppercase; color: var(--tsw-side-muted); padding: 10px 10px 4px; }
.tsw-nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 7px;
  color: var(--tsw-side-ink); font-size: 14px; text-decoration: none;
}
.tsw-nav a:hover { background: var(--tsw-side-hover); color: #fff; text-decoration: none; }
.tsw-nav a[aria-current="page"] { background: var(--tsw-side-active); color: #fff; font-weight: 600; }
.tsw-nav a:focus-visible { outline: 2px solid var(--tsw-side-ink); outline-offset: -2px; }
.tsw-nav svg { width: 17px; height: 17px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; }
.tsw-count { margin-left: auto; background: #e04545; color: #fff; font-size: 11px; font-weight: 600; border-radius: 10px; padding: 0 7px; line-height: 18px; }
.tsw-side-foot { margin-top: auto; padding: 0 20px; font-size: 12px; color: var(--tsw-side-muted); }

/* ---------- Django components restyled ---------- */
.module, fieldset.module, .inline-group, #changelist .changelist-form-container, .dashboard .module {
  background: var(--tsw-surface); border: 1px solid var(--tsw-line); border-radius: 10px;
}
.module h2, .module caption, .inline-group h2, fieldset.module h2, fieldset .fieldset-heading {
  background: transparent; color: var(--tsw-ink); font-family: var(--tsw-font-display); font-size: 18px;
  font-weight: 700; text-transform: none; letter-spacing: .01em; padding: 12px 16px; border-bottom: 1px solid var(--tsw-line);
}
.inline-group .tabular tr.add-row td, .inline-group div.add-row { background: var(--tsw-surface-2); }
fieldset.module { padding: 0; overflow: hidden; }
fieldset .form-row { padding: 10px 16px; border-bottom: 1px solid var(--tsw-line); }
fieldset .description, .module .description { padding: 8px 16px; color: var(--tsw-muted); }
.aligned label, form .aligned label { color: var(--tsw-muted); font-weight: 500; }
.help, p.help, form p.help, div.help { color: var(--tsw-muted); }
input[type=text], input[type=number], input[type=email], input[type=url], input[type=password], input[type=search],
input[type=date], input[type=time], input[type=tel], textarea, select, .vTextField {
  background: var(--tsw-surface); color: var(--tsw-ink); border: 1px solid var(--tsw-line); border-radius: 6px; padding: 6px 8px;
}

thead th, tfoot td, .module table thead th { background: var(--tsw-surface-2); color: var(--tsw-muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; font-weight: 600; border-bottom: 1px solid var(--tsw-line); }
thead th a, thead th a:link, thead th a:visited { color: var(--tsw-muted); }
td, th { border-bottom-color: var(--tsw-line); }
#result_list tbody tr:hover td, #result_list tbody tr:hover th { background: var(--tsw-surface-2); }
#result_list td, #result_list th { padding: 10px 12px; vertical-align: middle; }
#changelist .actions { background: var(--tsw-surface-2); border-bottom: 1px solid var(--tsw-line); color: var(--tsw-muted); }
#changelist #toolbar { background: var(--tsw-surface); border-bottom: 1px solid var(--tsw-line); }
#changelist-filter { background: var(--tsw-surface); border: 1px solid var(--tsw-line); border-radius: 10px; }
#changelist-filter h2 { background: transparent; color: var(--tsw-ink); font-family: var(--tsw-font-display); font-size: 17px; text-transform: none; border-bottom: 1px solid var(--tsw-line); }
#changelist-filter h3 { color: var(--tsw-muted); font-size: 11px; letter-spacing: .08em; text-transform: uppercase; }
#changelist-filter li.selected a { color: var(--tsw-accent); }
.paginator { color: var(--tsw-muted); }
#changelist #toolbar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
#changelist #toolbar #changelist-search { flex: 1; min-width: 0; }
.tsw-filter-toggle {
  margin-left: auto; display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 7px;
  border: 0; background: var(--tsw-surface); color: var(--tsw-accent); box-shadow: inset 0 0 0 1px var(--tsw-line);
  font: 600 13px var(--tsw-font-body); cursor: pointer; white-space: nowrap;
}
.tsw-filter-toggle:hover { background: var(--tsw-accent-soft); }
.tsw-filter-toggle svg { width: 15px; height: 15px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linejoin: round; }
#changelist.tsw-filters-hidden #changelist-filter { display: none; }
#changelist.tsw-filters-hidden { min-height: 0; }
#changelist.tsw-filters-hidden .changelist-form-container:has(#changelist-filter) > div { max-width: 100%; width: 100%; }

.button, input[type=submit], input[type=button], .submit-row input, a.button, button.button {
  border-radius: 7px; font-family: var(--tsw-font-body); font-weight: 600; padding: 8px 14px;
}
.submit-row input, .submit-row a { text-transform: none; letter-spacing: 0; }
.submit-row { background: var(--tsw-surface); border: 1px solid var(--tsw-line); border-radius: 10px; padding: 12px 14px; }
.object-tools a:link, .object-tools a:visited {
  border-radius: 7px; background: var(--tsw-surface); color: var(--tsw-accent); box-shadow: inset 0 0 0 1px var(--tsw-line);
  text-transform: none; letter-spacing: 0; font-weight: 600; font-size: 13px; padding: 7px 14px;
}
.object-tools a:hover { background: var(--tsw-accent-soft); }
ul.messagelist li { border-radius: 8px; margin-bottom: 8px; color: var(--tsw-ink); }
.errornote { border-radius: 8px; border-color: var(--tsw-crit); color: var(--tsw-crit); background: var(--tsw-crit-soft); }
.selector, .calendarbox, .clockbox { background: var(--tsw-surface); }

/* Date/time fields everywhere: one line, icons only (labels kept for screen readers) */
.inline-group .tabular td.original p { display: none; }
.inline-group .tabular td.original { padding-top: 10px; }
.inline-group .tabular td { vertical-align: middle; padding: 8px 10px; }
#content .datetime { display: flex; flex-wrap: nowrap; align-items: center; gap: 6px; margin: 0; font-size: 0; }
#content .datetime > * { font-size: 13px; }
#content .form-row .datetime, #content .form-row p.date { width: auto; }
#content .datetime br { display: none; }
#content .datetime input.vDateField { width: 7.5em; }
#content .datetime input.vTimeField { width: 5.5em; }
#content .datetime label {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
/* Keep only the calendar/clock icons ("Oggi"/"Adesso" text and the separator take too much room). */
#content .datetimeshortcuts { display: inline-flex; align-items: center; font-size: 0; }
#content .datetimeshortcuts a:first-child { display: none; }
.inline-group .tabular { overflow-x: auto; }
#content p.date { display: flex; flex-wrap: nowrap; align-items: center; gap: 6px; margin: 0; }
#content p.date input.vDateField { width: 7.5em; }
#content .date-icon, #content .clock-icon { width: 16px; height: 16px; background-size: 16px; vertical-align: middle; }
#content input.vDateField + .datetimeshortcuts { margin-left: 2px; }
.inline-group .tabular .select2-container { min-width: 220px; }
.inline-group .tabular input[type=text]:not(.vDateField):not(.vTimeField) { width: 100%; min-width: 90px; box-sizing: border-box; }

/* Stacked inlines (e.g. GPS installati): compact header, fields on two lines */
.inline-group .inline-related h3 {
  background: var(--tsw-surface-2); color: var(--tsw-ink); font-size: 13px; font-weight: 600; text-transform: none;
  letter-spacing: 0; padding: 8px 16px; border-bottom: 1px solid var(--tsw-line); display: flex; align-items: center; gap: 10px;
}
.inline-group .inline-related h3 b { display: none; }
.inline-group .inline-related h3 .inline_label { color: var(--tsw-muted); font-weight: 500; }
.inline-group .inline-related h3 span.delete { margin-left: auto; float: none; }
.inline-group .inline-related fieldset.module { border: 0; border-radius: 0; }
.inline-group .inline-related .form-row { padding: 10px 16px; }
.inline-group .inline-related .form-multiline { display: flex; flex-wrap: wrap; gap: 10px 32px; }
.inline-group .inline-related .form-multiline > :is(div, fieldset) { flex: 1 1 260px; min-width: 0; margin: 0; padding: 0; border: 0; }
.inline-group .inline-related .form-multiline > fieldset > legend { padding: 0; margin-bottom: 6px; font-size: 13px; color: var(--tsw-muted); font-weight: 500; }
.inline-group .inline-related input[type=text]:not(.vDateField):not(.vTimeField) { width: 100%; box-sizing: border-box; }

/* ---------- Our components ---------- */
.tsw-plate {
  display: inline-flex; align-items: stretch; border: 1.5px solid var(--tsw-plate-line); border-radius: 4px; overflow: hidden;
  background: var(--tsw-plate-bg); color: var(--tsw-plate-fg); font-family: var(--tsw-font-display); font-weight: 700;
  font-size: 15px; letter-spacing: .06em; line-height: 1; vertical-align: middle; text-decoration: none;
}
a.tsw-plate:hover { text-decoration: none; box-shadow: 0 0 0 2px var(--tsw-accent); }
.tsw-plate .eu { background: var(--tsw-plate-band); color: #fff; font-size: 9px; padding: 3px 4px; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; letter-spacing: 0; }
.tsw-plate .eu::before { content: "★"; font-size: 8px; color: #ffcc00; margin-bottom: 1px; }
.tsw-plate .txt { padding: 4px 7px; }
.tsw-plate.big { font-size: 26px; }
.tsw-plate.big .eu { font-size: 12px; padding: 4px 6px; }
.tsw-plate.big .txt { padding: 6px 12px; }

.tsw-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 500; white-space: nowrap; }
.tsw-pill i { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--tsw-muted); }
.tsw-pill.moving i, .tsw-pill.ok i { background: var(--tsw-ok); }
.tsw-pill.idle i, .tsw-pill.warn i { background: var(--tsw-warn); }
.tsw-pill.crit i { background: var(--tsw-crit); }
.tsw-chip { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 5px; white-space: nowrap; }
.tsw-chip.ok { background: var(--tsw-ok-soft); color: var(--tsw-ok); }
.tsw-chip.soon { background: var(--tsw-warn-soft); color: var(--tsw-warn); }
.tsw-chip.expired { background: var(--tsw-crit-soft); color: var(--tsw-crit); }
.tsw-chip.missing { background: var(--tsw-surface-2); color: var(--tsw-muted); box-shadow: inset 0 0 0 1px var(--tsw-line); }
.tsw-tacho { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; white-space: nowrap; }
.tsw-tacho svg { width: 17px; height: 17px; stroke: currentColor; fill: none; stroke-width: 1.8; flex: none; }
.tsw-tacho.present { color: var(--tsw-ok); }
.tsw-tacho.absent { color: var(--tsw-crit); }
.tsw-tacho.unknown { color: var(--tsw-muted); }
.tsw-muted { color: var(--tsw-muted); }

.tsw-page { display: flex; flex-direction: column; gap: 22px; }
.tsw-page-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 10px; }
.tsw-page-head p { margin: 2px 0 0; color: var(--tsw-muted); font-size: 14px; }
.tsw-btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: 7px; font-size: 14px; font-weight: 600; border: 0; cursor: pointer; background: var(--tsw-accent); color: var(--tsw-accent-ink); text-decoration: none; font-family: var(--tsw-font-body); }
.tsw-btn:hover { background: var(--tsw-accent-hover); color: var(--tsw-accent-ink); text-decoration: none; }
.tsw-btn.ghost { background: transparent; color: var(--tsw-accent); box-shadow: inset 0 0 0 1px var(--tsw-line); }
.tsw-btn.ghost:hover { background: var(--tsw-accent-soft); }
.tsw-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }

.tsw-strip { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); background: var(--tsw-surface); border: 1px solid var(--tsw-line); border-radius: 10px; }
.tsw-stat { padding: 14px 18px; display: flex; flex-direction: column; gap: 2px; text-decoration: none; color: inherit; }
a.tsw-stat:hover { background: var(--tsw-surface-2); text-decoration: none; }
.tsw-stat + .tsw-stat { border-left: 1px solid var(--tsw-line); }
.tsw-stat .label { font-size: 12px; letter-spacing: .06em; text-transform: uppercase; color: var(--tsw-muted); }
.tsw-stat .value { font-family: var(--tsw-font-display); font-weight: 700; font-size: 30px; line-height: 1.1; color: var(--tsw-ink); }
.tsw-stat .hint { font-size: 13px; color: var(--tsw-muted); }
.tsw-stat.crit .value { color: var(--tsw-crit); }

.tsw-grid-2 { display: grid; grid-template-columns: minmax(0, 1.5fr) minmax(0, 1fr); gap: 22px; align-items: start; }
.tsw-panel { background: var(--tsw-surface); border: 1px solid var(--tsw-line); border-radius: 10px; min-width: 0; }
.tsw-panel-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--tsw-line); }
#content .tsw-panel-head h2 { margin: 0; font-size: 19px; color: var(--tsw-ink); }
.tsw-panel-head a { font-size: 13px; }
.tsw-empty { padding: 16px 18px; color: var(--tsw-muted); margin: 0; }
.tsw-table-wrap { overflow-x: auto; }
table.tsw-table { width: 100%; border-collapse: collapse; font-size: 14px; }
table.tsw-table th { text-align: left; padding: 10px 14px; white-space: nowrap; background: transparent; }
table.tsw-table td { padding: 11px 14px; border-bottom: 1px solid var(--tsw-line); vertical-align: middle; white-space: nowrap; }
table.tsw-table tr:last-child td { border-bottom: 0; }
/* Group permissions: module per row, a tick per level. */
.tsw-perm-table { max-width: 640px; }
.tsw-perm-table tbody th { text-align: left; padding: 11px 14px; font-weight: 600; border-bottom: 1px solid var(--tsw-line); }
.tsw-perm-table tbody tr:last-child th { border-bottom: 0; }
.tsw-perm-table .tsw-perm-col { text-align: center; width: 130px; }
.tsw-perm-table input[type="checkbox"] { width: 18px; height: 18px; cursor: pointer; }
.tsw-perm-table input[type="checkbox"]:disabled { cursor: not-allowed; opacity: .35; }
table.tsw-table tbody tr:hover td { background: var(--tsw-surface-2); }

.tsw-alert {
  border: 1px solid var(--tsw-crit); border-left-width: 5px; background: var(--tsw-crit-soft); border-radius: 10px;
  padding: 14px 18px; display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 14px;
}
.tsw-alert .icon { grid-row: span 3; width: 38px; height: 38px; border-radius: 50%; background: var(--tsw-crit); display: grid; place-items: center; }
.tsw-alert .icon svg { width: 20px; height: 20px; stroke: #fff; fill: none; stroke-width: 2; }
#content .tsw-alert h3 { margin: 0; font-size: 18px; color: var(--tsw-crit); }
.tsw-alert p { margin: 0; color: var(--tsw-ink); font-size: 14px; }
.tsw-reasons { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; align-items: center; }
.tsw-reasons .label { font-size: 13px; color: var(--tsw-muted); }
.tsw-reason { cursor: pointer; font: inherit; font-size: 13px; padding: 5px 11px; border-radius: 16px; background: var(--tsw-surface); color: var(--tsw-ink); border: 0; box-shadow: inset 0 0 0 1px var(--tsw-line); }
.tsw-reason:hover, .tsw-reason[aria-pressed="true"] { box-shadow: inset 0 0 0 1.5px var(--tsw-crit); color: var(--tsw-crit); }
.tsw-reasons input[type=text] { font-size: 13px; padding: 5px 8px; min-width: 180px; flex: 1; max-width: 320px; }
.tsw-reasons .tsw-btn { background: var(--tsw-crit); color: #fff; }
.tsw-handled { color: var(--tsw-ok); font-weight: 600; }

.tsw-list { list-style: none; margin: 0; padding: 0; }
.tsw-list li { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; padding: 11px 18px; border-bottom: 1px solid var(--tsw-line); font-size: 14px; }
.tsw-list li:last-child { border-bottom: 0; }
.tsw-list .what { min-width: 0; }
.tsw-list .what b { font-weight: 600; }
.tsw-list .what small { display: block; color: var(--tsw-muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tsw-date { width: 46px; text-align: center; border: 1px solid var(--tsw-line); border-radius: 6px; overflow: hidden; line-height: 1.1; }
.tsw-date b { display: block; font-family: var(--tsw-font-display); font-size: 18px; padding-top: 3px; }
.tsw-date span { display: block; font-size: 10px; text-transform: uppercase; letter-spacing: .06em; background: var(--tsw-surface-2); color: var(--tsw-muted); padding: 2px 0; }

/* "Tutte le sezioni" */
.tsw-sections { display: grid; grid-template-columns: repeat(auto-fill, minmax(320px, 1fr)); gap: 18px; align-items: start; }
.tsw-section { background: var(--tsw-surface); border: 1px solid var(--tsw-line); border-radius: 10px; min-width: 0; }
.tsw-section header { display: flex; gap: 12px; align-items: flex-start; padding: 16px 18px; border-bottom: 1px solid var(--tsw-line); }
.tsw-section-icon { width: 38px; height: 38px; border-radius: 9px; background: var(--tsw-accent-soft); display: grid; place-items: center; flex: none; }
.tsw-section-icon svg { width: 20px; height: 20px; stroke: var(--tsw-accent); fill: none; stroke-width: 1.8; }
#content .tsw-section h2 { margin: 0; font-size: 18px; color: var(--tsw-ink); }
.tsw-section header p { margin: 2px 0 0; font-size: 13px; color: var(--tsw-muted); }
.tsw-section ul { list-style: none; margin: 0; padding: 6px 0; }
.tsw-section li { display: grid; grid-template-columns: minmax(0, 1fr) auto 28px; align-items: center; gap: 10px; padding: 7px 18px; }
.tsw-section li:hover { background: var(--tsw-surface-2); }
#container#container .tsw-section-link { color: var(--tsw-ink); text-decoration: none; font-weight: 500; }
#container#container .tsw-section-link:hover { color: var(--tsw-accent); }
.tsw-section-count { font-size: 12px; color: var(--tsw-muted); background: var(--tsw-surface-2); border-radius: 10px; padding: 1px 8px; }
#container#container .tsw-section-add {
  width: 26px; height: 26px; border-radius: 7px; display: grid; place-items: center; text-decoration: none;
  color: var(--tsw-accent); box-shadow: inset 0 0 0 1px var(--tsw-line); font-size: 17px; font-weight: 600; line-height: 1;
}
#container#container .tsw-section-add:hover { background: var(--tsw-accent-soft); }
#container#container .tsw-section-add.placeholder { box-shadow: none; }

/* Vehicle sheet */
.tsw-sheet-head { background: var(--tsw-surface); border: 1px solid var(--tsw-line); border-radius: 10px; padding: 18px; display: flex; flex-wrap: wrap; gap: 18px 30px; align-items: center; }
.tsw-ident { display: flex; flex-direction: column; gap: 8px; }
.tsw-facts { display: flex; flex-wrap: wrap; gap: 8px 30px; font-size: 14px; }
.tsw-facts div { display: flex; flex-direction: column; }
.tsw-facts span { font-size: 11px; letter-spacing: .08em; text-transform: uppercase; color: var(--tsw-muted); }
.tsw-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--tsw-line); overflow-x: auto; margin-bottom: 18px; }
.tsw-tabs button { all: unset; cursor: pointer; padding: 9px 14px; font-size: 14px; color: var(--tsw-muted); border-bottom: 2px solid transparent; white-space: nowrap; }
.tsw-tabs button[aria-selected="true"] { color: var(--tsw-ink); font-weight: 600; border-bottom-color: var(--tsw-accent); }
.tsw-tabs button:focus-visible { outline: 2px solid var(--tsw-accent); }
.tsw-tabs .err { color: var(--tsw-crit); margin-left: 4px; }
.tsw-cards-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 18px; }
.tsw-card { background: var(--tsw-surface); border: 1px solid var(--tsw-line); border-radius: 10px; padding: 16px 18px; display: flex; flex-direction: column; gap: 10px; min-width: 0; }
#content .tsw-card h3 { margin: 0; font-size: 17px; display: flex; justify-content: space-between; align-items: center; gap: 8px; color: var(--tsw-ink); }
.tsw-kv { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 4px 14px; font-size: 14px; margin: 0; }
.tsw-kv dt { color: var(--tsw-muted); }
.tsw-kv dd { margin: 0; text-align: right; overflow-wrap: anywhere; }
.tsw-kv dd .tsw-chip { white-space: normal; }  /* long statuses wrap inside the card instead of crossing its border */
.tsw-meter { height: 10px; background: var(--tsw-surface-2); border-radius: 5px; overflow: hidden; box-shadow: inset 0 0 0 1px var(--tsw-line); }
.tsw-meter i { display: block; height: 100%; border-radius: 5px; background: var(--tsw-ok); }
.tsw-meter.soon i { background: var(--tsw-warn); }
.tsw-meter.expired i { background: var(--tsw-crit); }
.tsw-meter-scale { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--tsw-muted); }
.tsw-files { display: flex; gap: 10px; flex-wrap: wrap; }
.tsw-file { width: 104px; border: 1px solid var(--tsw-line); border-radius: 7px; overflow: hidden; font-size: 12px; background: var(--tsw-surface-2); color: var(--tsw-ink); text-decoration: none; }
.tsw-file:hover { border-color: var(--tsw-accent); text-decoration: none; }
.tsw-file .thumb { height: 62px; display: grid; place-items: center; color: var(--tsw-muted); border-bottom: 1px solid var(--tsw-line); background: var(--tsw-surface); }
.tsw-file .thumb svg { width: 26px; height: 26px; stroke: currentColor; fill: none; stroke-width: 1.5; }
.tsw-file span { display: block; padding: 4px 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tsw-route-map { height: 260px; background: var(--tsw-surface-2); border-bottom: 1px solid var(--tsw-line); }

/* Scheda viaggio: anteprima tratta + grafico velocità */
.tsw-drive-preview { margin-bottom: 22px; }
.tsw-chart { position: relative; height: 260px; padding: 8px 12px 6px; }
.tsw-chart-tip {
  position: absolute; pointer-events: none; z-index: 2; white-space: nowrap;
  background: var(--tsw-surface); border: 1px solid var(--tsw-line); border-radius: 6px;
  padding: 3px 7px; font-size: 12px; color: var(--tsw-ink); box-shadow: 0 2px 8px rgba(0,0,0,.18);
  display: flex; flex-direction: column; line-height: 1.25;
}
.tsw-chart-tip span { color: var(--tsw-muted); font-size: 11px; }
.tsw-note { font-size: 13px; color: var(--tsw-muted); margin: 0; }
[data-tab-panel][hidden] { display: none !important; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .tsw-grid-2, .tsw-cards-3 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 800px) {
  #container:has(#tsw-sidebar) { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto; background: var(--tsw-bg); }
  #container:has(#tsw-sidebar) > #header, #container:has(#tsw-sidebar) > nav,
  #container:has(#tsw-sidebar) #content-start, #container:has(#tsw-sidebar) > #footer { grid-column: 1; }
  #tsw-sidebar { grid-row: auto; order: -1; position: static; height: auto; overflow: visible; padding: 10px 0; gap: 8px; }
  .tsw-nav { flex: none; }
  .tsw-user-name { display: none; }
  #container #header { flex-direction: row; flex-wrap: nowrap; align-items: center; justify-content: space-between; gap: 10px; }
  #container #header #branding { flex: 1; min-width: 0; margin: 0; }
  #container #header #user-tools { margin: 0; flex: none; }
  .tsw-search select { display: none; }
  .tsw-nav-label, .tsw-side-foot, .tsw-brand small { display: none; }
  .tsw-nav { flex-direction: row; overflow-x: auto; padding: 0 max(10px, env(safe-area-inset-left, 0px)); }
  .tsw-nav a { white-space: nowrap; }
  .tsw-brand { padding: 0 max(16px, env(safe-area-inset-left, 0px)); }
  #header { padding: 10px max(16px, env(safe-area-inset-right, 0px)) 10px max(16px, env(safe-area-inset-left, 0px)); flex-wrap: wrap; }
  #content { padding: 12px max(16px, env(safe-area-inset-right, 0px)) 32px max(16px, env(safe-area-inset-left, 0px)); }
  div.breadcrumbs { padding: 12px max(16px, env(safe-area-inset-left, 0px)) 0; }
  .tsw-strip { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .tsw-stat:nth-child(3) { border-left: 0; }
  .tsw-stat:nth-child(n+3) { border-top: 1px solid var(--tsw-line); }
}
@media (prefers-reduced-motion: no-preference) {
  .tsw-live { animation: tsw-blink 2.4s ease-in-out infinite; }
  @keyframes tsw-blink { 50% { opacity: .35; } }
}

/* On/off switch for boolean fields (red = off, green = on). */
input.tsw-switch {
  appearance: none; -webkit-appearance: none; position: relative; flex: none;
  width: 44px; height: 24px; margin: 0; border-radius: 12px; cursor: pointer;
  background: var(--tsw-crit); transition: background .15s;
}
input.tsw-switch::before {
  content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px;
  border-radius: 50%; background: #ffffff; box-shadow: 0 1px 2px rgba(0, 0, 0, .3); transition: transform .15s;
}
input.tsw-switch:checked { background: var(--tsw-ok); }
input.tsw-switch:checked::before { transform: translateX(20px); }
input.tsw-switch:focus-visible { outline: 2px solid var(--tsw-accent); outline-offset: 2px; }

/* Inline row actions: green tick (save) and red bin (delete after confirmation), see admin.js. */
.inline-group .tabular td.delete { text-align: left; white-space: nowrap; }
.tsw-row-actions { display: inline-flex; gap: 4px; align-items: center; vertical-align: middle; }
.tsw-row-btn {
  display: inline-flex; align-items: center; justify-content: center; width: 30px; height: 30px; padding: 0;
  border: 0; border-radius: 6px; background: none; cursor: pointer;
}
.tsw-row-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }
.tsw-row-btn.tick { color: var(--tsw-ok); opacity: .55; }
.tsw-row-btn.tick.dirty, .tsw-row-btn.tick:hover { opacity: 1; }
.tsw-row-btn.bin { color: var(--tsw-crit); }
.tsw-row-btn:hover { transform: scale(1.12); }
.tsw-row-btn:focus-visible { outline: 2px solid var(--tsw-accent); outline-offset: 1px; }
.tsw-file-cell .tsw-row-btn.bin { width: 24px; height: 24px; margin: 0 6px 0 2px; vertical-align: middle; }
.tsw-file-cell .tsw-row-btn.bin svg { width: 17px; height: 17px; }

.tsw-confirm {
  border: 1px solid var(--tsw-line); border-radius: 12px; padding: 22px 24px 18px; width: min(440px, calc(100vw - 32px));
  background: var(--tsw-surface); color: var(--tsw-ink); box-shadow: 0 18px 50px rgba(0, 0, 0, .3);
}
.tsw-confirm::backdrop { background: rgba(10, 18, 30, .45); }
.tsw-confirm h2 { margin: 0 0 10px; font-family: var(--tsw-font-display); font-size: 20px; color: var(--tsw-ink); }
.tsw-confirm .what { margin: 0 0 6px; font-weight: 600; overflow-wrap: anywhere; }
.tsw-confirm-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.tsw-confirm-actions button {
  border-radius: 7px; padding: 8px 16px; font: 600 14px var(--tsw-font-body); cursor: pointer; border: 1px solid var(--tsw-line);
}
.tsw-confirm .no { background: var(--tsw-surface); color: var(--tsw-ink); }
.tsw-confirm .yes { background: var(--tsw-crit); border-color: var(--tsw-crit); color: #ffffff; }

/* Multi-field rows of the main form: label above the field, equal columns, fields on the same line. */
#content-main fieldset.aligned > .form-multiline {
  display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 24px; align-items: start;
}
#content-main fieldset.aligned > .form-multiline > :is(.fieldBox, fieldset) {
  display: flex; flex-direction: column; gap: 6px; margin: 0; padding: 0; border: 0; min-width: 0; width: auto;
}
#content-main fieldset.aligned > .form-multiline > fieldset > .fieldBox { display: flex; flex-direction: column; gap: 6px; margin: 0; }
#content-main fieldset.aligned > .form-multiline :is(label:not(.vCheckboxLabel), legend) {
  float: none; width: auto; min-width: 0; margin: 0; padding: 0; line-height: 18px; font-size: 13px;
  color: var(--tsw-muted); font-weight: 500;
}
/* A legend is not a flex item: give it the same gap as the labels. */
#content-main fieldset.aligned > .form-multiline > fieldset > legend.inline { margin-bottom: 6px; }
#content-main fieldset.aligned > .form-multiline .help { order: 3; margin: 0; padding: 0; }
#content-main fieldset.aligned > .form-multiline > .fieldBox > :is(input.vTextField, input[type=number], select) { width: 100%; box-sizing: border-box; height: 34px; }
#content-main fieldset.aligned > .form-multiline .related-widget-wrapper { display: flex; align-items: center; gap: 6px; width: 100%; }
#content-main fieldset.aligned > .form-multiline .related-widget-wrapper select { flex: 1; min-width: 0; height: 34px; }
#content-main fieldset.aligned > .form-multiline :is(p.date, p.datetime) { margin: 0; padding: 0; min-height: 34px; }
#content-main fieldset.aligned > .form-multiline :is(input.vDateField, input.vTimeField) { height: 34px; box-sizing: border-box; }
#content-main fieldset.aligned > .form-multiline .readonly { margin: 0; padding: 0; min-height: 34px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
/* Checkboxes line up with the fields below the labels of the other columns. */
#content-main fieldset.aligned > .form-multiline > .checkbox-row { padding-top: 24px; }
#content-main fieldset.aligned > .form-multiline > .checkbox-row .checkbox { min-height: 34px; display: flex; align-items: center; gap: 8px; }
#content-main fieldset.aligned > .form-multiline > .checkbox-row .vCheckboxLabel { padding: 0; margin: 0; }

/* Vehicle overview: last drive and documents side by side, same size. */
#tsw-overview .tsw-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: stretch; }

/* Tabular inlines: compact fields so the whole row fits, everything vertically centred. */
.inline-group .tabular th { text-align: left; vertical-align: middle; }
.inline-group .tabular input[type=number] { width: 7.5em; }
.inline-group .tsw-file-cell > a { display: inline-block; max-width: 14em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; vertical-align: middle; }
.inline-group .tabular input[type=file] { max-width: 15em; font-size: 12px; }
.inline-group .tabular td.field-reminder { text-align: center; }
.inline-group .tabular th { white-space: normal; line-height: 1.3; }
/* Django's grey "remove" X on new rows: replaced by the red bin (admin.js). */
.inline-group .tabular td.delete > div:has(> .inline-deletelink) { display: none; }
.inline-group .tabular td { padding: 8px 5px; }
.inline-group .tabular input[type=file] { max-width: 12.5em; }
.inline-group .tabular input[type=number] { width: 6.5em; }
#tsw-overview .tsw-panel-head { min-height: 56px; box-sizing: border-box; }
#tsw-overview .tsw-grid-2 { margin-bottom: 18px; }

/* Positions toolbar: vehicle, date/time range, rows per page. */
.tsw-range { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px; padding: 12px 16px; border-bottom: 1px solid var(--tsw-line); }
.tsw-range label { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--tsw-muted); font-weight: 500; }
.tsw-range :is(select, input) { height: 34px; box-sizing: border-box; }
/* Fieldsets laid out in two columns (e.g. vehicle battery | GPS battery). */
#content-main fieldset.aligned.tsw-cols-2 > .form-multiline { grid-template-columns: repeat(2, minmax(0, 1fr)); }
/* A row made only of checkboxes has no labels to line up with. */
#content-main fieldset.aligned > .form-multiline:not(:has(> :not(.checkbox-row))) > .checkbox-row { padding-top: 0; }

/* Bottom bar: green tick saves, red bin deletes (templates/admin/submit_line.html). */
.submit-row.tsw-submit { display: flex; align-items: center; gap: 8px; }
.tsw-submit-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 6px 10px; border: 0; border-radius: 7px;
  background: none; font: 600 15px var(--tsw-font-body); cursor: pointer; text-decoration: none;
}
.tsw-submit-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.submit-row .tsw-submit-btn.save { color: var(--tsw-ok); }
.submit-row .tsw-submit-btn.delete { color: var(--tsw-crit); margin-left: auto; }
.submit-row .tsw-submit-btn.save:hover { background: var(--tsw-ok-soft); }
.submit-row .tsw-submit-btn.delete:hover { background: var(--tsw-crit-soft); text-decoration: none; }
.tsw-submit-btn:focus-visible { outline: 2px solid var(--tsw-accent); outline-offset: 2px; }

/* Vehicle sheet, Allarmi tab: last alerts of the vehicle. */
.tsw-history { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; width: 100%; }
.tsw-alert-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.tsw-alert-table td { padding: 6px 8px; border-bottom: 1px solid var(--tsw-line); vertical-align: middle; }
.tsw-alert-table td:first-child { white-space: nowrap; }
#content-main .form-row .readonly:has(> .tsw-history) { flex: 1; min-width: 0; }
/* Rows of four fields (e.g. tyre sets) keep them on one line. */
#content-main fieldset.aligned > .form-multiline:has(> :nth-child(4)) { grid-template-columns: repeat(4, minmax(0, 1fr)); }
/* Stacked inlines: Django's grey "remove" X on new rows is replaced by the red bin too. */
.inline-group .inline-related h3 span:has(> .inline-deletelink) { display: none; }
.inline-group .inline-related h3 > .tsw-row-actions { margin-left: auto; }
.inline-group .tabular select { max-width: 11em; }
.inline-group .tabular input[type=file] { max-width: 10.5em; }

/* Power take-off: green dot when on, grey when off. */
.tsw-pto { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; color: var(--tsw-muted); white-space: nowrap; }
.tsw-pto i { width: 9px; height: 9px; border-radius: 50%; background: var(--tsw-muted); flex: none; }
.tsw-pto.on { color: var(--tsw-ok); }
.tsw-pto.on i { background: var(--tsw-ok); box-shadow: 0 0 0 3px var(--tsw-ok-soft); }
td .tsw-pto { margin-left: 6px; }

/* Uscite e rientri: vehicle outlines with the damages placed on them (inspections). The drawing keeps a white
   sheet in both themes, like a paper form. */
.tsw-pad { padding: 16px 18px; }
.tsw-pad h2 { margin: 0 0 10px; font-size: 17px; }
.tsw-pad h3 { margin: 18px 0 8px; font-size: 15px; }
.tsw-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 8px; }
.tsw-tool input { position: absolute; opacity: 0; }
.tsw-tool span { display: inline-flex; align-items: center; min-height: 40px; padding: 0 14px; border-radius: 999px; border: 1px solid var(--tsw-line); cursor: pointer; font-size: 14px; }
.tsw-tool input:checked + span { background: var(--tsw-accent); color: var(--tsw-accent-ink); border-color: var(--tsw-accent); }
.tsw-tool input:focus-visible + span { outline: 2px solid var(--tsw-accent); outline-offset: 2px; }
.tsw-shapes { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; margin-top: 10px; }
.tsw-shape { display: flex; flex-direction: column; gap: 6px; }
.tsw-shape-label { font-size: 13px; font-weight: 600; color: var(--tsw-muted); }
.tsw-shape-draw { position: relative; background: #ffffff; border: 1px solid var(--tsw-line); border-radius: 10px; }
.tsw-inspection[data-mode="edit"] .tsw-shape-draw { cursor: crosshair; }
.tsw-shape-draw svg { display: block; width: 100%; height: auto; max-height: 220px; }
.tsw-shape-small { max-width: 420px; }
.tsw-dmg { position: absolute; transform: translate(-50%, -50%); width: 26px; height: 26px; border-radius: 50%; border: 2px solid #fff; background: #c2410c; color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; box-shadow: 0 1px 3px rgba(0,0,0,.35); pointer-events: auto; }
.tsw-dmg.known { background: #6b7280; }
.tsw-dmg.out { background: #1f6feb; }
.tsw-damage-list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.tsw-damage-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.tsw-damage-list input[type="text"] { flex: 1 1 220px; min-height: 36px; }
.tsw-dmg-n { flex: none; width: 26px; height: 26px; border-radius: 50%; background: #c2410c; color: #fff; font-size: 12px; font-weight: 700; display: grid; place-items: center; }
.tsw-dmg-n.known { background: #6b7280; }
.tsw-dmg-n.out { background: #1f6feb; }
.tsw-dmg-what { font-weight: 600; }
.tsw-photo-btn input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.tsw-photo-btn { position: relative; }
.tsw-form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px 16px; margin-bottom: 12px; }
.tsw-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--tsw-muted); }
.tsw-field input, .tsw-field select, .tsw-field textarea { font-size: 15px; min-height: 40px; }
.tsw-field-error { color: var(--tsw-crit); }
.tsw-signature { display: block; width: 100%; max-width: 600px; height: auto; aspect-ratio: 600 / 180; border: 1px dashed var(--tsw-line); border-radius: 8px; touch-action: none; background: #fff; }
.tsw-signature-img { display: block; max-width: 400px; width: 100%; background: #fff; border-radius: 8px; border: 1px solid var(--tsw-line); }
.tsw-sign-row { display: flex; flex-wrap: wrap; align-items: end; gap: 12px; margin-top: 10px; }
.tsw-form-actions { display: flex; gap: 10px; margin: 6px 0 24px; }
.tsw-form-actions .tsw-btn { min-height: 44px; }
.tsw-photos { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; width: 100%; }
.tsw-photos img { width: 120px; height: 90px; object-fit: cover; border-radius: 6px; border: 1px solid var(--tsw-line); }
.tsw-kv-wide { max-width: 720px; }
.tsw-head-actions { display: flex; gap: 8px; }
