:root {
    --color-primary: 249 115 22;
    --color-primary-hover: 234 88 12;
    --color-secondary: 59 130 246;
    --color-bg: 248 250 252;
    --color-surface: 255 255 255;
    --color-text: 15 23 42;
    --color-text-secondary: 51 65 85;
    --color-muted: 100 116 139;
    --color-border: 226 232 240;
    --color-success: 34 197 94;
    --color-warning: 245 158 11;
    --color-error: 239 68 68;
    --shadow-light: 0 1px 3px 0 #0001;
    --shadow-medium: 0 4px 6px -1px #0001;
    --shadow-heavy: 0 10px 15px -3px #0001;
    --safe-area-inset-top: env(safe-area-inset-top, 0px);
    --safe-area-inset-bottom: env(safe-area-inset-bottom, 0px);
}

.dark {
    --color-primary: 249 115 22;
    --color-primary-hover: 234 88 12;
    --color-secondary: 167 139 250;
    --color-bg: 24 24 27;
    --color-surface: 39 39 42;
    --color-text: 250 250 250;
    --color-text-secondary: 228 228 231;
    --color-muted: 161 161 170;
    --color-border: 63 63 70;
    --shadow-light: 0 1px 3px 0 #0003;
    --shadow-medium: 0 4px 6px -1px #0003;
    --shadow-heavy: 0 10px 15px -3px #0004
}

.loader-overlay {
    position: fixed;
    inset: 0;
    background: rgb(var(--color-bg));
    z-index: 9999;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: opacity .3s ease-in-out;
}
.loader-overlay.loader-hidden {
    opacity: 0;
    pointer-events: none;
}
.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid rgb(var(--color-border));
    border-top-color: rgb(var(--color-primary));
    border-radius: 50%;
    animation: spin 1s linear infinite;
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Top Notification - IMPROVED */
.top-notification {
    position: fixed;
    top: 0;
    left: var(--spacing-md, 10px);
    right: var(--spacing-md, 10px);
    background: rgb(var(--color-surface));
    border: 1px solid rgb(var(--color-border));
    border-radius: 0 0 16px 16px;
    padding: 14px 20px;
    z-index: 1001;
    box-shadow: var(--shadow-heavy);
    transform: translateY(-100%);
    transition: transform .4s cubic-bezier(.4, 0, .2, 1);
    font-weight: 500;
    text-align: center;
    color: rgb(var(--color-text));
    margin-top: var(--safe-area-inset-top);
    border-top: none;
}
.top-notification.visible {
    transform: translateY(0);
}
.top-notification.success {
    background: rgb(var(--color-success) / 0.95);
    color: #fff;
    border-color: rgb(var(--color-success) / 0.6);
}
.top-notification.info {
    background: rgb(var(--color-secondary) / 0.95);
    color: #fff;
    border-color: rgb(var(--color-secondary) / 0.6);
}
.top-notification.error {
    background: rgb(var(--color-error) / 0.95);
    color: #fff;
    border-color: rgb(var(--color-error) / 0.6);
}

html {
    width: 100%;
    overflow-x: hidden
}
* {
    -webkit-tap-highlight-color: transparent;
    user-select: none;
}
body {
    font-family: 'Noto Sans Thai', sans-serif;
    background-color: rgb(var(--color-bg));
    min-height: 100dvh;
    color: rgb(var(--color-text));
    display: flex;
    flex-direction: column;
    transition: color .3s ease, background-color .3s ease;
}
main#appMain {
    position: relative;
    flex: 1;
    overflow: hidden; 
}
.dark body {
    background-color: rgb(var(--color-bg));
    background-image: none;
    background-attachment: fixed
}
.page-container {
    position: absolute;
    inset: 0;
    transition: opacity .3s ease; 
    will-change: opacity
}
#welcomeView,#resetNewPinView,#resetConfirmOldPinView {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}
.page-hidden {
    opacity: 0;
    pointer-events: none;
}
.page-visible {
    opacity: 1;
}
.btn-icon {
    transition: all .2s cubic-bezier(.4, 0, .2, 1);
    border-radius: 12px;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center
}
.btn-icon:hover {
    background: rgb(var(--color-primary)/.1);
    color: rgb(var(--color-primary));
    transform: scale(1.05)
}
.btn-icon:active {
    transform: scale(.95)
}
.glass {
    background: rgba(var(--color-surface), 0.95);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border: 1px solid rgba(var(--color-border), 0.3);
    box-shadow: var(--shadow-light);
    transition: background-color .3s ease, border-color .3s ease;
}
.dark .glass {
    background: rgba(var(--color-surface), 0.95);
    border: 1px solid rgba(var(--color-border), 0.3)
}
.partners-header,.partners-footer {
    background: rgb(var(--color-surface)/.85);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    flex-shrink: 0;
    z-index: 10;
    transition: opacity .3s ease, transform .3s ease, background-color .3s ease;
}
.partners-header {
    border-bottom: 1px solid rgb(var(--color-border));
    box-shadow: var(--shadow-light);
    height: 50px;
    padding-top: var(--safe-area-inset-top);
}
.partners-footer {
    border-top: 1px solid rgb(var(--color-border));
    box-shadow: 0 -2px 8px #0000000d;
    height: 50px;
    padding-bottom: var(--safe-area-inset-bottom);
}
.header-content,.footer-content {
    padding: 0 16px;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: space-between
}

/* Sidebar - REDESIGNED */
.sidebar {
    position: fixed;
    top: 0;
    left: calc(-1 * min(75%, 300px));
    width: min(75%, 300px);
    height: 100vh;
    background: rgb(var(--color-surface));
    -webkit-backdrop-filter: blur(25px);
    backdrop-filter: blur(25px);
    z-index: 100;
    transition: transform .3s cubic-bezier(.4, 0, .2, 1), background-color .3s ease;
    box-shadow: var(--shadow-heavy);
    border-right: 1px solid rgb(var(--color-border));
    padding-top: var(--safe-area-inset-top);
    padding-bottom: var(--safe-area-inset-bottom);
}
.sidebar.open {
    transform: translateX(100%);
}
.sidebar-overlay {
    position: fixed;
    inset: 0;
    background: #0006;
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    z-index: 99;
    opacity: 0;
    pointer-events: none;
    transition: opacity .3s ease
}
.sidebar-overlay.open {
    opacity: 1;
    pointer-events: auto
}
.sidebar-link {
    display: flex;
    align-items: center;
    padding: 0.8rem 1rem;
    border-radius: 12px;
    color: rgb(var(--color-text-secondary));
    text-decoration: none;
    font-weight: 500;
    transition: background-color .3s ease, color .3s ease, transform .2s ease;
    width: 100%;
    background: rgba(var(--color-surface), 0.9);
    border: 1px solid rgba(var(--color-border), 0.2);
    text-align: left;
}
.sidebar-link:hover {
    background: rgba(var(--color-primary), 0.1);
    color: rgb(var(--color-primary));
    transform: translateX(5px);
}
.sidebar-link .material-icons {
    margin-right: 1rem;
    color: rgb(var(--color-secondary));
}

/* Theme Switch */
.theme-switch {
    position: relative;
    width: 44px;
    height: 24px;
    background: rgb(var(--color-border));
    border-radius: 12px;
    transition: background-color .3s ease;
}
.dark .theme-switch {
    background: rgb(var(--color-primary));
}
.theme-switch-slider {
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    transition: transform .3s ease;
    box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}
.dark .theme-switch-slider {
    transform: translateX(20px);
}

.workspace-iframe {
    width: 100%;
    height: 100%;
    border: none;
    background: transparent;
    transition: opacity .2s ease; 
}

/* Footer Navigation */
.nav-container {
    display: flex;
    gap: 4px;
    background: rgb(var(--color-surface)/.8);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    border: 1px solid rgb(var(--color-border)/.5);
    box-shadow: var(--shadow-light);
    border-radius: 24px;
    padding: 4px;
    transition: background-color .3s ease, border-color .3s ease;
}
.nav-button {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 20px;
    transition: all .3s cubic-bezier(.4, 0, .2, 1)
}
.nav-button:hover {
    background: rgb(var(--color-primary)/.1);
    transform: scale(1.05);
    color: rgb(var(--color-primary))
}
.nav-button.active {
    background: linear-gradient(135deg,rgb(var(--color-primary)),rgb(var(--color-primary-hover)));
    color: #fff!important;
    box-shadow: var(--shadow-medium), 0 0 20px rgb(var(--color-primary)/.4);
    transform: scale(1.05);
    border-radius: 20px
}
.theme-toggle:hover {
    transform: rotate(180deg) scale(1.1)
}
.welcome-title {
    font-size: 1.5rem;
    background: linear-gradient(90deg,#9b25f9,#26c5f3);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: 0 0 10px #fff4;
    position: relative;
    z-index: 20;
    margin: 0;
    text-align: center;
    font-weight: 700;
    transition: color .3s ease;
}
.input-wrapper {
    position: relative;
    width: 350px;
    max-width: 90%;
    height: 56px;
    z-index: 20
}
.input-wrapper.error {
    animation: shake .5s ease-in-out
}
.input-box {
    width: 100%;
    height: 100%;
    padding: 16px 20px;
    font-size: 1.2rem;
    border: none;
    border-radius: 16px;
    background: #1a1a1a;
    color: #fff;
    box-sizing: border-box;
    transition: all .3s ease;
    box-shadow: 0 0 15px #0008
}
.input-box:focus {
    outline: none
}
@keyframes shake {
    0%,100% {
        transform: translateX(0)
    }
    10%,30%,50%,70%,90% {
        transform: translateX(-5px)
    }
    20%,40%,60%,80% {
        transform: translateX(5px)
    }
}
.animated-gradient-border {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 100;
    opacity: 0;
    transition: opacity .3s ease;
}
.radius-16 { border-radius: 16px; }
.radius-16::before { border-radius: 16px; }
.radius-round { border-radius: 9999px; }
.radius-round::before { border-radius: 9999px; }
.input-wrapper:focus-within .animated-gradient-border,
.gradient-input-container:focus-within .animated-gradient-border {
    opacity: 1;
}
.animated-gradient-border::before {
    content: '';
    position: absolute;
    inset: 0;
    padding: 2px;
    background: linear-gradient(90deg,#9b25f9,#26c5f3,#9b25f9);
    background-size: 300% 100%;
    -webkit-mask: linear-gradient(#fff 0 0) content-box,linear-gradient(#fff 0 0);
    -webkit-mask-composite: xor;
    mask-composite: exclude;
    animation: draw 1.3s ease forwards,gradientFlow 3s linear infinite,glow 2s ease-in-out infinite alternate;
}
@keyframes draw {
    0% {
        clip-path: polygon(100% 100%,100% 100%,100% 100%,100% 100%)
    }
    25% {
        clip-path: polygon(100% 100%,0% 100%,0% 100%,0% 100%)
    }
    50% {
        clip-path: polygon(100% 100%,0% 100%,0% 0%,0% 0%)
    }
    75% {
        clip-path: polygon(100% 100%,0% 100%,0% 0%,100% 0%)
    }
    100% {
        clip-path: polygon(100% 100%,0% 100%,0% 0%,100% 0%,100% 100%)
    }
}
@keyframes gradientFlow {
    0% {
        background-position: 0% 50%
    }
    50% {
        background-position: 100% 50%
    }
    100% {
        background-position: 0% 50%
    }
}
@keyframes glow {
    0% {
        filter: drop-shadow(0 0 5px #b429f9b3)
    }
    50% {
        filter: drop-shadow(0 0 10px #26c5f3cc)
    }
    100% {
        filter: drop-shadow(0 0 12px #b429f9e6)
    }
}
.particles {
    position: absolute;
    inset: 0;
    z-index: 1;
    pointer-events: none;
    display: none; 
}
.particle {
    position: absolute;
    border-radius: 50%;
    background: linear-gradient(90deg,hsla(280,95%,80%,.3),hsla(193,90%,80%,.3));
    animation: float 15s infinite linear
}
@keyframes float {
    0% {
        transform: translateY(0) translateX(0) rotate(0);
        opacity: 0
    }
    10% {
        opacity: 1
    }
    90% {
        opacity: .5
    }
    100% {
        transform: translateY(-100vh) translateX(calc(var(--random-translateX, 1) * 50px)) rotate(360deg);
        opacity: 0
    }
}
.gradient-input-container {
    position: relative;
    width: 100%;
    height: 40px;
    z-index: 20;
    border-radius: 9999px
}
.gradient-input-container .gradient-input {
    width: 100%;
    height: 100%;
    padding: 0 20px;
    font-size: 1rem;
    border: none;
    border-radius: 9999px;
    background: #1a1a1a;
    color: #fff;
    box-sizing: border-box;
    transition: all .3s ease;
    box-shadow: 0 0 15px #0008
}
.gradient-input-container .gradient-input:focus {
    outline: none
}
.home-gif {
    width: 36px;
    height: 36px;
    padding: 6px;
    border-radius: 12px;
    object-fit: cover;
    cursor: pointer;
    transition: all .2s cubic-bezier(.4, 0, .2, 1)
}
.home-gif:hover {
    background: rgb(var(--color-primary)/.1);
    transform: scale(1.05)
}
.home-gif:active {
    transform: scale(.95)
}
.app-hidden {
    display: none
}
.confirm-button {
    background-color: rgb(var(--color-text));
    color: rgb(var(--color-bg));
    transition: opacity .3s ease, background-color .3s ease, color .3s ease;
}
.confirm-button:hover:not(:disabled) {
    opacity: .8;
}
.dark .confirm-button {
    background-color: rgb(var(--color-text));
    color: rgb(var(--color-bg));
}
button:disabled {
    opacity: .5;
    cursor: not-allowed;
}

/* Install Banner - IMPROVED */
.install-banner {
    position: fixed;
    bottom: -150px;
    left: 10px;
    right: 10px;
    background: rgb(var(--color-surface));
    border: 1px solid rgb(var(--color-border));
    border-radius: 16px;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    z-index: 1000;
    box-shadow: var(--shadow-heavy);
    transform: translateY(0);
    transition: transform .4s cubic-bezier(.4, 0, .2, 1);
    margin-bottom: calc(var(--safe-area-inset-bottom) + 10px);
}
.install-banner.visible {
    transform: translateY(calc(-100% - 10px));
}
.install-logo {
    width: 44px;
    height: 44px;
    border-radius: 8px;
    flex-shrink: 0;
}
.install-text {
    flex-grow: 1;
    font-size: .9rem;
    color: rgb(var(--color-text-secondary));
}
.install-text strong {
    font-size: 1rem;
    color: rgb(var(--color-text));
    display: block;
    font-weight: 600;
}
.install-button {
    background: rgb(var(--color-primary));
    color: white;
    border: none;
    border-radius: 20px;
    padding: 8px 16px;
    font-weight: 500;
    cursor: pointer;
    transition: background-color .3s ease;
    flex-shrink: 0;
}
.install-button:hover {
    background: rgb(var(--color-primary-hover));
}
.install-close {
    background: none;
    border: none;
    color: rgb(var(--color-muted));
    cursor: pointer;
    padding: 4px;
    flex-shrink: 0;
    border-radius: 50%;
}
.install-close:hover {
    background: rgba(var(--color-primary), 0.1);
    color: rgb(var(--color-primary));
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .top-notification {
        left: 8px;
        right: 8px;
        border-radius: 0 0 12px 12px;
    }
    .install-banner {
        left: 8px;
        right: 8px;
    }
}
