/* ==========================================================================
   Devi Grup Distribution: agent app design system
   --------------------------------------------------------------------------
   Everything below is built from the tokens in section 1. When adding UI,
   use the tokens instead of raw values:

   Type scale (font-size)     Use for
     --text-3xl  36px          Keypad quantity display
     --text-2xl  28px          Page title (h1) on wide screens
     --text-xl   22px          Page title (h1) on phones
     --text-lg   18px          Modal and section titles (h2), keypad digits
     --text-base 16px          Body text, inputs, buttons, card titles
     --text-sm   14px          Labels, meta lines, badges, small buttons
     --text-xs   12px          Overline section labels (uppercase)

   Fonts: Manrope for headings (h1, h2, display numbers), Inter for all other
   text. Weights: 400 body, 500 labels, 600 buttons and card titles, 700
   headings. Spacing is a 4px scale (--space-*). Controls are at least 44px
   tall; icon actions inside cards are 40px.
   ========================================================================== */

/* 1. Fonts and tokens ----------------------------------------------------- */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("../fonts/inter-latin-wght.260c81a4759b.woff2") format("woff2-variations");
}

@font-face {
  font-family: "Manrope";
  font-style: normal;
  font-weight: 200 800;
  font-display: swap;
  src: url("../fonts/manrope-latin-wght.938c6e8019b6.woff2") format("woff2-variations");
}

:root {
  /* Typography */
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-heading: "Manrope", "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --text-xs: 0.75rem;
  --text-sm: 0.875rem;
  --text-base: 1rem;
  --text-lg: 1.125rem;
  --text-xl: 1.375rem;
  --text-2xl: 1.75rem;
  --text-3xl: 2.25rem;
  --leading-tight: 1.25;
  --leading-normal: 1.5;
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* Spacing (4px scale) */
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
  --space-5: 1.25rem;
  --space-6: 1.5rem;
  --space-8: 2rem;
  --space-10: 2.5rem;

  /* Shape and sizing */
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-full: 999px;
  --control-height: 48px;
  --button-height: 44px;
  --button-height-sm: 36px;
  --icon-action: 40px;
  --focus-ring: 0 0 0 3px var(--brand-ring);
  --transition: 150ms ease;

  /* Colours: dark theme (default) */
  --bg: #0d1210;
  --surface: #141b18;
  --surface-2: #1b2420;
  --border: #26322d;
  --border-strong: #5b6b64;
  --text: #e8eeeb;
  --text-muted: #9caba4;
  --brand: #5ccfa8;
  --brand-hover: #77dbb9;
  --on-brand: #06261d;
  --brand-soft: #173229;
  --brand-text: #7fdcbc;
  --brand-ring: rgba(92, 207, 168, 0.35);
  --danger: #ff8a7a;
  --danger-soft: #3a1d1a;
  --warning-text: #f3b56b;
  --warning-soft: #35260f;
  --info-text: #8fb6ff;
  --info-soft: #172540;
  --neutral-text: #b8c4bf;
  --neutral-soft: #222b28;
  --teal-text: #6fd6cb;
  --teal-soft: #12302c;
  --overlay: rgba(4, 8, 6, 0.6);
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 12px 32px rgba(0, 0, 0, 0.45);

  /* Legacy names still referenced by older markup */
  --ink: var(--text);
  --muted: var(--text-muted);
  --card: var(--surface);
  --input-bg: var(--surface);

  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f4f6f5;
  --surface: #ffffff;
  --surface-2: #edf1ef;
  --border: #dbe2df;
  --border-strong: #85928c;
  --text: #16201c;
  --text-muted: #55625c;
  --brand: #2f6f61;
  --brand-hover: #275c50;
  --on-brand: #ffffff;
  --brand-soft: #e1efea;
  --brand-text: #245a4e;
  --brand-ring: rgba(47, 111, 97, 0.25);
  --danger: #b42318;
  --danger-soft: #fde8e6;
  --warning-text: #8a4b0f;
  --warning-soft: #fdf0dd;
  --info-text: #1f4f9e;
  --info-soft: #e5edfb;
  --neutral-text: #4b5752;
  --neutral-soft: #eceff0;
  --teal-text: #0b6b62;
  --teal-soft: #dcf3ef;
  --overlay: rgba(16, 24, 20, 0.45);
  --shadow-sm: 0 1px 2px rgba(16, 24, 20, 0.06);
  --shadow-lg: 0 12px 32px rgba(16, 24, 20, 0.14);

  color-scheme: light;
}

/* 2. Base ----------------------------------------------------------------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

.i18n-pending [data-i18n],
.i18n-pending [data-i18n-placeholder] {
  visibility: hidden;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

h1,
h2,
h3,
h4 {
  margin: 0;
  font-family: var(--font-heading);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  letter-spacing: -0.01em;
  color: var(--text);
}

h1 {
  font-size: var(--text-2xl);
  margin-bottom: var(--space-2);
}

h2 {
  font-size: var(--text-lg);
}

h3,
h4 {
  font-size: var(--text-base);
}

p {
  margin: 0;
}

strong {
  font-weight: var(--weight-semibold);
}

img {
  max-width: 100%;
}

:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
}

/* 3. Layout --------------------------------------------------------------- */

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-6) var(--space-10);
}

.card {
  /* Page shell: content sits directly on the background. */
  background: transparent;
}

.card > .stack:first-child {
  margin-bottom: var(--space-4);
}

.auth-card {
  width: min(100%, 440px);
  margin: var(--space-8) auto 0;
  padding: var(--space-8) var(--space-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.auth-form-shell {
  display: grid;
  gap: var(--space-4);
}

.auth-form-shell .btn {
  width: 100%;
}

.stack {
  display: grid;
  gap: var(--space-3);
}

.grid {
  display: grid;
  gap: var(--space-4);
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.hidden {
  display: none !important;
}

.mt-1 { margin-top: var(--space-1); }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-6 { margin-top: var(--space-6); }
.mb-4 { margin-bottom: var(--space-4); }
.mb-6 { margin-bottom: var(--space-6); }

/* App bar */
.appbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: 60px;
  padding: var(--space-2) var(--space-3);
  margin-bottom: var(--space-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

.toolbar {
  display: flex;
  align-items: center;
  gap: var(--space-1);
}

.toolbar button,
.toolbar a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* Account menu: name (and current branch for multi-branch users) in one
   button; branches and logout live in its menu. Keeps the app bar one line. */
.account-menu {
  margin-left: auto;
  min-width: 0;
}

.account-button {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  max-width: min(60vw, 320px);
  min-height: var(--button-height);
  padding: var(--space-1) var(--space-2) var(--space-1) var(--space-4);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-full);
  color: var(--text);
  transition: border-color var(--transition);
}

.account-button:hover,
.account-menu[open] .account-button {
  border-color: var(--border-strong);
}

.account-text {
  display: grid;
  min-width: 0;
  text-align: left;
  line-height: var(--leading-tight);
}

.account-text .user-name,
.account-branch {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.account-text .user-name {
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
}

.account-branch {
  color: var(--brand-text);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
}

.account-chevron {
  width: 16px;
  height: 16px;
  flex: none;
  color: var(--text-muted);
  transition: transform var(--transition);
}

.account-menu[open] .account-chevron {
  transform: rotate(180deg);
}

.menu {
  position: relative;
}

.menu summary {
  list-style: none;
  cursor: pointer;
}

.menu summary::-webkit-details-marker {
  display: none;
}

.menu-panel {
  position: absolute;
  right: 0;
  z-index: 40;
  display: grid;
  gap: var(--space-1);
  width: max-content;
  min-width: 220px;
  max-width: min(320px, calc(100vw - 2 * var(--space-4)));
  margin-top: var(--space-2);
  padding: var(--space-2);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}

.menu-panel .btn {
  width: 100%;
}

.menu-section-title {
  padding: var(--space-1) var(--space-2) 0;
}

.branch-options {
  display: grid;
  gap: var(--space-1);
  max-height: 50vh;
  overflow-y: auto;
}

.menu-option {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
  min-height: var(--button-height);
  padding: 0 var(--space-3);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: var(--text-base);
  text-align: left;
  cursor: pointer;
}

.menu-option:hover {
  background: var(--surface-2);
}

.menu-option.is-active {
  background: var(--brand-soft);
  color: var(--brand-text);
  font-weight: var(--weight-semibold);
  cursor: default;
}

.menu-option svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.menu-divider {
  height: 1px;
  margin: var(--space-1) 0;
  background: var(--border);
}

/* Page header */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.page-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.page-title h1 {
  margin: 0;
}

.page-title .icon-btn {
  margin-left: calc(-1 * var(--space-2));
}

.header-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
  justify-content: flex-end;
}

/* Intro line under a page title (e.g. the dashboard). */
.card > h1 + .muted {
  margin-bottom: var(--space-5);
}

/* 4. Text helpers --------------------------------------------------------- */

.muted {
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.section-title {
  color: var(--text-muted);
  font-family: var(--font-body);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.link {
  color: var(--brand-text);
  font-weight: var(--weight-medium);
  text-decoration: none;
}

.link:hover {
  text-decoration: underline;
  text-underline-offset: 3px;
}

.errorlist {
  margin: 0;
  padding: 0;
  list-style: none;
  color: var(--danger);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

/* 5. Forms ---------------------------------------------------------------- */

label {
  display: block;
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
}

input,
select,
textarea {
  width: 100%;
  min-height: var(--control-height);
  margin: 0;
  padding: 0 var(--space-4);
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  font-family: inherit;
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  transition: border-color var(--transition), box-shadow var(--transition);
}

input::placeholder,
textarea::placeholder {
  color: var(--text-muted);
  opacity: 1;
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--focus-ring);
}

input[readonly],
textarea[readonly] {
  background: var(--surface-2);
}

textarea {
  min-height: 96px;
  padding: var(--space-3) var(--space-4);
  resize: vertical;
}

select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: var(--space-10);
  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='%239caba4' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right var(--space-4) center;
  background-size: 16px 16px;
}

[data-theme="light"] select {
  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='%2355625c' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

input[type="file"] {
  display: flex;
  align-items: center;
  padding: 5px var(--space-2);
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: 36px;
  cursor: pointer;
}

input[type="file"]::file-selector-button {
  height: 36px;
  margin: 0 var(--space-3) 0 0;
  padding: 0 var(--space-4);
  border: none;
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  color: var(--text);
  font: inherit;
  font-weight: var(--weight-semibold);
  vertical-align: middle;
  cursor: pointer;
}

input[type="checkbox"],
input[type="radio"] {
  width: 20px;
  height: 20px;
  min-height: 0;
  padding: 0;
  margin: 0;
  accent-color: var(--brand);
  box-shadow: none;
}

button {
  font-family: inherit;
}

.field {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}

.field > label {
  line-height: var(--leading-tight);
}

.field .dropdown {
  z-index: auto;
}

/* A group of radio options reads as one list, not separate grid cells. */
.grid:has(> .radio) {
  gap: 0;
}

.check,
.radio {
  display: inline-flex;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--button-height);
  color: var(--text);
  font-size: var(--text-base);
  font-weight: var(--weight-medium);
  cursor: pointer;
}

/* Section titles inside forms (e.g. Client selection, Products, Photos):
   heading font and a divider, so they never read like a field label. */
.form-section-title {
  margin-top: var(--space-2);
  padding-top: var(--space-4);
  border-top: 1px solid var(--border);
  font-size: var(--text-lg);
}

.form-section-title + .field,
.form-section-title + .grid,
.form-section-title + .dropdown {
  margin-top: var(--space-1);
}

/* Search bar: one bordered box holding the input and a compact button. */
.search-bar {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--control-height);
  padding: var(--space-1) var(--space-1) var(--space-1) var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  transition: border-color var(--transition), box-shadow var(--transition);
}

.search-bar:focus-within {
  border-color: var(--brand);
  box-shadow: var(--focus-ring);
}

.search-bar input {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 38px;
  padding: 0;
  border: none;
  background: transparent;
  box-shadow: none;
}

.search-bar input:focus {
  box-shadow: none;
}

.search-bar .btn {
  width: auto;
  min-height: 38px;
  padding: 0 var(--space-3);
  border: none;
  background: var(--surface-2);
}

form.search-bar + .stack {
  margin-top: var(--space-4);
}

.filters {
  gap: var(--space-4);
}

.filters-grid {
  display: grid;
  gap: var(--space-4) var(--space-3);
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
}

#visitFilters > summary {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--button-height);
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  cursor: pointer;
}

/* Collapsible sections: custom chevron, since flex summaries drop the native marker. */
#visitFilters > summary,
.detail-materials > summary {
  list-style: none;
}

#visitFilters > summary::-webkit-details-marker,
.detail-materials > summary::-webkit-details-marker {
  display: none;
}

#visitFilters > summary::before,
.detail-materials > summary::before {
  content: "";
  width: 7px;
  height: 7px;
  margin: 0 var(--space-2) 0 2px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform var(--transition);
}

#visitFilters[open] > summary::before,
.detail-materials[open] > summary::before {
  transform: rotate(45deg);
}

/* Date picker (flatpickr) */
.flatpickr-calendar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-family: var(--font-body);
}

.flatpickr-calendar.arrowTop::before,
.flatpickr-calendar.arrowTop::after {
  border-bottom-color: var(--surface);
}

.flatpickr-months .flatpickr-month,
.flatpickr-current-month .flatpickr-monthDropdown-months,
.flatpickr-current-month input.cur-year,
span.flatpickr-weekday,
.flatpickr-months .flatpickr-prev-month,
.flatpickr-months .flatpickr-next-month {
  color: var(--text);
  fill: var(--text);
  background: transparent;
}

.flatpickr-calendar input,
.flatpickr-calendar select {
  width: auto;
  min-height: 0;
  height: auto;
  margin: 0;
  border: none;
  border-radius: 0;
  box-shadow: none;
  background-color: transparent;
  font-size: inherit;
  line-height: inherit;
}

.flatpickr-current-month {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-1);
  height: 34px;
  padding: 0;
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
}

.flatpickr-current-month .flatpickr-monthDropdown-months {
  padding: 0 var(--space-1);
  background-image: none;
  font-weight: var(--weight-semibold);
}

.flatpickr-current-month .numInputWrapper {
  width: 4.5ch;
}

.flatpickr-current-month input.cur-year {
  padding: 0;
  font-weight: var(--weight-semibold);
}

.flatpickr-months .flatpickr-prev-month,
.flatpickr-months .flatpickr-next-month {
  height: 34px;
  padding: 8px 10px;
}

.date-field {
  position: relative;
}

.date-field input {
  padding-right: var(--space-10);
}

.date-clear {
  position: absolute;
  right: var(--space-1);
  bottom: 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--icon-action);
  height: var(--icon-action);
  padding: 0;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
}

.date-clear[hidden] {
  display: none;
}

.date-clear:hover {
  background: var(--surface-2);
  color: var(--text);
}

.date-clear svg {
  width: 18px;
  height: 18px;
}

.flatpickr-day {
  color: var(--text);
  border-radius: var(--radius-sm);
}

.flatpickr-day:hover,
.flatpickr-day:focus {
  background: var(--surface-2);
  border-color: var(--surface-2);
}

.flatpickr-day.prevMonthDay,
.flatpickr-day.nextMonthDay,
.flatpickr-day.flatpickr-disabled {
  color: var(--text-muted);
  opacity: 0.6;
}

.flatpickr-day.today {
  border-color: var(--brand);
}

.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange,
.flatpickr-day.selected:hover {
  background: var(--brand);
  border-color: var(--brand);
  color: var(--on-brand);
}

/* 6. Buttons -------------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--button-height);
  padding: 0 var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  background: var(--brand);
  color: var(--on-brand);
  font-family: var(--font-body);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), color var(--transition);
}

.btn:hover {
  background: var(--brand-hover);
}

.btn:active {
  transform: scale(0.98);
}

.btn svg {
  width: 18px;
  height: 18px;
  flex: none;
}

.btn-ghost,
.ghost {
  background: var(--surface);
  border-color: var(--border-strong);
  color: var(--text);
}

.btn-ghost:hover,
.ghost:hover {
  background: var(--surface-2);
}

.btn-ghost.sm,
.btn-ghost.xs {
  min-height: var(--button-height-sm);
  padding: 0 var(--space-3);
  font-size: var(--text-sm);
}

.logout {
  border-color: var(--danger);
  color: var(--danger);
}

.logout:hover {
  background: var(--danger-soft);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: var(--button-height);
  height: var(--button-height);
  flex: none;
  padding: 0;
  border: none;
  border-radius: var(--radius-full);
  background: transparent;
  color: var(--text);
  text-decoration: none;
  cursor: pointer;
  transition: background var(--transition);
}

.icon-btn:hover {
  background: var(--surface-2);
}

.icon-btn svg {
  display: block;
  width: 22px;
  height: 22px;
}

.icon-btn.sm {
  width: var(--icon-action);
  height: var(--icon-action);
  border-radius: var(--radius-md);
}

.icon-btn.sm svg {
  width: 18px;
  height: 18px;
}

.icon-btn.edit-client {
  background: var(--brand-soft);
  color: var(--brand-text);
}

.search-btn,
.map-btn {
  gap: var(--space-2);
}

.map-btn {
  display: inline-flex;
  flex: none;
}

.visit-type-btn {
  justify-content: flex-start;
  min-height: 56px;
  gap: var(--space-3);
  padding: 0 var(--space-4);
}

.visit-type-btn svg {
  width: 22px;
  height: 22px;
}

/* 7. Badges and status ---------------------------------------------------- */

.badge,
.pill {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  min-height: 24px;
  padding: 0 var(--space-2);
  border-radius: var(--radius-full);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  line-height: 1;
  letter-spacing: 0.01em;
  white-space: nowrap;
}

.badge {
  background: var(--brand-soft);
  color: var(--brand-text);
}

/* Visit type: tinted pill. */
.pill.type-promo,
.pill.type-promo-request,
.pill.type-promo_request,
.pill.type-new-client,
.pill.type-new_client {
  background: var(--info-soft);
  color: var(--info-text);
}

.pill.type-order {
  background: var(--brand-soft);
  color: var(--brand-text);
}

.pill.type-visit {
  background: var(--warning-soft);
  color: var(--warning-text);
}

.type-text {
  font-weight: var(--weight-semibold);
}

.type-text.type-promo,
.type-text.type-promo-request,
.type-text.type-promo_request,
.type-text.type-new-client,
.type-text.type-new_client {
  color: var(--info-text);
}

.type-text.type-order {
  color: var(--brand-text);
}

.type-text.type-visit {
  color: var(--warning-text);
}

/* Visit status: coloured dot plus label, so it never relies on colour alone. */
.status-text {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-tight);
  white-space: nowrap;
}

.status-text::before {
  content: "";
  width: 8px;
  height: 8px;
  flex: none;
  border-radius: var(--radius-full);
  background: currentColor;
}

.status-text.status-submitted,
.pill.status-submitted {
  color: var(--neutral-text);
}

.status-text.status-approved,
.pill.status-approved {
  color: var(--brand-text);
}

.status-text.status-declined,
.pill.status-declined {
  color: var(--danger);
}

.status-text.status-prepared,
.pill.status-prepared {
  color: var(--info-text);
}

.status-text.status-delivered,
.pill.status-delivered {
  color: var(--teal-text);
}

.pill.status-submitted { background: var(--neutral-soft); }
.pill.status-approved { background: var(--brand-soft); }
.pill.status-declined { background: var(--danger-soft); }
.pill.status-prepared { background: var(--info-soft); }
.pill.status-delivered { background: var(--teal-soft); }

/* 8. Cards and lists ------------------------------------------------------ */

.list-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: var(--space-4);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: var(--text);
}

.list-card strong {
  font-size: var(--text-base);
  line-height: var(--leading-tight);
}

.list-meta {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  color: var(--text-muted);
  font-size: var(--text-sm);
}

.card-link {
  display: grid;
  gap: var(--space-2);
  align-content: start;
  padding: var(--space-5);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  color: inherit;
  text-decoration: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.card-link .badge {
  justify-self: start;
}

.card-link:hover {
  border-color: var(--brand);
  box-shadow: var(--shadow-sm);
}

.card-link h2 {
  font-size: var(--text-lg);
}

/* Visit list */
.visit-card {
  align-items: flex-start;
}

.visit-card-body {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: var(--space-2);
  justify-items: start;
}

.visit-card-actions {
  display: grid;
  justify-items: end;
  gap: var(--space-3);
  flex: none;
  margin-left: auto;
  text-align: right;
}

.visit-card-body .visit-agent-inline {
  overflow-wrap: anywhere;
}

.visit-card-comment {
  margin: 0;
  color: var(--text-muted);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  overflow-wrap: anywhere;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

/* Client list */
.client-card-body {
  flex: 1;
  min-width: 0;
  display: grid;
  gap: var(--space-1);
}

.client-card-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  min-width: 0;
}

.load-more {
  justify-items: center;
  justify-content: center;
}

/* Product search dropdown */
.dropdown {
  position: relative;
  z-index: 1;
}

.dropdown:focus-within {
  /* Above page content, but always below modals. */
  z-index: 30;
}

.dropdown-panel {
  position: absolute;
  top: calc(100% + var(--space-1));
  left: 0;
  right: 0;
  z-index: 30;
  max-height: 300px;
  overflow-y: auto;
  padding: var(--space-1);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
}

.dropdown-item {
  display: block;
  width: 100%;
  min-height: var(--button-height);
  padding: var(--space-2) var(--space-3);
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.dropdown-item:hover,
.dropdown-item:focus-visible {
  background: var(--surface-2);
  box-shadow: none;
}

.material-line {
  display: flex;
  align-items: baseline;
  gap: var(--space-2);
  width: 100%;
}

.material-code {
  color: var(--text-muted);
  font-size: var(--text-sm);
  font-variant-numeric: tabular-nums;
}

.material-name {
  flex: 1;
  min-width: 0;
  font-weight: var(--weight-semibold);
}

.material-price {
  margin-left: auto;
  color: var(--brand-text);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* Selected order lines */
#selectedMaterials .list-card > div:first-child {
  display: grid;
  gap: var(--space-1);
  min-width: 0;
}

.selected-qty,
.selected-price,
.selected-total {
  font-variant-numeric: tabular-nums;
}

.selected-total {
  color: var(--text);
  font-weight: var(--weight-semibold);
}

.selected-actions {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  flex: none;
}

.selected-actions .btn-ghost.xs {
  width: var(--icon-action);
  height: var(--icon-action);
  min-height: 0;
  padding: 0;
  border: none;
  border-radius: var(--radius-md);
}

.selected-actions .btn-ghost.xs svg {
  width: 18px;
  height: 18px;
}

.selected-actions .edit-item {
  background: var(--brand-soft);
  color: var(--brand-text);
}

.selected-actions .remove-item {
  /* Kept apart from the edit button to avoid accidental taps. */
  margin-left: var(--space-2);
  background: var(--danger-soft);
  color: var(--danger);
}

/* 9. Visit detail --------------------------------------------------------- */

.visit-detail-card {
  flex-direction: column;
  align-items: stretch;
  gap: 0;
  padding: 0 var(--space-5);
}

.detail-section {
  display: grid;
  gap: var(--space-2);
  padding: var(--space-4) 0;
}

.detail-section + .detail-section {
  border-top: 1px solid var(--border);
}

.detail-text {
  color: var(--text);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.visit-detail-status-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.visit-detail-created-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: var(--space-4);
}

.visit-detail-created-info {
  min-width: 0;
  display: grid;
  gap: var(--space-1);
}

.visit-detail-map-btn {
  flex: none;
}

.detail-materials > summary {
  display: flex;
  align-items: center;
  min-height: var(--button-height);
  cursor: pointer;
}

.detail-material {
  padding: var(--space-3) var(--space-4);
  background: var(--surface-2);
  border-color: transparent;
}

.photo-grid {
  display: grid;
  gap: var(--space-3);
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
}

.photo-card {
  padding: 0;
  overflow: hidden;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  cursor: pointer;
}

.photo-thumb {
  display: block;
  width: 100%;
  height: 140px;
  object-fit: cover;
}

.photo-modal .modal-card {
  width: min(900px, 100%);
  padding: var(--space-4);
}

.photo-full {
  display: block;
  width: 100%;
  max-height: 70vh;
  object-fit: contain;
  border-radius: var(--radius-md);
  background: var(--surface-2);
}

/* 10. Modals and keypad --------------------------------------------------- */

.modal-open {
  overflow: hidden;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  background: var(--overlay);
}

.modal[open] {
  display: flex;
}

.modal-card {
  width: min(560px, 100%);
  max-height: calc(100vh - 2 * var(--space-4));
  overflow-y: auto;
  padding: var(--space-6);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.modal-header h2 {
  font-size: var(--text-lg);
}

.modal-actions,
.client-modal-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--space-3);
}

.client-modal-actions {
  margin-top: var(--space-5);
}

.client-modal-actions .confirm-location-form {
  margin: 0;
}

.client-modal-actions .btn,
.modal-actions .btn {
  width: 100%;
}

#quantityModal .modal-card {
  width: min(400px, 100%);
}

.quantity-display {
  font-family: var(--font-heading);
  font-size: var(--text-3xl);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  font-variant-numeric: tabular-nums;
}

.keypad-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: var(--space-2);
  margin: var(--space-2) 0 var(--space-3);
}

#quantityModal .keypad {
  width: 100%;
  min-height: 56px;
  border: none;
  background: var(--surface-2);
  font-size: var(--text-lg);
  font-weight: var(--weight-semibold);
  font-variant-numeric: tabular-nums;
}

#quantityModal .keypad:hover {
  background: var(--border);
}

/* 11. Alerts (Django messages) ------------------------------------------- */

.alert {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  background: var(--neutral-soft);
  color: var(--neutral-text);
}

.alert::before {
  content: "";
  width: 8px;
  height: 8px;
  margin-top: 0.45em;
  flex: none;
  border-radius: var(--radius-full);
  background: currentColor;
}

.alert-success {
  background: var(--brand-soft);
  color: var(--brand-text);
}

.alert-error {
  background: var(--danger-soft);
  color: var(--danger);
}

.alert-warning {
  background: var(--warning-soft);
  color: var(--warning-text);
}

.alert-info {
  background: var(--info-soft);
  color: var(--info-text);
}

/* 12. Phones -------------------------------------------------------------- */

@media (max-width: 720px) {
  .container {
    padding: var(--space-3) var(--space-4) var(--space-8);
  }

  h1 {
    font-size: var(--text-xl);
  }

  .appbar {
    min-height: 56px;
    padding: var(--space-1) var(--space-2);
    margin-bottom: var(--space-5);
  }

  .account-button {
    max-width: calc(100vw - 2 * var(--space-4) - 156px);
  }

  .auth-card {
    margin-top: var(--space-4);
    padding: var(--space-6) var(--space-5);
  }

  .grid {
    grid-template-columns: 1fr;
  }

  .page-header {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-4);
  }

  .list-card {
    flex-direction: column;
    align-items: stretch;
    gap: var(--space-3);
  }

  #selectedMaterials .list-card,
  .client-card,
  .visit-card {
    flex-direction: row;
    align-items: center;
  }

  .visit-card {
    align-items: flex-start;
  }

  .client-card .map-btn {
    margin-left: auto;
  }

  .list-meta {
    flex-direction: column;
    gap: var(--space-1);
  }

  .visit-card .list-meta,
  .visit-detail-status-row,
  .visit-detail-material-meta {
    flex-direction: row;
    flex-wrap: wrap;
  }

  .modal {
    padding: var(--space-3);
  }

  .modal-card {
    padding: var(--space-5);
    max-height: calc(100vh - 2 * var(--space-3));
  }

  .client-modal-actions {
    grid-template-columns: 1fr;
  }

  .btn {
    width: 100%;
  }

  .search-bar .btn,
  .search-btn,
  .map-btn,
  .modal-close,
  .visit-card-actions .btn,
  .visit-detail-map-btn,
  .selected-actions .btn {
    width: auto;
  }

  .search-btn .btn-text {
    display: none;
  }

  .filters-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .filters-grid .field {
    grid-column: span 2;
  }

  .filters-grid .field:nth-child(-n + 4) {
    grid-column: span 1;
  }

  .dropdown-panel {
    max-height: 240px;
  }
}
