/* =============================================================================
	 CYBER_NODE — responsive layer
	 Loaded AFTER base.css + theme (user/admin). Touches ONLY layout/sizing for
	 small screens — the desktop look is left exactly as-is.

	 Goals:
	   · zero horizontal scroll at ANY viewport width
	   · top nav collapses into a burger-driven slide-in drawer (app-like)
	   · wide tables scroll inside their card instead of blowing out the page
	   · comfortable touch targets, tighter paddings on phones
	 ============================================================================= */

/* hard safety net against horizontal scroll everywhere.
   NB: use overflow-x: clip — NOT hidden. `hidden` turns html/body into a
   scroll container, which breaks `position: sticky` (the topbar would stick to
   body instead of the viewport and just scroll away). `clip` cuts the same
   horizontal overflow WITHOUT creating a scroll container, so sticky works.
   Engines without `clip` (old Safari) fall back to `hidden`: still no h-scroll,
   the topbar just won't stick there. */
html, body {
	max-width: 100%;
	overflow-x: hidden;   /* fallback */
	overflow-x: clip;     /* modern: clips overflow, keeps sticky alive */
}
img, svg, video, canvas { max-width: 100%; }

/* -----------------------------------------------------------------------------
	 BURGER BUTTON + DRAWER BACKDROP — hidden on desktop, shown on mobile
	 ----------------------------------------------------------------------------- */
.nav-burger { display: none; }

.nav-backdrop {
	display: none;
	position: fixed;
	inset: 0;
	z-index: 90;
	background: rgba(0, 0, 0, 0.55);
	opacity: 0;
	pointer-events: none;
	transition: opacity .25s ease;
	-webkit-backdrop-filter: blur(1px);
	backdrop-filter: blur(1px);
}

/* =============================================================================
	 TABLE SCROLL CONTAINER
	 forms.js wraps every <table class="tbl"> in <div class="tbl-scroll">.
	 On desktop this is a no-op (table fits). On mobile the wrapper scrolls
	 horizontally so wide tables stay readable and never push the page.
	 ============================================================================= */
.tbl-scroll {
	width: 100%;
	max-width: 100%;
	overflow-x: auto;
	-webkit-overflow-scrolling: touch;
	overscroll-behavior-x: contain;
}
.tbl-scroll::-webkit-scrollbar { height: 7px; }
.tbl-scroll::-webkit-scrollbar-track { background: var(--bg-0); }
.tbl-scroll::-webkit-scrollbar-thumb { background: var(--accent-dim); }
.tbl-scroll::-webkit-scrollbar-thumb:hover { background: var(--accent); }

/* =============================================================================
	 NAV BREAKPOINT — collapse the top nav into a drawer below ~860px
	 (the admin nav alone has 7+ items + logout, so it needs room)
	 ============================================================================= */
@media (max-width: 860px) {

	/* ---- topbar: brand left, burger right, user-info wraps to its own row ---- */
	.topbar {
		position: sticky;
		top: 0;
		z-index: 110;             /* above the drawer so the burger/X stays tappable */
		flex-wrap: wrap;
		gap: 8px 12px;
		padding: 12px 16px;
		margin: 0 0 14px;
		background: var(--bg-0);
		border-bottom: 1px solid var(--line);
	}
	.topbar .left  { order: 0; min-width: 0; }
	.nav-burger    { order: 1; margin-left: auto; }
	.topbar .right {
		order: 2;
		flex-basis: 100%;
		justify-content: flex-start;
		gap: 14px;
		font-size: 11px;
		color: var(--text-dim);
		flex-wrap: wrap;
	}
	.topbar .brand { font-size: 18px; }

	/* ---- the burger itself ---- */
	.nav-burger {
		display: inline-flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		gap: 5px;
		width: 44px;
		height: 44px;
		flex: none;
		padding: 0;
		background: var(--bg-1);
		border: 1px solid var(--line-bright);
		cursor: pointer;
		z-index: 70;                 /* stays tappable above the open drawer */
		transition: border-color .15s;
		clip-path: polygon(0 0, calc(100% - 8px) 0, 100% 8px, 100% 100%, 8px 100%, 0 calc(100% - 8px));
	}
	.nav-burger:hover { border-color: var(--accent); }
	.nav-burger span {
		display: block;
		width: 20px;
		height: 2px;
		background: var(--accent);
		transition: transform .25s ease, opacity .2s ease;
	}
	/* morph into an X while open */
	body.nav-open .nav-burger span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
	body.nav-open .nav-burger span:nth-child(2) { opacity: 0; }
	body.nav-open .nav-burger span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }

	/* ---- nav wrapper collapses to nothing; container becomes the drawer ---- */
	.nav {
		position: relative;
		z-index: 100;             /* lift the whole nav subtree above .page (base z-index:5) and backdrop */
		max-width: none;
		padding: 0;
		margin: 0;
		overflow: visible;
	}
	.nav .container {
		position: fixed;
		top: 0;
		right: 0;
		height: 100vh;
		height: 100dvh;
		width: min(84vw, 320px);
		flex-direction: column;
		flex-wrap: nowrap;
		align-items: stretch;
		gap: 0;
		padding: 64px 0 24px;        /* clear of the floating burger */
		background: var(--bg-1);
		border-left: 1px solid var(--line-bright);
		border-top: 2px solid var(--accent);
		clip-path: none;             /* drawer is a clean rectangle */
		transform: translateX(100%);
		transition: transform .25s cubic-bezier(.2, .9, .3, 1);
		z-index: 100;
		overflow-y: auto;
		-webkit-overflow-scrolling: touch;
		box-shadow: -18px 0 44px rgba(0, 0, 0, .5);
	}
	.nav .container::after { display: none; }   /* hide the desktop corner notch */
	body.nav-open .nav .container { transform: translateX(0); }

	/* drawer links become full-width rows with big touch targets */
	.nav .container a {
		width: 100%;
		gap: 14px;
		padding: 16px 22px;
		font-size: 15px;
		border-bottom: 1px solid var(--line);
	}
	.nav .container a .ico,
	.nav .container a .ico svg { width: 22px; height: 22px; }

	.nav .spacer { display: none; }

	/* logout sits at the bottom, full width, danger-tinted on hover */
	.nav form { width: 100%; }
	.nav form button {
		width: 100%;
		text-align: left;
		padding: 18px 22px;
		font-size: 13px;
	}

	/* show backdrop only while drawer is open */
	.nav-backdrop { display: block; }
	body.nav-open .nav-backdrop { opacity: 1; pointer-events: auto; }

	/* lock page scroll behind the drawer */
	body.nav-open { overflow: hidden; }
}

/* =============================================================================
	 GENERAL MOBILE — spacing, tables, media (<= 768px)
	 ============================================================================= */
@media (max-width: 768px) {

	.page  { padding: 16px; }
	.flash { margin: 12px 16px 0; }

	.card {
		padding: 16px 16px;
		margin-bottom: 16px;
	}
	.card-title { font-size: 14px; }

	/* tables: keep columns intact and let the wrapper scroll horizontally */
	.tbl th, .tbl td { padding: 10px 12px; }
	.tbl-scroll .tbl th,
	.tbl-scroll .tbl td { white-space: nowrap; }

	/* long monospace strings outside tables may wrap */
	.card p code,
	.muted code,
	p code,
	.hash { word-break: break-word; }

	pre, pre.code {
		max-width: 100%;
		overflow-x: auto;
		-webkit-overflow-scrolling: touch;
	}

	/* QR codes and any inline-sized image shrink to fit */
	.qr-wrap img,
	.card img { max-width: 100%; height: auto; }
	.qr-wrap { padding: 8px 0; }

	/* copy row: input on top, button below on tight widths */
	.copy-row { flex-wrap: wrap; }
	.copy-row input[type="text"] { flex: 1 1 100%; }
	.copy-row .btn { flex: 1 1 100%; text-align: center; }

	/* admin terminal: shorter on phones so the input stays in reach */
	.term {
		height: 58vh;
		min-height: 260px;
	}

	/* client / action button rows already wrap — make them comfy */
	.client-buttons .btn,
	.actions .btn-sm { flex: 0 1 auto; }
}

/* =============================================================================
	 SMALL PHONES (<= 440px)
	 ============================================================================= */
@media (max-width: 440px) {

	body { font-size: 13.5px; }

	.page  { padding: 14px 12px; }
	.flash { margin: 10px 12px 0; }
	.card  { padding: 14px 13px; }

	.topbar { padding: 10px 12px; }
	.topbar .brand { font-size: 16px; }
	.topbar .right { font-size: 10.5px; gap: 10px; }

	/* drop the live clock on very small screens to save the top row */
	#clock { display: none; }

	.tbl th, .tbl td { padding: 9px 10px; font-size: 13px; }

	.btn    { padding: 14px 18px; letter-spacing: .14em; }
	.btn-sm { padding: 8px 11px; }

	/* invoice / connection QR a touch smaller so it never crowds the card */
	.qr-wrap img { width: 200px; }

	.auth-wrap { padding: 28px 14px; }
	.auth-card { padding: 26px 20px; }
}

/* =============================================================================
	 ACCESSIBILITY — respect reduced-motion for the drawer
	 ============================================================================= */
@media (prefers-reduced-motion: reduce) {
	.nav .container,
	.nav-burger span,
	.nav-backdrop { transition: none; }
}

/* keyboard focus stays visible on the burger */
.nav-burger:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
