/* Copyright (C) 2026 Island Treasures Ltd <sergio@goldman.net>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
 */

/**
 * custom/itosgps/css/itosgps.css
 *
 * ============================================================================
 * DESIGN CONSTRAINTS THIS FILE IS WRITTEN AGAINST
 * ============================================================================
 *
 * 1. THIS IS USED ON A PHONE, OUTDOORS, IN THE SUN, ONE-HANDED, BY SOMEONE WHO
 *    IS STANDING UP AND IN A HURRY. Not at a desk. The check-in button, the
 *    check-out button and the camera button are therefore enormous (56px+ tall,
 *    full width) and high-contrast. A rep should be able to hit check-in with a
 *    thumb, without looking carefully, while holding a bag of samples in the
 *    other hand. Every millimetre of target we take away is a mis-tap in a shop
 *    doorway.
 *
 * 2. IT MUST OBEY THE HOST THEME. Every colour here comes from a Dolibarr theme
 *    variable (--colorbackbody, --colortext, ...) so the module looks like the
 *    ERP it lives in and follows it into dark mode automatically. Hardcoding
 *    #fff here would produce a module that turns into a white flashbang the
 *    moment an admin enables THEME_DARKMODEENABLED. The var() fallbacks exist
 *    only for the (impossible) case of the theme not loading -- they are not the
 *    design.
 *
 * 3. STATUS COLOURS ARE NOT THE ONLY SIGNAL. Every status badge carries text as
 *    well as a colour. About 1 man in 12 cannot reliably distinguish the
 *    red/green pair this module would otherwise lean on, and "your visit failed"
 *    is not a message to deliver by hue alone.
 *
 * No external fonts. No CDN. No @import. Everything ships with the module.
 */

/* ==========================================================================
   Layout primitives
   ========================================================================== */

.itosgps-field {
	max-width: 720px;
	margin: 0 auto;
	padding: 0.5rem;
	color: var(--colortext, #333);
}

.itosgps-card {
	background: var(--colorbacklineimpair2, #fff);
	border: 1px solid var(--inputbordercolor, rgba(0, 0, 0, 0.2));
	border-radius: 6px;
	padding: 0.9rem;
	margin-bottom: 0.9rem;
}

.itosgps-card-title {
	font-weight: 600;
	color: var(--colortexttitle, #444);
	margin: 0 0 0.5rem 0;
	font-size: 1.05rem;
}

.itosgps-row {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	align-items: center;
}

.itosgps-grow {
	flex: 1 1 auto;
	min-width: 0;
}

.itosgps-muted {
	color: var(--tableforfieldcolor, #666);
	font-size: 0.9em;
}

/* ==========================================================================
   The big field buttons
   --------------------------------------------------------------------------
   56px is the floor, not the target. It is roughly the width of an adult thumb
   pad; anything smaller is a coin toss on a moving bus. On a phone these go
   full-width, because a full-width target cannot be missed horizontally at all.
   ========================================================================== */

.itosgps-bigbtn {
	display: block;
	width: 100%;
	min-height: 56px;
	padding: 1rem 1.2rem;
	margin: 0.4rem 0;
	font-size: 1.15rem;
	font-weight: 600;
	line-height: 1.2;
	text-align: center;
	border: none;
	border-radius: 8px;
	cursor: pointer;
	background: var(--butactionbg, #263c5c);
	color: var(--textbutaction, #fff);
	/* No transition on the tap: a rep tapping in a hurry needs to see the state
	   change NOW, not fade in over 200ms while they wonder whether it registered. */
	-webkit-tap-highlight-color: rgba(0, 0, 0, 0.15);
	touch-action: manipulation; /* kills the 300ms double-tap-to-zoom delay */
}

.itosgps-bigbtn:active {
	filter: brightness(0.85);
}

.itosgps-bigbtn:disabled,
.itosgps-bigbtn.itosgps-busy {
	opacity: 0.55;
	cursor: progress;
}

.itosgps-bigbtn-checkin {
	background: #0a7d3f;
	color: #fff;
}

.itosgps-bigbtn-checkout {
	background: #a33;
	color: #fff;
}

.itosgps-bigbtn-photo {
	background: var(--colorbacktitle1, #e9e9e9);
	color: var(--colortexttitle, #333);
	border: 2px dashed var(--inputbordercolor, rgba(0, 0, 0, 0.25));
}

/* The camera input is hidden and driven by its label, so the label can be the
   big target. The input itself must stay focusable for keyboard/AT users --
   display:none would remove it from the accessibility tree entirely. */
.itosgps-photo-input {
	position: absolute;
	width: 1px;
	height: 1px;
	opacity: 0;
	overflow: hidden;
}

.itosgps-photo-input:focus + .itosgps-bigbtn-photo {
	outline: 3px solid var(--colortextlink, #2a5db0);
	outline-offset: 2px;
}

/* ==========================================================================
   GPS accuracy readout
   --------------------------------------------------------------------------
   The rep watches this tighten while the fix converges. It is the difference
   between "the app is broken" and "the app is waiting for the satellites".
   ========================================================================== */

.itosgps-gps {
	display: inline-flex;
	align-items: center;
	gap: 0.4rem;
	padding: 0.35rem 0.7rem;
	border-radius: 999px;
	font-size: 0.95rem;
	font-weight: 600;
	background: var(--colorbackgrey, #f0f0f0);
	color: var(--colortext, #333);
}

.itosgps-gps::before {
	content: "";
	width: 10px;
	height: 10px;
	border-radius: 50%;
	background: currentColor;
}

.itosgps-gps-searching {
	background: #fdf0d5;
	color: #7a5200;
}

.itosgps-gps-searching::before {
	animation: itosgps-pulse 1.1s ease-in-out infinite;
}

.itosgps-gps-good {
	background: #e2f4e9;
	color: #0a5d31;
}

.itosgps-gps-bad {
	background: #fae3e3;
	color: #8a1f1f;
}

@keyframes itosgps-pulse {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.25; }
}

@media (prefers-reduced-motion: reduce) {
	.itosgps-gps-searching::before {
		animation: none;
	}
}

/* ==========================================================================
   Offline / sync status
   --------------------------------------------------------------------------
   Permanently on screen. A rep must be able to answer "is my day uploaded?"
   without asking anyone, at a glance, from arm's length.
   ========================================================================== */

.itosgps-queue {
	display: inline-block;
	padding: 0.35rem 0.75rem;
	border-radius: 999px;
	font-size: 0.9rem;
	font-weight: 600;
}

.itosgps-queue-empty {
	background: #e2f4e9;
	color: #0a5d31;
}

.itosgps-queue-pending {
	background: #fdf0d5;
	color: #7a5200;
}

/* Storage full, or the server rejected something. This must not be possible to
   overlook: it is the state in which the rep's work is at risk. */
.itosgps-queue-error {
	background: #b3261e;
	color: #fff;
	animation: itosgps-flash 2s ease-in-out infinite;
}

@keyframes itosgps-flash {
	0%, 100% { opacity: 1; }
	50% { opacity: 0.6; }
}

@media (prefers-reduced-motion: reduce) {
	.itosgps-queue-error {
		animation: none;
		outline: 2px solid #b3261e;
		outline-offset: 2px;
	}
}

.itosgps-notice {
	display: none;
	padding: 0.8rem 1rem;
	margin: 0.5rem 0;
	border-radius: 6px;
	font-weight: 600;
	line-height: 1.35;
}

.itosgps-notice-ok {
	background: #e2f4e9;
	color: #0a5d31;
	border-left: 5px solid #0a7d3f;
}

.itosgps-notice-warn {
	background: #fdf0d5;
	color: #7a5200;
	border-left: 5px solid #c58a00;
}

.itosgps-notice-error {
	background: #fae3e3;
	color: #8a1f1f;
	border-left: 5px solid #b3261e;
}

/* The offline banner. Not an error -- offline is the NORMAL state in the field,
   and styling it red would train reps to ignore red. */
.itosgps-offline-banner {
	background: var(--colorbacktitle1, #eee);
	color: var(--colortexttitle, #333);
	padding: 0.6rem 1rem;
	border-radius: 6px;
	font-weight: 600;
	text-align: center;
}

/* ==========================================================================
   Photo strip
   ========================================================================== */

.itosgps-photos {
	display: flex;
	flex-wrap: wrap;
	gap: 0.5rem;
	margin-top: 0.6rem;
}

.itosgps-thumb {
	position: relative;
	width: 92px;
	height: 92px;
	border-radius: 6px;
	overflow: hidden;
	border: 1px solid var(--inputbordercolor, rgba(0, 0, 0, 0.2));
	background: var(--colorbackgrey, #f0f0f0);
}

.itosgps-thumb img {
	width: 100%;
	height: 100%;
	object-fit: cover;
	display: block;
}

.itosgps-thumb-badge {
	position: absolute;
	left: 0;
	right: 0;
	bottom: 0;
	padding: 2px 4px;
	font-size: 0.68rem;
	font-weight: 700;
	text-align: center;
	background: rgba(0, 0, 0, 0.68);
	color: #fff;
}

.itosgps-thumb-verified .itosgps-thumb-badge {
	background: rgba(10, 125, 63, 0.9);
}

.itosgps-thumb-rejected {
	border-color: #b3261e;
}

.itosgps-thumb-rejected .itosgps-thumb-badge {
	background: rgba(179, 38, 30, 0.9);
}

/* ==========================================================================
   Status badges
   --------------------------------------------------------------------------
   Colour + text, always. Never colour alone. See the header.
   ========================================================================== */

.itosgps-badge {
	display: inline-block;
	padding: 0.2rem 0.55rem;
	border-radius: 4px;
	font-size: 0.8rem;
	font-weight: 700;
	white-space: nowrap;
	border: 1px solid transparent;
}

/* Visit: 0 planned, 1 checked in, 2 done, 8 missed, 9 canceled */
.itosgps-badge-visit-0 { background: #e8eaf0; color: #3a4256; border-color: #c3c9d8; }
.itosgps-badge-visit-1 { background: #fdf0d5; color: #7a5200; border-color: #e0bd6b; }
.itosgps-badge-visit-2 { background: #e2f4e9; color: #0a5d31; border-color: #85c9a4; }
.itosgps-badge-visit-8 { background: #fae3e3; color: #8a1f1f; border-color: #d99; }
.itosgps-badge-visit-9 { background: #eee; color: #666; border-color: #ccc; text-decoration: line-through; }

/* Route: 0 draft, 1 planned, 2 active, 3 done, 9 canceled */
.itosgps-badge-route-0 { background: #eee; color: #555; border-color: #ccc; }
.itosgps-badge-route-1 { background: #e8eaf0; color: #3a4256; border-color: #c3c9d8; }
.itosgps-badge-route-2 { background: #fdf0d5; color: #7a5200; border-color: #e0bd6b; }
.itosgps-badge-route-3 { background: #e2f4e9; color: #0a5d31; border-color: #85c9a4; }
.itosgps-badge-route-9 { background: #eee; color: #666; border-color: #ccc; text-decoration: line-through; }

/* Mileage: 0 open, 1 submitted, 2 approved, 9 rejected */
.itosgps-badge-mileage-0 { background: #eee; color: #555; border-color: #ccc; }
.itosgps-badge-mileage-1 { background: #fdf0d5; color: #7a5200; border-color: #e0bd6b; }
.itosgps-badge-mileage-2 { background: #e2f4e9; color: #0a5d31; border-color: #85c9a4; }
.itosgps-badge-mileage-9 { background: #fae3e3; color: #8a1f1f; border-color: #d99; }

/* Device: 0 inactive, 1 active, 9 revoked */
.itosgps-badge-device-0 { background: #eee; color: #555; border-color: #ccc; }
.itosgps-badge-device-1 { background: #e2f4e9; color: #0a5d31; border-color: #85c9a4; }
.itosgps-badge-device-9 { background: #fae3e3; color: #8a1f1f; border-color: #d99; }

/* Geofence outcome. "Outside the fence" is a FACT, not an accusation -- see
   llx_itosgps_visit.sql. Styled as information (amber), never as a violation
   (red), because the customer's stored coordinates are very often the thing
   that is wrong. */
.itosgps-fence-ok { color: #0a5d31; font-weight: 600; }
.itosgps-fence-out { color: #7a5200; font-weight: 600; }

/* ==========================================================================
   Map
   --------------------------------------------------------------------------
   The no-basemap case is the DEFAULT and must look deliberate, not broken. A
   neutral surface with a faint graticule reads as "a diagram", which is what it
   is. See js/itosgps_map.js for why there is no tile server here.
   ========================================================================== */

.itosgps-map {
	position: relative;
	width: 100%;
	height: 460px;
	min-height: 260px;
	background: var(--colorbackgrey, #f4f5f7);
	border: 1px solid var(--inputbordercolor, rgba(0, 0, 0, 0.2));
	border-radius: 6px;
	overflow: hidden;
	touch-action: none; /* we handle pan/pinch ourselves */
}

.itosgps-map-svg {
	display: block;
	width: 100%;
	height: 100%;
	cursor: grab;
}

.itosgps-map-svg:active {
	cursor: grabbing;
}

.itosgps-map-nobasemap {
	background: var(--colorbackgrey, #f4f5f7);
	background-image:
		linear-gradient(0deg, rgba(128, 128, 128, 0.05) 1px, transparent 1px),
		linear-gradient(90deg, rgba(128, 128, 128, 0.05) 1px, transparent 1px);
	background-size: 24px 24px;
}

.itosgps-grid-line {
	stroke: var(--colortext, #333);
	stroke-opacity: 0.14;
	stroke-width: 1;
	stroke-dasharray: 3 4;
}

.itosgps-grid-label {
	fill: var(--colortext, #333);
	fill-opacity: 0.45;
	font-size: 10px;
	font-family: inherit;
	pointer-events: none;
}

.itosgps-map-scale {
	position: absolute;
	left: 10px;
	bottom: 10px;
	height: 20px;
	border: 2px solid var(--colortext, #333);
	border-top: none;
	font-size: 0.7rem;
	font-weight: 700;
	color: var(--colortext, #333);
	background: rgba(255, 255, 255, 0.55);
	text-align: center;
	line-height: 18px;
	pointer-events: none;
}

.itosgps-map-attrib {
	position: absolute;
	right: 4px;
	bottom: 2px;
	font-size: 0.65rem;
	color: var(--tableforfieldcolor, #666);
	background: rgba(255, 255, 255, 0.6);
	padding: 0 4px;
	pointer-events: none;
}

.itosgps-map-zoom {
	position: absolute;
	right: 10px;
	top: 10px;
	display: flex;
	flex-direction: column;
	gap: 4px;
}

.itosgps-map-zoombtn {
	width: 44px;   /* 44px: the smallest target a phone user can hit reliably */
	height: 44px;
	font-size: 1.4rem;
	font-weight: 700;
	line-height: 1;
	border: 1px solid var(--inputbordercolor, rgba(0, 0, 0, 0.25));
	border-radius: 6px;
	background: var(--inputbackgroundcolor, #fff);
	color: var(--colortext, #333);
	cursor: pointer;
	touch-action: manipulation;
}

/* Map vector layers */
.itosgps-marker {
	stroke: var(--colorwhite, #fff);
	stroke-width: 2;
	fill: #888;
}

.itosgps-marker-customer {
	fill: #4a6fa5;
}

.itosgps-marker-visit {
	fill: #666;
}

.itosgps-visit-status-0 { fill: #8a93a8; }  /* planned    */
.itosgps-visit-status-1 { fill: #c58a00; }  /* checked in */
.itosgps-visit-status-2 { fill: #0a7d3f; }  /* done       */
.itosgps-visit-status-8 { fill: #b3261e; }  /* missed     */
.itosgps-visit-status-9 { fill: #bbb; }     /* canceled   */

/* Out of the geofence: dashed ring. A shape difference, not just a colour one --
   so it survives both colourblindness and a phone screen in direct sunlight. */
.itosgps-visit-outfence {
	stroke: #7a5200;
	stroke-width: 3;
	stroke-dasharray: 3 2;
}

.itosgps-marker-device {
	fill: #b3261e;
	stroke: var(--colorwhite, #fff);
	stroke-width: 3;
}

.itosgps-marker-label {
	fill: var(--colortext, #333);
	font-size: 11px;
	font-family: inherit;
	paint-order: stroke;
	stroke: var(--colorbackbody, #fff);
	stroke-width: 3px;
	stroke-linejoin: round;
	pointer-events: none;
}

.itosgps-trail {
	stroke: #2a5db0;
	stroke-width: 3;
	stroke-opacity: 0.8;
	stroke-linejoin: round;
	stroke-linecap: round;
	fill: none;
}

.itosgps-trail-today {
	stroke: #b3261e;
}

.itosgps-territory {
	stroke: #4a6fa5;
	stroke-width: 2;
	fill: #4a6fa5;
	fill-opacity: 0.12;
}

.itosgps-territory:hover {
	fill-opacity: 0.22;
}

/* ==========================================================================
   Dashboard / boxes
   ========================================================================== */

.itosgps-kpi {
	display: flex;
	flex-wrap: wrap;
	gap: 0.6rem;
}

.itosgps-kpi-tile {
	flex: 1 1 130px;
	min-width: 120px;
	padding: 0.8rem;
	border-radius: 6px;
	background: var(--colorbacklineimpair2, #fff);
	border: 1px solid var(--colorboxstatsborder, #ddd);
	text-align: center;
}

.itosgps-kpi-value {
	display: block;
	font-size: 1.65rem;
	font-weight: 700;
	color: var(--colortexttitle, #333);
	line-height: 1.15;
}

.itosgps-kpi-label {
	display: block;
	font-size: 0.78rem;
	color: var(--tableforfieldcolor, #666);
	margin-top: 0.2rem;
}

.itosgps-box-row {
	display: flex;
	align-items: center;
	gap: 0.4rem;
}

.itosgps-dot {
	display: inline-block;
	width: 9px;
	height: 9px;
	border-radius: 50%;
	flex: 0 0 auto;
}

.itosgps-dot-live { background: #0a7d3f; }
.itosgps-dot-stale { background: #c58a00; }
.itosgps-dot-off { background: #999; }

/* ==========================================================================
   Setup page warnings
   --------------------------------------------------------------------------
   Some settings in this module have consequences the person clicking cannot see
   (tile URL leaks coordinates to a third party; GEOFENCE_BLOCK can stop a rep
   recording a real visit; retention 0 grows a table without bound). Those
   warnings are styled to be READ, not skimmed past.
   ========================================================================== */

.itosgps-setup-warning {
	display: block;
	margin-top: 0.35rem;
	padding: 0.6rem 0.8rem;
	border-left: 4px solid #c58a00;
	background: rgba(197, 138, 0, 0.09);
	color: var(--colortext, #333);
	font-size: 0.87rem;
	line-height: 1.45;
	max-width: 70ch;
}

.itosgps-setup-warning-danger {
	border-left-color: #b3261e;
	background: rgba(179, 38, 30, 0.09);
	font-weight: 600;
}

/* ==========================================================================
   Phone
   --------------------------------------------------------------------------
   Below 768px is the PRIMARY case for the field pages, not an afterthought.
   ========================================================================== */

@media screen and (max-width: 767px) {
	.itosgps-field {
		padding: 0.35rem;
	}

	.itosgps-bigbtn {
		min-height: 64px;      /* even bigger on the device it is actually used on */
		font-size: 1.25rem;
	}

	.itosgps-map {
		height: 62vh;          /* the map is the page: give it the screen */
	}

	.itosgps-thumb {
		width: 78px;
		height: 78px;
	}

	.itosgps-kpi-tile {
		flex: 1 1 45%;
	}

	/* Sticky action bar: the rep scrolls the visit form, and check-in must never
	   scroll off the bottom of a 5-inch screen. */
	.itosgps-actionbar {
		position: sticky;
		bottom: 0;
		z-index: 5;
		padding: 0.5rem;
		background: var(--colorbackbody, #fff);
		border-top: 1px solid var(--inputbordercolor, rgba(0, 0, 0, 0.2));
		box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.08);
	}
}

/* ==========================================================================
   Dark mode
   --------------------------------------------------------------------------
   Dolibarr's own dark mode (THEME_DARKMODEENABLED) rewrites the --color* vars,
   so everything above that uses them follows it with no help from us. What does
   NOT follow are the handful of fixed status tints (which must stay legible on
   a dark surface) and the semi-transparent white overlays on the map chrome
   (which would glow). Those are corrected here.
   ========================================================================== */

@media (prefers-color-scheme: dark) {
	.itosgps-gps-good,
	.itosgps-queue-empty,
	.itosgps-notice-ok { background: rgba(10, 125, 63, 0.22); color: #7fd6a4; }

	.itosgps-gps-searching,
	.itosgps-queue-pending,
	.itosgps-notice-warn { background: rgba(197, 138, 0, 0.22); color: #f0c464; }

	.itosgps-gps-bad,
	.itosgps-notice-error { background: rgba(179, 38, 30, 0.25); color: #f09a95; }

	.itosgps-map-scale,
	.itosgps-map-attrib { background: rgba(0, 0, 0, 0.45); }

	.itosgps-thumb-badge { background: rgba(0, 0, 0, 0.8); }
}

/* Dolibarr's dark mode is a class/attr on <body>, not a media query -- an admin
   can force it on a device whose OS is in light mode. Cover that too, or the
   module would be the one bright rectangle in an otherwise dark ERP. */
body[data-theme="dark"] .itosgps-map-scale,
body[data-theme="dark"] .itosgps-map-attrib,
.dark-mode .itosgps-map-scale,
.dark-mode .itosgps-map-attrib {
	background: rgba(0, 0, 0, 0.45);
}

body[data-theme="dark"] .itosgps-badge,
.dark-mode .itosgps-badge {
	filter: brightness(0.85) saturate(1.1);
}

/* ==========================================================================
   Print
   --------------------------------------------------------------------------
   A mileage claim or a visit report gets printed and stapled to an expense form.
   Buttons and map chrome have no business on that paper.
   ========================================================================== */

@media print {
	.itosgps-bigbtn,
	.itosgps-map-zoom,
	.itosgps-actionbar,
	.itosgps-queue {
		display: none !important;
	}

	.itosgps-map {
		height: 340px;
		border: 1px solid #999;
		page-break-inside: avoid;
	}

	.itosgps-card {
		break-inside: avoid;
	}
}
