/* =========================================================
   Manage Me Up -- the one shared stylesheet. Every page links it
   (../css/common.css) BEFORE its own <style>, so a page only keeps
   the rules that are specific to it.

   1. Base and page frame  -- all pages
   2. Design tokens        -- all pages
   3. Legacy shared rules  -- the older table-based pages
   4. App pages            -- body.app-page (panels, buttons, badges,
                              tables, forms, modals...). Scoped with
                              :where(.app-page) so Bootstrap pages and
                              older pages are not restyled, and a page's
                              own rule of the same name still wins.
   ========================================================= */

/* ---------- 1. Base and page frame ---------- */
* {
	box-sizing: border-box;
}

body {
	margin: 0;
	display: flex;
	flex-direction: column;
	min-height: 100vh;
	background: #ffffff;
	font-family: 'Inter', sans-serif;
}

/* The header and footer always run edge to edge -- the page body never
   pads them. Content gets its own gutter and a gap below the header. */
app-header, app-footer {
	display: block;
	width: 100%;
	flex-shrink: 0;
}

app-footer {
	margin-top: auto;
}

main {
	flex: 1;
	padding: 0px;
	width: 100%;
	max-width: none;
	margin: 0;
	overflow-x: hidden;
}

/* ---------- 2. Design tokens ---------- */
:root {
	--bg: #f6f7fb;
	--card: #ffffff;
	--text: #1f2937;
	--muted: #6b7280;
	--border: #e5e7eb;
	--primary: #2563eb;
	--primary-soft: #dbeafe;
	--success: #16a34a;
	--success-soft: #dcfce7;
	--danger: #dc2626;
	--danger-soft: #fee2e2;
	--warning: #d97706;
	--warning-soft: #fef3c7;
}

/* ---------- 3. Legacy shared rules (before the app rules, as the
   two files used to load) ---------- */
.body-header {
	text-align: center;
	margin-bottom: 1rem;
}

.body-header h1 {
	margin: 0;
	font-size: 1.8rem;
}

.updated-date {
	display: block;
	text-align: center;
	margin-top: 0.25rem;
	font-size: 0.95rem;
	color: #555;
}

table {
	width: 100%;
	border-collapse: separate;
	/* Essential for border-radius to work on the table */
	border-radius: 10px;
	/* Adjust the value for desired rounding */
	border: 1px solid #ccc;
	/* Add a border for visibility */
	overflow: hidden;
	/* Important to clip content at the rounded corners */
}

table td, table th {
	border-bottom: 1px solid #ccc;
	padding: 10px;
}

/* Remove border from last row cells */
table tr:last-child td {
	border-bottom: 1px solid #ccc;
}

/* Remove border from last row in thead (in case multiple header rows exist) */
table tr:last-child th {
	border-bottom: 1px solid #ccc;
}

th {
	background-color: #f0f0f0;
	text-align: left;
}

.unpaid {
	color: red;
}

.paid {
	color: green;
}

ul {
	list-style-type: disc;
	padding-left: 20px;
}

label {
	display: block;
	margin-bottom: 10px;
}

.amount {
	text-align: right;
}

.center {
	text-align: center;
}

.total {
	text-align: right;
	font-weight: bold;
	/* total row label cell */
	background-color: #f2f2f2;
}

.total-red {
	text-align: right;
	font-weight: bold;
	color: indianred;
}

.total-label-blue {
	text-align: left;
	font-weight: bold;
	color: dodgerblue;
}

.light-green {
	background-color: #d4edda;
}

.orange {
	background-color: #ffe5b4;
}

.red {
	background-color: #f8d7da;
}

.gray {
	background-color: #cccccc;
	/* Negative utilization */
	color: black;
}

.dark-red {
	background-color: #b30000;
	/* Dark red for over-limit */
	color: white;
}

.greenish-red {
	background-color: yellowgreen;
	/* Amber/orange */
	color: black;
}

.green {
	background-color: #d4edda;
	/* Soft green */
	color: black;
}

/* Style for the numeric cells in the total row */
.total-cell {
	font-weight: bold;
	background-color: #f9f9f9;
	/* slightly lighter gray for contrast */
}

/* Show red asterisk only for required fields */
label.form-label:has(+input[required]), label.form-label:has(+select[required]),
	label.form-label:has(+textarea[required]) {
	position: relative;
}

label.form-label:has(+input[required])::after, label.form-label:has(+select[required])::after,
	label.form-label:has(+textarea[required])::after {
	content: " *";
	color: #d32f2f; /* red */
	font-weight: 600;
	font-size: 0.85em; /* slightly smaller */
	vertical-align: top; /* aligns neatly with text */
	margin-left: 2px; /* small spacing from label text */
}

.page-header-title {
	margin: 0 0 8px 0;
	font-size: 20px;
	font-weight: 600;
}

.page-header-sub {
	color: var(--muted);
	font-size: 14px;
}

#totalBalance {
	font-size: 18px;
	font-weight: 600;
	color: #0b1220;
}

.balance-number {
	color: #ef4444;
	font-weight: 600;
}

/* ---------- 4. App pages ---------- */
/* body:where() keeps a page's own "body { ... }" rule able to override this */
body:where(.app-page) {
	font-family: "Inter", Arial, sans-serif;
	background: var(--bg);
	color: var(--text);
}

/* 24px below the header and at the sides; pages may lower max-width */
:where(.app-page) .page {
	width: calc(100% - 48px);
	max-width: 1300px;
	margin: 24px auto 32px;
	display: grid;
	grid-template-columns: minmax(0, 1fr);  /* never wider than the screen */
	gap: 24px;
}

:where(.app-page) .panel {
	background: var(--card);
	border: 1px solid var(--border);
	border-radius: 16px;
	padding: 20px;
	box-shadow: 0 4px 14px rgba(0, 0, 0, 0.04);
	min-width: 0;
}

:where(.app-page) .panel-title-row {
	display: flex;
	justify-content: space-between;
	align-items: flex-start;
	gap: 16px;
	flex-wrap: wrap;
	margin-bottom: 16px;
}

:where(.app-page) .panel h2 {
	margin: 0 0 4px;
	font-size: 20px;
}

:where(.app-page) .panel h3 {
	margin: 0 0 10px;
	font-size: 14px;
	text-transform: uppercase;
	letter-spacing: .04em;
	color: var(--muted);
}

:where(.app-page) .subtext {
	color: var(--muted);
	font-size: 13px;
}

:where(.app-page) .actions {
	display: flex;
	gap: 8px;
	flex-wrap: wrap;
	align-items: center;
}

/* ---------- Buttons ---------- */

:where(.app-page) .btn {
	border: none;
	border-radius: 10px;
	padding: 9px 16px;
	font-size: 14px;
	font-weight: 600;
	cursor: pointer;
	display: inline-flex;
	align-items: center;
	justify-content: center;
	gap: 6px;
	font-family: inherit;
	text-decoration: none;
}

:where(.app-page) .btn-primary { background: var(--primary); color: #fff; }

:where(.app-page) .btn-secondary { background: #eef2ff; color: #3730a3; }

:where(.app-page) .btn-danger { background: var(--danger-soft); color: #991b1b; }

:where(.app-page) .btn-light { background: #f3f4f6; color: var(--text); }

:where(.app-page) .btn-sm { padding: 6px 12px; font-size: 12px; }

:where(.app-page) .btn-icon {
	width: 30px;
	height: 30px;
	padding: 0;
	font-size: 13px;
}

:where(.app-page) .btn:disabled {
	opacity: .45;
	cursor: not-allowed;
}

/* ---------- Detail tiles ---------- */

:where(.app-page) .detail-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
	gap: 10px 14px;
}

:where(.app-page) .detail-item {
	background: #fafafa;
	border: 1px solid var(--border);
	border-radius: 12px;
	padding: 10px 12px;
	min-width: 0;
}

:where(.app-page) .detail-item .label {
	color: var(--muted);
	font-size: 12px;
	margin-bottom: 4px;
}

:where(.app-page) .detail-item .value {
	font-size: 14px;
	font-weight: 700;
	word-break: break-word;
}

:where(.app-page) .card-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
	gap: 14px;
}

:where(.app-page) .mini-card {
	border: 1px solid var(--border);
	border-radius: 12px;
	padding: 14px;
	background: #fdfdfe;
	min-width: 0;
}

:where(.app-page) .mini-card h4 {
	margin: 0 0 8px;
	font-size: 14px;
}

:where(.app-page) .mini-card ul {
	margin: 0;
	padding-left: 18px;
	font-size: 13px;
	line-height: 1.6;
}

:where(.app-page) .kv {
	display: flex;
	justify-content: space-between;
	gap: 12px;
	font-size: 13px;
	padding: 4px 0;
	border-bottom: 1px dashed var(--border);
}

:where(.app-page) .kv:last-child {
	border-bottom: none;
}

:where(.app-page) .kv span:first-child {
	color: var(--muted);
}

:where(.app-page) .kv span:last-child {
	font-weight: 600;
	text-align: right;
	word-break: break-word;
}

/* ---------- Badges ---------- */

:where(.app-page) .badge {
	display: inline-flex;
	align-items: center;
	border-radius: 999px;
	padding: 3px 10px;
	font-size: 12px;
	font-weight: 700;
	white-space: nowrap;
}

:where(.app-page) .badge-success { background: var(--success-soft); color: #166534; }

:where(.app-page) .badge-warning { background: var(--warning-soft); color: #92400e; }

:where(.app-page) .badge-danger { background: var(--danger-soft); color: #991b1b; }

:where(.app-page) .badge-muted { background: #f3f4f6; color: var(--muted); }

/* ---------- Tables ---------- */

:where(.app-page) .table-wrap {
	overflow-x: auto;
	border: 1px solid var(--border);
	border-radius: 12px;
}

:where(.app-page) table.data-table {
	width: 100%;
	border-collapse: collapse;
	font-size: 13px;
}

:where(.app-page) .data-table th,
:where(.app-page) .data-table td {
	padding: 9px 12px;
	border-bottom: 1px solid var(--border);
	text-align: left;
	vertical-align: top;
}

:where(.app-page) .data-table th {
	background: #f9fafb;
	color: var(--muted);
	font-size: 11px;
	text-transform: uppercase;
	letter-spacing: .04em;
	white-space: nowrap;
}

:where(.app-page) .data-table tr:last-child td {
	border-bottom: none;
}

:where(.app-page) .data-table .num {
	text-align: right;
	white-space: nowrap;
	font-variant-numeric: tabular-nums;
}

:where(.app-page) .data-table tr.total td {
	font-weight: 700;
	background: #f9fafb;
}

:where(.app-page) .data-table tr.section-row td {
	background: #f3f4f6;
	font-weight: 700;
	font-size: 12px;
	text-transform: uppercase;
	letter-spacing: .03em;
	color: #374151;
}

:where(.app-page) .empty-state {
	color: var(--muted);
	font-size: 14px;
	padding: 24px;
	text-align: center;
}

:where(.app-page) .notice {
	border-radius: 12px;
	padding: 12px 16px;
	font-size: 14px;
	display: none;
}

:where(.app-page) .notice.show { display: block; }

:where(.app-page) .notice-success { background: var(--success-soft); color: #166534; }

:where(.app-page) .notice-error { background: var(--danger-soft); color: #991b1b; }

:where(.app-page) .text-success { color: #15803d; }

:where(.app-page) .text-danger { color: #b91c1c; }

:where(.app-page) .pre-line { white-space: pre-line; }

/* ---------- Modal ---------- */

:where(.app-page) .modal-overlay {
	display: none;
	position: fixed;
	inset: 0;
	background: rgba(15, 23, 42, .45);
	align-items: flex-start;
	justify-content: center;
	z-index: 1000;
	padding: 30px 16px;
	overflow-y: auto;
}

:where(.app-page) .modal-overlay.open {
	display: flex;
}

:where(.app-page) .modal-box {
	background: #fff;
	border-radius: 16px;
	width: 100%;
	max-width: 640px;
	padding: 24px;
	box-shadow: 0 20px 50px rgba(0, 0, 0, .2);
}

:where(.app-page) .modal-box.wide {
	max-width: 1100px;
}

:where(.app-page) .modal-box h3 {
	margin-top: 0;
}

:where(.app-page) .modal-box h4 {
	margin: 18px 0 8px;
	font-size: 13px;
	text-transform: uppercase;
	letter-spacing: .04em;
	color: var(--muted);
}

:where(.app-page) .modal-footer {
	display: flex;
	justify-content: flex-end;
	gap: 10px;
	margin-top: 18px;
}

:where(.app-page) .form-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
	gap: 12px 14px;
}

:where(.app-page) .field {
	display: flex;
	flex-direction: column;
	gap: 5px;
	min-width: 0;
}

:where(.app-page) .field.full {
	grid-column: 1 / -1;
}

:where(.app-page) .field label {
	font-size: 12px;
	color: var(--muted);
	font-weight: 600;
}

:where(.app-page) .field input,
:where(.app-page) .field select,
:where(.app-page) .field textarea {
	height: 40px;
	border: 1px solid var(--border);
	border-radius: 10px;
	padding: 0 11px;
	font-size: 14px;
	width: 100%;
	font-family: inherit;
	background: #fff;
}

:where(.app-page) .field textarea {
	height: 84px;
	padding: 9px 11px;
	resize: vertical;
}

:where(.app-page) .checkbox-field {
	display: flex;
	align-items: center;
	gap: 8px;
	font-size: 14px;
}

:where(.app-page) .form-error {
	background: var(--danger-soft);
	color: #991b1b;
	border-radius: 10px;
	padding: 10px 14px;
	font-size: 13px;
	margin-bottom: 14px;
	display: none;
}

:where(.app-page) .form-error.show {
	display: block;
}

/* ---------- Row editor (editable lists in modals) ---------- */

:where(.app-page) .row-editor {
	overflow-x: auto;
}

:where(.app-page) .row-editor table {
	width: 100%;
	border-collapse: collapse;
}

:where(.app-page) .row-editor th {
	font-size: 11px;
	color: var(--muted);
	text-align: left;
	padding: 0 4px 4px;
	white-space: nowrap;
	font-weight: 600;
}

:where(.app-page) .row-editor td {
	padding: 3px 4px;
	vertical-align: middle;
}

:where(.app-page) .row-editor input,
:where(.app-page) .row-editor select,
:where(.app-page) .row-editor textarea {
	width: 100%;
	min-width: 70px;
	height: 34px;
	border: 1px solid var(--border);
	border-radius: 8px;
	padding: 0 8px;
	font-size: 13px;
	font-family: inherit;
	background: #fff;
}

:where(.app-page) .row-editor textarea {
	height: 58px;
	padding: 6px 8px;
	min-width: 200px;
}

:where(.app-page) .row-editor .add-row {
	margin-top: 6px;
}

@media (max-width: 768px) {
	:where(.app-page) .page {
		width: calc(100% - 24px);
		margin: 12px auto 24px;
	}
	:where(.app-page) .panel {
		padding: 14px;
	}
}

/* ---------- Legal pages (privacy-policy.html, terms-of-use.html) ---------- */
:where(.app-page) .legal-layout {
	display: grid;
	grid-template-columns: 240px 1fr;
	gap: 24px;
	align-items: start;
}

:where(.app-page) .legal-toc {
	position: sticky;
	top: 16px;
}

:where(.app-page) .legal-toc ol {
	margin: 0;
	padding-left: 18px;
	font-size: 13px;
	line-height: 1.9;
}

:where(.app-page) .legal-toc a {
	color: var(--text);
	text-decoration: none;
}

:where(.app-page) .legal-toc a:hover {
	color: var(--primary);
}

:where(.app-page) .legal-body {
	font-size: 14px;
	line-height: 1.7;
}

:where(.app-page) .legal-body section {
	scroll-margin-top: 16px;
}

:where(.app-page) .legal-body section + section {
	margin-top: 22px;
	padding-top: 18px;
	border-top: 1px solid var(--border);
}

:where(.app-page) .legal-body h3 {
	font-size: 15px;
	text-transform: none;
	letter-spacing: 0;
	color: var(--text);
	margin: 0 0 6px;
}

:where(.app-page) .legal-body p {
	margin: 0 0 10px;
}

:where(.app-page) .legal-body ul {
	list-style: disc;
	margin: 0 0 10px;
	padding-left: 20px;
}

:where(.app-page) .legal-body a {
	color: var(--primary);
}

@media (max-width: 900px) {
	:where(.app-page) .legal-layout {
		grid-template-columns: 1fr;
	}
	:where(.app-page) .legal-toc {
		position: static;
	}
}

/* ---------- Phones: tables keep readable columns and scroll inside their
   .table-wrap (which already has overflow-x: auto) instead of squeezing
   every column until words break letter by letter ---------- */
@media (max-width: 600px) {
	/* zero specificity: a page's own table min-width (e.g. 720px) still wins */
	:where(.app-page .table-wrap > table.data-table) {
		min-width: 560px;
	}
}

/* flex/grid items default to min-width:auto and would grow to fit such a
   table; let the containers shrink so the table scrolls inside them */
:where(.app-page) .panel-title-row > *,
:where(.app-page) .detail-grid > *,
:where(.app-page) .card-grid > * {
	min-width: 0;
}
