/**
 * Legal Communications Tools — shared UI component primitives.
 *
 * Plugin-wide, un-scoped CSS for components that any module can reuse.
 *
 * Modules opt in by declaring this stylesheet as a dependency of their
 * own enqueued style handles. Existing module-scoped equivalents in
 * modules/email-signature-generator/assets/tailwind-builder.css remain
 * in place for backward compatibility; new components should be added
 * here.
 *
 * Naming convention: `.lct-<component>` for primitives, `.lct-<component>-<state>`
 * for states (e.g. .lct-spinner, .lct-btn-state.is-busy).
 *
 * @package Legal_Communications_Tools
 */

/* =========================================================================
   Spinner — plugin-wide loading indicator. Inherits currentColor so the
   spinner adopts the host element's foreground.
   ========================================================================= */
.lct-spinner {
	display: inline-block;
	width: 1em;
	height: 1em;
	border: 2px solid currentColor;
	border-right-color: transparent;
	border-radius: 50%;
	animation: lctSpin .8s linear infinite;
	vertical-align: -2px;
}
@keyframes lctSpin {
	to { transform: rotate(360deg); }
}

/* =========================================================================
   Icon glyphs — inline check / x used by button state animations and
   inline flash feedback. Foreground colour via currentColor.
   ========================================================================= */
.lct-icon-check,
.lct-icon-x {
	display: inline-block;
	font-weight: 700;
	line-height: 1;
}

/* =========================================================================
   Button state machine — any module's button can opt into the busy /
   success / error visual phases by toggling .is-busy / .is-success /
   .is-error on a .lct-btn-state element.
   ========================================================================= */
.lct-btn-state {
	transition: transform .15s ease, box-shadow .15s ease, background-color .25s ease, opacity .15s ease;
}
.lct-btn-state.is-busy {
	cursor: progress;
}
.lct-btn-state.is-success {
	background: #16a34a !important;
	background-image: none !important;
	transform: none;
	box-shadow: 0 0 0 3px rgba(22, 163, 74, .25);
	color: #ffffff;
}
.lct-btn-state.is-error {
	background: #dc2626 !important;
	background-image: none !important;
	transform: none;
	box-shadow: 0 0 0 3px rgba(220, 38, 38, .25);
	color: #ffffff;
}

/* =========================================================================
   Visually-hidden text for accessibility (sr-only equivalent). Not scoped
   under .lct-tw so any plugin button or label can use it.
   ========================================================================= */
.lct-sr-only {
	position: absolute;
	width: 1px;
	height: 1px;
	padding: 0;
	margin: -1px;
	overflow: hidden;
	clip: rect(0, 0, 0, 0);
	white-space: nowrap;
	border: 0;
}

/* =========================================================================
   Pill primitive — un-scoped reusable form of the variable-chip badge.
   The email-signature-generator's .lct-pill defined inside
   tailwind-builder.css already has identical declarations; this entry
   exists so other modules can rely on the primitive without coupling to
   that module's stylesheet.
   ========================================================================= */
.lct-pill-base {
	display: inline-flex;
	align-items: center;
	padding: 0.25rem 0.5rem;
	border-radius: 9999px;
	font-size: 0.75rem;
	font-weight: 500;
	background: #f3f4f6;
	color: #374151;
}
.lct-pill-base.is-matched { background: #dcfce7; color: #166534; }
.lct-pill-base.is-missing { background: #fee2e2; color: #991b1b; }
.lct-pill-base.is-unused  { background: #fef3c7; color: #92400e; }

/* =========================================================================
   Card primitive — neutral panel container for tools. Un-scoped so any
   admin page can use it without depending on the .lct-tw wrapper.
   ========================================================================= */
.lct-card-base {
	border: 1px solid #e5e7eb;
	background: #ffffff;
	border-radius: 0.5rem;
	box-shadow: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
	padding: 1.25rem;
}
.lct-card-base > .lct-card-header {
	margin-bottom: 0.5rem;
}

/* =========================================================================
   Inline notice — lightweight status / error / warning callout for any
   admin or shortcode UI.
   ========================================================================= */
.lct-notice {
	padding: 0.5rem 0.75rem;
	border-radius: 0.375rem;
	font-size: 0.875rem;
	border: 1px solid;
}
.lct-notice.is-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.lct-notice.is-error   { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.lct-notice.is-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.lct-notice.is-info    { background: #eff6ff; border-color: #bfdbfe; color: #1d4ed8; }

/* =========================================================================
   Admin page primitives — used by tabbed Settings, Analytics, Logs, and any
   future module admin page. Matches the visual identity of the Email
   Signature builder so the suite feels coherent.
   ========================================================================= */

.lct-admin-wrap {
	max-width: 100%;
	padding-right: 20px;
	margin: 1rem 0;
	color: #111827;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.lct-admin-wrap h1 {
	font-size: 1.5rem;
	font-weight: 600;
	margin: 0 0 .25rem;
	letter-spacing: -.01em;
}

.lct-admin-wrap > .description,
.lct-admin-wrap > p.description {
	color: #6b7280;
	margin: 0 0 1.5rem;
	font-size: .9rem;
}

/* Tab bar — horizontal nav above the active tab body. Uses WP admin's
   nav-tab semantics so screen readers and keyboard nav keep working. */
.lct-admin-tabs {
	display: flex;
	gap: 2px;
	border-bottom: 1px solid #e5e7eb;
	margin: 0 0 1.5rem;
	padding: 0;
	list-style: none;
	flex-wrap: wrap;
}

.lct-admin-tab {
	display: inline-flex;
	align-items: center;
	gap: .4rem;
	padding: .65rem 1.1rem;
	text-decoration: none;
	color: #6b7280;
	font-weight: 500;
	font-size: .9rem;
	border: 1px solid transparent;
	border-bottom: none;
	border-radius: 6px 6px 0 0;
	background: transparent;
	transition: color .15s ease, background-color .15s ease, border-color .15s ease;
	margin-bottom: -1px;
}

.lct-admin-tab:hover,
.lct-admin-tab:focus {
	color: #111827;
	background: #f9fafb;
	outline: none;
	box-shadow: none;
}

.lct-admin-tab.is-active {
	color: #2563eb;
	background: #ffffff;
	border-color: #e5e7eb;
	border-bottom-color: #ffffff;
	cursor: default;
}

.lct-admin-tab-icon {
	width: 1em;
	height: 1em;
	flex-shrink: 0;
}

/* Tab body card — host for the active tab's content. */
.lct-admin-panel {
	background: #ffffff;
	border: 1px solid #e5e7eb;
	border-radius: 10px;
	padding: 24px;
	box-shadow: 0 1px 2px rgba(0,0,0,.04);
}

.lct-admin-panel + .lct-admin-panel {
	margin-top: 1.5rem;
}

.lct-admin-panel h2 {
	font-size: 1.05rem;
	font-weight: 600;
	margin: 0 0 .35rem;
	line-height: 1.3;
}

/* Non-first h2 sections inside a settings tab need vertical breathing
   room so they don't sit flush against the previous form-row's
   border-bottom. Spacing only — NO border-top. The preceding form-row's
   border-bottom already serves as the section divider; adding a
   border-top here would stack two 1px lines into a visible double
   border (same problem the .lct-submit-bar rule had before).
   The :not(:first-of-type) selector works through the <form> wrapper
   that settings tabs use; the older `> h2:not(:first-child)` direct-
   child variant never matched. */
.lct-admin-panel h2:not(:first-of-type) {
	margin-top: 2rem;
	padding-top: 0;
}

.lct-admin-panel .lct-section-description {
	font-size: .85rem;
	color: #6b7280;
	margin: 0 0 1.25rem;
	line-height: 1.5;
}

/* Form-row primitive — replaces the WP form-table layout with a stacked
   label-over-field pattern that's friendlier on narrow screens. */
.lct-form-row {
	display: grid;
	grid-template-columns: minmax(220px, 280px) minmax(0, 1fr);
	gap: 1.5rem;
	align-items: start;
	padding: 1rem 0;
	border-bottom: 1px solid #f3f4f6;
}

.lct-form-row:last-child {
	border-bottom: none;
}

.lct-form-row-label {
	font-weight: 600;
	font-size: .9rem;
	color: #111827;
	padding-top: .35rem;
}

.lct-form-row-label-help {
	display: block;
	font-weight: 400;
	font-size: .8rem;
	color: #6b7280;
	margin-top: .25rem;
	line-height: 1.5;
}

.lct-form-row-control {
	min-width: 0;
}

.lct-form-row-control input[type="text"],
.lct-form-row-control input[type="url"],
.lct-form-row-control input[type="email"],
.lct-form-row-control input[type="number"],
.lct-form-row-control input[type="password"],
.lct-form-row-control select,
.lct-form-row-control textarea {
	width: 100%;
	max-width: 480px;
	padding: .5rem .75rem;
	font-size: .9rem;
	line-height: 1.4;
	border: 1px solid #d1d5db;
	border-radius: 6px;
	background: #ffffff;
	color: #111827;
	box-shadow: none;
}

.lct-form-row-control input[type="text"]:focus,
.lct-form-row-control input[type="url"]:focus,
.lct-form-row-control input[type="email"]:focus,
.lct-form-row-control input[type="number"]:focus,
.lct-form-row-control input[type="password"]:focus,
.lct-form-row-control select:focus,
.lct-form-row-control textarea:focus {
	border-color: #2563eb;
	outline: none;
	box-shadow: 0 0 0 3px rgba(37,99,235,.15);
}

.lct-form-row-control textarea {
	min-height: 120px;
	font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

.lct-form-row-help {
	display: block;
	font-size: .8rem;
	color: #6b7280;
	margin-top: .4rem;
	line-height: 1.5;
}

@media (max-width: 768px) {
	.lct-form-row {
		grid-template-columns: 1fr;
		gap: .5rem;
	}
}

/* Switch / toggle — boolean control with a visual switch instead of a
   raw checkbox. Pure CSS, no JS required.

   The knob (::before) lives on the LABEL, not on the input — browsers
   skip generated content on replaced form elements like <input>. The
   :has() selector propagates the input's :checked state up so we can
   slide the knob from the label level. Requires :has() (Chrome 105+,
   Safari 15.4+, Firefox 121+ — safe for WP admin in 2026). */
.lct-switch {
	position: relative;
	display: inline-flex;
	align-items: center;
	gap: .65rem;
	cursor: pointer;
	user-select: none;
	overflow: hidden;
}

.lct-switch input[type="checkbox"] {
	appearance: none;
	-webkit-appearance: none;
	width: 36px;
	height: 20px;
	background: #d1d5db;
	border-radius: 9999px;
	cursor: pointer;
	margin: 0;
	padding: 0;
	transition: background-color .2s ease;
	flex-shrink: 0;
	border: none;
	box-shadow: none;
	vertical-align: middle;
}

.lct-switch input[type="checkbox"]:checked {
	background: #2563eb;
}

/* Suppress WP admin's `input[type=checkbox]:checked::before` checkmark.
   wp-admin/css/forms.css renders a white SVG check on top of any checked
   checkbox; we need a plain track here, so explicitly disable the
   generated content. */
.lct-switch input[type="checkbox"]::before,
.lct-switch input[type="checkbox"]:checked::before {
	content: none;
	display: none;
}

.lct-switch input[type="checkbox"]:focus-visible {
	outline: none;
	box-shadow: 0 0 0 3px rgba(37,99,235,.25);
}

/* Knob — drawn over the input from the label level so it survives the
   :has() state propagation regardless of browser pseudo-on-input quirks. */
.lct-switch::before {
	content: "";
	position: absolute;
	left: 2px;
	top: 50%;
	width: 16px;
	height: 16px;
	background: #ffffff;
	border-radius: 9999px;
	box-shadow: 0 1px 2px rgba(0,0,0,.15);
	pointer-events: none;
	transform: translate(0, -50%);
	transition: transform .2s ease;
}

.lct-switch:has(input[type="checkbox"]:checked)::before {
	transform: translate(16px, -50%);
}

.lct-switch-label {
	font-size: .9rem;
	color: #111827;
}

/* Submit-bar — sits at the bottom of a settings tab. The preceding
   .lct-form-row's `border-bottom` already provides a visual divider, so
   the submit-bar gets margin / padding only (no border-top) to avoid
   stacking two 1px lines into a visible double border. */
.lct-submit-bar {
	display: flex;
	gap: .75rem;
	align-items: center;
	padding-top: 1.5rem;
	margin-top: 1rem;
}

.lct-btn {
	display: inline-flex;
	align-items: center;
	gap: .4rem;
	padding: .55rem 1.1rem;
	font-size: .9rem;
	font-weight: 500;
	border-radius: 6px;
	border: 1px solid transparent;
	cursor: pointer;
	transition: background-color .15s ease, border-color .15s ease, color .15s ease, box-shadow .15s ease;
	text-decoration: none;
	font-family: inherit;
	line-height: 1.4;
}

.lct-btn-primary {
	background: #2563eb;
	color: #ffffff;
}

.lct-btn-primary:hover,
.lct-btn-primary:focus {
	background: #1d4ed8;
	color: #ffffff;
	outline: none;
	box-shadow: 0 0 0 3px rgba(37,99,235,.25);
}

.lct-btn-secondary {
	background: #ffffff;
	color: #374151;
	border-color: #d1d5db;
}

.lct-btn-secondary:hover,
.lct-btn-secondary:focus {
	background: #f9fafb;
	color: #111827;
	outline: none;
	box-shadow: 0 0 0 3px rgba(209,213,219,.4);
}

.lct-btn-danger {
	background: #ffffff;
	color: #b91c1c;
	border-color: #fecaca;
}

.lct-btn-danger:hover,
.lct-btn-danger:focus {
	background: #fef2f2;
	color: #991b1b;
	outline: none;
	box-shadow: 0 0 0 3px rgba(220,38,38,.2);
}

/* Stat tiles — metric grid used on Analytics + Logs pages. */
.lct-stat-grid {
	display: grid;
	grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
	gap: 1rem;
	margin: 0 0 1.5rem;
}

.lct-stat-tile {
	background: #ffffff;
	border: 1px solid #e5e7eb;
	border-radius: 10px;
	padding: 1rem 1.25rem;
	box-shadow: 0 1px 2px rgba(0,0,0,.04);
}

.lct-stat-tile-value {
	font-size: 1.5rem;
	font-weight: 600;
	line-height: 1.2;
	color: #111827;
}

.lct-stat-tile-label {
	font-size: .8rem;
	color: #6b7280;
	margin-top: .3rem;
}

/* Data table — list-table replacement that matches the rest of the admin
   visual identity. Falls back to WP's wp-list-table styles if a page
   uses both classes. */
.lct-data-table {
	width: 100%;
	background: #ffffff;
	border: 1px solid #e5e7eb;
	border-radius: 8px;
	border-collapse: separate;
	border-spacing: 0;
	overflow: hidden;
	font-size: .88rem;
}

.lct-data-table thead th {
	background: #f9fafb;
	color: #374151;
	font-weight: 600;
	font-size: .75rem;
	text-transform: uppercase;
	letter-spacing: .04em;
	padding: .65rem .85rem;
	text-align: left;
	border-bottom: 1px solid #e5e7eb;
}

.lct-data-table tbody td {
	padding: .65rem .85rem;
	border-bottom: 1px solid #f3f4f6;
	color: #111827;
	vertical-align: middle;
}

.lct-data-table tbody tr:last-child td {
	border-bottom: none;
}

.lct-data-table tbody tr:hover {
	background: #f9fafb;
}

.lct-data-table code {
	font-size: .8rem;
	padding: 2px 6px;
	background: #f3f4f6;
	border-radius: 4px;
	color: #374151;
}

/* Filter bar — sits above a data table. */
.lct-filter-bar {
	display: flex;
	gap: .75rem;
	flex-wrap: wrap;
	align-items: end;
	margin-bottom: 1rem;
	padding: 1rem;
	background: #f9fafb;
	border: 1px solid #e5e7eb;
	border-radius: 8px;
}

.lct-filter-field {
	display: flex;
	flex-direction: column;
	gap: .25rem;
	min-width: 140px;
}

.lct-filter-field label {
	font-size: .75rem;
	font-weight: 600;
	color: #374151;
	text-transform: uppercase;
	letter-spacing: .03em;
}

.lct-filter-field input,
.lct-filter-field select {
	padding: .4rem .6rem;
	font-size: .85rem;
	border: 1px solid #d1d5db;
	border-radius: 6px;
	background: #ffffff;
}

/* Log-level badge — colored chip used by the Logs table to highlight
   severity. Matches the .lct-notice palette. */
.lct-level-badge {
	display: inline-block;
	padding: 2px 8px;
	font-size: .7rem;
	font-weight: 600;
	border-radius: 9999px;
	text-transform: uppercase;
	letter-spacing: .03em;
}

.lct-level-badge.is-error   { background: #fee2e2; color: #991b1b; }
.lct-level-badge.is-warning { background: #fef3c7; color: #92400e; }
.lct-level-badge.is-info    { background: #dbeafe; color: #1d4ed8; }
.lct-level-badge.is-debug   { background: #f3f4f6; color: #4b5563; }
/* Tool-run statuses share the badge palette */
.lct-level-badge.is-completed  { background: #dcfce7; color: #166534; }
.lct-level-badge.is-processing { background: #dbeafe; color: #1d4ed8; }
.lct-level-badge.is-pending    { background: #f3f4f6; color: #4b5563; }
.lct-level-badge.is-failed     { background: #fee2e2; color: #991b1b; }
.lct-level-badge.is-cancelled  { background: #fef3c7; color: #92400e; }

/* Empty-state — shown when a table has zero rows. */
.lct-empty-state {
	padding: 3rem 1rem;
	text-align: center;
	color: #6b7280;
	background: #f9fafb;
	border: 1px dashed #d1d5db;
	border-radius: 8px;
}

.lct-empty-state-title {
	font-size: 1rem;
	font-weight: 600;
	color: #374151;
	margin: 0 0 .25rem;
}

.lct-empty-state-text {
	margin: 0;
	font-size: .85rem;
}

/* =======================================================================
   Token tooltip — pure-CSS popover used by any module to attach a
   hover/focus tooltip to a token-style or label element. Apply
   `class="lct-token-tip"` + `data-tooltip="help text"` to the trigger.
   Lifted from email-signature-generator/assets/tailwind-builder.css so
   every module can use the same component without re-declaring the rules.

   z-index: 100 outranks segmented controls and pill containers. When
   nested inside a clipped container (accordion, overflow:hidden parent),
   the container must transition to overflow:visible after its own open
   animation finishes for the popover to render unclipped.
   ======================================================================= */
.lct-token-tip {
	position: relative;
	display: inline-block;
	cursor: help;
}
.lct-token-tip::after {
	content: attr(data-tooltip);
	position: absolute;
	bottom: 100%;
	left: 0;
	margin-bottom: 8px;
	padding: 8px 10px;
	background: #0f172a;
	color: #f1f5f9;
	border-radius: 6px;
	font-size: 11px;
	line-height: 1.5;
	font-weight: 400;
	font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
	white-space: normal;
	width: max-content;
	max-width: 280px;
	box-shadow: 0 8px 24px rgba(15, 23, 42, .18), 0 2px 4px rgba(15, 23, 42, .08);
	opacity: 0;
	pointer-events: none;
	transform: translateY(4px);
	transition: opacity .18s ease-out, transform .18s ease-out;
	z-index: 100;
}
.lct-token-tip:hover::after,
.lct-token-tip:focus-visible::after {
	opacity: 1;
	transform: translateY(0);
}
