/*
 * DTS design system.
 *
 * Tokens, shell and components from the DocTrack UX mock-up
 * (doctrack_12042026.html). Loaded after sb-admin-2.min.css, which stays only
 * as the Bootstrap 4 base for the grid, utilities, modals and form validation;
 * every Bootstrap component the pages use is restyled here to the design's
 * look. login.html and the error pages load this file on its own, without
 * Bootstrap, so nothing below may depend on Bootstrap being present.
 */

:root {
	--accent: #1D4ED8;
	--accent-dark: #1E3A8A;
	--ink: #111827;
	--muted: #4B5563;
	--line: #E5E7EB;
	--field: #D1D5DB;
	--bg: #F4F5F7;
	--mono: 'JetBrains Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
	--sans: Inter, system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
	/* Bootstrap/SB Admin and loader.css read --primary. */
	--primary: #1D4ED8;
}

* { box-sizing: border-box; }

body {
	margin: 0;
	font-family: var(--sans);
	font-size: 15px;
	line-height: 1.5;
	color: var(--ink);
	background: var(--bg);
}

a { color: var(--accent); }
a:hover { color: var(--accent-dark); }

input:focus, select:focus, textarea:focus, button:focus-visible, a:focus-visible,
.form-control:focus, .btn:focus, .btn.focus {
	outline: 2px solid var(--accent);
	outline-offset: 1px;
	box-shadow: none !important;
}

.sr, .sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	overflow: hidden;
	clip: rect(0 0 0 0);
	white-space: nowrap;
}

.mono { font-family: var(--mono); }
[hidden] { display: none !important; }

h1, h2, h3, h4, h5, h6 { color: var(--ink); font-family: var(--sans); }

/* ---------------------------------------------------------------- shell */

.shell { min-height: 100vh; display: flex; flex-wrap: wrap; }

nav.side {
	flex: 1 1 240px;
	max-width: 100%;
	background: #111827;
	color: #E5E7EB;
	padding: 24px 16px;
	display: flex;
	flex-direction: column;
	gap: 22px;
}

@media (min-width: 761px) {
	nav.side {
		flex: 0 0 248px;
		position: sticky;
		top: 0;
		height: 100vh;
		overflow-y: auto;
	}
}

.brand {
	display: flex;
	align-items: center;
	gap: 12px;
	justify-content: center;
	font-size: 22px;
	font-weight: 700;
	color: var(--ink);
	text-decoration: none;
}

.brand:hover { text-decoration: none; }

.logo {
	width: 40px;
	height: 40px;
	border-radius: 10px;
	background: var(--accent);
	color: #fff;
	display: flex;
	align-items: center;
	justify-content: center;
	flex: none;
}

.side .brand { justify-content: flex-start; font-size: 17px; color: #fff; padding: 0 8px; gap: 10px; }
.side .brand:hover { color: #fff; }
.side .logo { width: 32px; height: 32px; border-radius: 8px; }
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-sub { font-size: 11px; font-weight: 500; color: #9CA3AF; letter-spacing: .01em; }

.sidetop { display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.menubtn {
	display: none;
	width: 44px;
	height: 44px;
	border-radius: 8px;
	border: 1px solid #374151;
	background: none;
	color: #fff;
	align-items: center;
	justify-content: center;
	cursor: pointer;
}

.sidenav { display: flex; flex-direction: column; gap: 2px; }
.navgroup { display: flex; flex-direction: column; gap: 2px; margin: 16px 0; }
.navgroup:first-child { margin-top: 0; }
.navgroup:last-child { margin-bottom: 0; }

.navlabel {
	font-size: 11px;
	font-weight: 600;
	letter-spacing: .08em;
	text-transform: uppercase;
	color: #9CA3AF;
	padding: 0 10px 6px;
}

.navlink {
	display: flex;
	align-items: center;
	gap: 10px;
	min-height: 38px;
	padding: 6px 10px;
	border-radius: 8px;
	color: #D1D5DB;
	text-decoration: none;
	font-size: 14px;
	line-height: 1.25;
}

.navlink i { font-size: 15px; color: #9CA3AF; width: 18px; text-align: center; flex: none; }
.navlink:hover { background: #1F2937; color: #fff; text-decoration: none; }
.navlink:hover i { color: #fff; }
.navlink[aria-current="page"] { background: #1F2937; color: #fff; font-weight: 500; }
.navlink[aria-current="page"] i { color: #93C5FD; }

.who {
	margin-top: auto;
	display: flex;
	flex-direction: column;
	gap: 6px;
	padding: 12px 10px;
	border-top: 1px solid #374151;
}

.who b { font-size: 14px; color: #fff; font-weight: 500; }
.who span { font-size: 12px; color: #9CA3AF; }
.who form { margin: 0; }
.who .linkbtn { font-size: 13px; color: #93C5FD; }
.who .linkbtn:hover { color: #fff; }

.linkbtn {
	border: 0;
	background: none;
	padding: 0;
	font: inherit;
	color: var(--accent);
	cursor: pointer;
	text-align: left;
}

.linkbtn:hover { text-decoration: underline; }

main.content {
	flex: 999 1 560px;
	min-width: 0;
	padding: 32px clamp(16px, 3vw, 40px);
	display: flex;
	flex-direction: column;
	gap: 24px;
}

.page { display: flex; flex-direction: column; gap: 24px; }

.pagehead {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	align-items: flex-end;
	gap: 12px;
}

.eyebrow { font-size: 13px; color: var(--muted); }
h1, .h1 { margin: 4px 0 0; font-size: 26px; font-weight: 700; letter-spacing: -.01em; line-height: 1.2; }
h2, .h2 { margin: 0; font-size: 16px; font-weight: 600; line-height: 1.3; }

.appfoot { margin-top: auto; font-size: 12px; color: var(--muted); }

/* ------------------------------------------------------------ components */

.card {
	background: #fff;
	border: 1px solid var(--line);
	border-radius: 12px;
	box-shadow: none;
}

.card.shadow { box-shadow: none !important; }
.pad { padding: 24px; }
.stack { display: flex; flex-direction: column; gap: 18px; }

.cardhead {
	padding: 18px 24px;
	border-bottom: 1px solid var(--line);
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	align-items: center;
	gap: 12px;
}

.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .field label.lbl { font-size: 13px; font-weight: 500; color: #374151; margin: 0; }
.req { color: #B91C1C; }
.hint { font-size: 12px; color: var(--muted); }

.row-flex, .actions { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; }
.actions { justify-content: flex-end; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 24px; align-items: start; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.section { display: flex; flex-direction: column; gap: 14px; padding-top: 20px; border-top: 1px solid var(--line); }
.section:first-child { padding-top: 0; border-top: 0; }

/* Inputs: bare elements and Bootstrap's .form-control share one look. */
input:not([type=checkbox]):not([type=radio]):not([type=hidden]), select, textarea, .form-control {
	font: inherit;
	font-size: 15px;
	border: 1px solid var(--field);
	border-radius: 8px;
	background-color: #fff;
	color: var(--ink);
	max-width: 100%;
	min-width: 0;
}

input:not([type=checkbox]):not([type=radio]):not([type=hidden]), select, .form-control {
	height: 44px;
	padding: 0 12px;
}

textarea, textarea.form-control { height: auto; padding: 10px 12px; resize: vertical; }
.form-control { display: block; width: 100%; }
.form-control::placeholder, input::placeholder, textarea::placeholder { color: #9CA3AF; }
.form-control:disabled, .form-control[readonly], fieldset:disabled .form-control,
input[readonly] { background-color: #F9FAFB; color: var(--muted); opacity: 1; }
.form-control-sm, .input-sm { height: 40px !important; font-size: 14px !important; }

input[type=checkbox] { width: 18px; height: 18px; margin: 0; flex: none; accent-color: var(--accent); }

.check { display: flex; gap: 10px; align-items: center; font-size: 14px; line-height: 1.35; cursor: pointer; margin: 0; }

/* Password field with an inline show/hide button. */
/* Wraps so a Bootstrap .invalid-feedback sibling can drop below the input;
   the toggle is pinned to the input's row, not centred on the whole box. */
.pw { position: relative; display: flex; flex-wrap: wrap; }
.pw input { width: 100%; padding-right: 48px !important; }
.pw .invalid-feedback { margin-top: 6px; }
.pw .pwtoggle {
	position: absolute;
	right: 4px;
	top: 4px;
	width: 36px;
	height: 36px;
	border: 0;
	border-radius: 6px;
	background: none;
	color: var(--muted);
	cursor: pointer;
	display: flex;
	align-items: center;
	justify-content: center;
}

.pw .pwtoggle:hover { background: #F3F4F6; color: var(--ink); }

/* Bootstrap validation, recoloured. */
.invalid-feedback { font-size: 12px; color: #B91C1C; margin-top: 0; }
.was-validated .form-control:invalid, .form-control.is-invalid { border-color: #B91C1C; background-image: none; padding-right: 12px; }
.was-validated .form-control:valid, .form-control.is-valid { border-color: var(--field); background-image: none; padding-right: 12px; }
.was-validated .pw .form-control { padding-right: 48px !important; }
.text-danger { color: #B91C1C !important; }
.text-success { color: #047857 !important; }
.text-muted { color: var(--muted) !important; }

/* Buttons. Bootstrap's modifiers map onto the design's variants. */
.btn {
	height: 44px;
	padding: 0 18px;
	border-radius: 8px;
	border: 1px solid var(--field);
	background: #fff;
	color: var(--ink);
	font: inherit;
	font-size: 14px;
	font-weight: 500;
	line-height: 1;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 8px;
	text-decoration: none;
	white-space: nowrap;
	box-shadow: none;
}

.btn:hover { background: #F9FAFB; color: var(--ink); text-decoration: none; }
.btn:disabled, .btn.disabled { opacity: .6; cursor: not-allowed; }
.btn i { font-size: 15px; }

.btn.primary, .btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover, .btn-primary:hover, .btn-primary:not(:disabled):not(.disabled):active { background: var(--accent-dark); border-color: var(--accent-dark); color: #fff; }
.btn.green, .btn-success { background: #047857; border-color: #047857; color: #fff; font-weight: 600; }
.btn.green:hover, .btn-success:hover { background: #065F46; border-color: #065F46; color: #fff; }
.btn.dark, .btn-dark { background: #111827; border-color: #111827; color: #fff; font-weight: 600; }
.btn.danger, .btn-danger { background: #B91C1C; border-color: #B91C1C; color: #fff; font-weight: 600; }
.btn.danger:hover, .btn-danger:hover { background: #991B1B; border-color: #991B1B; color: #fff; }
.btn-secondary, .btn-outline-secondary, .btn-light { background: #fff; border-color: var(--field); color: var(--ink); }
.btn-secondary:hover, .btn-outline-secondary:hover, .btn-light:hover { background: #F9FAFB; border-color: var(--field); color: var(--ink); }

.btn.sm, .btn-sm { height: 36px; padding: 0 14px; font-size: 13px; }
.btn.link, .btn-link { border: 0; background: none; color: var(--accent); padding: 0 6px; height: 36px; font-weight: 500; }
.btn.link:hover, .btn-link:hover { background: none; color: var(--accent-dark); text-decoration: underline; }
.btn.link.danger, .btn-link.danger { color: #B91C1C; background: none; }
.btn.link.danger:hover, .btn-link.danger:hover { color: #991B1B; }
.btn-block { display: flex; width: 100%; }

/* Status pills (Bootstrap .badge-* map onto them too). */
.pill, .badge {
	font-size: 12px;
	font-weight: 600;
	border-radius: 999px;
	padding: 3px 10px;
	display: inline-block;
	white-space: nowrap;
	line-height: 1.5;
}

.p-blue, .badge-primary, .badge-info { color: #1E40AF; background: #DBEAFE; }
.p-amber, .badge-warning { color: #92400E; background: #FEF3C7; }
.p-green, .badge-success { color: #065F46; background: #D1FAE5; }
.p-gray, .badge-secondary { color: #374151; background: #F3F4F6; }
.p-red, .badge-danger { color: #991B1B; background: #FEE2E2; }

/* Notices (flash messages). */
.notice { border-radius: 10px; padding: 12px 16px; font-size: 14px; margin: 0; }
.notice.ok { background: #ECFDF5; border: 1px solid #A7F3D0; color: #065F46; }
.notice.err { background: #FEF2F2; border: 1px solid #FECACA; color: #991B1B; }
.notice.warn { background: #FFFBEB; border: 1px solid #FDE68A; color: #92400E; }
.notice.info { background: #EFF6FF; border: 1px solid #BFDBFE; color: #1E40AF; }
.alerts { display: flex; flex-direction: column; gap: 10px; }
.alerts:empty { display: none; }

/* Tables. */
.tablewrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; margin: 0; color: var(--ink); }

.tbl th {
	text-align: left;
	color: var(--muted);
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: .04em;
	font-weight: 600;
	padding: 10px 12px;
	background: #F9FAFB;
	white-space: nowrap;
	border: 0;
}

.tbl td { padding: 12px; border-top: 1px solid #F3F4F6; vertical-align: middle; }
.tbl th:first-child, .tbl td:first-child { padding-left: 24px; }
.tbl th:last-child, .tbl td:last-child { padding-right: 24px; }
.tbl tbody tr:hover { background: #FAFAFB; }
.tbl .num { text-align: right; white-space: nowrap; }
.tbl .center { text-align: center; }
.tbl td.mono { white-space: nowrap; }
.tbl td.actions-cell { text-align: right; white-space: nowrap; }
.tbl td.actions-cell .btn { display: inline-flex; }
.empty { padding: 28px 24px !important; text-align: center; color: var(--muted); font-size: 14px; }
.empty i { display: block; font-size: 28px; margin-bottom: 6px; color: #9CA3AF; }
.cellsub { font-size: 12px; color: var(--muted); }

.changes { list-style: none; margin: 0; padding: 0; font-size: 13px; display: flex; flex-direction: column; gap: 4px; }
.changes .before { color: #991B1B; }
.changes .after { color: #065F46; }

/* Search/filter bar inside a card head. */
.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: 0; }
.filters input, .filters select { height: 40px !important; font-size: 14px !important; }
.filters input[type=search], .filters input[type=text] { width: 240px; }
.filters .btn { height: 40px; }

/* Pagination. */
.pager {
	display: flex;
	flex-wrap: wrap;
	justify-content: space-between;
	align-items: center;
	gap: 12px;
	padding: 14px 24px;
	border-top: 1px solid var(--line);
	font-size: 13px;
	color: var(--muted);
}

.pagination { display: flex; gap: 4px; list-style: none; margin: 0; padding: 0; }
.pagination .page-link {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	min-width: 36px;
	height: 36px;
	padding: 0 10px;
	border: 1px solid var(--field);
	border-radius: 8px !important;
	background: #fff;
	color: var(--ink);
	font-size: 13px;
	font-weight: 500;
	margin: 0;
	text-decoration: none;
}

.pagination .page-link:hover { background: #F9FAFB; color: var(--ink); }
.pagination .page-item.active .page-link { background: var(--accent); border-color: var(--accent); color: #fff; }
.pagination .page-item.disabled .page-link { color: #9CA3AF; background: #fff; }

/* Permission grid on the role form. */
.permgrid th.center, .permgrid td.center { text-align: center; width: 110px; }
.permhead { display: flex; justify-content: space-between; align-items: center; gap: 12px; }

/* Avatar initials (user list). */
.avatar-initials {
	display: inline-flex;
	align-items: center;
	justify-content: center;
	width: 34px;
	height: 34px;
	border-radius: 50%;
	background-color: #DBEAFE;
	color: #1E40AF;
	font-size: 12px;
	font-weight: 700;
	flex: 0 0 34px;
}

.usercell { display: flex; align-items: center; gap: 10px; }
.usercell b { font-weight: 500; display: block; }

/* KPI tiles. */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }
.kpi { padding: 20px; display: flex; flex-direction: column; gap: 6px; }
.kpi .k { font-size: 13px; color: var(--muted); }
.kpi .v { font-size: 30px; font-weight: 700; letter-spacing: -.02em; line-height: 1.1; }
.kpi .s { font-size: 12px; color: var(--muted); }

/* Bootstrap modals, restyled as the design's dialog. */
.modal-backdrop.show { background: #111827; opacity: .55; }
.modal-content { border: 0; border-radius: 14px; color: var(--ink); overflow: hidden; }
.modal-header { padding: 20px 24px; border-bottom: 1px solid var(--line); align-items: center; }
.modal-title { font-size: 16px; font-weight: 600; }
.modal-header .close { padding: 0; margin: 0; width: 36px; height: 36px; border-radius: 8px; font-size: 22px; opacity: .6; }
.modal-header .close:hover { opacity: 1; background: #F3F4F6; }
.modal-body { padding: 20px 24px; font-size: 14px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--line); background: #FAFAFA; gap: 8px; }
.modal-footer > * { margin: 0 !important; }

/* ---------------------------------------------------------------- login */

.login { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 48px 20px; }
.login-inner { width: 100%; max-width: 420px; display: flex; flex-direction: column; gap: 28px; }
.login-card { padding: 32px; display: flex; flex-direction: column; gap: 20px; }
.login-card h1 { font-size: 22px; font-weight: 600; margin: 0; }
.login-card .sub { margin: 6px 0 0; font-size: 14px; color: var(--muted); }
.login-foot { text-align: center; font-size: 12px; color: var(--muted); margin: 0; }

/* ----------------------------------------------------------- error page */

.errpage { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 48px 20px; }
.errcard { width: 100%; max-width: 480px; padding: 36px 32px; display: flex; flex-direction: column; gap: 14px; align-items: flex-start; }
.errcard h1 { font-size: 40px; margin: 0; letter-spacing: -.02em; }
.errcard p { margin: 0; color: var(--muted); font-size: 15px; }
.errcard .btn { margin-top: 8px; }

/* --------------------------------------------------------------- mobile */

@media (max-width: 760px) {
	.shell { flex-direction: column; }
	main.content { flex: 1 1 auto; width: 100%; max-width: 100vw; padding: 18px 14px; gap: 18px; }
	.card { min-width: 0; max-width: 100%; }
	nav.side { flex: none; width: 100%; padding: 10px 14px; gap: 12px; position: sticky; top: 0; z-index: 20; }
	.menubtn { display: inline-flex; }
	nav.side:not(.open) .sidenav, nav.side:not(.open) .who { display: none !important; }
	nav.side.open { max-height: 100vh; overflow: auto; }
	.who { margin-top: 0; }
	h1, .h1 { font-size: 22px; }
	.pad { padding: 16px; }
	.cardhead { padding: 14px 16px; }
	.pager { padding: 12px 16px; }
	.filters, .filters input[type=search], .filters input[type=text] { width: 100%; }
	.filters select { flex: 1 1 auto; }
	.tbl th:first-child, .tbl td:first-child { padding-left: 16px; }
	.tbl th:last-child, .tbl td:last-child { padding-right: 16px; }
	.kpi { padding: 16px; }
	.kpi .v { font-size: 24px; }
	.kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
	.login { padding: 24px 14px; }
	.login-card { padding: 22px; }
	.btn { white-space: normal; }

	/* Tables collapse into labelled rows; each <td> carries data-label. */
	.tablewrap table.tbl:not(.keep), .tablewrap table.tbl:not(.keep) tbody { display: block; width: 100%; min-width: 0 !important; }
	.tablewrap table.tbl:not(.keep) thead { display: none; }
	.tablewrap table.tbl:not(.keep) tr { display: block; padding: 10px 0; border-top: 1px solid var(--line); }
	.tablewrap table.tbl:not(.keep) td { display: flex; justify-content: space-between; align-items: center; gap: 12px; border: 0; padding: 4px 16px !important; text-align: right; white-space: normal; }
	.tablewrap table.tbl:not(.keep) td::before { content: attr(data-label); font-family: var(--sans); font-size: 12px; color: var(--muted); text-align: left; flex: none; max-width: 45%; }
	.tablewrap table.tbl:not(.keep) td[data-label=""]::before, .tablewrap table.tbl:not(.keep) td:not([data-label])::before { content: none; }
	.tablewrap table.tbl:not(.keep) td.empty { display: block; text-align: center; }
	.tablewrap table.tbl:not(.keep) td.actions-cell { justify-content: flex-end; }
}

@media (max-width: 420px) { .kpis { grid-template-columns: 1fr; } }

/* Form-level fieldset (view mode disables it); a bare element so the
   rendered tag stays <fieldset disabled="disabled">. */
fieldset { border: 0; padding: 0; margin: 0; min-width: 0; }
form.stack > fieldset { display: flex; flex-direction: column; gap: 18px; }

/* ---- Divisions & flow: the transaction-flow chain ---------------------- */
.chain { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; list-style: none; margin: 0; padding: 0; }
.chipwrap { display: flex; align-items: center; gap: 8px; border-radius: 10px; }
.chip { background: #EFF6FF; color: #1E3A8A; border: 1px solid #BFDBFE; border-radius: 8px; padding: 6px 10px; font-size: 13px; line-height: 1.3; }
.chip.drag { cursor: grab; display: inline-flex; align-items: center; gap: 6px; }
.chip.fixed { background: #F3F4F6; border-color: var(--line); color: #374151; }
.grip { color: #93C5FD; letter-spacing: -2px; font-size: 12px; }
.chain .arrow { color: #6B7280; font-size: 14px; }
.chipwrap.dragging .chip { opacity: .4; }
.chipwrap.dropbefore .chip { box-shadow: -4px 0 0 0 var(--accent); }
.chipwrap.dropafter .chip { box-shadow: 4px 0 0 0 var(--accent); }
