/* Sandhills Portal — responsive portal tiles + Hail dashboard.
   Status palette: clear (green), watch (amber), warning (red). */

:root {
	--sp-clear:   #1a7f37;
	--sp-watch:   #b26a00;
	--sp-warning: #b3261e;
	--sp-clear-bg:   #eaf6ec;
	--sp-watch-bg:   #fdf3e3;
	--sp-warning-bg: #fbeae9;
	--sp-border:  #d8dee4;
	--sp-text:    #1f2328;
	--sp-muted:   #57606a;
	--sp-accent:  #0b5394;
}

/* Light-gray app background on portal/login/hail pages (class added in PHP).
   White cards/tiles stand out against it and the layout reads as a section. */
body.sp-portal-bg { background-color: #f1f3f5; }

.sp-portal,
.sp-hail {
	max-width: 1100px;
	margin: 0 auto 1.5rem;
	/* Top padding clears the theme's floating/transparent header so the
	   portal content doesn't slide underneath it. Adjust if your header
	   height differs. */
	padding: 120px 1rem 2rem;
	color: var(--sp-text);
	font-size: 16px;
	line-height: 1.5;
}

/* ── Login form ──────────────────────────────────────────────────────────── */
.sp-login {
	max-width: 420px;
	/* Top margin clears the theme's floating/transparent header; the gray page
	   background shows above the white login card. */
	margin: 120px auto 3rem;
	padding: 1.75rem;
	background: #fff;
	border: 1px solid var(--sp-border);
	border-radius: 10px;
	box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
	color: var(--sp-text);
	font-size: 16px;
	line-height: 1.5;
}
.sp-login__title { margin: 0 0 1rem; font-size: 1.6rem; }
.sp-login form p { margin: 0 0 0.85rem; }
.sp-login .login-username label,
.sp-login .login-password label {
	display: block;
	margin-bottom: 0.25rem;
	font-weight: 600;
}
.sp-login input[type="text"],
.sp-login input[type="password"] {
	width: 100%;
	box-sizing: border-box;
	padding: 0.55rem 0.65rem;
	border: 1px solid var(--sp-border);
	border-radius: 6px;
	font: inherit;
}
.sp-login .login-remember label { font-weight: 400; }
.sp-login .login-remember input { margin-right: 0.4rem; }
/* Match the site's "Contact Us" button: rounded amber pill that flips to
   charcoal on hover. Colors are the Sandhills brand: #EDAF2A amber, #313B36 charcoal. */
.sp-login .button-primary,
.sp-login #wp-submit {
	display: inline-block;
	background: #EDAF2A;
	color: #313B36;
	border: 1px solid #EDAF2A;
	padding: 0.6rem 1.6rem;
	border-radius: 50px;
	font-weight: 600;
	cursor: pointer;
	transition: background-color 0.2s ease, color 0.2s ease, border-color 0.2s ease;
}
.sp-login .button-primary:hover,
.sp-login .button-primary:focus,
.sp-login #wp-submit:hover,
.sp-login #wp-submit:focus {
	background: #313B36;
	color: #fff;
	border-color: #313B36;
}
.sp-login__lost { margin: 0.75rem 0 0; }
.sp-login__lost a {
	color: #313B36;
	text-decoration: underline;
}
.sp-login__lost a:hover,
.sp-login__lost a:focus { color: #EDAF2A; }
.sp-login--in p { margin: 0 0 0.75rem; }

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.sp-btn {
	display: inline-block;
	padding: 0.5rem 1rem;
	border-radius: 6px;
	text-decoration: none;
	font-weight: 600;
	cursor: pointer;
	border: 1px solid transparent;
}
.sp-btn--ghost {
	background: #fff;
	border-color: var(--sp-border);
	color: var(--sp-accent);
}
.sp-btn--ghost:hover { background: #f3f6f9; }

/* ── Portal header + tiles ───────────────────────────────────────────────── */
.sp-portal__header {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	margin-bottom: 1.25rem;
	flex-wrap: wrap;
}
.sp-portal__welcome { margin: 0; font-size: 1.5rem; }
.sp-portal__empty {
	background: #f6f8fa;
	border: 1px solid var(--sp-border);
	border-radius: 8px;
	padding: 1.25rem;
	color: var(--sp-muted);
}

.sp-tiles {
	display: grid;
	grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
	gap: 1rem;
}
.sp-tile {
	display: flex;
	flex-direction: column;
	gap: 0.4rem;
	padding: 1.25rem;
	border: 1px solid var(--sp-border);
	border-radius: 10px;
	background: #fff;
	text-decoration: none;
	color: var(--sp-text);
	transition: box-shadow 0.15s, transform 0.15s;
}
.sp-tile:hover {
	box-shadow: 0 4px 14px rgba(0,0,0,0.08);
	transform: translateY(-2px);
}
.sp-tile__icon { font-size: 2rem; width: 2rem; height: 2rem; color: var(--sp-accent); }
.sp-tile__label { font-weight: 700; font-size: 1.1rem; }
.sp-tile__desc { color: var(--sp-muted); font-size: 0.9rem; }

.sp-portal__actions { display: inline-flex; gap: 0.5rem; flex-wrap: wrap; }

/* ── Account / change password ───────────────────────────────────────────── */
.sp-account {
	margin-top: 2rem;
	padding: 1.25rem;
	border: 1px solid var(--sp-border);
	border-radius: 10px;
	background: #fff;
	max-width: 420px;
}
.sp-account__title { margin: 0 0 0.75rem; font-size: 1.15rem; }
.sp-account__form { display: flex; flex-direction: column; gap: 0.75rem; }
.sp-account__label { display: flex; flex-direction: column; gap: 0.25rem; font-size: 0.9rem; font-weight: 600; }
.sp-account__label input {
	padding: 0.5rem 0.6rem;
	border: 1px solid var(--sp-border);
	border-radius: 6px;
	font: inherit;
	font-weight: 400;
}
.sp-account__form .sp-btn { align-self: flex-start; background: var(--sp-accent); color: #fff; }
.sp-account__notice {
	margin: 0 0 0.75rem;
	padding: 0.6rem 0.75rem;
	border-radius: 6px;
	font-size: 0.9rem;
}
.sp-account__notice--ok { background: #e7f6ec; border: 1px solid #b6e0c4; color: #14622f; }
.sp-account__notice--err { background: #fdeaea; border: 1px solid #f3c2c2; color: #8a1c1c; }
.sp-account__notice--warn { background: #fff5e0; border: 1px solid #f1d999; color: #6b4e00; }

/* ── Invite user (admins) ────────────────────────────────────────────────── */
.sp-invite {
	margin-top: 2rem;
	padding: 1.25rem;
	border: 1px solid var(--sp-border);
	border-radius: 10px;
	background: #f8fafc;
	max-width: 560px;
}
.sp-invite__title { margin: 0 0 0.25rem; font-size: 1.15rem; }
.sp-invite__sub { margin: 0 0 0.85rem; color: var(--sp-muted); font-size: 0.9rem; }
.sp-invite__form { display: flex; flex-direction: column; gap: 0.75rem; }
.sp-invite__row { display: flex; gap: 0.75rem; flex-wrap: wrap; }
.sp-invite__row .sp-account__label { flex: 1 1 180px; }
.sp-invite__form input[type="email"],
.sp-invite__form input[type="text"] {
	padding: 0.5rem 0.6rem;
	border: 1px solid var(--sp-border);
	border-radius: 6px;
	font: inherit;
	font-weight: 400;
	width: 100%;
	box-sizing: border-box;
}
.sp-invite__apps {
	border: 1px solid var(--sp-border);
	border-radius: 6px;
	padding: 0.6rem 0.85rem;
	margin: 0;
}
.sp-invite__apps legend { font-weight: 600; font-size: 0.9rem; padding: 0 0.25rem; }
.sp-invite__check { display: block; margin: 0.25rem 0; font-size: 0.95rem; }
.sp-invite__check input { margin-right: 0.4rem; }
.sp-invite__form .sp-btn { align-self: flex-start; background: var(--sp-accent); color: #fff; }

/* ── Hail dashboard bar ──────────────────────────────────────────────────── */
.sp-hail__bar {
	display: flex;
	align-items: center;
	justify-content: space-between;
	gap: 1rem;
	flex-wrap: wrap;
	margin-bottom: 1rem;
}
.sp-hail__title { margin: 0; font-size: 1.5rem; }
.sp-hail__meta {
	display: flex;
	align-items: center;
	gap: 1rem;
	color: var(--sp-muted);
	font-size: 0.95rem;
}

/* ── Table (desktop) ─────────────────────────────────────────────────────── */
.sp-hail-table {
	width: 100%;
	border-collapse: collapse;
	background: #fff;
	border: 1px solid var(--sp-border);
	border-radius: 8px;
	overflow: hidden;
}
.sp-hail-table th,
.sp-hail-table td {
	padding: 0.65rem 0.75rem;
	text-align: left;
	border-bottom: 1px solid var(--sp-border);
	vertical-align: middle;
}
.sp-hail-table th {
	background: #f6f8fa;
	font-size: 0.8rem;
	text-transform: uppercase;
	letter-spacing: 0.03em;
	color: var(--sp-muted);
}
.sp-row__name { font-weight: 600; }
.sp-cell--score { font-weight: 700; }

/* Sortable column headers. */
.sp-hail-table th.sp-sortable {
	cursor: pointer;
	user-select: none;
	white-space: nowrap;
}
.sp-hail-table th.sp-sortable:hover { color: var(--sp-text); }
.sp-sort-arrow { color: var(--sp-accent); font-size: 0.7em; }

/* Row tint by overall status. */
.sp-row--warning { background: var(--sp-warning-bg); }
.sp-row--watch   { background: var(--sp-watch-bg); }

/* Per-cell emphasis by that source's status. */
.sp-cell--warning { color: var(--sp-warning); font-weight: 600; }
.sp-cell--watch   { color: var(--sp-watch);   font-weight: 600; }

/* ── Status badge ────────────────────────────────────────────────────────── */
.sp-badge {
	display: inline-block;
	padding: 0.2rem 0.6rem;
	border-radius: 999px;
	font-size: 0.8rem;
	font-weight: 700;
	color: #fff;
}
.sp-badge--clear   { background: var(--sp-clear); }
.sp-badge--watch   { background: var(--sp-watch); }
.sp-badge--warning { background: var(--sp-warning); }

/* ── Mobile: collapse table to cards under 640px ─────────────────────────── */
@media (max-width: 640px) {
	.sp-hail-table thead { display: none; }
	.sp-hail-table,
	.sp-hail-table tbody,
	.sp-hail-table tr,
	.sp-hail-table td { display: block; width: 100%; }
	.sp-hail-table tr {
		margin-bottom: 1rem;
		border: 1px solid var(--sp-border);
		border-radius: 10px;
		overflow: hidden;
	}
	.sp-hail-table td {
		display: flex;
		justify-content: space-between;
		gap: 1rem;
		padding: 0.55rem 0.85rem;
		border-bottom: 1px solid var(--sp-border);
		text-align: right;
	}
	.sp-hail-table td::before {
		content: attr(data-label);
		font-weight: 600;
		color: var(--sp-muted);
		text-align: left;
	}
	.sp-row__name { font-size: 1.05rem; }
}

/* ── Clickable rows + hint ───────────────────────────────────────────────── */
.sp-hail__hint {
	margin: 0 0 0.75rem;
	color: var(--sp-muted);
	font-size: 0.9rem;
}
.sp-row--clickable { cursor: pointer; }
.sp-row--clickable:hover { background: #eef4fb; }
.sp-row--clickable:focus { outline: 2px solid var(--sp-accent); outline-offset: -2px; }

/* ── Detail popup: native <dialog> (browser top layer) ───────────────────── */
.sp-dialog {
	border: none;
	border-radius: 12px;
	padding: 0;
	/* Definite, screen-aware width, wide enough to hold all 5 summary cards on one
	   row. (width:auto pinned to the 720px cap because the wide hourly table forces
	   shrink-to-fit to its max-content; a definite width lets the table lay out
	   INSIDE the dialog instead of dictating its size.) */
	width: min(920px, calc(100vw - 2rem));
	background: #fff;
	color: var(--sp-text);
	box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.sp-dialog::backdrop { background: rgba(0,0,0,0.5); }
/* Fallback positioning for browsers without dialog.showModal() (open attr only):
   keep the popup centered and above the theme header. Harmless when showModal()
   is used, since the top layer handles placement. */
.sp-dialog[open] {
	position: fixed;
	top: 50%;
	left: 50%;
	transform: translate(-50%, -50%);
	margin: 0;
	z-index: 100000;
}
/* Wider dialog for the SPC map; allow the tall map inside. */
/* The map has no intrinsic width (it's width:100%), so give the map dialog a
   definite width capped to the viewport rather than auto-fitting to the title. */
.sp-dialog--map { width: min(1000px, calc(100% - 2rem)); max-width: min(1000px, calc(100% - 2rem)); }
.sp-dialog--map .sp-dialog__inner { max-height: 90vh; }
.sp-dialog__inner {
	position: relative;
	padding: 1.5rem;
	max-height: 85vh;
	overflow-y: auto;
	/* Keep the scroll inside the popup — don't chain it to the page behind. */
	overscroll-behavior: contain;
}

/* ── Detail modal ────────────────────────────────────────────────────────── */
/* Lock the page scroll while a popup is open. The JS pins <body> in place
   (position:fixed + a saved top offset) so the page behind cannot scroll on any
   theme, regardless of which element is the scroll container. The scroll position
   is restored on close. */
html.sp-modal-open { overflow: hidden; }
body.sp-modal-open {
	position: fixed;
	left: 0;
	right: 0;
	width: 100%;
	overflow: hidden;
	overscroll-behavior: none;
}
.sp-modal {
	position: fixed;
	inset: 0;
	z-index: 100000;
	display: flex;
	align-items: flex-start;
	justify-content: center;
	padding: 2rem 1rem;
	overflow-y: auto;
}
.sp-modal[hidden] { display: none; }
.sp-modal__backdrop {
	position: fixed;
	inset: 0;
	background: rgba(0,0,0,0.5);
}
.sp-modal__dialog {
	position: relative;
	background: #fff;
	border-radius: 12px;
	max-width: 720px;
	width: 100%;
	box-shadow: 0 12px 40px rgba(0,0,0,0.25);
	padding: 1.5rem;
	z-index: 1;
}
.sp-modal__close {
	position: absolute;
	top: 0.5rem;
	right: 0.75rem;
	background: none;
	border: none;
	font-size: 1.8rem;
	line-height: 1;
	color: var(--sp-muted);
	cursor: pointer;
}
.sp-modal__close:hover { color: var(--sp-text); }
.sp-modal__head { margin-bottom: 1rem; padding-right: 2rem; }
.sp-modal__head h3 { margin: 0; font-size: 1.5rem; }
.sp-modal__sub { color: var(--sp-muted); font-size: 0.95rem; margin-top: 0.2rem; }
.sp-modal__status { margin-top: 0.5rem; display: flex; align-items: center; gap: 0.6rem; }
.sp-modal__score { font-weight: 700; }
.sp-modal__sec { margin-top: 1.25rem; }
.sp-modal__sec h4 {
	margin: 0 0 0.5rem;
	font-size: 0.85rem;
	text-transform: uppercase;
	letter-spacing: 0.03em;
	color: var(--sp-muted);
	border-bottom: 1px solid var(--sp-border);
	padding-bottom: 0.3rem;
}
.sp-modal__empty { color: var(--sp-muted); font-style: italic; margin: 0; }

/* ── Summary cards (mirror the desktop HourlyDialog card row) ─────────────── */
.sp-cards {
	display: grid;
	/* All five summary cards on a single row (collapses on small screens below). */
	grid-template-columns: repeat(5, minmax(0, 1fr));
	gap: 0.6rem;
	margin-top: 0.25rem;
}
.sp-card {
	border: 1px solid var(--sp-border);
	border-radius: 8px;
	padding: 0.6rem 0.7rem;
	background: var(--sp-clear-bg);
	border-left: 4px solid var(--sp-clear);
}
.sp-card--watch   { background: var(--sp-watch-bg);   border-left-color: var(--sp-watch); }
.sp-card--warning { background: var(--sp-warning-bg); border-left-color: var(--sp-warning); }
.sp-card__title {
	font-size: 0.7rem;
	text-transform: uppercase;
	letter-spacing: 0.02em;
	color: var(--sp-muted);
	margin-bottom: 0.25rem;
}
.sp-card__value { font-weight: 700; font-size: 0.95rem; }

/* Breakdown + hourly tables */
.sp-bd, .sp-hourly {
	width: 100%;
	border-collapse: collapse;
	font-size: 0.9rem;
}
/* Share the container width across columns instead of expanding to content, so
   the table fits inside the dialog rather than forcing it wider. */
.sp-hourly { table-layout: fixed; }
.sp-bd th, .sp-bd td,
.sp-hourly th, .sp-hourly td {
	padding: 0.4rem 0.5rem;
	border-bottom: 1px solid var(--sp-border);
	text-align: left;
}
.sp-bd th, .sp-hourly th {
	font-size: 0.75rem;
	text-transform: uppercase;
	color: var(--sp-muted);
}
.sp-bd__num { text-align: right; white-space: nowrap; }
.sp-bd__bar {
	width: 40%;
	background: #eef1f4;
	border-radius: 4px;
	padding: 0 !important;
}
.sp-bd__fill {
	display: block;
	height: 0.8rem;
	background: var(--sp-accent);
	border-radius: 4px;
	min-width: 2px;
}
.sp-hourly-wrap { max-height: 18rem; overflow-y: auto; overflow-x: auto; overscroll-behavior: contain; border: 1px solid var(--sp-border); border-radius: 6px; }
.sp-hourly th {
	position: sticky;
	top: 0;
	background: #f6f8fa;
	z-index: 1;
}

/* SPC detail */
.sp-spc__line { padding: 0.25rem 0; }
.sp-spc__day { font-weight: 700; color: var(--sp-muted); margin-right: 0.4rem; }

/* NWS alert list */
.sp-alertlist { list-style: none; margin: 0; padding: 0; }
.sp-alertlist__item {
	border-left: 4px solid var(--sp-border);
	padding: 0.5rem 0.75rem;
	margin-bottom: 0.5rem;
	background: #f6f8fa;
	border-radius: 0 6px 6px 0;
}
.sp-alertlist__item--warning { border-left-color: var(--sp-warning); background: var(--sp-warning-bg); }
.sp-alertlist__item--watch   { border-left-color: var(--sp-watch);   background: var(--sp-watch-bg); }
.sp-alertlist__src { color: var(--sp-muted); font-size: 0.85rem; }

/* ── SPC Map modal ───────────────────────────────────────────────────────── */
.sp-modal__dialog--map {
	max-width: 1000px;
	padding: 1.25rem;
}
.sp-map__title { margin: 0 0 0.75rem; font-size: 1.3rem; padding-right: 2rem; }
.sp-map {
	height: 70vh;
	min-height: 360px;
	width: 100%;
	border: 1px solid var(--sp-border);
	border-radius: 8px;
}

/* Leaflet legend panel (bottom-right). */
.sp-map-legend {
	background: #fff;
	padding: 0.5rem 0.7rem;
	border-radius: 6px;
	box-shadow: 0 1px 6px rgba(0,0,0,0.25);
	font-size: 0.8rem;
	line-height: 1.4;
	color: var(--sp-text);
	max-height: 40vh;
	overflow-y: auto;
}
.sp-map-legend__h {
	font-weight: 700;
	margin: 0.35rem 0 0.2rem;
	font-size: 0.78rem;
}
.sp-map-legend__h:first-child { margin-top: 0; }
.sp-map-legend__row { display: flex; align-items: center; gap: 0.4rem; }
.sp-map-legend__sw {
	display: inline-block;
	width: 14px;
	height: 14px;
	border-radius: 3px;
	border: 1px solid rgba(0,0,0,0.25);
	flex: 0 0 auto;
}

/* Snapshot freshness stamp (bottom-left) + data-unavailable warning (top-right). */
.sp-map-stamp {
	background: rgba(255,255,255,0.9);
	border: 1px solid var(--sp-border);
	border-radius: 4px;
	padding: 3px 7px;
	font-size: 0.72rem;
	color: var(--sp-muted);
	max-width: 60vw;
}
.sp-map-warn {
	background: #fff3cd;
	border: 1px solid #ffecb5;
	border-radius: 4px;
	padding: 4px 9px;
	font-size: 0.78rem;
	color: #664d03;
	font-weight: 600;
}

/* Permanent site name labels on the map (mirror the desktop app). */
.leaflet-tooltip.sp-map-label {
	background: rgba(255,255,255,0.92);
	border: 1px solid var(--sp-border);
	border-radius: 3px;
	padding: 1px 5px;
	font-size: 0.72rem;
	font-weight: 600;
	color: var(--sp-text);
	box-shadow: 0 1px 3px rgba(0,0,0,0.2);
	white-space: nowrap;
}
.leaflet-tooltip.sp-map-label::before { display: none; }

@media (max-width: 640px) {
	.sp-modal { padding: 0.5rem; }
	.sp-modal__dialog { padding: 1.1rem; }
	.sp-map { height: 60vh; }
	/* Five cards don't fit on a phone — wrap to a comfortable grid. */
	.sp-cards { grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); }
}
