/* ===================== */
/*  PCW HUB — Variables  */
/* ===================== */
:root {
    color-scheme: light only;
    --primary-green: #16a34a;
    --primary-green-700: #15803d;
    --primary-green-50: #f0fdf4;
    --secondary-blue: #0066ff;
    --text-color: #1f2937;
    --muted-text: #4b5563;
    --subtle-text: #6b7280;
    --background-color: #f8fafc;
    --panel-bg: #ffffff;
    --panel-border: #e2e8f0;
    --panel-border-strong: #cbd5e1;
    --table-border: #e2e8f0;
    --table-row-hover: #f8fafc;
    --table-header-bg: #f1f5f9;
    --input-border: #cbd5e1;
    --input-border-hover: #94a3b8;
    --input-bg: #ffffff;
    --white: #ffffff;
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 14px;
    --radius-pill: 999px;
    --shadow-xs: 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-sm: 0 1px 3px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.04);
    --shadow-md: 0 4px 16px rgba(15, 23, 42, 0.06);
    --shadow-lg: 0 12px 28px rgba(15, 23, 42, 0.1);
    --shadow-xl: 0 24px 48px rgba(15, 23, 42, 0.14);
    --brand-blue-50: #eff6ff;
    --brand-blue-100: #dbeafe;
    --brand-blue-600: #2563eb;
    --brand-blue-700: #1d4ed8;
    --focus-ring: 0 0 0 3px rgba(37, 99, 235, 0.18);
    --danger: #dc2626;
    --danger-50: #fef2f2;
    --warning: #d97706;
    --warning-50: #fffbeb;
    --success: #16a34a;
    --success-50: #f0fdf4;
    --info: #2563eb;
    --info-50: #eff6ff;
    --neutral-50: #f8fafc;
    --neutral-100: #f1f5f9;
    --neutral-200: #e2e8f0;
    --neutral-300: #cbd5e1;
    --neutral-500: #64748b;
    --neutral-700: #334155;
    --sidebar-width: 220px;
    --header-height: 56px;
    --transition-fast: 0.12s ease;
    --transition: 0.18s ease;
    --transition-slow: 0.28s ease;
}

/* ===================== */
/*        Reset          */
/* ===================== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* ===================== */
/*        Base           */
/* ===================== */
html {
    font-size: 16px;
    scroll-behavior: smooth;
}

body {
    font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
    color: var(--text-color);
    background-color: var(--background-color);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
}

a {
    color: var(--brand-blue-600);
    text-decoration: none;
}

a:hover {
    color: var(--brand-blue-700);
    text-decoration: underline;
}

img {
    max-width: 100%;
    display: block;
}

/* ===================== */
/*       Header          */
/* ===================== */
header {
    background-color: var(--panel-bg);
    border-bottom: 1px solid var(--panel-border);
    box-shadow: var(--shadow-md);
    position: sticky;
    top: 0;
    z-index: 100;
    height: var(--header-height);
}

header nav {
    height: 100%;
    padding: 0 1.25rem;
    display: flex;
    align-items: center;
    justify-content: flex-start;
}

header nav .branding {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    width: var(--sidebar-width);
    flex-shrink: 0;
}

header nav .branding img {
    width: 38px;
    height: 38px;
    object-fit: contain;
}

header nav .branding .branding-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

header nav .branding .branding-text span:first-child {
    font-size: 0.95rem;
    font-weight: 700;
    color: #15803d;
}

header nav .branding .branding-text span:last-child {
    font-size: 0.85rem;
    font-weight: 800;
    color: var(--brand-blue-700);
}

/* ===================== */
/*        Main           */
/* ===================== */
.page-wrapper {
    display: flex;
    flex: 1;
    min-height: 0;
}

.content-wrapper {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-width: 0;
}

main {
    flex: 1;
    padding: 2rem;
    width: 100%;
}

/* ===================== */
/*      Sections         */
/* ===================== */
section {
    background-color: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 2rem;
    margin-bottom: 2rem;
    box-shadow: var(--shadow-md);
}

section h2 {
    font-size: 1.75rem;
    font-weight: 700;
    margin-bottom: 0.75rem;
    color: var(--text-color);
}

section p {
    color: var(--muted-text);
    font-size: 1.05rem;
}

/* ===================== */
/*       Buttons         */
/* ===================== */
button,
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.45rem;
    padding: 0.55rem 1.1rem;
    font-size: 0.9rem;
    font-weight: 600;
    border: 1px solid transparent;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background-color var(--transition), box-shadow var(--transition),
        border-color var(--transition), transform var(--transition-fast), color var(--transition);
    user-select: none;
}

button:focus-visible,
.btn:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
}

button:active:not(:disabled),
.btn:active:not(:disabled) {
    transform: translateY(1px);
}

button:disabled,
.btn:disabled {
    opacity: 0.55;
    cursor: not-allowed;
    transform: none;
}

.btn-primary {
    background-color: var(--primary-green);
    color: var(--white);
    border-color: var(--primary-green);
}

.btn-primary:hover:not(:disabled) {
    background-color: var(--primary-green-700);
    border-color: var(--primary-green-700);
    box-shadow: var(--shadow-sm);
}

.btn-secondary {
    background-color: var(--brand-blue-600);
    color: var(--white);
    border-color: var(--brand-blue-600);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--brand-blue-700);
    border-color: var(--brand-blue-700);
    box-shadow: var(--shadow-sm);
}

/* ===================== */
/*       Inputs          */
/* ===================== */
input,
select,
textarea {
    width: 100%;
    padding: 0.55rem 0.8rem;
    font-size: 0.9rem;
    color: var(--text-color);
    background-color: var(--input-bg);
    border: 1px solid var(--input-border);
    border-radius: var(--radius);
    outline: none;
    transition: border-color var(--transition), box-shadow var(--transition), background-color var(--transition);
    font-family: inherit;
}

input:hover:not(:disabled):not(:focus),
select:hover:not(:disabled):not(:focus),
textarea:hover:not(:disabled):not(:focus) {
    border-color: var(--input-border-hover);
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--brand-blue-600);
    box-shadow: var(--focus-ring);
}

input:disabled,
select:disabled,
textarea:disabled {
    background-color: var(--neutral-100);
    color: var(--subtle-text);
    cursor: not-allowed;
}

input[aria-invalid="true"],
select[aria-invalid="true"],
textarea[aria-invalid="true"],
input.is-invalid,
select.is-invalid,
textarea.is-invalid {
    border-color: var(--danger);
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15);
}

::placeholder {
    color: #94a3b8;
    opacity: 1;
}

/* ===================== */
/*       Tables          */
/* ===================== */
table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 0.7rem 1rem;
    text-align: left;
    border-bottom: 1px solid var(--table-border);
    vertical-align: middle;
}

th {
    font-weight: 600;
    color: var(--neutral-700);
    background-color: var(--table-header-bg);
    font-size: 0.78rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    white-space: nowrap;
}

td {
    color: var(--text-color);
    font-size: 0.92rem;
}

tbody tr {
    transition: background-color var(--transition-fast);
}

tbody tr:hover {
    background-color: var(--table-row-hover);
}

tbody tr:last-child td {
    border-bottom: none;
}

/* ===================== */
/*       Footer          */
/* ===================== */
footer {
    background-color: var(--panel-bg);
    border-top: 1px solid var(--panel-border);
    text-align: center;
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: center;
}

footer p {
    color: var(--muted-text);
    font-size: 0.875rem;
}

/* ===================== */
/*    Utility Classes    */
/* ===================== */
.text-muted {
    color: var(--muted-text);
}

.text-green {
    color: var(--primary-green);
}

.text-blue {
    color: var(--secondary-blue);
}

.panel {
    background-color: var(--panel-bg);
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    padding: 1.5rem;
    box-shadow: var(--shadow-md);
}

/* ===== Shared Asset Picker Modal ===== */
.tpl-asset-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.tpl-asset-modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.45);
}

.tpl-asset-modal-panel {
    position: relative;
    width: 90%;
    max-width: 560px;
    max-height: 80vh;
    background: var(--panel-bg);
    border-radius: 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.tpl-asset-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--panel-border);
}

.tpl-asset-modal-header h3 {
    font-size: 1rem;
    font-weight: 700;
    color: var(--text-color);
    margin: 0;
}

.tpl-asset-modal-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    background: none;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    cursor: pointer;
    color: var(--muted-text);
    transition: background-color 0.15s;
}

.tpl-asset-modal-close:hover {
    background-color: #fef2f2;
    color: #ef4444;
    border-color: #fecaca;
}

.tpl-asset-modal-close svg {
    width: 16px;
    height: 16px;
    stroke: currentColor;
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.tpl-asset-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: 0.85rem;
    padding: 1.25rem;
    overflow-y: auto;
}

.tpl-asset-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.4rem;
    padding: 0.75rem 0.5rem;
    border: 1px solid var(--panel-border);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: var(--input-bg);
}

.tpl-asset-item:hover {
    border-color: var(--primary-green);
    box-shadow: 0 2px 8px rgba(22, 163, 74, 0.12);
}

.tpl-asset-item img {
    width: 64px;
    height: 64px;
    object-fit: contain;
    border-radius: 4px;
}

.tpl-asset-item span {
    font-size: 0.68rem;
    color: var(--muted-text);
    text-align: center;
    word-break: break-all;
    line-height: 1.3;
}

.tpl-asset-empty {
    grid-column: 1 / -1;
    text-align: center;
    padding: 2rem;
    color: var(--muted-text);
    font-size: 0.85rem;
}

/* ===================================== */
/*   PCW HUB — Polish Layer (v2)         */
/*   Shared utilities used across pages  */
/* ===================================== */

/* Status badge utility */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    padding: 0.22rem 0.6rem;
    font-size: 0.72rem;
    font-weight: 600;
    line-height: 1.3;
    border-radius: var(--radius-pill);
    border: 1px solid transparent;
    text-transform: capitalize;
    letter-spacing: 0.01em;
    white-space: nowrap;
}
.status-badge::before {
    content: "";
    width: 6px; height: 6px;
    border-radius: 50%;
    background: currentColor;
    flex-shrink: 0;
    opacity: 0.85;
}
.status-badge.is-neutral { background: var(--neutral-100); color: var(--neutral-700); border-color: var(--neutral-200); }
.status-badge.is-info    { background: var(--info-50);    color: #1e40af;            border-color: #bfdbfe; }
.status-badge.is-success { background: var(--success-50); color: #15803d;            border-color: #bbf7d0; }
.status-badge.is-warning { background: var(--warning-50); color: #b45309;            border-color: #fde68a; }
.status-badge.is-danger  { background: var(--danger-50);  color: #b91c1c;            border-color: #fecaca; }
.status-badge.is-purple  { background: #f5f3ff;            color: #6d28d9;            border-color: #ddd6fe; }

/* Empty state */
.empty-state {
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    text-align: center;
    padding: 3rem 1.5rem;
    color: var(--muted-text);
}
.empty-state .empty-icon {
    width: 64px; height: 64px;
    border-radius: 50%;
    background: var(--neutral-100);
    color: var(--neutral-500);
    display: inline-flex; align-items: center; justify-content: center;
    margin-bottom: 1rem;
}
.empty-state .empty-icon svg {
    width: 28px; height: 28px;
    stroke: currentColor; fill: none;
    stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}
.empty-state h3,
.empty-state .empty-title {
    font-size: 1rem; font-weight: 600;
    color: var(--text-color);
    margin: 0 0 0.35rem;
}
.empty-state p,
.empty-state .empty-message {
    font-size: 0.9rem; color: var(--muted-text);
    max-width: 360px; margin: 0 0 1rem;
}
.empty-state .empty-cta { margin-top: 0.5rem; }

/* Skeleton loader */
@keyframes pcw-skeleton-shimmer {
    0%   { background-position: -400px 0; }
    100% { background-position: 400px 0; }
}
.skeleton {
    display: block;
    background: linear-gradient(90deg,
        var(--neutral-100) 0%,
        var(--neutral-200) 40%,
        var(--neutral-100) 80%);
    background-size: 800px 100%;
    animation: pcw-skeleton-shimmer 1.4s ease-in-out infinite;
    border-radius: var(--radius-sm);
    color: transparent;
    pointer-events: none;
    user-select: none;
}
.skeleton-line    { height: 0.85rem; margin-bottom: 0.5rem; }
.skeleton-line.lg { height: 1.25rem; }
.skeleton-line.sm { height: 0.65rem; }
.skeleton-block   { height: 80px; border-radius: var(--radius); }
.skeleton-circle  { border-radius: 50%; }

/* Page header (heading + actions) */
.page-header {
    display: flex; align-items: center; justify-content: space-between;
    flex-wrap: wrap; gap: 1rem;
    margin-bottom: 1.25rem;
}

/* Generic modal animation */
@keyframes pcw-modal-fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pcw-modal-pop  {
    from { opacity: 0; transform: translateY(8px) scale(0.98); }
    to   { opacity: 1; transform: translateY(0)   scale(1); }
}
.tpl-asset-modal-backdrop { animation: pcw-modal-fade 0.18s ease-out; }
.tpl-asset-modal-panel    { animation: pcw-modal-pop  0.22s ease-out; }

/* Table polish (sticky header) */
.table-wrap {
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    overflow: hidden;
    background: var(--panel-bg);
    box-shadow: var(--shadow-xs);
}
.table-wrap > table { margin: 0; }
.table-wrap thead th { position: sticky; top: 0; z-index: 1; }

/* Sort indicators */
th[data-sortable] {
    cursor: pointer; user-select: none;
    position: relative; padding-right: 1.6rem;
}
th[data-sortable]::after {
    content: "";
    position: absolute; right: 0.65rem; top: 50%;
    width: 0.55rem; height: 0.55rem;
    transform: translateY(-50%) rotate(45deg);
    border-right: 2px solid var(--neutral-300);
    border-bottom: 2px solid var(--neutral-300);
    transition: border-color var(--transition-fast), transform var(--transition-fast);
}
th[data-sortable][aria-sort="ascending"]::after  { border-color: var(--brand-blue-600); transform: translateY(-30%) rotate(-135deg); }
th[data-sortable][aria-sort="descending"]::after { border-color: var(--brand-blue-600); transform: translateY(-70%) rotate(45deg); }

/* Toolbar utility */
.toolbar {
    display: flex; flex-wrap: wrap; align-items: center;
    gap: 0.6rem; margin-bottom: 1rem;
}
.toolbar > * { flex: 0 0 auto; }
.toolbar .toolbar-search { flex: 1 1 240px; min-width: 200px; }

/* Reduced motion */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}

/* Scrollbar polish */
* { scrollbar-width: thin; scrollbar-color: var(--neutral-300) transparent; }
*::-webkit-scrollbar       { width: 8px; height: 8px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb { background: var(--neutral-300); border-radius: 8px; }
*::-webkit-scrollbar-thumb:hover { background: var(--neutral-500); }

/* Section heading polish */
section h2 { font-size: 1.5rem; font-weight: 700; margin-bottom: 0.5rem; }

/* Better focus visible for links */
a:focus-visible {
    outline: none;
    box-shadow: var(--focus-ring);
    border-radius: var(--radius-sm);
}

/* Inline button spinner */
@keyframes pcw-spin { to { transform: rotate(360deg); } }
.btn-spinner {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    animation: pcw-spin 0.7s linear infinite;
    vertical-align: -2px;
    margin-right: 4px;
    opacity: 0.85;
}
button.is-loading,
.btn.is-loading {
    cursor: progress;
    opacity: 0.85;
}
