/* GPC Scratch - Main Application Styles */
/* Using Tailwind CSS for utility classes - this file is for component-specific styles only */

/* reCAPTCHA v3 badge — hidden globally, shown only on auth pages (desktop only) */
.grecaptcha-badge {
    visibility: hidden !important;
    opacity: 0 !important;
    transition: opacity 0.3s ease, visibility 0.3s ease !important;
    z-index: 9999 !important;
}
.grecaptcha-badge.show {
    visibility: visible !important;
    opacity: 1 !important;
    right: 4px !important;
    bottom: 14px !important;
    width: 256px !important;
    overflow: visible !important;
}
/* Hide reCAPTCHA badge on mobile — saves screen space, Google allows this with text attribution */
@media (max-width: 639px) {
    .grecaptcha-badge.show {
        visibility: hidden !important;
        opacity: 0 !important;
    }
}

/* Base Styles */
html, body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ── Viewport height fix for auth pages ──
   Desktop: 100vh / 100dvh works perfectly.
   iOS Safari: 100vh includes collapsed address bar → use -webkit-fill-available.
   The .dvh-screen utility replaces min-h-screen on auth pages. */
.dvh-screen {
    min-height: 100vh;
    min-height: 100dvh; /* Chrome 108+, Safari 15.4+, Firefox 94+ */
    overflow-y: auto;
}

.auth-safe-screen {
    align-items: flex-start;
    overflow-x: hidden;
}

.auth-safe-panel {
    margin-top: 0.5rem;
    margin-bottom: 0.5rem;
}

@media (min-width: 640px) {
    .auth-safe-screen {
        align-items: center;
    }

    .auth-safe-panel {
        margin-top: auto;
        margin-bottom: auto;
    }
}

/* iOS Safari specific: override with -webkit-fill-available + safe-area insets */
@supports (-webkit-touch-callout: none) {
    .dvh-screen {
        min-height: -webkit-fill-available;
        padding-top: env(safe-area-inset-top);
        padding-bottom: env(safe-area-inset-bottom);
        -webkit-overflow-scrolling: touch;
    }
    html, body {
        min-height: -webkit-fill-available;
    }
}

/* Focus ring reset for custom styling */
*:focus {
    outline: none;
}

/* Error UI */
#blazor-error-ui {
    display: none;
}

#blazor-error-ui.show {
    display: block;
}

/* Blockly Workspace Container */
.blockly-workspace {
    width: 100%;
    height: 100%;
    position: relative;
}

.blockly-workspace .injectionDiv {
    border-radius: 0.5rem;
    overflow: hidden;
}

/* Blockly Theme Overrides */
.blocklySvg {
    background-color: var(--blockly-workspace-bg) !important;
}

.blocklyMainBackground {
    fill: var(--blockly-workspace-bg) !important;
}

.blocklyFlyoutBackground {
    fill: var(--blockly-flyout-bg) !important;
}

.blocklyScrollbarBackground {
    fill: var(--blockly-scrollbar-bg) !important;
}

.blocklyScrollbarHandle {
    fill: var(--blockly-scrollbar-color) !important;
}

.blocklyToolboxDiv {
    background-color: var(--color-surface) !important;
    border-right: 1px solid var(--color-border) !important;
}

.blocklyTreeRow {
    padding: 4px 8px !important;
}

.blocklyTreeLabel {
    color: var(--color-text) !important;
    font-family: inherit !important;
}

.blocklyTreeSelected {
    background-color: rgb(59 130 246 / 0.1) !important;
}

.blocklyTreeSelected .blocklyTreeLabel {
    color: rgb(59 130 246) !important;
}

/* Fix: Hide flyout scrollbar when flyout is closed */
.blocklyFlyout {
    transition: opacity 0.15s ease-out;
}

.blocklyFlyout[style*="display: none"],
.blocklyFlyout:not([style*="display"]):empty {
    visibility: hidden !important;
}

/* Fix: Scrollbar visibility when flyout is hidden */
.blocklyFlyoutScrollbar {
    transition: opacity 0.1s ease-out;
}

.blocklyFlyout[style*="display: none"] + .blocklyFlyoutScrollbar,
.blocklyFlyout[style*="display: none"] ~ .blocklyFlyoutScrollbar {
    display: none !important;
    opacity: 0 !important;
    visibility: hidden !important;
}

/* Hide scrollbar when flyout background is not visible */
.blocklyFlyoutBackground[style*="display: none"] ~ .blocklyScrollbarVertical,
.blocklyFlyoutBackground[style*="display: none"] ~ .blocklyScrollbarHorizontal {
    display: none !important;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    pointer-events: none;
}

.toast {
    pointer-events: auto;
    animation: toast-slide-in 0.3s ease-out;
}

.toast.toast-exit {
    animation: toast-slide-out 0.2s ease-in forwards;
}

@keyframes toast-slide-in {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes toast-slide-out {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(100%);
        opacity: 0;
    }
}

/* Modal/Dialog Backdrop */
.modal-backdrop {
    position: fixed;
    inset: 0;
    background-color: rgb(0 0 0 / 0.5);
    backdrop-filter: blur(4px);
    z-index: 50;
    animation: backdrop-fade-in 0.2s ease-out;
}

.modal-backdrop.modal-backdrop-exit {
    animation: backdrop-fade-out 0.15s ease-in forwards;
}

@keyframes backdrop-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes backdrop-fade-out {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Moyasar forms ship with light-theme text utilities by default.
   In dark mode we only lift labels/captions, while keeping typed input values dark
   because the fields themselves stay on a light surface. */
.dark .moyasar-host div#mysr label,
.dark .moyasar-host div#mysr legend,
.dark .moyasar-host div#mysr .text-black:not(input):not(select):not(textarea),
.dark .moyasar-host div#mysr .text-black\/90:not(input):not(select):not(textarea),
.dark .moyasar-host div#mysr .text-neutral-800\/90:not(input):not(select):not(textarea) {
    color: rgb(241 245 249 / 0.94) !important;
}

.dark .moyasar-host div#mysr input,
.dark .moyasar-host div#mysr input.text-black,
.dark .moyasar-host div#mysr input.text-black\/90,
.dark .moyasar-host div#mysr input.text-neutral-800\/90,
.dark .moyasar-host div#mysr select,
.dark .moyasar-host div#mysr select.text-black,
.dark .moyasar-host div#mysr select.text-black\/90,
.dark .moyasar-host div#mysr select.text-neutral-800\/90,
.dark .moyasar-host div#mysr textarea {
    color: rgb(15 23 42 / 0.96) !important;
    caret-color: rgb(15 23 42 / 0.96) !important;
}

/* Modal Content */
.modal-content {
    animation: modal-scale-in 0.2s ease-out;
}

.modal-content.modal-content-exit {
    animation: modal-scale-out 0.15s ease-in forwards;
}

@keyframes modal-scale-in {
    from {
        transform: scale(0.95);
        opacity: 0;
    }
    to {
        transform: scale(1);
        opacity: 1;
    }
}

@keyframes modal-scale-out {
    from {
        transform: scale(1);
        opacity: 1;
    }
    to {
        transform: scale(0.95);
        opacity: 0;
    }
}

/* Code Preview Panel */
.code-preview {
    font-family: 'Fira Code', 'JetBrains Mono', 'Consolas', monospace;
    font-size: 0.875rem;
    line-height: 1.5;
    tab-size: 4;
}

.code-preview .line-number {
    color: var(--color-text-muted);
    user-select: none;
    text-align: right;
    padding-right: 1rem;
    border-right: 1px solid var(--color-border);
    margin-right: 1rem;
}

/* Keyboard Shortcut Badge */
.kbd {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.125rem 0.375rem;
    font-family: inherit;
    font-size: 0.75rem;
    font-weight: 500;
    line-height: 1;
    border-radius: 0.25rem;
    background-color: var(--color-surface-tertiary);
    border: 1px solid var(--color-border);
    color: var(--color-text-secondary);
}

/* Loading States */
.skeleton {
    background: linear-gradient(
        90deg,
        var(--color-surface-secondary) 25%,
        var(--color-surface-tertiary) 50%,
        var(--color-surface-secondary) 75%
    );
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s infinite;
}

@keyframes skeleton-loading {
    0% { background-position: 200% 0; }
    100% { background-position: -200% 0; }
}

/* Dropdown Menu */
.dropdown-menu {
    animation: dropdown-fade-in 0.15s ease-out;
}

@keyframes dropdown-fade-in {
    from {
        transform: translateY(-4px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

/* Tooltip */
.tooltip {
    animation: tooltip-fade-in 0.15s ease-out;
}

@keyframes tooltip-fade-in {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Search Highlight */
.search-highlight {
    background-color: rgb(250 204 21 / 0.4);
    border-radius: 2px;
}

.dark .search-highlight {
    background-color: rgb(250 204 21 / 0.3);
}

/* Resize Handle */
.resize-handle {
    cursor: col-resize;
    transition: background-color 0.2s;
}

.resize-handle:hover,
.resize-handle:active {
    background-color: rgb(59 130 246 / 0.5);
}

/* Button Styles */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.25rem;
    border-radius: 0.375rem;
    transition: all 0.15s ease-in-out;
    cursor: pointer;
    border: none;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background-color: rgb(59 130 246);
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: rgb(37 99 235);
}

.btn-secondary {
    background-color: var(--color-surface-tertiary);
    color: var(--color-text);
    border: 1px solid var(--color-border);
}

.btn-secondary:hover:not(:disabled) {
    background-color: var(--color-border);
}

.btn-danger {
    background-color: rgb(239 68 68);
    color: white;
}

.btn-danger:hover:not(:disabled) {
    background-color: rgb(220 38 38);
}

.btn-ghost {
    background-color: transparent;
    color: var(--color-text-secondary);
}

.btn-ghost:hover:not(:disabled) {
    background-color: var(--color-surface-tertiary);
    color: var(--color-text);
}

/* Icon Button */
.btn-icon {
    padding: 0.5rem;
    width: 2.25rem;
    height: 2.25rem;
}

/* Input Styles */
.input {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    line-height: 1.25rem;
    background-color: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: 0.375rem;
    color: var(--color-text);
    transition: border-color 0.15s, box-shadow 0.15s;
}

.input:focus {
    border-color: var(--color-border-focus);
    box-shadow: 0 0 0 3px rgb(59 130 246 / 0.1);
}

.input::placeholder {
    color: var(--color-text-muted);
}

/* Native select option styling for dark mode */
.dark select.input option,
.dark .input option {
    background-color: var(--color-surface);
    color: var(--color-text);
}

select.input {
    color-scheme: light dark;
}

/* Select Styles */
.select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
    background-position: right 0.5rem center;
    background-repeat: no-repeat;
    background-size: 1.5em 1.5em;
    padding-right: 2.5rem;
}

/* Checkbox */
.checkbox {
    width: 1rem;
    height: 1rem;
    border: 1px solid var(--color-border);
    border-radius: 0.25rem;
    background-color: var(--color-surface);
    cursor: pointer;
    transition: all 0.15s;
}

.checkbox:checked {
    background-color: rgb(59 130 246);
    border-color: rgb(59 130 246);
}

/* Toggle Switch */
.toggle {
    position: relative;
    width: 2.75rem;
    height: 1.5rem;
    background-color: var(--color-surface-tertiary);
    border-radius: 9999px;
    cursor: pointer;
    transition: background-color 0.2s;
}

.toggle::after {
    content: '';
    position: absolute;
    top: 0.125rem;
    left: 0.125rem;
    width: 1.25rem;
    height: 1.25rem;
    background-color: white;
    border-radius: 50%;
    transition: transform 0.2s;
    box-shadow: 0 1px 3px rgb(0 0 0 / 0.1);
}

.toggle.active {
    background-color: rgb(59 130 246);
}

.toggle.active::after {
    transform: translateX(1.25rem);
}

/* Panel Divider */
.panel-divider {
    width: 1px;
    background-color: var(--color-border);
}

.panel-divider-horizontal {
    height: 1px;
    width: 100%;
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    text-align: center;
}

.empty-state-icon {
    width: 4rem;
    height: 4rem;
    margin-bottom: 1rem;
    color: var(--color-text-muted);
}

.empty-state-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--color-text);
    margin-bottom: 0.5rem;
}

.empty-state-description {
    font-size: 0.875rem;
    color: var(--color-text-secondary);
    max-width: 24rem;
}


code {
    color: #c02d76;
}

/* ===================== RTL Support ===================== */

/* Toast container: flip to left side in RTL */
[dir="rtl"] .toast-container {
    right: auto;
    left: 1rem;
}

/* Toast slide animations: flip direction in RTL */
[dir="rtl"] .toast {
    animation: toast-slide-in-rtl 0.3s ease-out;
}

[dir="rtl"] .toast.toast-exit {
    animation: toast-slide-out-rtl 0.2s ease-in forwards;
}

@keyframes toast-slide-in-rtl {
    from {
        transform: translateX(-100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

@keyframes toast-slide-out-rtl {
    from {
        transform: translateX(0);
        opacity: 1;
    }
    to {
        transform: translateX(-100%);
        opacity: 0;
    }
}

/* Code preview line numbers: flip padding/border in RTL */
[dir="rtl"] .code-preview .line-number {
    text-align: left;
    padding-right: 0;
    padding-left: 1rem;
    border-right: none;
    border-left: 1px solid var(--color-border);
    margin-right: 0;
    margin-left: 1rem;
}

/* Select dropdown arrow: flip to left side in RTL */
[dir="rtl"] .select {
    background-position: left 0.5rem center;
    padding-right: 0.75rem;
    padding-left: 2.5rem;
}

/* Blockly toolbox border: flip to left in RTL */
[dir="rtl"] .blocklyToolboxDiv {
    border-right: none !important;
    border-left: 1px solid var(--color-border) !important;
}

/* Toggle switch: flip direction in RTL */
[dir="rtl"] .toggle::after {
    left: auto;
    right: 0.125rem;
}

[dir="rtl"] .toggle.active::after {
    transform: translateX(-1.25rem);
}

/* Resize handle: flip cursor in RTL */
[dir="rtl"] .resize-handle {
    cursor: col-resize;
}

/* Dropdown menu animation: flip in RTL */
[dir="rtl"] .dropdown-menu {
    right: auto;
    left: 0;
}

/* ==================== MOBILE / RESPONSIVE ==================== */

/* Larger touch targets on touch devices */
@media (pointer: coarse) {
    .btn-icon {
        min-width: 2.75rem;
        min-height: 2.75rem;
    }
    
    .btn {
        min-height: 2.75rem;
    }
    
    .input, .select, .form-select {
        min-height: 2.75rem;
        font-size: 1rem; /* Prevent iOS zoom on focus */
    }
}

/* Small screens: adjust toast position to avoid nav overlap */
@media (max-width: 639px) {
    .toast-container {
        top: 3.5rem; /* Below the mobile nav bar (h-12 = 3rem + margin) */
        right: 0.5rem;
        left: 0.5rem;
    }
    
    .toast-container .toast {
        width: 100%;
    }
    
    /* Blockly toolbox: compact on mobile */
    .blocklyToolboxDiv {
        width: auto !important;
    }
    
    /* Card padding adjustments */
    .card-header {
        padding: 0.75rem 1rem;
    }
    
    .card-body {
        padding: 0.75rem 1rem;
    }
    
    /* Form select full width on mobile */
    .form-select {
        width: 100%;
    }
}

/* Safe area support for notched devices */
@supports (padding-bottom: env(safe-area-inset-bottom)) {
    .safe-area-bottom {
        padding-bottom: env(safe-area-inset-bottom);
    }
}

/* ─── Animations ───────────────────────────────────────────────────────── */
@keyframes animate-in-scale {
    from { opacity: 0; transform: scale(0.95); }
    to   { opacity: 1; transform: scale(1);    }
}
.animate-in {
    animation: animate-in-scale 0.15s ease-out;
}

/* Hide scrollbar but allow scroll (tab strip) */
.scrollbar-hidden::-webkit-scrollbar { display: none; }
.scrollbar-hidden { scrollbar-width: none; -ms-overflow-style: none; }
