/* Picasso ERP colours: the one place colours are defined. Loaded right after Bootstrap; every other stylesheet and
   template uses these tokens and classes instead of its own colours (docs/conventions/colours.md).

   1. Tones: what a status means (success, info, warning, danger, neutral, accent, purple, teal, orange). Which
      status gets which tone is decided in apps/app_core/tones.py, never in a template.
   2. Sections: each menu section has its colour. `data-ui-section="<key>"` on an element (a sidebar section, a
      menu link, the page itself: <main id="ui-content">) sets --ui-section and its shades for everything inside.
   3. Days: the colours of attendance days (holiday, weekend, leave, visit, absent, off) on every attendance page.
   4. Pieces that use them: badges, coloured text and numbers, table rows, legends, stat tiles, tabs, page bar,
      panels, table headers.
   Soft tints everywhere (light background, dark text, a coloured line); a solid colour only for alarms. */

:root {
  --ui-muted: #6b7280;

  /* 1. tones: bg (tinted background), fg (text on it or on white), line (border), solid (bars, dots, alarms) */
  --ui-tone-success-bg: #f0fdf4; --ui-tone-success-fg: #15803d; --ui-tone-success-line: #bbf7d0; --ui-tone-success-solid: #16a34a;
  --ui-tone-info-bg: #f0f9ff;    --ui-tone-info-fg: #0369a1;    --ui-tone-info-line: #bae6fd;    --ui-tone-info-solid: #0ea5e9;
  --ui-tone-warning-bg: #fffbeb; --ui-tone-warning-fg: #b45309; --ui-tone-warning-line: #fde68a; --ui-tone-warning-solid: #f59e0b;
  --ui-tone-danger-bg: #fef2f2;  --ui-tone-danger-fg: #b91c1c;  --ui-tone-danger-line: #fecaca;  --ui-tone-danger-solid: #dc2626;
  --ui-tone-neutral-bg: #f1f5f9; --ui-tone-neutral-fg: #475569; --ui-tone-neutral-line: #e2e8f0; --ui-tone-neutral-solid: #94a3b8;
  --ui-tone-purple-bg: #faf5ff;  --ui-tone-purple-fg: #7e22ce;  --ui-tone-purple-line: #e9d5ff;  --ui-tone-purple-solid: #a855f7;
  --ui-tone-teal-bg: #f0fdfa;    --ui-tone-teal-fg: #0f766e;    --ui-tone-teal-line: #99f6e4;    --ui-tone-teal-solid: #14b8a6;
  --ui-tone-orange-bg: #fff7ed;  --ui-tone-orange-fg: #c2410c;  --ui-tone-orange-line: #fed7aa;  --ui-tone-orange-solid: #f97316;
  /* accent follows the brand (--ui-accent is set by app_core/branding.py) */
  --ui-tone-accent-bg: color-mix(in srgb, var(--ui-accent) 8%, #fff);
  --ui-tone-accent-fg: color-mix(in srgb, var(--ui-accent) 82%, #000);
  --ui-tone-accent-line: color-mix(in srgb, var(--ui-accent) 28%, #fff);
  --ui-tone-accent-solid: var(--ui-accent);

  /* 3. attendance days: the personal attendance page's colours, shared by every attendance page */
  --ui-day-holiday: #fdd5d5;
  --ui-day-holiday-fg: #b91c1c;
  --ui-day-weekend: #fedcb0;
  --ui-day-weekend-fg: #b45309;
  --ui-day-leave: #e0f2fe;
  --ui-day-visit: #dcfce7;
  --ui-day-absent: #dc2626;
  --ui-day-off-fg: #64748b;

  /* 2. section colour where no section is set (pages outside the menu): the brand's accent */
  --ui-section: var(--ui-accent);
}

/* 2. sections: one colour each, in the order of the menu */
[data-ui-section="workspace"] { --ui-section: #6366f1; }  /* indigo */
[data-ui-section="people"] { --ui-section: #8b5cf6; }     /* violet */
[data-ui-section="attendance"] { --ui-section: #14b8a6; } /* teal */
[data-ui-section="payroll"] { --ui-section: #22c55e; }    /* green */
[data-ui-section="sales"] { --ui-section: #3b82f6; }      /* blue */
[data-ui-section="purchasing"] { --ui-section: #f97316; } /* orange */
[data-ui-section="projects"] { --ui-section: #d946ef; }   /* fuchsia */
[data-ui-section="inventory"] { --ui-section: #f59e0b; }  /* amber */
[data-ui-section="accounting"] { --ui-section: #0ea5e9; } /* sky */
[data-ui-section="loans"] { --ui-section: #f43f5e; }      /* rose */
[data-ui-section="assets"] { --ui-section: #84cc16; }     /* lime */
[data-ui-section="analytics"] { --ui-section: #06b6d4; }  /* cyan */
[data-ui-section="contacts"] { --ui-section: #ec4899; }   /* pink */
[data-ui-section="settings"] { --ui-section: #64748b; }   /* slate */
/* the shades are worked out where the colour is set, so each element gets its own section's */
:root, [data-ui-section] {
  --ui-section-strong: color-mix(in srgb, var(--ui-section) 68%, #000);  /* text and icons on white */
  --ui-section-soft: color-mix(in srgb, var(--ui-section) 8%, #fff);     /* tinted backgrounds */
  --ui-section-line: color-mix(in srgb, var(--ui-section) 32%, #fff);    /* borders */
  --ui-section-light: color-mix(in srgb, var(--ui-section) 62%, #fff);   /* icons on the dark sidebar */
  --ui-section-glow: color-mix(in srgb, var(--ui-section) 22%, transparent);  /* backgrounds on the dark sidebar */
}

/* --- 1. tones on any piece: `ui-tone--<name>` sets --t-* for the piece to use ------------------------------ */
.ui-tone--success { --t-bg: var(--ui-tone-success-bg); --t-fg: var(--ui-tone-success-fg); --t-line: var(--ui-tone-success-line); --t-solid: var(--ui-tone-success-solid); }
.ui-tone--info { --t-bg: var(--ui-tone-info-bg); --t-fg: var(--ui-tone-info-fg); --t-line: var(--ui-tone-info-line); --t-solid: var(--ui-tone-info-solid); }
.ui-tone--warning { --t-bg: var(--ui-tone-warning-bg); --t-fg: var(--ui-tone-warning-fg); --t-line: var(--ui-tone-warning-line); --t-solid: var(--ui-tone-warning-solid); }
.ui-tone--danger { --t-bg: var(--ui-tone-danger-bg); --t-fg: var(--ui-tone-danger-fg); --t-line: var(--ui-tone-danger-line); --t-solid: var(--ui-tone-danger-solid); }
.ui-tone--neutral { --t-bg: var(--ui-tone-neutral-bg); --t-fg: var(--ui-tone-neutral-fg); --t-line: var(--ui-tone-neutral-line); --t-solid: var(--ui-tone-neutral-solid); }
.ui-tone--accent { --t-bg: var(--ui-tone-accent-bg); --t-fg: var(--ui-tone-accent-fg); --t-line: var(--ui-tone-accent-line); --t-solid: var(--ui-tone-accent-solid); }
.ui-tone--purple { --t-bg: var(--ui-tone-purple-bg); --t-fg: var(--ui-tone-purple-fg); --t-line: var(--ui-tone-purple-line); --t-solid: var(--ui-tone-purple-solid); }
.ui-tone--teal { --t-bg: var(--ui-tone-teal-bg); --t-fg: var(--ui-tone-teal-fg); --t-line: var(--ui-tone-teal-line); --t-solid: var(--ui-tone-teal-solid); }
.ui-tone--orange { --t-bg: var(--ui-tone-orange-bg); --t-fg: var(--ui-tone-orange-fg); --t-line: var(--ui-tone-orange-line); --t-solid: var(--ui-tone-orange-solid); }
/* the section's colour as a tone */
.ui-tone--section { --t-bg: var(--ui-section-soft); --t-fg: var(--ui-section-strong); --t-line: var(--ui-section-line); --t-solid: var(--ui-section); }

/* badges: {% ui_status %} and the tables give `badge ui-badge ui-tone--<tone>`; Bootstrap's text-bg-* badges
   written in templates get the same soft look (a toast or a button keeps Bootstrap's solid colours) */
.badge.text-bg-success { --t-bg: var(--ui-tone-success-bg); --t-fg: var(--ui-tone-success-fg); --t-line: var(--ui-tone-success-line); }
.badge.text-bg-info { --t-bg: var(--ui-tone-info-bg); --t-fg: var(--ui-tone-info-fg); --t-line: var(--ui-tone-info-line); }
.badge.text-bg-warning { --t-bg: var(--ui-tone-warning-bg); --t-fg: var(--ui-tone-warning-fg); --t-line: var(--ui-tone-warning-line); }
.badge.text-bg-danger { --t-bg: var(--ui-tone-danger-bg); --t-fg: var(--ui-tone-danger-fg); --t-line: var(--ui-tone-danger-line); }
.badge.text-bg-primary { --t-bg: var(--ui-tone-accent-bg); --t-fg: var(--ui-tone-accent-fg); --t-line: var(--ui-tone-accent-line); }
.badge.text-bg-secondary { --t-bg: var(--ui-tone-neutral-bg); --t-fg: var(--ui-tone-neutral-fg); --t-line: var(--ui-tone-neutral-line); }
.badge.text-bg-light { --t-bg: #f8fafc; --t-fg: var(--ui-tone-neutral-fg); --t-line: var(--ui-tone-neutral-line); }
.badge.ui-badge, .badge.text-bg-success, .badge.text-bg-info, .badge.text-bg-warning, .badge.text-bg-danger,
.badge.text-bg-primary, .badge.text-bg-secondary, .badge.text-bg-light {
  color: var(--t-fg, var(--ui-tone-neutral-fg)) !important; background-color: var(--t-bg, var(--ui-tone-neutral-bg)) !important;
  border: 1px solid var(--t-line, var(--ui-tone-neutral-line)); font-weight: 600;
}
/* an alarm (overdue, late): solid */
.badge.ui-badge--solid { color: #fff !important; background-color: var(--t-solid) !important; border-color: var(--t-solid); }
/* a small dot before a label */
.ui-dot { display: inline-block; width: .5rem; height: .5rem; border-radius: 50%; background: var(--t-solid, var(--ui-section));
  vertical-align: .1em; margin-right: .3rem; }

/* coloured text and numbers (--bs-table-color too: a table cell takes its colour from it) */
.ui-text--success { --bs-table-color: var(--ui-tone-success-fg); color: var(--ui-tone-success-fg); }
.ui-text--info { --bs-table-color: var(--ui-tone-info-fg); color: var(--ui-tone-info-fg); }
.ui-text--warning { --bs-table-color: var(--ui-tone-warning-fg); color: var(--ui-tone-warning-fg); }
.ui-text--danger { --bs-table-color: var(--ui-tone-danger-fg); color: var(--ui-tone-danger-fg); }
.ui-text--neutral, .ui-text--muted { --bs-table-color: var(--ui-muted); color: var(--ui-muted); }
.ui-text--alarm { --bs-table-color: var(--ui-tone-danger-solid); color: var(--ui-tone-danger-solid); font-weight: 600; }  /* late in, early out, overdue */
/* a negative amount: tables mark it (ui-table.js), report cells too (ui-core.js marks td.acc-col-amount, .acc-col-balance,
   .text-end and .ui-num whose text is a negative number) */
.ui-num--neg { --bs-table-color: var(--ui-tone-danger-fg); color: var(--ui-tone-danger-fg); }
.ui-num--pos { --bs-table-color: var(--ui-tone-success-fg); color: var(--ui-tone-success-fg); }

/* alerts: Bootstrap's soft colours with a bar in the tone */
.alert { border-left-width: 4px; }
.alert-success { border-left-color: var(--ui-tone-success-solid); }
.alert-info { border-left-color: var(--ui-tone-info-solid); }
.alert-warning { border-left-color: var(--ui-tone-warning-solid); }
.alert-danger { border-left-color: var(--ui-tone-danger-solid); }
.alert-primary { border-left-color: var(--ui-tone-accent-solid); }
.alert-secondary, .alert-light { border-left-color: var(--ui-tone-neutral-solid); }

/* rows of a table (or any block) tinted by a tone; `ui-row--mark` puts a bar on the left instead */
.ui-row { --bs-table-bg: var(--t-bg); background-color: var(--t-bg); }
.ui-row--mark { --bs-table-bg: transparent; background-color: transparent; }
.ui-row--mark > :first-child { box-shadow: inset 4px 0 0 var(--t-solid); }

/* --- 3. attendance days: a row, a cell, a column head or a legend swatch -------------------------------- */
.ui-day--holiday { --bs-table-bg: var(--ui-day-holiday); background-color: var(--ui-day-holiday); }
.ui-day--weekend, .ui-day--weekly_off { --bs-table-bg: var(--ui-day-weekend); background-color: var(--ui-day-weekend); }
.ui-day--leave { --bs-table-bg: var(--ui-day-leave); background-color: var(--ui-day-leave); }
.ui-day--visit { --bs-table-bg: var(--ui-day-visit); background-color: var(--ui-day-visit); }
tr.ui-day--absent > :first-child, .tabulator-row.ui-day--absent, .ui-swatch.ui-day--absent { box-shadow: inset 4px 0 0 var(--ui-day-absent); }
.ui-day--off { --bs-table-color: var(--ui-day-off-fg); color: var(--ui-day-off-fg); }
/* the day's type in a holiday or weekend row: bold, in the day's colour */
.ui-day--holiday .ui-day__type { --bs-table-color: var(--ui-day-holiday-fg); color: var(--ui-day-holiday-fg); font-weight: 600; }
.ui-day--weekend .ui-day__type, .ui-day--weekly_off .ui-day__type { --bs-table-color: var(--ui-day-weekend-fg); color: var(--ui-day-weekend-fg); font-weight: 600; }
/* Tabulator paints even rows itself */
.tabulator-row.ui-day--holiday, .tabulator-row.ui-day--holiday.tabulator-row-even { background-color: var(--ui-day-holiday); }
.tabulator-row.ui-day--weekend, .tabulator-row.ui-day--weekend.tabulator-row-even { background-color: var(--ui-day-weekend); }
.tabulator-row.ui-day--leave, .tabulator-row.ui-day--leave.tabulator-row-even { background-color: var(--ui-day-leave); }
.tabulator-row.ui-day--visit, .tabulator-row.ui-day--visit.tabulator-row-even { background-color: var(--ui-day-visit); }
/* a value someone set by hand in a grid (the monthly attendance, the roster) */
.ui-cell--set { font-weight: 700; color: var(--ui-section-strong); }
.ui-cell--set-alarm { font-weight: 700; color: var(--ui-tone-danger-solid); }

/* legends: what the colours mean */
/* filter bars: the labels (layout: ui-layout.css .ui-filters) */
.ui-filter > .form-label { color: #475569; font-weight: 500; }
/* plain tables (ui-table.css .ui-report-table): the header like the Tabulator tables', soft lines */
.ui-report-table { --bs-table-border-color: #e3e8ef; }
.ui-report-table > thead > tr > th { --bs-table-bg: #f8fafc; --bs-table-color: #334155; }
.ui-report-table .ui-muted-cell { --bs-table-color: var(--ui-muted); color: var(--ui-muted); }
.ui-report-table tr.ui-row--today > :first-child { box-shadow: inset 4px 0 0 var(--ui-section); }
.ui-note { background: rgba(15, 23, 42, .06); color: #334155; }
.ui-note--alarm { background: var(--ui-tone-danger-bg); color: var(--ui-tone-danger-fg); }
.ui-today-chip { background: var(--ui-section); color: #fff; }
.ui-legend { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem 1rem; font-size: .8rem; }
.ui-legend__item { display: inline-flex; align-items: center; gap: .35rem; }
.ui-swatch { display: inline-block; flex: none; width: .9rem; height: .9rem; border-radius: .2rem; border: 1px solid var(--ui-border); }
.ui-swatch[class*="ui-tone--"] { background-color: var(--t-bg); border-color: var(--t-line); }  /* a day swatch takes .ui-day--* */

/* stat tiles: a figure with its label; a tone (or the section) colours the bar; an alarm figure adds ui-text--alarm */
.ui-stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.5rem, 1fr)); gap: .5rem; }
.ui-stat { padding: .45rem .7rem; background: #fff; border: 1px solid var(--ui-border); border-left: 3px solid var(--t-solid, var(--ui-section-line));
  border-radius: .45rem; }
.ui-stat__value { display: block; font-size: 1.05rem; font-weight: 600; line-height: 1.25;
  font-variant-numeric: tabular-nums; }
.ui-stat__label { display: block; font-size: .75rem; color: var(--ui-muted); }

/* --- 4. the page in its section's colour ---------------------------------------------------------------- */
.ui-pagebar { border-bottom: 2px solid var(--ui-section-line); }
.ui-pagebar__icon { display: grid; place-items: center; flex: none; width: 32px; height: 32px; margin-right: -.25rem; border-radius: .55rem;
  background: var(--ui-section-soft); color: var(--ui-section-strong); border: 1px solid var(--ui-section-line); }
.ui-pagebar__icon svg { width: 17px; height: 17px; }

/* tabs: the open tab in the section's colour */
.nav-tabs { --bs-nav-tabs-link-active-color: var(--ui-section-strong); --bs-nav-tabs-link-active-border-color: var(--ui-border) var(--ui-border) var(--bs-body-bg); }
.nav-tabs .nav-link, .nav-pills .nav-link, .nav-underline .nav-link { color: var(--ui-muted); }
.nav-tabs .nav-link:hover, .nav-pills .nav-link:hover, .nav-underline .nav-link:hover { color: var(--ui-section-strong); }
.nav-tabs .nav-link.active { font-weight: 600; box-shadow: inset 0 3px 0 var(--ui-section); }
.nav-pills .nav-link.active, .nav-pills .show > .nav-link { color: var(--ui-section-strong); background: var(--ui-section-soft);
  box-shadow: inset 0 0 0 1px var(--ui-section-line); font-weight: 600; }
.nav-underline .nav-link.active { color: var(--ui-section-strong); border-bottom-color: var(--ui-section); font-weight: 600; }

/* panels: the header's icon in the section's colour; `ui-panel ui-tone--<tone> ui-panel--toned` puts a bar on top */
.ui-panel__header > svg, .ui-panel__header > i[data-lucide] { color: var(--ui-section-strong); }
.ui-panel--toned { border-top: 3px solid var(--t-solid, var(--ui-section)); }

/* tables: a line in the section's colour under the header, a tint on the row under the pointer */
.ui-table.tabulator .tabulator-header { border-bottom: 2px solid var(--ui-section-line); }
.ui-table.tabulator .tabulator-row:hover { background-color: var(--ui-section-soft); }
.ui-panel .table > thead > tr > th { border-bottom-color: var(--ui-section-line); }

/* forms and the approval timeline */
.ui-form__heading { color: var(--ui-section-strong); border-bottom-color: var(--ui-section-line); }
.ui-timeline { border-left-color: var(--ui-section-line); }
.ui-timeline__item::before { background: var(--ui-section); }

/* the import check's data: a cell the import changes (warning tint, the value now struck through under it), a
   cell left empty in the file showing what the record keeps (grey) */
.ui-import-changed { background: var(--ui-tone-warning-bg); color: var(--ui-tone-warning-fg); font-weight: 500; }
.ui-import-preview td.ui-import-changed { --bs-table-bg: var(--ui-tone-warning-bg); --bs-table-color: var(--ui-tone-warning-fg);
  box-shadow: inset 0 0 0 1px var(--ui-tone-warning-line); }
.ui-import-was { font-size: .75rem; font-weight: 400; color: var(--ui-tone-neutral-fg); text-decoration: line-through; }
.ui-import-legend .ui-import-was { font-size: inherit; }
.ui-import-kept, .ui-import-preview td.ui-import-kept { --bs-table-color: var(--ui-tone-neutral-solid); color: var(--ui-tone-neutral-solid); font-style: italic; }
.ui-import-preview td.ui-import-unused { --bs-table-color: var(--ui-tone-neutral-solid); color: var(--ui-tone-neutral-solid); }
.ui-import-note { font-size: .7rem; text-transform: uppercase; letter-spacing: .03em; color: var(--ui-tone-neutral-fg); }
.ui-import-preview th, .ui-import-preview td { white-space: nowrap; }
.ui-import-columns > summary { cursor: pointer; list-style: none; }
.ui-import-columns > summary::-webkit-details-marker { display: none; }
.ui-import-columns:not([open]) > summary { border-bottom: 0; }

/* a box for a one-time code (two-factor sign-in): empty boxes look empty; a hint inside is pale, never like a typed code */
.ui-code-input { background: var(--ui-tone-neutral-bg); border-color: var(--ui-tone-neutral-line); }
.ui-code-input:focus { background: #fff; border-color: var(--ui-section); box-shadow: 0 0 0 .2rem var(--ui-section-soft); }
.ui-code-input::placeholder { color: var(--ui-tone-neutral-solid); opacity: .6; }

/* tinted rows and day colours print as on screen */
@media print {
  .ui-row, .ui-day--holiday, .ui-day--weekend, .ui-day--weekly_off, .ui-day--leave, .ui-day--visit, .ui-day--absent, .ui-swatch, .badge {
    -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
