:root {
    --app-sidebar-width: 260px;
    --app-primary: #2f5bea;
    --app-sidebar-bg: #172554;
    --app-bg: #f4f6fb;
}

html { font-size: 15px; }
body { background: var(--app-bg); }

/* Lucide icons inline with text */
svg.lucide { width: 1.1em; height: 1.1em; vertical-align: -0.15em; stroke-width: 2; }
.btn svg.lucide { margin-right: .25rem; }

/* ---------- Layout ---------- */
.app-sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--app-sidebar-width);
    background: var(--app-sidebar-bg); color: #fff; z-index: 1030; overflow-y: auto;
}
.app-main { min-height: 100vh; }
@media (min-width: 992px) { .app-main { margin-left: var(--app-sidebar-width); } }

.app-topbar {
    position: sticky; top: 0; z-index: 1020; height: 56px; padding: 0 .5rem;
    display: flex; align-items: center; gap: .5rem; background: #fff; border-bottom: 1px solid #e5e7eb;
}
.topbar-spacer { flex: 1; }

.app-brand {
    display: flex; align-items: center; gap: .6rem; padding: 1.1rem 1.25rem;
    font-weight: 700; font-size: 1.1rem; color: #fff; text-decoration: none;
}
.app-brand-sm { padding: 0; color: var(--app-sidebar-bg); }

.app-offcanvas { background: var(--app-sidebar-bg); color: #fff; width: 285px; }

.app-nav { padding: .5rem .75rem; }
.nav-org { background: rgba(255,255,255,.08); border-radius: .5rem; padding: .6rem .75rem; margin-bottom: .75rem; }
.app-nav .nav-link {
    color: rgba(255,255,255,.8); border-radius: .5rem; padding: .6rem .75rem; margin-bottom: .15rem;
    display: flex; align-items: center; gap: .6rem;
}
.app-nav .nav-link:hover { background: rgba(255,255,255,.1); color: #fff; }
.app-nav .nav-link.active { background: var(--app-primary); color: #fff; }
.nav-user { padding: .9rem .75rem 1rem; border-top: 1px solid rgba(255,255,255,.12); }

.page-header { margin-bottom: 1.25rem; }

/* ---------- Cards / stats ---------- */
.card { border: 0; border-radius: .75rem; }
.stat-card {
    background: #fff; border-radius: .75rem; padding: 1rem; display: flex; gap: .9rem; align-items: center;
    box-shadow: 0 .125rem .25rem rgba(0,0,0,.075); height: 100%;
}
.stat-icon { width: 46px; height: 46px; border-radius: .75rem; display: grid; place-items: center; flex: 0 0 46px; }
.stat-icon svg.lucide { width: 24px; height: 24px; }
.stat-value { font-size: 1.6rem; font-weight: 700; line-height: 1.1; }
.stat-label { color: #6b7280; font-size: .85rem; }

.empty-icon { width: 64px; height: 64px; margin: 0 auto; border-radius: 50%; background: #eef2ff; color: var(--app-primary); display: grid; place-items: center; }
.empty-icon svg.lucide { width: 30px; height: 30px; }

/* ---------- Loading overlay ---------- */
.loading-overlay {
    position: fixed; inset: 0; background: rgba(255,255,255,.65); z-index: 2000;
    display: flex; align-items: center; justify-content: center;
}
.loading-overlay.d-none { display: none !important; }

/* ---------- Auth ---------- */
.auth-body { background: linear-gradient(135deg, #172554 0%, #2f5bea 100%); min-height: 100vh; }
.auth-wrapper { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem; }
.auth-card { width: 100%; max-width: 420px; }
.auth-logo { width: 56px; height: 56px; border-radius: 1rem; background: #eef2ff; color: var(--app-primary); display: inline-grid; place-items: center; }
.auth-logo svg.lucide { width: 30px; height: 30px; }

/* ---------- Students / photos ---------- */
.student-thumb { width: 44px; height: 58px; object-fit: cover; border-radius: .35rem; border: 1px solid #e5e7eb; display: inline-grid; place-items: center; background: #f3f4f6; color: #9ca3af; }
.photo-card-img { aspect-ratio: 3 / 4; background: #f3f4f6; border-radius: .75rem .75rem 0 0; overflow: hidden; }
.photo-card-img img { width: 100%; height: 100%; object-fit: cover; }
.photo-card-empty { width: 100%; height: 100%; display: grid; place-items: center; color: #9ca3af; }
.photo-card-empty svg.lucide { width: 48px; height: 48px; }

.camera-frame {
    position: relative; width: 100%; aspect-ratio: 3 / 4; background: #111827; border-radius: .75rem;
    overflow: hidden; display: grid; place-items: center;
}
.camera-frame video, .camera-frame img { width: 100%; height: 100%; object-fit: cover; }
.camera-frame video { transform: scaleX(-1); }
.camera-frame video.rear { transform: none; }
.camera-placeholder { width: 100%; height: 100%; display: grid; place-items: center; color: #9ca3af; }
.camera-placeholder svg.lucide { width: 48px; height: 48px; }

/* ---------- Responsive tables (stack on phones) ---------- */
@media (max-width: 767.98px) {
    .table-stack thead { display: none; }
    .table-stack, .table-stack tbody, .table-stack tr, .table-stack td { display: block; width: 100%; }
    .table-stack tr { padding: .75rem 1rem; border-bottom: 1px solid #e5e7eb; }
    .table-stack td { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .25rem 0; border: 0; text-align: right; }
    .table-stack td::before { content: attr(data-label); font-weight: 600; color: #6b7280; text-align: left; }
    .table-stack td[data-label="Actions"] { justify-content: flex-end; padding-top: .5rem; }
    .table-stack td[data-label="Actions"]::before { display: none; }
}

:focus-visible { outline: 3px solid rgba(47, 91, 234, .5); outline-offset: 2px; }

/* ---------- Phase 2 additions ---------- */
.row-inactive { opacity: .65; }
.sort-link { color: inherit; text-decoration: none; white-space: nowrap; }
.sort-link:hover { text-decoration: underline; }
.org-logo { width: 160px; height: 160px; margin: 0 auto; border-radius: .75rem; background: #f3f4f6; display: grid; place-items: center; overflow: hidden; }
.org-logo img { max-width: 100%; max-height: 100%; object-fit: contain; }
.org-logo-empty { color: #9ca3af; text-align: center; }
.org-logo-empty svg.lucide { width: 40px; height: 40px; }
.org-logo-thumb { width: 72px; height: 72px; object-fit: contain; border: 1px solid #e5e7eb; border-radius: .5rem; background: #fff; }
.detail-list dt { color: #6b7280; font-weight: 500; }
.detail-list dd { margin-bottom: .75rem; }
@media (max-width: 767.98px) {
    .table-stack td[data-label="Details"], .table-stack td[data-label="Errors"] { flex-direction: column; align-items: flex-end; }
}

/* ---------- Phase 3: card fonts, thumbnails and designer ---------- */
@font-face { font-family: 'Poppins'; font-weight: 400; font-style: normal; src: url('../fonts/Poppins-Regular.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'Poppins'; font-weight: 500; font-style: normal; src: url('../fonts/Poppins-Medium.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'Poppins'; font-weight: 600; font-style: normal; src: url('../fonts/Poppins-SemiBold.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'Poppins'; font-weight: 700; font-style: normal; src: url('../fonts/Poppins-Bold.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'Lato'; font-weight: 400; font-style: normal; src: url('../fonts/Lato-Regular.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'Lato'; font-weight: 700; font-style: normal; src: url('../fonts/Lato-Bold.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'PT Serif'; font-weight: 400; font-style: normal; src: url('../fonts/PT_Serif-Web-Regular.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'PT Serif'; font-weight: 700; font-style: normal; src: url('../fonts/PT_Serif-Web-Bold.ttf') format('truetype'); font-display: swap; }

.card-thumb { line-height: 0; background: #fff; box-shadow: 0 1px 5px rgba(0, 0, 0, .3); }
.card-thumb svg { display: block; width: 100%; height: auto; }
.template-thumbs, .design-thumbs { background: #eef1f7; padding: 1rem; display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; justify-content: center; border-radius: .75rem .75rem 0 0; min-height: 230px; }
.template-thumbs .card-thumb { flex: 0 1 auto; }
.template-thumbs .card-thumb.portrait { width: 118px; }
.template-thumbs .card-thumb.landscape { width: 168px; }
.template-thumbs .card-thumb.is-back { opacity: .92; }
.design-thumb .card-thumb.portrait { width: 130px; }
.design-thumb .card-thumb.landscape { width: 230px; }

.stage-center { display: flex; justify-content: center; background: #eef1f7; border-radius: .75rem; padding: 1rem; }
.stage-box { position: relative; width: 100%; }
.card-stage { position: absolute; inset: 0; filter: drop-shadow(0 2px 8px rgba(0, 0, 0, .3)); }
.card-stage svg { display: block; width: 100%; height: 100%; }
.card-overlay { position: absolute; inset: 0; touch-action: none; user-select: none; }
.card-overlay .hit { position: absolute; border: 1px dashed transparent; cursor: move; min-width: 6px; min-height: 6px; }
.card-overlay .hit:hover { border-color: rgba(47, 91, 234, .55); }
.card-overlay .hit.selected { border: 1.5px solid #2f5bea; background: rgba(47, 91, 234, .08); }
.card-overlay .handle { position: absolute; width: 12px; height: 12px; background: #fff; border: 2px solid #2f5bea; border-radius: 50%; }
.card-overlay .h-nw { top: -7px; left: -7px; cursor: nwse-resize; }
.card-overlay .h-ne { top: -7px; right: -7px; cursor: nesw-resize; }
.card-overlay .h-sw { bottom: -7px; left: -7px; cursor: nesw-resize; }
.card-overlay .h-se { bottom: -7px; right: -7px; cursor: nwse-resize; }
@media (pointer: coarse) { .card-overlay .handle { width: 22px; height: 22px; } .card-overlay .h-nw { top: -12px; left: -12px; } .card-overlay .h-ne { top: -12px; right: -12px; } .card-overlay .h-sw { bottom: -12px; left: -12px; } .card-overlay .h-se { bottom: -12px; right: -12px; } }
@media (min-width: 1200px) { .designer-preview-col { position: sticky; top: 12px; align-self: flex-start; } }

.designer-section > summary { cursor: pointer; list-style: none; }
.designer-section > summary::-webkit-details-marker { display: none; }
.swatch-row { display: flex; flex-wrap: wrap; gap: .4rem; }
.swatch { width: 32px; height: 32px; border-radius: 50%; border: 2px solid #fff; box-shadow: 0 0 0 1px #9ca3af; cursor: pointer; }
.swatch:hover { transform: scale(1.1); }
.items-list { max-height: 300px; overflow: auto; }
.item-row { display: flex; align-items: center; gap: .5rem; padding: .25rem .4rem; border-radius: .4rem; }
.item-row.selected { background: #eef2ff; }
.item-label { flex: 1; text-align: left; background: none; border: 0; padding: .15rem .25rem; display: flex; align-items: center; gap: .4rem; }
.warning-list { display: flex; flex-direction: column; gap: .25rem; max-height: 230px; overflow: auto; }
.warning-item { display: flex; gap: .5rem; align-items: flex-start; background: #fff; border: 1px solid #e5e7eb; border-radius: .4rem; padding: .35rem .5rem; font-size: .85rem; }
.logo-preview { width: 72px; height: 72px; border: 1px solid #e5e7eb; border-radius: .5rem; display: grid; place-items: center; background: #fff; overflow: hidden; }
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* ---------- Phase 4: photo studio ---------- */
.person-photo { aspect-ratio: 3 / 4; background: #f3f4f6; border-radius: .75rem; overflow: hidden; max-width: 220px; margin: 0 auto; }
.person-photo img { width: 100%; height: 100%; object-fit: cover; }
.person-photo-empty { width: 100%; height: 100%; display: grid; place-content: center; text-align: center; color: #9ca3af; }
.person-photo-empty svg.lucide { width: 44px; height: 44px; margin: 0 auto; }
.camera-box { background: #111827; border-radius: .75rem; overflow: hidden; display: flex; justify-content: center; align-items: center; min-height: 220px; }
.camera-box video, .camera-box canvas { display: block; width: 100%; max-height: 62vh; object-fit: contain; }
.camera-box video.mirror { transform: scaleX(-1); }
.editor-wrap { width: 100%; border-radius: .5rem; overflow: hidden; line-height: 0; box-shadow: 0 1px 6px rgba(0, 0, 0, .3);
    background-image: linear-gradient(45deg, #e5e7eb 25%, transparent 25%), linear-gradient(-45deg, #e5e7eb 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #e5e7eb 75%), linear-gradient(-45deg, transparent 75%, #e5e7eb 75%);
    background-size: 16px 16px; background-position: 0 0, 0 8px, 8px -8px, -8px 0; }
.editor-wrap canvas { width: 100%; height: auto; touch-action: none; cursor: grab; display: block; outline-offset: 2px; }
.editor-wrap canvas.grabbing { cursor: grabbing; }
.frame-preview { width: 100%; height: auto; border-radius: .5rem;
    background-image: linear-gradient(45deg, #e5e7eb 25%, transparent 25%), linear-gradient(-45deg, #e5e7eb 25%, transparent 25%), linear-gradient(45deg, transparent 75%, #e5e7eb 75%), linear-gradient(-45deg, transparent 75%, #e5e7eb 75%);
    background-size: 12px 12px; background-position: 0 0, 0 6px, 6px -6px, -6px 0; }
.card-preview-live { max-width: 260px; }
.card-preview-live.portrait { max-width: 150px; }

/* ---------- Phase 5: card gallery ---------- */
.design-strip { display: flex; gap: .9rem; overflow-x: auto; padding-bottom: .5rem; }
.strip-item { flex: 0 0 auto; width: 150px; display: flex; flex-direction: column; align-items: flex-start; gap: .25rem; }
.strip-item .card-thumb.portrait { width: 96px; }
.strip-item .card-thumb.landscape { width: 150px; }
.strip-name { font-size: .85rem; font-weight: 600; line-height: 1.2; }
.strip-item.is-default .card-thumb { box-shadow: 0 0 0 2px #198754, 0 1px 5px rgba(0, 0, 0, .3); }
.summary-bar { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.summary-chip { text-decoration: none; padding: .25rem .65rem; border-radius: 2rem; font-size: .85rem; border: 1px solid transparent; color: #111827; background: #fff; box-shadow: 0 1px 2px rgba(0, 0, 0, .08); }
.summary-chip:hover { box-shadow: 0 0 0 2px rgba(47, 91, 234, .35); }
.chip-ok { background: #d1e7dd; } .chip-warn { background: #fff3cd; } .chip-bad { background: #f8d7da; } .chip-neutral { background: #e9ecef; }
.gcard-thumb { display: flex; justify-content: center; align-items: center; min-height: 230px; padding: .9rem; background: #eef1f7; border-radius: .75rem .75rem 0 0; text-decoration: none; color: #6b7280; }
.gcard-thumb .card-thumb.portrait { width: 120px; }
.gcard-thumb .card-thumb.landscape { width: 200px; }
.gcard-skeleton { width: 120px; height: 190px; border-radius: .5rem; background: linear-gradient(90deg, #e5e7eb 25%, #f3f4f6 50%, #e5e7eb 75%); background-size: 200% 100%; animation: gcard-shimmer 1.4s infinite; }
@keyframes gcard-shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }
.gcard-empty { font-size: .85rem; }
.gcard:hover { box-shadow: 0 .4rem 1rem rgba(0, 0, 0, .15) !important; }
.big-card { max-width: 100%; }
.status-list svg.lucide { flex: 0 0 auto; margin-top: .15rem; }
.design-choices { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: .75rem; }
.design-choice { display: flex; flex-direction: column; align-items: center; gap: .4rem; padding: .75rem; border: 1px solid #dee2e6; border-radius: .6rem; cursor: pointer; text-align: center; position: relative; background: #fff; }
.design-choice:has(input:checked) { border-color: #2f5bea; box-shadow: 0 0 0 2px rgba(47, 91, 234, .25); }
.design-choice input { position: absolute; top: .55rem; left: .55rem; }
.design-choice .card-thumb.portrait { width: 88px; }
.design-choice .card-thumb.landscape { width: 150px; }
.design-choice-reset { justify-content: center; min-height: 120px; }
.preview-cards { display: flex; flex-wrap: wrap; gap: 1rem; }
.preview-rep { width: 130px; }
.preview-rep .card-thumb.portrait { width: 110px; }
.preview-rep .card-thumb.landscape { width: 130px; }

/* ---------- Phase 6: selection and downloads ---------- */
.gcard { position: relative; }
.gcard-select { position: absolute; top: .55rem; left: .55rem; z-index: 3; background: rgba(255, 255, 255, .92); border-radius: .35rem; padding: .2rem .4rem .2rem 1.9rem; box-shadow: 0 1px 3px rgba(0, 0, 0, .25); margin: 0; }
.gcard-select .form-check-input { cursor: pointer; }
.select-bar { position: sticky; bottom: 12px; z-index: 20; display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; justify-content: center; padding: .6rem .9rem; margin-top: 1rem; background: #fff; border: 1px solid #c7d2fe; border-radius: .75rem; box-shadow: 0 .4rem 1.2rem rgba(0, 0, 0, .2); }
