/*
 * Light and dark theme of the office app (the planner, Settings, Orders, Reports, the Ask panel, login).
 *
 * <html data-theme="light"|"dark"> says which one is on screen. js/theme.js (and the tiny script in index.html's <head>, which runs before the first paint) sets it
 * from the person's choice: Light (the default), Dark, or Same as computer. The choice is kept per computer in localStorage.
 *
 * Every colour the office screens draw is a token. tokens.css (shared with the driver app) holds the light values of the tokens that already existed; this file adds
 * the tokens it never had, gives their light values (the colours the screens always drew, so Light looks exactly as it did), and gives the dark value of each.
 * The driver app does not load this file and is not changed. Its dark theme (driver/app.css) is where this palette comes from: the same greens and greys, Forest
 * Green bar, Lime as the accent on the dark ground, a lighter forest for filled buttons.
 *
 * Two tokens used to do two jobs and are now split, because one value cannot be right for both on a dark ground:
 *   --blue (a fill under white text)  and  --accent (the same green as text, an icon, an outline or a focus ring);
 *   --danger / --warning / --success (colour as text or an outline)  and  --danger-fill / --warning-fill / --success-fill (colour behind white text).
 * In Light each pair is one value, as before.
 *
 * Left light on purpose: anything printed or exported (delivery notes, run sheets, PDFs, xlsx), the public tracking page, the picture of the customer's tracking
 * widget in SETTINGS (.wp-*, it shows what the customer sees), and signatures and photos (--paper). The driver app has its own theme.
 */
:root {
  color-scheme: light;

  /* roles of white (a card, a field, a button and a pane were all #fff; on a dark ground they are different greens) */
  --surface: #FFFFFF;           /* dialogs, menus, popovers, toasts, cards, stop blocks */
  --field: #FFFFFF;             /* inputs, selects, tick boxes, search boxes */
  --control: #FFFFFF;           /* buttons on a toolbar or a footer */
  --paper: #FFFFFF;             /* always white: signatures, photos, what a customer sees */
  --on-fill: #FFFFFF;           /* text and glyphs on a coloured fill (white in both themes) */
  --on-bar: #FFFFFF;            /* text on the Forest Green top bar */
  --on-bar-dim: #CCCDE2;        /* the tabs that are not open */
  --on-bar-dim-2: #E2E3F0;      /* the role under the user's name */
  --pin-edge: #FFFFFF;          /* the white edge of a map pin and the other markers */
  --pin-ink: #1F2733;           /* text on a white marker */
  --sunken: #F5F5F5;            /* disabled controls, chips, a quiet band */
  --field-off: #EEF0F4;         /* a disabled or read-only field */
  --hover: #F5F6FA;             /* a row of a menu or a list under the pointer */
  --hover-soft: #F2F2F2;        /* a flat icon button under the pointer */
  --hover-faint: #F7F7F7;       /* a very light hover (a toolbar button, a stop block) */
  --seg-bg: #EEEEEE;            /* the groove behind a segmented switch, a folded section */
  --btn-bg: #F2F2F2;            /* a small boxed button */
  --btn-bg-hover: #E6E6E6;
  --hover-veil: rgba(27, 28, 65, .06);   /* a dim layer over anything under the pointer */
  --on-bar-hover: rgba(255, 255, 255, .07);

  /* lines */
  --row-line: #F0F0F2;          /* between table rows */
  --input-line: #CED2DA;        /* the border of a field */
  --input-line-hover: #AEB3BF;
  --ctl-line: #E4E4E4;          /* the border of a toolbar control */
  --check-line: #C4C7D1;        /* the border of a tick box */
  --check-line-hover: #8F95A8;
  --check-off: #F1F2F5;         /* a disabled tick box and its border */
  --check-off-line: #DADCE3;
  --check-on-off: #A9CBFF;      /* a ticked box that is disabled */

  /* text */
  --ink-max: #111111;           /* the strongest text: table cells of orders */
  --ink: #222222;               /* text of compact controls and the plan */
  --ink-3: #333333;
  --ink-4: #444444;
  --ink-5: #555555;
  --ink-6: #777777;
  --icon: #8A8FA0;              /* quiet icons and secondary glyphs */
  --icon-soft: #9A9EAE;         /* the search box's buttons */
  --icon-grey: #A6A6A6;         /* the calendar button of a date field */
  --ink-slate: #3A3F52;         /* the square icon buttons of the list footers */
  --readonly-ink: #9A9A9A;      /* text of a read-only field */
  --placeholder: #B0B3BF;       /* placeholders and hints */
  --faint: #C9CCD6;             /* decorative icons and tick marks */

  /* the green of the brand as text, an icon, an outline or a focus ring (see the note at the top about --blue) */
  --accent: #0F3A27;
  --focus-glow: rgba(15, 58, 39, .18);

  /* red, amber and green behind white text; as text they are --danger, --warning and --success */
  --danger-fill: #E5334B;
  --danger-fill-hover: #C92A40;
  --danger-deep: #D7263D;       /* the congestion charge badge */
  --danger-deep-hover: #B51D31;
  --danger-ring: #E5334B;       /* the ring round a late pin */
  --danger-ink: #8E1F2F;        /* text on --danger-tint */
  --danger-line: #F3B5BD;
  --warning-fill: #FA9600;
  --over-fill: #B26A00;         /* an item count that is over */
  --success-fill: #22BD22;
  --alert-bg: #B3261E;          /* the red bar when the OrderWise feed has stopped */
  --warn-line: #F3E5B0;         /* the border of a pale amber note */
  --warn-bg: #FFF8E1;
  --warn-ink: #8A6A1A;
  --warn-card-bg: #FFF6E0;      /* the amber boxes of the vehicle check forms */
  --warn-card-line: #E7C98C;
  --warn-card-ink: #7A4A00;
  --warn-chip-bg: #FFF1D6;
  --warn-chip-ink: #8A5A00;
  --note-line: #F5DDA8;         /* "run start time" note */
  --note-ink: #7A5A12;
  --banner-ink: #5C3B00;        /* text of the amber notice on an order */
  --viol-bg: #F2194F;           /* a stop that breaks a hard rule */
  --ok-bg: #D9F5D9;
  --ok-fg: #1E9E3A;
  --ok-icon: #3FB950;
  --ok-chip-bg: #DFF1E2;
  --ok-chip-ink: #1F6B2A;
  --ok-ink: #2E7D32;
  --bad-ink: #B3261E;
  --over-ink: #B26A00;
  --note-fill-ink: #3D2600;     /* dark text on the amber "!" of an order note */

  /* a stop on the timeline and an order card: selected, done, failed, late */
  --sel-bg: #CFE4FF;
  --sel-line: #7FB4FF;
  --sel-row: #D6E9FF;
  --sel-wash: #F5FAFF;
  --drop-bg: #E3F0FF;
  --drop-wash: #F0F7FF;
  --hover-blue: #EEF5FF;
  --toggle-on-bg: #D9ECFF;      /* the view switch that is on */
  --done-bg: #DDF3E3;
  --done-bg-hover: #CBEBD4;
  --done-line: #2E9E4F;
  --done-ink: #2C5E3B;
  --failed-bg: #FDE8EA;
  --failed-bg-hover: #FAD6DA;
  --failed-line: #D64550;
  --late-line: #F3A1AB;
  --noinv-bg: #FDE2E4;
  --noinv-card: #FFF4F5;
  --noinv-line: #C8102E;
  --viol-wash: #FDE0E4;
  --viol-wash-hover: #FBCFD6;
  --ok-wash: #E8F5EE;           /* the "nothing missed" line when all is fine */
  --ok-wash-line: #BFE0CD;
  --ok-wash-ink: #1D6B43;
  --end-bg: #F5F5F5;            /* the loading and route-end blocks */
  --end-line: #E1E3E8;
  --bar-idle: #BFC3CE;
  --bar-load: #7BC47F;
  --bar-load-op: #2F4A63;
  --hatch-a: #F6F6F6;           /* outside the working hours */
  --hatch-b: #F9F9F9;
  --lock-on: #1B1C41;           /* a locked run */

  /* greys of buttons that sit on the map and the plan */
  --grip-bg: #8A8FA0;
  --grip-bg-hover: #5F6475;
  --tab-grey: #4B505E;
  --tab-grey-hover: #2F3340;
  --cancel-bg: #6E6E6E;
  --cancel-bg-hover: #555555;
  --map-bg: #E8EBEF;            /* behind the tiles while they load */
  --map-chip-bg: rgba(255, 255, 255, .93);
  --scroll-thumb: #B9BCC8;
  --scroll-thumb-hover: #9A9EAE;
  --scroll-thumb-plan: #8C8C8C;
  --switch-off: #C9CCD6;
  --toggle-off: #9A9EAE;

  /* tooltips and hover cards are dark in both themes; in Dark they get an edge so they do not melt into the page */
  --tip-bg: #2A2C46;
  --tip-bg-2: #1E2530;
  --tip-bg-3: #222222;
  --tip-text: #FFFFFF;
  --tip-text-2: #D6D8E6;
  --tip-text-3: #B9BCD0;
  --tip-line: rgba(255, 255, 255, .18);
  --tip-amber: #FFC266;
  --tip-edge: transparent;

  /* shadows and veils (a black shadow is stronger on a dark ground) */
  --sh-1: rgba(0, 0, 0, .08);
  --sh-2: rgba(0, 0, 0, .25);
  --sh-3: rgba(0, 0, 0, .45);
  --sh-pop: rgba(27, 28, 65, .22);
  --sh-card: rgba(15, 58, 39, .16);
  --scrim: rgba(40, 44, 60, .55);
  --veil: rgba(255, 255, 255, .7);
  --veil-mid: rgba(255, 255, 255, .55);
  --veil-lo: rgba(255, 255, 255, .4);
  --select-veil: rgba(27, 122, 78, .1);
  --on-fill-edge: rgba(255, 255, 255, .45);

  /* the timeline of TRACK&TRACE: bars and dots take the stronger colour, table cells the pale one */
  --tt-green-mark: #A7E4A9;
  --tt-blue-mark: #B5E6E9;
  --tt-amber-mark: #F2D59B;
  --tt-red-mark: #DE9C9E;
  --tt-grey-mark: #DDDFE5;
}

/* Dark. The values come from the driver app's dark theme (driver/app.css); the planner's own greys and tints are matched to them. */
:root[data-theme="dark"] {
  color-scheme: dark;

  /* tokens.css */
  --blue: #2F7A55;
  --blue-hover: #276646;
  --blue-link: #B1D354;
  --blue-tint: #243528;
  --blue-tint-2: #2F4632;
  --page: #141A16;
  --panel: #101512;
  --toolbar: #232E27;
  --grid-head: #19211C;
  --grid-hover: #202A24;
  --line: #2E3932;
  --line-strong: #46534B;
  --line-soft: #26302A;
  --sidebar-line: #38443D;
  --text: #E1DED4;
  --text-strong: #F1EFE7;
  --muted: #A9AFA7;
  --muted-2: #B9BEB6;
  --disabled: #78827B;
  --danger: #FF9A92;
  --danger-tint: #3B1F1D;
  --warning: #F0B04A;
  --warning-tint: #382C12;
  --success: #86D78D;
  --success-tint: #1B3A22;
  --amber-text: #F0B04A;
  --toolbar-plan: #19211C;
  --past-banner: #2F7A55;
  --off-hours: #181F1A;
  --pill: #26322B;
  --green-text: #6FCB77;
  --run-head: #26322B;
  --focus-ring: 0 0 0 2px #141A16, 0 0 0 4px #B1D354;

  /* tracktrace.css */
  --tt-white: #141A16;
  --tt-ink: #F4F2EB;
  --tt-ink-2: #ECE9DF;
  --tt-ink-3: #D8D5CB;
  --tt-ink-4: #C9C6BC;
  --tt-ink-5: #BBB8AE;
  --tt-ink-6: #A9ADA6;
  --tt-hairline: #6B7A70;
  --tt-head-line: #2E3932;
  --tt-row-line: #232D27;
  --tt-hover: #26322B;
  --tt-head: #19211C;
  --tt-faint: #1D2620;
  --tt-seg: #26322B;
  --tt-hint: #8E968F;
  --tt-hint-2: #78827B;
  --tt-tick: #5F6A63;
  --tt-tip-hint: #B9BCD0;
  --tt-mute: #959D96;
  --tt-pin: #ECE9DF;
  --tt-green: #1F4D2B;
  --tt-blue: #1B4A52;
  --tt-amber: #5A4313;
  --tt-red: #5E2327;
  --tt-grey: #2A332D;
  --tt-lime: #3B4A1A;
  --tt-green-mark: #4FAE57;
  --tt-blue-mark: #4AA7B3;
  --tt-amber-mark: #D9A53A;
  --tt-red-mark: #D8646B;
  --tt-grey-mark: #66746B;
  --track-red: #FF7A80;

  /* roles of white */
  --surface: #1C251F;
  --field: #111713;
  --control: #212C25;
  --sunken: #19211C;
  --field-off: #171E19;
  --hover: #26322B;
  --hover-soft: #26322B;
  --hover-faint: #222D26;
  --seg-bg: #26322B;
  --btn-bg: #28342D;
  --btn-bg-hover: #34423A;
  --hover-veil: rgba(255, 255, 255, .09);

  /* lines */
  --row-line: #232D27;
  --input-line: #66746B;
  --input-line-hover: #86948B;
  --ctl-line: #6B7A70;
  --check-line: #66746B;
  --check-line-hover: #86948B;
  --check-off: #171E19;
  --check-off-line: #2E3932;
  --check-on-off: #2A4A3A;

  /* text */
  --ink-max: #F4F2EB;
  --ink: #ECE9DF;
  --ink-3: #D8D5CB;
  --ink-4: #C9C6BC;
  --ink-5: #BBB8AE;
  --ink-6: #A9ADA6;
  --icon: #959D96;
  --icon-soft: #959D96;
  --icon-grey: #8E968F;
  --ink-slate: #D8D5CB;
  --readonly-ink: #959D96;
  --placeholder: #8E968F;
  --faint: #6A756D;

  --accent: #B1D354;
  --focus-glow: rgba(177, 211, 84, .3);

  --danger-fill: #C8362D;
  --danger-fill-hover: #A92B23;
  --danger-deep: #C8362D;
  --danger-deep-hover: #A92B23;
  --danger-ring: #FF7A70;
  --danger-ink: #FFD0CB;
  --danger-line: #6B2F2B;
  --warning-fill: #9A5B00;
  --over-fill: #9A5B00;
  --success-fill: #2E7D32;
  --alert-bg: #A92B23;
  --warn-line: #5A4719;
  --warn-bg: #382C12;
  --warn-ink: #F0B04A;
  --warn-card-bg: #382C12;
  --warn-card-line: #5A4719;
  --warn-card-ink: #F0C57A;
  --warn-chip-bg: #382C12;
  --warn-chip-ink: #F0B04A;
  --note-line: #5A4719;
  --note-ink: #F0C57A;
  --banner-ink: #F6D9A0;
  --viol-bg: #D41B48;
  --ok-bg: #1B3A22;
  --ok-fg: #86D78D;
  --ok-icon: #6FD08C;
  --ok-chip-bg: #1B3A22;
  --ok-chip-ink: #86D78D;
  --ok-ink: #86D78D;
  --bad-ink: #FF9A92;
  --over-ink: #F0B04A;

  --sel-bg: #1D3A57;
  --sel-line: #5B9BDB;
  --sel-row: #1A3350;
  --sel-wash: #172C44;
  --drop-bg: #1D3A57;
  --drop-wash: #172C44;
  --hover-blue: #1B3047;
  --toggle-on-bg: #1D3A57;
  --done-bg: #1B3A22;
  --done-bg-hover: #224A2B;
  --done-line: #4FAE57;
  --done-ink: #A7E4A9;
  --failed-bg: #3B1F1D;
  --failed-bg-hover: #4A2623;
  --failed-line: #E0646B;
  --late-line: #C0606A;
  --noinv-bg: #4A1F24;
  --noinv-card: #3B1F1D;
  --noinv-line: #D4303F;
  --viol-wash: #3F2128;
  --viol-wash-hover: #4D2830;
  --ok-wash: #1B3A22;
  --ok-wash-line: #2F6B3C;
  --ok-wash-ink: #A7E4A9;
  --end-bg: #19211C;
  --end-line: #2E3932;
  --bar-idle: #5B665F;
  --bar-load: #5FAE64;
  --bar-load-op: #6F96B8;
  --hatch-a: #171E19;
  --hatch-b: #1A221D;
  --lock-on: #4A5A86;

  --grip-bg: #46534B;
  --grip-bg-hover: #5A6A60;
  --tab-grey: #3A463F;
  --tab-grey-hover: #4A5A50;
  --cancel-bg: #4A554E;
  --cancel-bg-hover: #5A675F;
  --map-bg: #181C19;
  --map-chip-bg: rgba(28, 37, 31, .93);
  --scroll-thumb: #4A5850;
  --scroll-thumb-hover: #66746B;
  --scroll-thumb-plan: #5A675F;
  --switch-off: #46534B;
  --toggle-off: #66746B;

  --tip-bg: #2B3830;
  --tip-bg-2: #2B3830;
  --tip-bg-3: #2B3830;
  --tip-text-2: #D6DAD2;
  --tip-text-3: #B8BEB5;
  --tip-line: rgba(255, 255, 255, .16);
  --tip-edge: rgba(255, 255, 255, .16);

  --sh-1: rgba(0, 0, 0, .4);
  --sh-2: rgba(0, 0, 0, .55);
  --sh-3: rgba(0, 0, 0, .7);
  --sh-pop: rgba(0, 0, 0, .6);
  --sh-card: rgba(0, 0, 0, .5);
  --scrim: rgba(0, 0, 0, .66);
  --veil: rgba(20, 26, 22, .7);
  --veil-mid: rgba(20, 26, 22, .55);
  --veil-lo: rgba(20, 26, 22, .4);
  --select-veil: rgba(177, 211, 84, .14);
}

/* ---- Dark: rules that are not just a colour swapped for a token ---- */
:root[data-theme="dark"] .topbar { border-bottom: 1px solid rgba(255, 255, 255, .08); }
/* tokens.css draws these with colours of its own (it is shared with the driver app, so it is left alone) */
:root[data-theme="dark"] .btn[disabled], :root[data-theme="dark"] .btn[aria-disabled="true"] { background: var(--sunken); border-color: var(--line); color: var(--disabled); }
:root[data-theme="dark"] .btn-outline { background: var(--control); color: var(--text); border-color: var(--line-strong); }
:root[data-theme="dark"] .btn-outline:hover { background: var(--hover); border-color: var(--input-line-hover); }
:root[data-theme="dark"] .btn-danger { background: var(--danger-fill); border-color: var(--danger-fill); }
:root[data-theme="dark"] .btn-danger:hover { background: var(--danger-fill-hover); border-color: var(--danger-fill-hover); }
/* native pieces (the date picker's icon, the number spinner) follow color-scheme; a ticked box keeps its white tick */
:root[data-theme="dark"] .mx-select { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23D8D5CB' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
:root[data-theme="dark"] .mx-input.od-box.od-select, :root[data-theme="dark"] .mx-input.od-box.od-select:disabled, :root[data-theme="dark"] .od-prio { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23A9ADA6' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"); }
:root[data-theme="dark"] .mx-check:checked { border-color: var(--accent); }
:root[data-theme="dark"] .mx-radio:checked { border-color: var(--accent); }
:root[data-theme="dark"] .hovercard, :root[data-theme="dark"] .ertip, :root[data-theme="dark"] .tt-tl-tip { border: 1px solid var(--tip-edge); }
:root[data-theme="dark"] .bc-box.over { color: var(--on-fill); }
:root[data-theme="dark"] .empty-inbox { color: var(--muted); }

/* map pins: an unplanned order is a square of a lighter forest on the dark map (the pin's own colour is set in the page, hence !important); a route line
   gets a pale glow so a van's dark colour still reads on the dark tiles. Pins and labels are not filtered. */
:root[data-theme="dark"] .pin.unplanned { --pc: #2F7A55 !important; }
:root[data-theme="dark"] .leaflet-overlay-pane path.leaflet-interactive { filter: drop-shadow(0 0 2px rgba(255, 255, 255, .85)) drop-shadow(0 0 1px rgba(255, 255, 255, .6)); }

/* the map: OpenStreetMap has no dark style that needs no key, so only the tiles are darkened (the same filter as the driver app). Route lines, pins, labels and
   the controls are on other panes and are not touched. The grey-map switch (Settings gear > Grey map) adds to it. */
:root[data-theme="dark"] .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) brightness(.92) contrast(.9); }
:root[data-theme="dark"] .mp-gray .leaflet-tile-pane { filter: invert(1) hue-rotate(180deg) grayscale(1) brightness(.92) contrast(.9); }
:root[data-theme="dark"] .leaflet-container { background: var(--map-bg); }
:root[data-theme="dark"] .leaflet-container .leaflet-control-attribution, :root[data-theme="dark"] .leaflet-control-scale-line {
  background: var(--map-chip-bg); color: var(--ink-4); border-color: var(--input-line); }
:root[data-theme="dark"] .leaflet-container .leaflet-control-attribution a { color: var(--blue-link); }
:root[data-theme="dark"] .leaflet-control-layers, :root[data-theme="dark"] .leaflet-bar a { background-color: var(--surface); color: var(--ink); border-color: var(--line-strong); }
:root[data-theme="dark"] .leaflet-control-layers-separator { border-top-color: var(--line); }
:root[data-theme="dark"] .leaflet-control-layers-toggle { filter: invert(1); }   /* the layers picture is dark lines; this turns only the picture light */
:root[data-theme="dark"] .leaflet-popup-content-wrapper, :root[data-theme="dark"] .leaflet-popup-tip { background: var(--surface); color: var(--ink); }
:root[data-theme="dark"] .leaflet-tooltip { background-color: var(--surface); border-color: var(--line-strong); color: var(--ink); }
:root[data-theme="dark"] .leaflet-tooltip-top::before { border-top-color: var(--line-strong); }
:root[data-theme="dark"] .leaflet-tooltip-bottom::before { border-bottom-color: var(--line-strong); }
:root[data-theme="dark"] .leaflet-tooltip-left::before { border-left-color: var(--line-strong); }
:root[data-theme="dark"] .leaflet-tooltip-right::before { border-right-color: var(--line-strong); }
:root[data-theme="dark"] .leaflet-interactive { outline-color: var(--accent); }
