/**
 * AirPlaan shared UI layer.
 *
 * Loaded unconditionally by tpl/start_and_header.php, after the
 * device-specific sheet (style.css or style-mobile.css) and alongside
 * otp.css. Everything here is therefore the ONE place a component is
 * described - desktop and mobile pick up the same cards, buttons,
 * dialogs and toasts instead of each sheet growing its own copy.
 *
 * The palette is taken from the OTP sign-in card so the signed-in
 * pages and the sign-in screen read as the same product.
 *
 * Conventions
 *   - Components are prefixed .ap- and are opt-in: adding this sheet
 *     does not restyle a page that has not asked for it.
 *   - The only global rules are the form-control baseline and the
 *     focus ring, both deliberately conservative (see below).
 */

:root{
	/* Ink */
	--ap-ink:#1a2b4a;
	--ap-ink-soft:#3f4f5a;
	--ap-muted:#6b7787;
	--ap-faint:#8a97a8;

	/* Surfaces and lines */
	--ap-bg:#f6f8f6;
	--ap-surface:#ffffff;
	--ap-surface-sunk:#fbfcfe;
	--ap-line:#e6ecf3;
	--ap-line-strong:#d5dde8;

	/* Accents */
	--ap-brand:#2f6bff;
	--ap-brand-dark:#1e46c8;
	--ap-brand-wash:#eaf1ff;
	--ap-ok:#1e9e5a;
	--ap-ok-wash:#e7f7ee;
	--ap-warn:#b7791f;
	--ap-warn-wash:#fff6e6;
	--ap-danger:#d13b3b;
	--ap-danger-wash:#fdecec;

	/* Shape */
	--ap-r-sm:8px;
	--ap-r-md:12px;
	--ap-r-lg:18px;

	--ap-shadow-sm:0 1px 2px rgba(26,43,74,0.06);
	--ap-shadow-md:0 6px 18px rgba(31,58,110,0.10);
	--ap-shadow-lg:0 16px 40px rgba(31,58,110,0.16);
}

/**
 * Global baseline - kept to two things on purpose.
 *
 * 1. box-sizing on form controls. Dozens of pages set an explicit
 *    width on an input (width:80px on the SDT field, width:22px on the
 *    pax fields). Under content-box any padding we add would widen
 *    them and reflow the tables, so border-box comes first and the
 *    padding stays inside the width the page already asked for.
 * 2. A visible focus ring. Keyboard users currently get whatever the
 *    browser default is, which several of the custom-styled controls
 *    suppress entirely.
 */
input,select,textarea,button{
	box-sizing:border-box;
	font-family:inherit;
}

:focus-visible{
	outline:2px solid var(--ap-brand);
	outline-offset:2px;
	border-radius:4px;
}

/* ------------------------------------------------------------------
 * Panels
 *
 * .block is the duty/myduty panel. Both pages carried their own
 * near-identical copy in an inline <style>; this is the shared one.
 * ------------------------------------------------------------------ */
.block{
	vertical-align:top;
	display:inline-block;
	box-sizing:border-box;
	margin:0 20px 22px 0;
	padding:14px 0 16px 0;
	text-align:left;
	background:var(--ap-surface);
	border:1px solid var(--ap-line);
	border-radius:var(--ap-r-lg);
	box-shadow:var(--ap-shadow-sm);
}
.block>*{margin:0 16px;}

.block h3{
	font-size:13px;
	font-weight:700;
	letter-spacing:0.4px;
	text-transform:uppercase;
	color:var(--ap-ink);
	margin-bottom:2px;
}

/* The "Users in this duty" / "Click the name to add" lines under each
   heading are captions, not body copy - they were competing with the
   data for attention. */
.block h3+p{
	margin-top:0;
	margin-bottom:12px;
	font-size:12px;
	color:var(--ap-muted);
}

/* ------------------------------------------------------------------
 * Action tiles
 *
 * Replaces the ~200-character inline style that was pasted onto every
 * page-level action link. One class, one place to change the size.
 * ------------------------------------------------------------------ */
.ap-actions{
	display:flex;
	flex-wrap:wrap;
	justify-content:center;
	gap:10px;
	margin:0 auto 26px auto;
}

.ap-action{
	display:flex;
	flex-direction:column;
	align-items:center;
	justify-content:center;
	gap:4px;
	box-sizing:border-box;
	width:112px;
	min-height:76px;
	padding:10px 6px;
	text-align:center;
	text-decoration:none;
	font-size:11px;
	line-height:1.25;
	color:var(--ap-ink);
	background:var(--ap-surface);
	border:1px solid var(--ap-line-strong);
	border-radius:var(--ap-r-md);
	box-shadow:var(--ap-shadow-sm);
	cursor:pointer;
	transition:transform .12s ease, box-shadow .12s ease, border-color .12s ease, background .12s ease;
}
.ap-action:hover{
	color:var(--ap-ink);
	border-color:var(--ap-brand);
	background:var(--ap-brand-wash);
	box-shadow:var(--ap-shadow-md);
	transform:translateY(-1px);
}
.ap-action:active{transform:translateY(0);box-shadow:var(--ap-shadow-sm);}

.ap-action .ap-action-icon{
	font-size:24px;
	line-height:1;
	color:var(--ap-brand);
}

.ap-action--primary{
	color:#ffffff;
	background:linear-gradient(135deg,var(--ap-brand) 0%,var(--ap-brand-dark) 100%);
	border-color:var(--ap-brand-dark);
}
.ap-action--primary:hover{
	color:#ffffff;
	background:linear-gradient(135deg,var(--ap-brand-dark) 0%,var(--ap-brand-dark) 100%);
}
.ap-action--primary .ap-action-icon{color:#ffffff;}

.ap-action--danger:hover{
	border-color:var(--ap-danger);
	background:var(--ap-danger-wash);
}
.ap-action--danger .ap-action-icon{color:var(--ap-danger);}

/* ------------------------------------------------------------------
 * Buttons
 * ------------------------------------------------------------------ */
.ap-btn{
	display:inline-flex;
	align-items:center;
	justify-content:center;
	gap:6px;
	padding:9px 16px;
	font-size:13.5px;
	font-weight:600;
	line-height:1.2;
	color:var(--ap-ink);
	background:var(--ap-surface);
	border:1px solid var(--ap-line-strong);
	border-radius:10px;
	cursor:pointer;
	transition:background .15s ease, border-color .15s ease, color .15s ease;
}
.ap-btn:hover{background:var(--ap-surface-sunk);border-color:var(--ap-faint);}

.ap-btn--primary{
	color:#ffffff;
	background:linear-gradient(135deg,var(--ap-brand) 0%,var(--ap-brand-dark) 100%);
	border-color:var(--ap-brand-dark);
}
.ap-btn--primary:hover{background:var(--ap-brand-dark);}

.ap-btn--danger{
	color:#ffffff;
	background:var(--ap-danger);
	border-color:var(--ap-danger);
}
.ap-btn--danger:hover{background:#b73232;border-color:#b73232;}

.ap-btn--ghost{background:transparent;border-color:transparent;color:var(--ap-muted);}
.ap-btn--ghost:hover{background:var(--ap-surface-sunk);color:var(--ap-ink);}

.ap-btn:disabled{opacity:.55;cursor:not-allowed;}

/* ------------------------------------------------------------------
 * Wide-table scroller
 *
 * .scrl_h existed only in style-mobile.css, so on desktop the flights
 * table simply ran off the page - and html{overflow-x:hidden} meant
 * the far columns were unreachable rather than merely awkward. This
 * makes the rule apply on every viewport.
 * ------------------------------------------------------------------ */
.scrl_h,
.ap-scroll-x{
	width:100%;
	max-width:100%;
	overflow-x:auto;
	-webkit-overflow-scrolling:touch;
}
/* width:auto, not 100%: inside .block the scroller carries the panel's
   16px side margins, and a 100% width would then push past the card. */
.block .scrl_h{width:auto;}

/* ------------------------------------------------------------------
 * Data tables
 * ------------------------------------------------------------------ */
.ap-table{
	border-collapse:separate;
	border-spacing:0;
	font-size:13px;
	background:var(--ap-surface);
}
.ap-table th,
.ap-table td{
	border:0;
	border-bottom:1px solid var(--ap-line);
	padding:6px 8px;
	text-align:center;
	white-space:nowrap;
}
.ap-table thead th{
	position:sticky;
	top:0;
	z-index:2;
}
.ap-table thead th,
.ap-table tr.flight_header th{
	background:var(--ap-brand-wash);
	color:var(--ap-ink);
	font-size:11px;
	font-weight:700;
	letter-spacing:0.3px;
	text-transform:uppercase;
	border-bottom:1px solid var(--ap-line-strong);
}
.ap-table tbody tr:nth-child(even) td,
.ap-table tr.flight:nth-of-type(even) td{background:var(--ap-surface-sunk);}
.ap-table tbody tr:hover td,
.ap-table tr.flight:hover td{background:var(--ap-brand-wash);}
.ap-table tr:last-child td{border-bottom:0;}

/* ------------------------------------------------------------------
 * Status markers and badges
 * ------------------------------------------------------------------ */
.ap-badge{
	display:inline-block;
	padding:3px 10px;
	font-size:11px;
	font-weight:700;
	letter-spacing:0.5px;
	text-transform:uppercase;
	border-radius:999px;
	color:var(--ap-ink);
	background:var(--ap-brand-wash);
	border:1px solid var(--ap-line-strong);
}
.ap-badge--ok{color:var(--ap-ok);background:var(--ap-ok-wash);border-color:#bfe6cf;}
.ap-badge--warn{color:var(--ap-warn);background:var(--ap-warn-wash);border-color:#f0dcb4;}
.ap-badge--danger{color:var(--ap-danger);background:var(--ap-danger-wash);border-color:#f3c9c9;}

/* The retimed dot and the overlap triangle in the flights table were
   bare glyphs in the page text colour - they read as punctuation. */
.sdt_retimed{
	color:var(--ap-brand);
	font-size:10px;
	vertical-align:middle;
	cursor:help;
}
.sdt_clash{
	color:var(--ap-warn);
	font-size:13px;
	vertical-align:middle;
	cursor:help;
}

.ap-empty{
	margin:20px auto;
	padding:22px;
	max-width:420px;
	text-align:center;
	font-size:13.5px;
	color:var(--ap-muted);
	background:var(--ap-surface);
	border:1px dashed var(--ap-line-strong);
	border-radius:var(--ap-r-lg);
}

/* ------------------------------------------------------------------
 * Page head
 * ------------------------------------------------------------------ */
.ap-pagehead{
	margin:0 auto 22px auto;
	text-align:center;
}
.ap-pagehead h2{
	margin:0 0 4px 0;
	font-family:"times new roman",Times,serif;
	font-style:italic;
	font-size:2em;
	color:var(--ap-ink);
}
.ap-pagehead .ap-pagehead-sub{
	margin:0;
	font-size:13px;
	color:var(--ap-muted);
}

/* ==================================================================
 * Dialogs and toasts - the replacement for window.alert / confirm
 *
 * Driven entirely by js/ui.js. The markup it builds is:
 *
 *   .ap-modal[data-tone]        backdrop, fixed, covers the viewport
 *     .ap-modal-card            role=alertdialog
 *       .ap-modal-icon
 *       .ap-modal-title
 *       .ap-modal-body          one <p> per line of the message
 *       .ap-modal-actions       cancel first in DOM, confirm last
 * ================================================================== */
.ap-modal{
	position:fixed;
	inset:0;
	z-index:10000;
	display:flex;
	align-items:center;
	justify-content:center;
	padding:16px;
	background:rgba(16,26,45,0.55);
	-webkit-backdrop-filter:blur(2px);
	backdrop-filter:blur(2px);
	opacity:0;
	transition:opacity .16s ease;
}
.ap-modal.is-open{opacity:1;}

.ap-modal-card{
	box-sizing:border-box;
	width:100%;
	max-width:min(440px, calc(100vw - 32px));
	max-height:calc(100vh - 32px);
	overflow-y:auto;
	padding:26px 26px 20px 26px;
	text-align:center;
	background:var(--ap-surface);
	border:1px solid var(--ap-line);
	border-radius:var(--ap-r-lg);
	box-shadow:var(--ap-shadow-lg);
	transform:translateY(8px) scale(.98);
	transition:transform .16s ease;
}
.ap-modal.is-open .ap-modal-card{transform:none;}

.ap-modal-icon{
	display:inline-flex;
	align-items:center;
	justify-content:center;
	width:52px;
	height:52px;
	margin-bottom:12px;
	font-size:24px;
	line-height:1;
	border-radius:50%;
	color:var(--ap-brand);
	background:var(--ap-brand-wash);
}
.ap-modal[data-tone="warn"] .ap-modal-icon{color:var(--ap-warn);background:var(--ap-warn-wash);}
.ap-modal[data-tone="danger"] .ap-modal-icon{color:var(--ap-danger);background:var(--ap-danger-wash);}
.ap-modal[data-tone="ok"] .ap-modal-icon{color:var(--ap-ok);background:var(--ap-ok-wash);}

.ap-modal-title{
	margin:0 0 6px 0;
	font-size:18px;
	font-weight:700;
	color:var(--ap-ink);
}

.ap-modal-body{
	margin:0 0 20px 0;
	font-size:13.5px;
	line-height:1.55;
	color:var(--ap-ink-soft);
	text-align:left;
}
.ap-modal-body p{margin:0 0 8px 0;}
.ap-modal-body p:last-child{margin-bottom:0;}
.ap-modal-body ul{
	margin:6px 0 10px 0;
	padding-left:20px;
	list-style:disc;
}
.ap-modal-body li{margin:2px 0;}

/* The "this overlaps ..." block in the SDT dialog. */
.ap-modal-note{
	margin:12px 0 0 0;
	padding:10px 12px;
	font-size:12.5px;
	text-align:left;
	border-radius:var(--ap-r-sm);
	color:var(--ap-warn);
	background:var(--ap-warn-wash);
	border:1px solid #f0dcb4;
}
.ap-modal-note strong{display:block;margin-bottom:4px;color:var(--ap-ink);}

.ap-modal-actions{
	display:flex;
	justify-content:flex-end;
	gap:8px;
	flex-wrap:wrap;
}
.ap-modal-actions .ap-btn{min-width:96px;}

@media (max-width:480px){
	.ap-modal-card{padding:22px 18px 16px 18px;}
	.ap-modal-actions{flex-direction:column-reverse;}
	.ap-modal-actions .ap-btn{width:100%;}
}

/* Toasts - for "saved" style confirmations that do not need a button. */
.ap-toasts{
	position:fixed;
	right:16px;
	bottom:16px;
	z-index:10001;
	display:flex;
	flex-direction:column;
	align-items:flex-end;
	gap:8px;
	pointer-events:none;
}
.ap-toast{
	display:flex;
	align-items:center;
	gap:9px;
	max-width:min(360px, calc(100vw - 32px));
	padding:11px 15px;
	font-size:13px;
	text-align:left;
	color:var(--ap-ink);
	background:var(--ap-surface);
	border:1px solid var(--ap-line);
	border-left:4px solid var(--ap-brand);
	border-radius:var(--ap-r-md);
	box-shadow:var(--ap-shadow-md);
	opacity:0;
	transform:translateY(8px);
	transition:opacity .18s ease, transform .18s ease;
	pointer-events:auto;
}
.ap-toast.is-open{opacity:1;transform:none;}
.ap-toast[data-tone="ok"]{border-left-color:var(--ap-ok);}
.ap-toast[data-tone="warn"]{border-left-color:var(--ap-warn);}
.ap-toast[data-tone="danger"]{border-left-color:var(--ap-danger);}
.ap-toast-icon{font-size:15px;line-height:1;}

/* Set on <html> while a dialog is open so the page behind cannot scroll. */
.ap-modal-lock{overflow:hidden;}

@media (prefers-reduced-motion:reduce){
	.ap-modal,
	.ap-modal-card,
	.ap-toast,
	.ap-action{transition:none;}
	.ap-action:hover{transform:none;}
}

/* Nothing in this layer belongs on paper. */
@media print{
	.ap-modal,.ap-toasts,.ap-actions{display:none!important;}
}

/* ==================================================================
 * Duty page
 *
 * The selectors below repeat the ones in style.css / style-mobile.css
 * on purpose. Those two sheets each carry their own copy of the duty
 * table rules at a specificity classes cannot reach (two IDs), so the
 * only way to restyle both from one place is to match them and rely on
 * ui.css loading last. Column widths stay where they are - they differ
 * between the desktop and mobile sheets and are not a design concern.
 * ================================================================== */

/* Panels: a wrapping row of cards.
 *
 * They were inline-blocks in source order, so the row broke wherever
 * the content happened to run out and left ragged holes between the
 * cards. The form is the flex container instead - its other children
 * are hidden inputs, <script> and <style>, none of which lay out - and
 * the one full-width panel opts out with .block--wide. */
.duty-page form#duty{
	display:flex;
	flex-wrap:wrap;
	align-items:flex-start;
	gap:16px;
}
.duty-page .block{
	margin:0;
	min-width:230px;
}
.duty-page form#duty>.duty_type,
.duty-page form#duty>.ap-empty,
.duty-page form#duty>.block--wide{
	flex:0 0 100%;
	width:100%;
}
/* On the create-duty screen the type selector is the first thing to
   fill in, so it gets its own row above the cards. */
.duty-page form#duty>.duty_type{margin:0 0 4px 0;}

/* The flights panel is the full-width one - it holds the scroller. */
.block--wide{
	display:block;
	width:100%;
	margin-right:0;
}

.duty-page .ap-pagehead-sub .ap-badge{vertical-align:middle;}
.duty-page .ap-pagehead-dates{
	margin-left:8px;
	font-variant-numeric:tabular-nums;
	color:var(--ap-ink-soft);
}
.duty-page .ap-pagehead-flag{
	margin-left:8px;
	font-size:11px;
	font-weight:700;
	letter-spacing:0.5px;
	text-transform:uppercase;
	color:var(--ap-ok);
}

/* Inline editors in the flights table (SDT, alternates, level). These
   replace per-element inline widths; data-prev holds the saved value so
   a cancelled dialog can put the cell back. */
.ap-cell-input,
.ap-cell-select{
	width:100%;
	min-width:64px;
	max-width:92px;
	padding:3px 4px;
	text-align:center;
	font-size:13px;
	color:var(--ap-ink);
	background:var(--ap-surface);
	border:1px solid transparent;
	border-radius:6px;
	transition:border-color .12s ease, background .12s ease;
}
.ap-cell-input{text-transform:uppercase;}
/* A time input carries a picker glyph (and AM/PM in some locales). */
.ap-cell-input[type="time"]{max-width:112px;text-transform:none;}
.ap-cell-input:hover,
.ap-cell-select:hover{border-color:var(--ap-line-strong);background:var(--ap-surface-sunk);}
.ap-cell-input:focus,
.ap-cell-select:focus{border-color:var(--ap-brand);background:var(--ap-surface);}

/* A departure time that no longer matches the filed flight plan. */
.ap-cell-input.is-retimed{
	font-weight:700;
	color:var(--ap-brand);
}

/* Flights table treatment. Same selectors as the device sheets, so this
   wins by source order on desktop and on mobile alike. */
form#duty div#flights table{border-collapse:separate;border-spacing:0;}

form#duty div#flights table tr.flight_header{background:var(--ap-brand-wash);}
form#duty div#flights table tr.flight_header th{
	font-size:11px;
	font-weight:700;
	letter-spacing:0.3px;
	text-transform:uppercase;
	color:var(--ap-ink);
}
form#duty div#flights table th,
form#duty div#flights table td{
	border:0;
	border-bottom:1px solid var(--ap-line);
	padding:4px 6px;
	text-align:center;
	white-space:nowrap;
}
form#duty div#flights table tr.flight_header th{
	border-bottom:1px solid var(--ap-line-strong);
}
/* Vertical rules only between the column groups a reader actually
   needs separated - a full grid on a 30-column table is noise. */
form#duty div#flights table td.icao_route,
form#duty div#flights table th.icao_route,
form#duty div#flights table td.reg,
form#duty div#flights table th.reg{
	border-right:1px solid var(--ap-line);
}
form#duty div#flights table tr.flight:nth-of-type(even) td{background:var(--ap-surface-sunk);}
form#duty div#flights table tr.flight:hover td{background:var(--ap-brand-wash);}
form#duty div#flights table td.flight_number{
	font-weight:700;
	color:var(--ap-ink);
}
form#duty div#flights table td.sdt,
form#duty div#flights table td.sat,
form#duty div#flights table td.blkoff,
form#duty div#flights table td.takeoff,
form#duty div#flights table td.landing,
form#duty div#flights table td.blkon{font-variant-numeric:tabular-nums;}

/* The totalizer rows printed by printTotalizer(). */
form#duty div#flights table tr.totalizer td{
	font-weight:700;
	background:var(--ap-brand-wash);
	border-top:1px solid var(--ap-line-strong);
}

/* Crew list. */
form#duty ul#duty_users li{
	display:flex;
	align-items:center;
	gap:8px;
	padding:4px 0;
	border-bottom:1px solid var(--ap-line);
}
form#duty ul#duty_users li:last-child{border-bottom:0;}
form#duty ul#duty_users li span.user{
	font-weight:700;
	letter-spacing:0.5px;
	color:var(--ap-ink);
}
form#duty ul#duty_users li a.remove{
	margin-left:auto;
	font-size:12px;
	color:var(--ap-danger);
	cursor:pointer;
}

/* The two pick-lists ("Available Users to add", "Available Flights"). */
/* Height is a whole number of rows, so the list never stops halfway
   through a name the way the old inline height:102px did. */
form#duty ul#users_available{
	overflow-y:auto;
	max-height:calc(4 * 26px);
	border:1px solid var(--ap-line-strong);
	border-radius:var(--ap-r-sm);
	background:var(--ap-surface-sunk);
	padding:0;
}
form#duty ul#users_available li{
	line-height:26px;
	padding:0 8px;
	cursor:pointer;
}
form#duty ul#users_available li:hover{background:var(--ap-brand-wash);}
form#duty .available_flights select{
	border:1px solid var(--ap-line-strong);
	border-radius:var(--ap-r-sm);
	padding:4px;
	font-family:inherit;
	font-size:12.5px;
}

/* Flight Time Limitations table - a red cell is the whole point of this
   table, so it gets a readable wash instead of pure #f00. */
.ftl th,
.ftl td{border-color:var(--ap-line-strong)!important;}
.ftl td[style*="background:#f00"],
.ftl td[style*="background: #f00"]{
	background:var(--ap-danger-wash)!important;
	color:var(--ap-danger);
	font-weight:700;
}
.ftl .time_limit{
	font-weight:400;
	color:var(--ap-muted);
}

/* The duty-time footer row printed by printDT(). */
form#duty div#flights table tr.fdp td{
	padding:8px;
	text-align:right;
	font-size:12px;
	font-weight:700;
	letter-spacing:0.5px;
	color:var(--ap-ink);
	background:var(--ap-surface-sunk);
	border-top:1px solid var(--ap-line-strong);
	border-bottom:0;
}

/* FPL message panel. */
.fpl_message textarea{
	box-sizing:border-box;
	width:100%;
	min-width:300px;
	height:150px;
	padding:10px 12px;
	font-family:ui-monospace,"SFMono-Regular",Menlo,Consolas,monospace;
	font-size:12.5px;
	line-height:1.5;
	color:var(--ap-ink);
	background:var(--ap-surface-sunk);
	border:1px solid var(--ap-line-strong);
	border-radius:var(--ap-r-sm);
	resize:vertical;
}
.fpl_message textarea:focus{
	outline:none;
	background:var(--ap-surface);
	border-color:var(--ap-brand);
	box-shadow:0 0 0 3px rgba(47,107,255,0.12);
}
.fpl_message>div{margin-top:10px;}
