/**
 * Sketchbook Generator - Frontend Styles
 * Clean editorial/utilitarian design matching the Sketch or Die mockup
 */

/* ===================== BASE ===================== */
.skg-app {
    --accent: #000000;
    --bg: #ffffff;
    --border: #333333;
    --border-light: #aaaaaa;
    --dashed: #999999;
    --text: #111111;
    --text-muted: #666666;
    --slot-bg: #fafafa;

    display: flex;
    flex-direction: row;
    min-height: 700px;
    max-width: 1100px;
    margin: 40px auto;
    padding: 0;
    font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
    color: var(--text);
    background: var(--bg);
    box-sizing: border-box;
}

*, *::before, *::after {
    box-sizing: inherit;
}

/* ===================== LEFT PANEL ===================== */
.skg-left {
    flex: 0 0 420px;
    padding: 32px 36px 32px 0;
    display: flex;
    flex-direction: column;
    gap: 28px;
}

/* Brand row */
.skg-brand {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
}

.skg-brand-text {
    flex: 1;
    min-width: 0;
}

/* Logo */
.skg-logo {
    flex: 0 0 160px;
    width: 160px;
    height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.skg-logo img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    display: block;
}

.skg-logo-placeholder {
    border: 2px dashed var(--border-light);
    border-radius: 4px;
    background: var(--bg-secondary, #f5f5f5);
    cursor: default;
}

.skg-logo-placeholder span {
    font-size: 11px;
    font-weight: 700;
    color: var(--border-light);
    letter-spacing: 1px;
}

/* Brand / Title */
.skg-title {
    font-size: 22px;
    font-weight: 700;
    margin: 0 0 10px 0;
    letter-spacing: -0.3px;
    line-height: 1.2;
}

.skg-divider {
    height: 2px;
    background: var(--border);
    margin-bottom: 14px;
    width: 100%;
}

.skg-subtitle {
    margin: 0;
    font-size: 14px;
    color: var(--text-muted);
    line-height: 1.4;
}

/* Template Grid — dynamic columns via CSS custom properties */
.skg-template-grid {
    display: grid;
    grid-template-columns: repeat(var(--grid-columns, 5), 1fr);
    gap: 10px;
}

.skg-template-btn {
    width: 70px;
    height: 70px;
    padding: 6px;
    background: white;
    border: 2px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.1s ease, border-color 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
}

.skg-template-btn img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

.skg-template-btn:hover {
    transform: translateY(-3px);
    box-shadow: 4px 4px 0 var(--border);
    border-color: var(--accent);
}

.skg-template-btn:active {
    transform: translateY(0);
    box-shadow: 1px 1px 0 var(--border);
}

.skg-template-btn.just-added {
    border-color: var(--accent);
    background: #f0f0f0;
}

.skg-icon-placeholder {
    font-size: 24px;
    color: var(--border-light);
}

.skg-no-templates {
    font-size: 13px;
    color: var(--text-muted);
    font-style: italic;
}

/* Instructions */
.skg-instructions {
    display: flex;
    flex-direction: column;
    gap: 0;
}

.skg-instructions-label {
    margin: 0 0 8px 0;
    font-size: 14px;
    color: var(--text-muted);
}

.skg-instruction-block {
    padding: 10px 0;
}

.skg-instruction-block p {
    margin: 0;
    font-size: 15px;
    line-height: 1.5;
}

.skg-instruction-row {
    display: flex;
    align-items: center;
    gap: 20px;
}

.skg-instruction-row > div:first-child {
    flex: 1;
}

/* Instruction images (or fallback SVG) */
.skg-instr-img {
    flex: 0 0 70px;
    width: 70px;
    height: 80px;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

.skg-instr-img svg,
.skg-instr-img img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
}

/* ===================== VERTICAL DIVIDER ===================== */
.skg-divider-vertical {
    flex: 0 0 1px;
    background: transparent;
    border-right: 2px dashed var(--dashed);
    margin: 0 36px;
    align-self: stretch;
}

/* ===================== RIGHT PANEL ===================== */
.skg-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 32px 0 32px 0;
    gap: 20px;
}

/* Move controls very close to A5 landscape preview */
.skg-page-preview:has(.skg-page--a5) + .skg-bottom-bar,
.skg-page--a5 + * {
    margin-top: 8px;
}

/* Reduce flex-grow for A5 to bring controls up */
.skg-page--a5 {
    flex-grow: 0;
    margin-bottom: 8px;
}

.skg-right:has(.skg-page--a5) {
    gap: 8px;
}

/* Page preview wrapper */
/* Page preview container */
.skg-page-preview {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px 0;
}

/* Controls right below preview for A5 */
.skg-bottom-bar {
    margin-top: 20px;
}

/* A5 landscape: controls immediately below */
.skg-page--a5 {
    margin-bottom: 0;
}

.skg-page--a5 + * {
    margin-top: 0;
}

.skg-right:has(.skg-page--a5) .skg-bottom-bar {
    margin-top: 0;
}

/* The A4 page */
.skg-page {
    display: grid;
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    border: 1.5px solid var(--border);
    width: 100%;
    max-width: 460px;
    aspect-ratio: 210 / 297;
    background: white;
}

/* A5 Layout: 2 slots arranged horizontally on landscape A4 */
.skg-page--a5 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr;
    max-width: 100%;
    width: 100%;
    aspect-ratio: 297 / 210; /* Landscape A4 proportions */
}

/* A6 Layout: 4 slots in 2x2 grid (original layout) - explicit for clarity */
.skg-page--a6 {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: 1fr 1fr;
    max-width: 460px;
    aspect-ratio: 210 / 297; /* A4 proportions */
}

/* A5 landscape preview scaling - larger and full width */
.skg-page--a5 {
    max-width: 100%;
    width: 100%;
    aspect-ratio: 297 / 210; /* Landscape A4 proportions */
}

/* Each slot */
.skg-slot {
    border: 1.5px dashed var(--dashed);
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--slot-bg);
    transition: background 0.15s;
    overflow: hidden;
}

/* A6 layout slot borders (2x2 grid) */
.skg-page--a6 .skg-slot:nth-child(1) { border-top: none; border-left: none; }
.skg-page--a6 .skg-slot:nth-child(2) { border-top: none; border-right: none; }
.skg-page--a6 .skg-slot:nth-child(3) { border-bottom: none; border-left: none; }
.skg-page--a6 .skg-slot:nth-child(4) { border-bottom: none; border-right: none; }

/* A5 layout slot borders (2x1 grid - horizontal) */
.skg-page--a5 .skg-slot:nth-child(1) { border-top: none; border-left: none; border-bottom: none; }
.skg-page--a5 .skg-slot:nth-child(2) { border-top: none; border-right: none; border-bottom: none; }

.skg-slot.filled {
    background: white;
}

.skg-slot-number {
    font-size: clamp(28px, 5cqi, 48px);
    font-weight: 700;
    color: #e0e0e0;
    user-select: none;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    transition: opacity 0.2s;
    line-height: 1;
}

.skg-slot.filled .skg-slot-number {
    opacity: 0;
}

/* Template preview inside slot */
.skg-slot-inner {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.2s, transform 0.3s ease;
    padding: 8px;
}

/* Rotation applied to slots 3 & 4 when toggle is active */
.skg-slot[data-slot="3"].skg-rotated .skg-slot-inner,
.skg-slot[data-slot="4"].skg-rotated .skg-slot-inner {
    transform: rotate(180deg);
}

.skg-slot[data-slot="3"].skg-rotated .skg-slot-number,
.skg-slot[data-slot="4"].skg-rotated .skg-slot-number {
    transform: translate(-50%, -50%) rotate(180deg);
}

.skg-slot.filled .skg-slot-inner {
    opacity: 1;
}

.skg-slot-inner img {
    width: 60%;
    height: 60%;
    object-fit: contain;
}

.skg-slot-inner span {
    font-size: 10px;
    font-weight: 600;
    color: var(--text-muted);
    margin-top: 6px;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Remove button on slot */
.skg-slot-clear {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    background: var(--border);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 15px;
    line-height: 1;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 0;
    z-index: 2;
    transition: background 0.15s;
}

.skg-slot.filled .skg-slot-clear {
    display: flex;
}

.skg-slot-clear:hover {
    background: #c00;
}

/* ===================== BOTTOM BAR ===================== */
.skg-bottom-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding-top: 4px;
}

/* Simple inline layout selector */
.skg-layout-inline {
    font-size: 13px;
    color: var(--text-muted);
    margin: 8px 0;
}

.skg-layout-inline select {
    font-size: 12px;
    padding: 2px 4px;
    border: 1px solid var(--border);
    border-radius: 3px;
    background: white;
    margin-left: 4px;
}

.skg-page-counter {
    font-size: 14px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.skg-page-btn {
    font-size: 14px;
    font-weight: 700;
    color: var(--text-muted);
    background: none;
    border: 1.5px solid var(--border-light);
    border-radius: 3px;
    padding: 1px 8px;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    line-height: 1.5;
}

.skg-page-btn:hover {
    color: var(--text);
    border-color: var(--border);
}

.skg-page-btn.skg-page-active {
    color: var(--text);
    border-color: var(--text);
    background: #f0f0f0;
}

.skg-page-btn.skg-page-done::after {
    content: ' ✓';
    font-size: 11px;
    color: #4a4;
}

.skg-actions {
    display: flex;
    gap: 10px;
    align-items: center;
}

.skg-clear-btn {
    padding: 10px 20px;
    background: white;
    border: 2px solid var(--border);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
    letter-spacing: 0.3px;
}

.skg-clear-btn:hover {
    background: #f0f0f0;
}

.skg-rotate-btn {
    padding: 10px 16px;
    background: white;
    border: 2px solid var(--border);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    letter-spacing: 0.2px;
    color: var(--text);
}

.skg-rotate-btn:hover {
    background: #f0f0f0;
}

.skg-rotate-btn.active {
    background: var(--text);
    color: white;
    border-color: var(--text);
}

/* Rotate button text spans - controlled by JavaScript */
.rotate-text-a5, .rotate-text-a6 { display: inline; }

.skg-generate-btn {
    padding: 10px 28px;
    background: var(--accent);
    color: white;
    border: 2px solid var(--accent);
    font-size: 14px;
    font-weight: 700;
    cursor: pointer;
    letter-spacing: 0.5px;
    text-transform: uppercase;
    transition: opacity 0.15s, transform 0.1s;
}

.skg-generate-btn:not(:disabled):hover {
    opacity: 0.85;
    transform: translateY(-1px);
}

.skg-generate-btn:disabled {
    background: #ccc;
    border-color: #ccc;
    cursor: not-allowed;
}

.skg-generate-btn.loading {
    opacity: 0.6;
    cursor: wait;
}

/* accent color override from PHP settings */
.skg-app[data-accent] .skg-generate-btn,
.skg-app[data-accent] .skg-template-btn.just-added {
    /* overridden via JS inline style */
}

/* ===================== STATUS ===================== */
.skg-status {
    padding: 10px 16px;
    font-size: 13px;
    font-weight: 500;
    border-radius: 2px;
    margin-top: 4px;
}

.skg-status.success { background: #e8f5e9; color: #1b5e20; border: 1px solid #a5d6a7; }
.skg-status.error   { background: #ffebee; color: #b71c1c; border: 1px solid #ef9a9a; }
.skg-status.loading { background: #e3f2fd; color: #0d47a1; border: 1px solid #90caf9; }

/* Version badge in title */
.skg-version {
    font-size: 13px;
    font-weight: 400;
    color: var(--text-muted);
    letter-spacing: 0;
}
