/* Ghep Anh AI Mockup Tool - Style */
:root {
    --bg-color: #0f172a; /* Slate 900 */
    --surface-color: rgba(30, 41, 59, 0.7); /* Slate 800 with glass opacity */
    --accent-color: #3b82f6; /* Blue 500 */
    --accent-hover: #2563eb; /* Blue 600 */
    --text-color: #f8fafc; /* Slate 50 */
    --subtext-color: #94a3b8; /* Slate 400 */
    --border-color: rgba(148, 163, 184, 0.2); /* Slate 400 with opacity */
    --glass-blur: blur(12px);
    --border-radius: 12px;
}

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

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--text-color);
    overflow: hidden;
    height: 100vh;
}

.glass {
    background: var(--surface-color);
    backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
}

header {
    height: 70px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    z-index: 100;
}

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    font-size: 24px;
}

.logo h1 {
    font-size: 20px;
    font-weight: 700;
}

.logo h1 sup {
    font-size: 10px;
    color: var(--accent-color);
    vertical-align: super;
}

main {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: calc(100vh - 70px);
}

.sidebar {
    padding: 24px;
    display: flex;
    flex-direction: column;
    gap: 32px;
    border-right: 1px solid var(--border-color);
}

.control-group h3 {
    font-size: 14px;
    color: var(--subtext-color);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 16px;
}

.upload-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.upload-label {
    padding: 14px;
    background: var(--accent-color);
    color: white;
    border-radius: var(--border-radius);
    text-align: center;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    font-weight: 600;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.upload-label:hover {
    background: var(--accent-hover);
}

.upload-label.secondary {
    background: rgba(148, 163, 184, 0.1);
    border: 1px solid var(--border-color);
}

.upload-label.secondary:hover {
    background: rgba(148, 163, 184, 0.2);
}

.btn {
    padding: 12px;
    border-radius: var(--border-radius);
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    width: 100%;
}

.btn-primary {
    background: var(--accent-color);
    color: white;
}

.btn-action {
    background: #8b5cf6; /* Violet 500 */
    color: white;
}

.btn-action:hover {
    background: #7c3aed; /* Violet 600 */
}

.control-item label {
    display: block;
    margin-bottom: 8px;
    color: var(--subtext-color);
    font-size: 13px;
}

input[type="range"] {
    width: 100%;
    margin: 8px 0;
}

kbd {
    background: rgba(148, 163, 184, 0.1);
    color: var(--subtext-color);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 0.8em;
}

ul li {
    list-style: none;
    font-size: 13px;
    color: var(--subtext-color);
    margin-bottom: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.canvas-container {
    position: relative;
    background: radial-gradient(circle, #1e293b 0%, #0f172a 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
}

.loader-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(15, 23, 42, 0.9);
    backdrop-filter: var(--glass-blur);
    padding: 28px 44px;
    border-radius: 20px;
    text-align: center;
    z-index: 200;
    border: 1px solid var(--accent-color);
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 220px;
}

.loader-inner {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    width: 100%;
}

/* PWA-01: AI progress bar */
.ai-progress-track {
    width: 100%;
    height: 6px;
    background: rgba(148, 163, 184, 0.2);
    border-radius: 999px;
    overflow: hidden;
    animation: progressPulse 2s ease-in-out infinite;
}

.ai-progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-color), #8b5cf6);
    border-radius: 999px;
    transition: width 0.4s ease;
    width: 60%; /* Indeterminate animation fallback */
    animation: progressSlide 1.8s ease-in-out infinite;
}

@keyframes progressSlide {
    0%   { transform: translateX(-100%); width: 50%; }
    50%  { transform: translateX(100%); width: 50%; }
    100% { transform: translateX(-100%); width: 50%; }
}

@keyframes progressPulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.75; }
}

.spinner {
    border: 4px solid rgba(148, 163, 184, 0.1);
    border-top: 4px solid var(--accent-color);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 16px;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Crop Button */
.btn-crop {
    background: #f59e0b; /* Amber 500 */
    color: #1e293b;
}
.btn-crop:hover {
    background: #d97706; /* Amber 600 */
}

/* Cancel Button */
.btn-cancel {
    background: rgba(148, 163, 184, 0.15);
    color: var(--subtext-color);
    border: 1px solid var(--border-color);
}
.btn-cancel:hover {
    background: rgba(148, 163, 184, 0.3);
}

/* Modal Overlay */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(6px);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    width: 80vw;
    max-width: 900px;
    max-height: 90vh;
    border-radius: 20px;
    padding: 28px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.modal-header h2 {
    font-size: 20px;
    margin-bottom: 4px;
}

.modal-hint {
    font-size: 13px;
    color: var(--subtext-color);
}

.crop-canvas-wrapper {
    background: #0f172a;
    border-radius: var(--border-radius);
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    border: 1px solid var(--border-color);
}

.modal-actions {
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

.modal-actions .btn {
    width: auto;
    padding: 12px 28px;
}
/* Control Grid for buttons */
.control-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-bottom: 24px;
}

.btn-secondary {
    background: rgba(148, 163, 184, 0.1);
    color: var(--text-color);
    border: 1px solid var(--border-color);
    font-size: 13px;
    padding: 10px 8px;
}

.btn-secondary:hover {
    background: rgba(148, 163, 184, 0.2);
}

.select-input {
    width: 100%;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-color);
    padding: 10px;
    font-family: inherit;
    outline: none;
    cursor: pointer;
    transition: all 0.2s;
}

.select-input:focus {
    border-color: var(--accent-color);
}

.control-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 24px;
}

/* Layer List styling */
.layer-list {
    background: rgba(15, 23, 42, 0.3);
    border-radius: var(--border-radius);
    max-height: 250px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
}

.layer-empty {
    padding: 30px;
    text-align: center;
    color: var(--subtext-color);
    font-size: 13px;
    font-style: italic;
}

.layer-item {
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: all 0.2s;
}

.layer-item:last-child {
    border-bottom: none;
}

.layer-item:hover {
    background: rgba(59, 130, 246, 0.1);
}

.layer-item.active {
    background: rgba(59, 130, 246, 0.2);
    border-left: 3px solid var(--accent-color);
}

.layer-thumb {
    width: 40px;
    height: 40px;
    background: #1e293b;
    border-radius: 4px;
    object-fit: cover;
    border: 1px solid var(--border-color);
}

.layer-name {
    flex: 1;
    font-size: 13px;
    font-weight: 500;
}

.layer-actions {
    display: flex;
    gap: 4px;
    align-items: center;
    flex-shrink: 0;
}

.layer-btn {
    width: 26px;
    height: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(148, 163, 184, 0.08);
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    opacity: 0.4;
    transition: all 0.15s;
    padding: 0;
    color: var(--text-color);
}

.layer-item:hover .layer-btn {
    opacity: 0.8;
}

.layer-btn:hover {
    opacity: 1 !important;
    background: rgba(59, 130, 246, 0.2);
    border-color: var(--accent-color);
}

.layer-btn:disabled {
    opacity: 0.15 !important;
    cursor: not-allowed;
    background: none;
    border-color: transparent;
}

.layer-btn-delete:hover {
    background: rgba(239, 68, 68, 0.2) !important;
    border-color: #ef4444 !important;
    color: #ef4444;
}

.layer-btn-dup:hover {
    background: rgba(20, 184, 166, 0.2) !important;
    border-color: #14b8a6 !important;
}

.layer-btn-up:hover,
.layer-btn-down:hover {
    background: rgba(59, 130, 246, 0.2) !important;
    border-color: var(--accent-color) !important;
}

/* Initialize on Load */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

/* Dim Line Controls */
.dim-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.dim-btn {
    flex: 1;
    padding: 10px 8px;
    font-size: 13px;
}

.dim-colors {
    display: flex;
    align-items: center;
    gap: 5px;
    flex-shrink: 0;
}

.dim-swatch {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
    display: inline-block;
    flex-shrink: 0;
}

.dim-swatch:hover {
    transform: scale(1.25);
}

.dim-swatch.active {
    box-shadow: 0 0 0 2px white, 0 0 0 4px var(--accent-color);
    transform: scale(1.15);
}

/* ======================================== */
/* DUPLICATE BUTTON                         */
/* ======================================== */

.btn-duplicate {
    background: linear-gradient(135deg, #14b8a6, #0d9488);
    color: white;
    border: none;
    font-weight: 600;
}

.btn-duplicate:hover {
    background: linear-gradient(135deg, #0d9488, #0f766e);
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(20, 184, 166, 0.35);
}

/* ======================================== */
/* TEXT FEATURE STYLES                      */
/* ========================================  */

.text-btn {
    background: linear-gradient(135deg, #8b5cf6, #6366f1) !important;
    color: white;
    border: none;
    font-weight: 600;
}

.text-btn:hover {
    background: linear-gradient(135deg, #7c3aed, #4f46e5) !important;
    transform: translateY(-1px);
    box-shadow: 0 4px 12px rgba(139, 92, 246, 0.35);
}

.text-control-item {
    margin-bottom: 12px;
}

.text-control-item label {
    display: block;
    margin-bottom: 6px;
    color: var(--subtext-color);
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.text-input {
    width: 100%;
    background: rgba(15, 23, 42, 0.6);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-color);
    padding: 10px 12px;
    font-family: inherit;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.text-input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(59, 130, 246, 0.15);
}

input[type="number"].text-input {
    -moz-appearance: textfield;
    appearance: textfield;
}

input[type="number"].text-input::-webkit-inner-spin-button,
input[type="number"].text-input::-webkit-outer-spin-button {
    opacity: 1;
}

.text-control-row {
    display: flex;
    gap: 12px;
    align-items: flex-end;
}

.text-color-picker {
    width: 100%;
    height: 36px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: none;
    cursor: pointer;
    padding: 2px;
}

.text-style-buttons {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.text-style-btn {
    flex: 1;
    padding: 8px 4px !important;
    font-size: 15px !important;
    text-align: center;
    border-radius: 8px;
    transition: all 0.15s;
    min-width: 0;
}

.text-style-btn.active {
    background: rgba(59, 130, 246, 0.3) !important;
    border-color: var(--accent-color) !important;
    color: var(--accent-color);
    box-shadow: 0 0 0 1px var(--accent-color);
}

.text-bg-row {
    display: flex;
    align-items: center;
    gap: 12px;
}

.text-bg-row .text-color-picker {
    width: 50px;
    flex-shrink: 0;
}

.text-bg-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--subtext-color);
    cursor: pointer;
    user-select: none;
}

.text-bg-toggle input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--accent-color);
    cursor: pointer;
}


/* Sidebar scrollable */
.sidebar {
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border-color) transparent;
}

.sidebar::-webkit-scrollbar {
    width: 6px;
}

.sidebar::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

/* =============================================
   PWA-02: MOBILE BOTTOM SHEET
   ============================================= */

/* Hide sidebar, show bottom sheet on mobile */
@media (max-width: 768px) {
    body { overflow: hidden; }

    main {
        grid-template-columns: 1fr !important;
    }

    .sidebar {
        display: none !important;
    }

    .app-header {
        padding: 0 16px;
        height: 56px;
    }

    .app-header h1 {
        font-size: 16px;
    }

    .canvas-container {
        height: calc(100dvh - 56px - 180px); /* leave room for bottom sheet collapsed */
    }
}

/* Bottom Sheet base */
.bottom-sheet {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 500;
    border-radius: 20px 20px 0 0;
    padding: 0 16px 32px;
    max-height: 85dvh;
    overflow-y: auto;
    transform: translateY(calc(100% - 170px)); /* collapsed: show tabs + handle */
    transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
    will-change: transform;
    /* Hide on desktop */
    display: none;
    touch-action: none;
}

@media (max-width: 768px) {
    .bottom-sheet {
        display: block;
    }
}

.bottom-sheet.expanded {
    transform: translateY(0);
}

/* Backdrop */
.bs-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.45);
    z-index: 499;
    backdrop-filter: blur(4px);
    opacity: 0;
    transition: opacity 0.3s ease;
    pointer-events: none;
}

.bs-backdrop.visible {
    opacity: 1;
    pointer-events: auto;
}

/* Handle pill */
.bs-handle {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px 0 8px;
    cursor: grab;
    user-select: none;
    touch-action: none;
}

.bs-handle-pill {
    width: 40px;
    height: 4px;
    background: rgba(148, 163, 184, 0.4);
    border-radius: 999px;
    transition: background 0.2s;
}

.bs-handle:hover .bs-handle-pill {
    background: var(--accent-color);
}

/* Bottom Sheet Tabs */
.bs-tabs {
    display: flex;
    gap: 4px;
    background: rgba(15, 23, 42, 0.5);
    border-radius: 12px;
    padding: 4px;
    margin-bottom: 12px;
}

.bs-tab {
    flex: 1;
    background: none;
    border: none;
    color: var(--subtext-color);
    font-size: 12px;
    font-weight: 600;
    font-family: inherit;
    padding: 8px 4px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
    /* min tap target */
    min-height: 44px;
}

.bs-tab.active {
    background: var(--accent-color);
    color: white;
    box-shadow: 0 2px 8px rgba(59,130,246,0.4);
}

/* Upload Row (Inputs tab) */
.bs-upload-row {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 8px;
}

.bs-upload-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    background: var(--accent-color);
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-family: inherit;
    font-weight: 600;
    font-size: 11px;
    padding: 12px 6px;
    transition: all 0.2s;
    /* iOS tap target */
    min-height: 64px;
    text-align: center;
}

.bs-upload-btn span:first-child {
    font-size: 20px;
}

.bs-upload-btn:active {
    transform: scale(0.96);
}

.bs-upload-btn--secondary {
    background: rgba(148,163,184,0.12);
    border: 1px solid var(--border-color);
    color: var(--text-color);
}

.bs-upload-btn--dim {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

.bs-upload-btn--text {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
}

/* Adjust tab */
.bs-adjust-row {
    margin-bottom: 12px;
}

.bs-label {
    display: block;
    font-size: 12px;
    color: var(--subtext-color);
    margin-bottom: 6px;
}

.bs-slider {
    width: 100%;
    accent-color: var(--accent-color);
    height: 6px;
}

.bs-btn-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
}

.bs-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    background: rgba(148,163,184,0.1);
    border: 1px solid var(--border-color);
    color: var(--text-color);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    border-radius: 12px;
    cursor: pointer;
    padding: 12px;
    min-height: 48px;
    transition: all 0.2s;
}

.bs-action-btn:active {
    transform: scale(0.96);
}

.bs-action-btn--ai {
    background: linear-gradient(135deg, #8b5cf6, #6366f1);
    border: none;
    color: white;
    grid-column: 1 / -1; /* full width */
}

.bs-action-btn--crop {
    background: rgba(245,158,11,0.15);
    border-color: #f59e0b;
    color: #f59e0b;
}

.bs-action-btn--download {
    background: rgba(59,130,246,0.15);
    border-color: var(--accent-color);
    color: var(--accent-color);
}

/* Layers tab in Bottom Sheet */
.bs-layer-list {
    background: rgba(15, 23, 42, 0.3);
    border-radius: var(--border-radius);
    max-height: 180px;
    overflow-y: auto;
    border: 1px solid var(--border-color);
}

/* =============================================
   PWA-02: FAB (Floating Action Button)
   ============================================= */

.mobile-fab {
    position: fixed;
    bottom: 188px; /* above bottom sheet collapsed handle */
    right: 16px;
    z-index: 501;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--accent-color);
    color: white;
    border: none;
    font-size: 22px;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(59, 130, 246, 0.5);
    display: none;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    /* min tap target */
    touch-action: manipulation;
}

@media (max-width: 768px) {
    .mobile-fab {
        display: flex;
    }
}

.mobile-fab:active {
    transform: scale(0.92);
    box-shadow: 0 2px 10px rgba(59, 130, 246, 0.35);
}
