@font-face {
    font-family: 'Brush Script';
    src: url('../assets/fonts/BrushScriptOpti-Regular.otf') format('opentype');
    font-weight: 400;
    font-style: normal;
    font-display: swap;
}

/* Brand Togas Alessandro — azules y verdes */
:root {
    --brand-blue: #0d4f8b;
    --brand-blue-dark: #0a3a66;
    --brand-blue-soft: #e8f1f8;
    --brand-green: #1a7a4c;
    --brand-green-dark: #145c3a;
    --brand-green-soft: #e6f5ee;
    --brand-gold: #c9a227;
    --brand-whatsapp: #25D366;
    --text: #1e293b;
    --muted: #64748b;
    --border: #dbe3ec;
    --surface: #ffffff;
    --bg: #f0f5fa;
    --radius: 14px;
    --shadow: 0 4px 24px rgba(13, 79, 139, 0.08);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
}

.app-container {
    max-width: 1480px;
    margin: 0 auto;
    padding: 24px 20px;
}

header {
    text-align: center;
    margin-bottom: 28px;
}

header h1 {
    font-size: 1.85rem;
    color: var(--brand-blue-dark);
    margin-bottom: 6px;
    font-weight: 700;
}

header p {
    color: #666;
    font-size: 0.95rem;
}

.main-content {
    display: flex;
    gap: 28px;
    flex-wrap: wrap;
}

/* ========== PANEL DE CONTROLES ========== */
.controls-panel {
    flex: 0 0 380px;
    background: var(--surface);
    border-radius: var(--radius);
    padding: 22px 20px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border);
    max-height: 92vh;
    overflow-y: auto;
}

.control-section {
    margin-bottom: 22px;
    padding-bottom: 18px;
    border-bottom: 1px solid #eee;
}

.control-section:last-child {
    border-bottom: none;
}

.control-section h3 {
    font-size: 1rem;
    color: var(--brand-blue-dark);
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.step-num {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 1.6em;
    height: 1.6em;
    padding: 0 6px;
    border-radius: 50px;
    background: var(--brand-blue);
    color: #fff;
    font-weight: 700;
    font-size: 0.85rem;
}

/* ========== PILLS DE NIVEL ========== */
.level-pills {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.level-pill {
    padding: 8px 16px;
    border-radius: 50px;
    border: 1.5px solid #ddd;
    background: #f8f8f8;
    color: #444;
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s ease;
}

.level-pill:hover {
    border-color: #1a3a5c;
    background: #f0f4f8;
}

.level-pill.active {
    background: #1a3a5c;
    color: #fff;
    border-color: #1a3a5c;
    box-shadow: 0 2px 8px rgba(26,58,92,0.25);
}

/* ========== GRID DE ESTILOS ========== */
.style-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.style-card {
    position: relative;
    background: #fafafa;
    border: 2px solid #e8e8e8;
    border-radius: 12px;
    padding: 8px;
    cursor: pointer;
    transition: all 0.2s ease;
    text-align: center;
    overflow: hidden;
}

.style-card:hover {
    border-color: var(--brand-blue);
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(13, 79, 139, 0.12);
}

.style-card.selected {
    border-color: var(--brand-blue);
    border-width: 2.5px;
    box-shadow: 0 0 0 3px rgba(13, 79, 139, 0.22);
}

.style-card .check-badge {
    position: absolute;
    top: 6px;
    right: 6px;
    width: 22px;
    height: 22px;
    background: var(--brand-green);
    color: #fff;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    font-weight: bold;
    z-index: 2;
}

.style-card.selected .check-badge {
    display: flex;
}
.style-card .check-badge::after {
    content: "";
    width: 5px;
    height: 9px;
    border: solid #fff;
    border-width: 0 2px 2px 0;
    transform: rotate(45deg);
    margin-top: -2px;
}

.style-preview {
    width: 100%;
    aspect-ratio: 4 / 5;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 6px;
    background: linear-gradient(180deg, #f5f5f5 0%, #ebebeb 100%);
    border-radius: 8px;
    overflow: hidden;
}

.style-preview img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    object-position: top center;
    display: block;
}

.style-preview svg {
    max-width: 90%;
    max-height: 100%;
}

.style-code {
    font-size: 0.85rem;
    font-weight: 600;
    color: #333;
}

/* ========== SELECTS E INPUTS ========== */
select, input[type="text"], input[type="file"] {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid #ddd;
    border-radius: 8px;
    font-size: 0.95rem;
    margin-bottom: 8px;
    background: #fff;
    transition: border-color 0.2s;
}

select:focus, input[type="text"]:focus {
    outline: none;
    border-color: #1a3a5c;
}

.text-options {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 8px;
}

.text-options label {
    font-size: 0.9rem;
    min-width: 55px;
}

input[type="color"] {
    width: 48px;
    height: 36px;
    border: none;
    cursor: pointer;
    border-radius: 6px;
}

input[type="range"] {
    flex: 1;
}

.hint {
    font-size: 0.8rem;
    color: #777;
}

.section-intro {
    font-size: 0.82rem;
    color: var(--muted);
    margin: -4px 0 12px;
    line-height: 1.4;
}

.field-label {
    display: block;
    font-size: 0.86rem;
    font-weight: 600;
    color: var(--brand-blue-dark);
    margin-bottom: 6px;
}

.text-slot-swatches {
    margin: 6px 0 4px;
}

.optional-block {
    margin-top: 10px;
    padding: 10px 0 0;
}

.btn-optional {
    background: #fff;
    color: var(--brand-blue);
    border: 1.5px dashed var(--brand-blue);
    margin-top: 8px;
}

.btn-optional:hover {
    background: var(--brand-blue-soft);
}

.btn-optional-confirm {
    background: var(--brand-green);
    color: #fff;
}

.btn-optional-confirm:hover {
    background: var(--brand-green-dark);
}

.btn-add-text {
    background: #6b7280;
    color: #fff;
    border: 1px solid #4b5563;
    margin-top: 8px;
}

.btn-add-text:hover {
    background: #4b5563;
}

/* Tipos de letra del bordado: Block / Avant Garde / Script */
.fuente-block {
    font-family: 'Archivo', sans-serif;
    font-weight: 900;
}

.fuente-avant-garde {
    font-family: 'Poppins', sans-serif;
    font-weight: 500;
    letter-spacing: 0.5px;
}

.fuente-script {
    font-family: 'Brush Script', cursive;
    font-weight: 400;
}

.font-picker {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 8px;
    margin: 2px 0 12px;
}

.font-option {
    appearance: none;
    border: 1.5px solid var(--border);
    background: #fff;
    border-radius: 10px;
    padding: 8px 6px 7px;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    min-width: 0;
    color: var(--brand-blue-dark);
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}

.font-option:hover {
    border-color: var(--brand-blue);
    background: var(--brand-blue-soft);
}

.font-option.is-active {
    border-color: var(--brand-green);
    background: var(--brand-green-soft);
    box-shadow: inset 0 0 0 1px var(--brand-green);
}

.font-option-sample {
    font-size: 1.05rem;
    line-height: 1.15;
    color: #1a5f2a;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.font-option-sample.fuente-script {
    font-size: 1.2rem;
    line-height: 1.3;
}

.font-option-name {
    font-size: 0.68rem;
    font-weight: 600;
    letter-spacing: 0.01em;
    color: var(--muted);
    font-family: 'Segoe UI', system-ui, sans-serif;
}

.font-option.is-active .font-option-name {
    color: var(--brand-green-dark);
}

.selected-color {
    font-size: 0.85rem;
    margin-top: 8px;
    color: #444;
}

/* ========== MUESTRAS DE COLOR ========== */
.color-swatches {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 7px;
    margin-bottom: 4px;
}

.color-swatch {
    width: 100%;
    aspect-ratio: 1;
    border-radius: 8px;
    border: 2px solid #ddd;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s;
    box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}

.color-swatch:hover {
    transform: scale(1.12);
    border-color: #999;
}

.color-swatch.selected {
    border-color: #0d6efd;
    border-width: 3px;
    box-shadow: 0 0 0 2px rgba(13,110,253,0.3);
}

/* ========== BOTONES ========== */
.btn {
    display: block;
    width: 100%;
    padding: 12px;
    margin-bottom: 10px;
    border: none;
    border-radius: 8px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary { background: #1a5f2a; color: white; }
.btn-primary:hover { background: #144a21; }

.btn-success { background: #0d6efd; color: white; }
.btn-success:hover { background: #0b5ed7; }

.btn-danger { background: #dc3545; color: white; }
.btn-danger:hover { background: #bb2d3b; }

.btn-whatsapp { background: #25D366; color: white; }
.btn-whatsapp:hover { background: #1da851; }

.btn-secondary { background: #6c757d; color: white; }
.btn-secondary:hover { background: #5a6268; }

/* ========== CANVAS ========== */
.canvas-area-container {
    flex: 1;
    min-width: 320px;
    display: flex;
    flex-direction: column;
}

.canvas-area {
    flex: 1;
    min-width: 0;
    background: #fff;
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.06);
    text-align: center;
}

.canvas-wrapper {
    display: inline-block;
    border: 1px solid #e0e0e0;
    border-radius: 12px;
    overflow: hidden;
    background: #e8e8e8;
    max-width: 100%;
}

#stoleCanvas {
    display: block;
    max-width: 100%;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 980px) {
    .main-content { flex-direction: column; }
    .controls-panel { flex: none; width: 100%; max-height: none; }
    .style-grid { grid-template-columns: repeat(3, 1fr); }
    .color-swatches { grid-template-columns: repeat(6, 1fr); }
}

@media (max-width: 560px) {
    .style-grid { grid-template-columns: repeat(2, 1fr); }
    .level-pill { padding: 7px 12px; font-size: 0.85rem; }
}


/* ========== MODO ADMIN ========== */
#adminLoginOverlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.65);
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
}
.admin-login-box {
    background: #fff;
    padding: 28px 32px;
    border-radius: 14px;
    width: min(360px, 90vw);
    text-align: center;
    box-shadow: 0 12px 40px rgba(0,0,0,0.25);
}
.admin-login-box h2 { margin: 0 0 8px; font-size: 1.25rem; }
.admin-login-box p { color: #666; font-size: 0.9rem; margin-bottom: 14px; }
.admin-login-box input[type=password] {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid #ddd;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 1rem;
}
.admin-login-box button#adminLoginBtn {
    width: 100%;
    padding: 10px;
    background: #1a5f2a;
    color: #fff;
    border: none;
    border-radius: 8px;
    font-weight: 600;
    cursor: pointer;
}
.admin-login-box .btn-link {
    background: none;
    border: none;
    color: #888;
    margin-top: 10px;
    cursor: pointer;
    text-decoration: underline;
}

#adminPanel {
    position: fixed;
    bottom: 16px;
    right: 16px;
    width: min(340px, 92vw);
    background: #1a1a1a;
    color: #f0f0f0;
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.4);
    z-index: 9000;
    overflow: hidden;
    border: 1px solid #c9a227;
}
.admin-panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    background: #c9a227;
    color: #1a1a1a;
    font-size: 0.9rem;
}
.admin-panel-header #adminStyleLabel {
    flex: 1;
    font-weight: 600;
}
.admin-panel-header button {
    background: #1a1a1a;
    color: #fff;
    border: none;
    border-radius: 6px;
    padding: 4px 10px;
    cursor: pointer;
    font-size: 0.8rem;
}
.admin-panel-body {
    padding: 12px 14px 16px;
}
.admin-hint {
    font-size: 0.78rem;
    color: #aaa;
    margin: 0 0 10px;
    line-height: 1.35;
}
.admin-controls {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin-bottom: 10px;
}
.admin-controls label {
    display: flex;
    flex-direction: column;
    font-size: 0.75rem;
    color: #ccc;
    gap: 3px;
}
.admin-controls input {
    padding: 6px 8px;
    border-radius: 6px;
    border: 1px solid #444;
    background: #2a2a2a;
    color: #fff;
    font-size: 0.9rem;
}
.admin-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}
.admin-actions button {
    flex: 1;
    min-width: 90px;
    padding: 8px 6px;
    border: none;
    border-radius: 7px;
    cursor: pointer;
    font-size: 0.8rem;
    font-weight: 600;
}
#adminSaveLayoutBtn { background: #1a5f2a; color: #fff; }
#adminResetLayoutBtn { background: #444; color: #fff; }
#adminToggleEditBtn { background: #c9a227; color: #1a1a1a; }
.admin-status {
    margin: 8px 0 0;
    font-size: 0.78rem;
    color: #8f8;
    min-height: 1.2em;
}
body.admin-mode .canvas-wrapper {
    outline: 2px dashed #c9a227;
    outline-offset: 2px;
}


/* ========== UX Alessandro: header brand + canvas ========== */
header {
    background: linear-gradient(135deg, var(--brand-blue-dark) 0%, var(--brand-blue) 55%, var(--brand-green) 100%);
    color: #fff;
    border-radius: var(--radius);
    padding: 20px 24px 22px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
}
header h1 { color: #fff !important; letter-spacing: -0.02em; }
header p { color: rgba(255,255,255,0.88) !important; }

.canvas-area-container {
    flex: 1;
    min-width: 280px;
}
.canvas-area {
    min-width: 0;
}
.canvas-wrapper {
    background: #fff;
    border-radius: var(--radius);
    padding: 0px;

    display: flex;
    justify-content: center;
    align-items: center;
}
.canvas-area .hint {
    color: var(--muted);
    font-size: 0.85rem;
    margin-top: 10px;
    text-align: center;
}

/* Botones principales */
#saveDesignBtn, .btn-primary {
    background: var(--brand-blue) !important;
    border-color: var(--brand-blue) !important;
}
#saveDesignBtn:hover, .btn-primary:hover {
    background: var(--brand-blue-dark) !important;
}
#whatsappBtn, .btn-whatsapp {
    background: var(--brand-whatsapp) !important;
    border-color: var(--brand-whatsapp) !important;
    color: #fff !important;
}

.color-swatch.selected {
    outline: 2px solid var(--brand-blue);
    outline-offset: 2px;
}

.selected-color strong {
    color: var(--brand-green-dark);
}

/* Admin panel: azul/verde */
#adminPanel {
    border-color: var(--brand-blue) !important;
}
.admin-panel-header {
    background: linear-gradient(90deg, var(--brand-blue), var(--brand-green)) !important;
    color: #fff !important;
}


/* ============================================
   CANVAS RESPONSIVE — proporción nativa 480×720
   ============================================ */

.canvas-wrapper,
#canvas-wrapper,
.canvas-container-wrapper {
  width: 100%;
  max-width: 480px;
  margin: 0 auto;
  display: block;
  overflow: hidden;
  position: relative;
}

.canvas-zoom-stage {
  width: 100%;
  display: block;
  transform-origin: center center;
  will-change: transform;
}

/* Fabric.js: mantener 2:3 (480/720), sin estirar */
.canvas-container {
  width: 100% !important;
  height: auto !important;
  aspect-ratio: 480 / 720;
  margin: 0 auto !important;
  position: relative !important;
}

.canvas-container canvas,
.lower-canvas,
.upper-canvas {
  position: absolute !important;
  left: 0 !important;
  top: 0 !important;
  width: 100% !important;
  height: 100% !important;
  max-width: none !important;
  display: block;
}

@media (max-width: 560px) {
  .canvas-wrapper,
  #canvas-wrapper,
  .canvas-container-wrapper {
    width: calc(100vw - 48px);
    max-width: 480px;
  }
  
  .canvas-area {
      padding:0px !important;
  }
}

/* Visor de zoom sobre canvas-wrapper */
.canvas-preview-toolbar {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    margin-top: 12px;
}
.btn-zoom {
    width: auto;
    min-width: 220px;
    max-width: 100%;
    padding: 12px 18px;
    background: #1a3a5c;
    color: #fff;
}
.btn-zoom:hover { background: #12283f; }
.btn-zoom.is-active {
    background: #c9a227;
    color: #1a1a1a;
}
.canvas-zoom-hint {
    margin: 0;
    max-width: 420px;
}
.canvas-desktop-hint { display: block; }

.canvas-zoom-window {
    display: none;
}
.canvas-zoom-window.is-visible {
    display: block;
}

.canvas-zoom-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    justify-content: center;
    background: #12283f;
    color: #fff;
    padding: 8px;
    border-radius: 10px;
    margin-bottom: 10px;
}
.zoom-tool {
    border: 0;
    background: #1a3a5c;
    color: #fff;
    border-radius: 8px;
    padding: 8px 10px;
    font-size: 0.82rem;
    font-weight: 600;
    cursor: pointer;
}
.zoom-tool.is-active { background: #c9a227; color: #1a1a1a; }
.zoom-tool-close { background: #b71c1c; }
.zoom-pct {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
}
.zoom-pct input[type="range"] {
    width: 110px;
}

body.canvas-zoom-open {
    overflow: hidden;
}
body.canvas-zoom-open .canvas-area-container {
    position: fixed;
    inset: 0;
    z-index: 9000;
    width: 100%;
    max-width: none;
    min-width: 0;
    height: 100dvh;
    margin: 0;
    background: #2a2a2a;
    display: flex;
    flex-direction: column;
}
body.canvas-zoom-open .canvas-zoom-window {
    display: block;
    margin: 0;
    flex: 0 0 auto;
    z-index: 2;
}
body.canvas-zoom-open .canvas-zoom-bar {
    margin: 0;
    border-radius: 0;
    min-height: 52px;
}
body.canvas-zoom-open .canvas-area {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    background: #2a2a2a;
    box-shadow: none;
    border-radius: 0;
    padding: 0;
}
body.canvas-zoom-open .canvas-wrapper {
    width: 100% !important;
    max-width: none !important;
    height: 100%;
    margin: 0 !important;
    overflow: hidden;
    background: #2a2a2a;
    border-radius: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: none;
}
body.canvas-zoom-open .canvas-wrapper.mode-pan .canvas-container {
    pointer-events: none;
}
body.canvas-zoom-open .canvas-preview-toolbar,
body.canvas-zoom-open .canvas-desktop-hint {
    display: none;
}

@media (max-width: 980px) {
    .canvas-desktop-hint { display: none; }
}

/* Móviles muy pequeños: misma proporción 480×720 */
@media (max-width: 380px) {
  .canvas-wrapper,
  #canvas-wrapper,
  .canvas-container-wrapper {
    width: calc(100vw - 32px);
    max-width: 480px;
  }
}

.saved-view {
    margin-top: 10px;
    padding: 12px;
    background: var(--brand-green-soft);
    border: 1px solid #b7e0c8;
    border-radius: 10px;
}
.saved-view a,
.share-modal-card a {
    color: var(--brand-blue);
    font-weight: 700;
    word-break: break-all;
    font-size: 0.82rem;
}
#designViewThumb {
    display: block;
    width: 100%;
    max-height: 240px;
    object-fit: contain;
    background: #fff;
    border-radius: 8px;
    margin: 0 0 8px;
    border: 1px solid var(--border);
}
#designViewThumb[hidden] { display: none; }
.btn-outline {
    background: #fff !important;
    color: var(--brand-blue-dark) !important;
    border: 1px solid var(--border) !important;
}
.share-modal {
    position: fixed;
    inset: 0;
    z-index: 10050;
    background: rgba(10, 30, 50, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.share-modal[hidden] { display: none !important; }
.share-modal-card {
    width: min(460px, 100%);
    max-height: min(92vh, 820px);
    overflow: auto;
    background: #fff;
    border-radius: 16px;
    padding: 18px 18px 12px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
}
.share-modal-card h2 {
    margin: 0 0 6px;
    color: var(--brand-blue-dark);
    font-size: 1.2rem;
}
.share-modal-id {
    margin: 0 0 10px;
    font-weight: 700;
    color: var(--brand-green-dark);
}
#shareModalImg {
    display: block;
    width: 100%;
    max-height: 320px;
    object-fit: contain;
    background: #f4f7fb;
    border-radius: 12px;
    margin-bottom: 8px;
}
.share-modal-actions .btn { margin-bottom: 8px; }

.seo-block {
    margin-top: 28px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px 22px 8px;
    box-shadow: var(--shadow);
}
.seo-block h2 {
    color: var(--brand-blue-dark);
    font-size: 1.25rem;
    margin-bottom: 8px;
}
.seo-block p, .seo-steps {
    color: var(--text);
    font-size: 0.98rem;
}
.seo-steps {
    margin: 12px 0 16px 1.2rem;
}
.seo-steps li { margin: 6px 0; }
.faq-list details {
    border-top: 1px solid var(--border);
    padding: 10px 0;
}
.faq-list summary {
    cursor: pointer;
    font-weight: 700;
    color: var(--brand-blue-dark);
}
.faq-list details p {
    margin: 8px 0 4px;
    color: var(--muted);
}
.seo-note {
    margin-top: 14px;
    font-size: 0.88rem;
    color: var(--muted);
}
.seo-block a { color: var(--brand-blue); font-weight: 700; }