/* =========================================================
   CSS VARIABLES - PERFECT CONTRAST
   ========================================================= */

:root {
    /* Blue Accent */
    --primary: #2563eb;
    --primary-light: #3b82f6;
    --primary-dark: #1d4ed8;
    --primary-alpha: rgba(37, 99, 235, 0.1);
    --primary-glow: rgba(37, 99, 235, 0.4);
    
    /* Light Theme */
    --bg: #f5f7fa;
    --card: #ffffff;
    --input: #f0f2f5;
    --text: #0d1117;
    --text-2: #57606a;
    --text-3: #6e7781;
    --border: #d0d7de;
    --shadow: rgba(0, 0, 0, 0.1);
    
    /* Status */
    --success: #10b981;
    --success-bg: #d1fae5;
    --success-text: #065f46;
    
    --error: #ef4444;
    --error-bg: #fee2e2;
    --error-text: #991b1b;
    
    --warning: #f59e0b;
    --warning-bg: #fed7aa;
    --warning-text: #92400e;
}

body.dark {
    /* Dark Theme */
    --bg: #0d1117;
    --card: #161b22;
    --input: #0d1117;
    --text: #f0f6fc;
    --text-2: #c9d1d9;
    --text-3: #8b949e;
    --border: #30363d;
    --shadow: rgba(0, 0, 0, 0.5);
    
    --success: #3fb950;
    --success-bg: #033a16;
    --success-text: #7ee787;
    
    --error: #f85149;
    --error-bg: #490202;
    --error-text: #ffa198;
    
    --warning: #d29922;
    --warning-bg: #341a00;
    --warning-text: #f0cc83;
}

/* =========================================================
   RESET & BASE
   ========================================================= */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    transition: background 0.3s, color 0.3s;
}

/* =========================================================
   ARCHIVE DECORATIONS
   ========================================================= */

.decorations {
    position: fixed;
    inset: 0;
    overflow: hidden;
    pointer-events: none;
    z-index: 0;
}

.decoration-item {
    position: absolute;
    font-size: 48px;
    color: var(--primary);
    opacity: 0.2;
    transition: opacity 0.3s ease;
    will-change: transform;
    user-select: none;
    pointer-events: none;
}

body.dark .decoration-item {
    opacity: 0.25;
}

/* Variation sizes */
.decoration-item.small {
    font-size: 36px;
}

.decoration-item.medium {
    font-size: 48px;
}

.decoration-item.large {
    font-size: 60px;
}

/* =========================================================
   GRID BACKGROUND
   ========================================================= */

.grid-bg {
    position: fixed;
    inset: 0;
    background-image: 
        linear-gradient(var(--primary-alpha) 1px, transparent 1px),
        linear-gradient(90deg, var(--primary-alpha) 1px, transparent 1px);
    background-size: 50px 50px;
    opacity: 0.3;
    pointer-events: none;
    z-index: 0;
}

/* =========================================================
   MAIN CONTAINER
   ========================================================= */

.main {
    width: 100%;
    max-width: 360px;
    padding: 16px;
    z-index: 1;
    position: relative;
}

/* =========================================================
   CARD - COMPACT
   ========================================================= */

.card {
    background: var(--card);
    border-radius: 16px;
    padding: 28px 24px 10px;
    box-shadow: 
        0 8px 32px var(--shadow),
        0 0 0 1px var(--border);
    position: relative;
    overflow: hidden;
    animation: slideIn 0.5s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
}

/* =========================================================
   LOGO AS THEME TOGGLE
   ========================================================= */

.logo-section {
    position: relative;
    display: flex;
    justify-content: center;
    margin-bottom: 16px;
    animation: fadeIn 0.6s 0.1s both;
    cursor: pointer;
    user-select: none;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.logo-box {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 
        0 8px 24px var(--primary-glow),
        0 4px 12px rgba(0, 0, 0, 0.15);
    position: relative;
    animation: logoFloat 3s ease-in-out infinite;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.logo-section:hover .logo-box {
    transform: translateY(-6px) scale(1.05);
    box-shadow: 
        0 12px 32px var(--primary-glow),
        0 6px 16px rgba(0, 0, 0, 0.2);
}

.logo-section:active .logo-box {
    transform: translateY(-3px) scale(0.98);
}

@keyframes logoFloat {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-6px); }
}

.logo-img {
    width: 60px;
    height: 60px;
    object-fit: contain;
    filter: brightness(1) invert(0);
}

.logo-fallback {
    display: none;
    font-size: 32px;
    color: white;
}

/* Theme Indicator Badge */
.theme-indicator {
    position: absolute;
    bottom: -2px;
    right: -2px;
    width: 24px;
    height: 24px;
    background: var(--card);
    border: 2px solid var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px var(--shadow);
    transition: all 0.3s ease;
}

.theme-indicator i {
    font-size: 14px;
    color: var(--text);
    transition: transform 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

.logo-section:hover .theme-indicator {
    transform: scale(1.1);
    box-shadow: 0 4px 12px var(--shadow);
}

.logo-section.spin .theme-indicator i {
    animation: spinIcon 0.5s cubic-bezier(0.68, -0.55, 0.265, 1.55);
}

@keyframes spinIcon {
    0% {
        transform: rotate(0deg) scale(1);
    }
    50% {
        transform: rotate(180deg) scale(0);
    }
    100% {
        transform: rotate(360deg) scale(1);
    }
}

/* =========================================================
   HEADER - COMPACT
   ========================================================= */

.header {
    text-align: center;
    margin-bottom: 20px;
    animation: fadeIn 0.6s 0.2s both;
}

.title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
    letter-spacing: -0.3px;
}

.desc {
    font-size: 14px;
    color: var(--text-2);
    line-height: 1.4;
}

/* =========================================================
   ALERT - SMOOTH TRANSITIONS
   ========================================================= */

.alert-box {
    margin-bottom: 0;
    min-height: 0;
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.35s cubic-bezier(0.4, 0, 0.2, 1),
                margin-bottom 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.alert-box.has-alert {
    max-height: 250px;
    margin-bottom: 14px;
}

.alert {
    padding: 11px 15px;
    border-radius: 10px;
    font-size: 13px;
    line-height: 1.5;
    border: none;
    border-left: 3px solid;
    opacity: 0;
    transform: translateY(-12px) scale(0.96);
    transition: all 0.35s cubic-bezier(0.4, 0, 0.2, 1);
    pointer-events: none;
    margin: 0;
    font-weight: 500;
}

.alert.show {
    opacity: 1;
    transform: translateY(0) scale(1);
    pointer-events: auto;
}

.alert.hiding {
    opacity: 0;
    transform: translateY(-10px) scale(0.97);
    transition: all 0.28s cubic-bezier(0.4, 0, 0.6, 1);
}

.alert.success {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.13), rgba(22, 163, 74, 0.09));
    border-left-color: #22c55e;
    color: #16a34a;
    box-shadow: 0 2px 10px rgba(34, 197, 94, 0.18);
}

.alert.error {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.13), rgba(220, 38, 38, 0.09));
    border-left-color: #ef4444;
    color: #dc2626;
    box-shadow: 0 2px 10px rgba(239, 68, 68, 0.18);
}

.alert.warning {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.13), rgba(217, 119, 6, 0.09));
    border-left-color: #f59e0b;
    color: #d97706;
    box-shadow: 0 2px 10px rgba(245, 158, 11, 0.18);
}

/* Subtle pulse for warnings */
@keyframes subtlePulse {
    0%, 100% {
        box-shadow: 0 2px 10px rgba(245, 158, 11, 0.18);
    }
    50% {
        box-shadow: 0 2px 14px rgba(245, 158, 11, 0.28), 
                    0 0 0 5px rgba(245, 158, 11, 0.06);
    }
}

.alert.warning.show {
    animation: subtlePulse 2.8s ease-in-out infinite;
}

/* Dark mode adjustments */
body.dark .alert.error {
    background: linear-gradient(135deg, rgba(239, 68, 68, 0.2), rgba(220, 38, 38, 0.14));
    color: #fca5a5;
    box-shadow: 0 2px 12px rgba(239, 68, 68, 0.25);
}

body.dark .alert.warning {
    background: linear-gradient(135deg, rgba(245, 158, 11, 0.2), rgba(217, 119, 6, 0.14));
    color: #fcd34d;
    box-shadow: 0 2px 12px rgba(245, 158, 11, 0.25);
}

body.dark .alert.success {
    background: linear-gradient(135deg, rgba(34, 197, 94, 0.2), rgba(22, 163, 74, 0.14));
    color: #86efac;
    box-shadow: 0 2px 12px rgba(34, 197, 94, 0.25);
}

/* =========================================================
   TABS - COMPACT
   ========================================================= */

.tabs {
    position: relative;
    display: flex;
    gap: 6px;
    background: var(--input);
    padding: 4px;
    border-radius: 10px;
    margin-bottom: 16px;
    animation: fadeIn 0.6s 0.3s both;
}

.tab {
    flex: 1;
    padding: 8px 10px;
    background: transparent;
    border: none;
    border-radius: 8px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-3);
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    position: relative;
    z-index: 2;
}

.tab i {
    font-size: 16px;
}

.tab.active {
    color: white;
}

.tab:hover:not(.active) {
    color: var(--text);
}

.slider {
    position: absolute;
    top: 4px;
    left: 4px;
    width: calc(50% - 3px);
    height: calc(100% - 8px);
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border-radius: 8px;
    transition: transform 0.4s cubic-bezier(0.68, -0.55, 0.265, 1.55);
    z-index: 1;
    box-shadow: 0 3px 10px var(--primary-glow);
}

.tab:nth-child(2).active ~ .slider {
    transform: translateX(calc(100% + 3px));
}

/* =========================================================
   FORMS
   ========================================================= */

.forms {
    position: relative;
}

.form-panel {
    display: none;
    animation: formSlide 0.4s ease;
}

.form-panel.active {
    display: block;
}

@keyframes formSlide {
    from {
        opacity: 0;
        transform: translateX(10px);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.form {
    animation: fadeIn 0.6s 0.4s both;
}

/* =========================================================
   FIELD - COMPACT
   ========================================================= */

.field {
    margin-bottom: 12px;
}

.label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 6px;
}

.input-box {
    position: relative;
}

.input {
    width: 100%;
    height: 42px;
    padding: 0 12px;
    font-size: 14px;
    font-family: inherit;
    background: var(--input);
    border: 2px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    transition: all 0.3s;
    outline: none;
}

.input::placeholder {
    color: var(--text-3);
}

.input:hover {
    border-color: var(--text-3);
}

/* REDUCED HIGHLIGHT - box-shadow reduced from 3px to 2px */
.input:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.15);
    transform: translateY(-1px);
}

/* FIX AUTOFILL DARK MODE */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus,
textarea:-webkit-autofill,
select:-webkit-autofill {
    -webkit-text-fill-color: var(--text) !important;
    -webkit-box-shadow: 0 0 0 1000px var(--input) inset !important;
    box-shadow: 0 0 0 1000px var(--input) inset !important;
    transition: background-color 5000s ease-in-out 0s;
}

.line {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--primary);
    transition: width 0.4s;
}

.input:focus ~ .line {
    width: 100%;
}

.pwd-toggle {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 30px;
    height: 30px;
    background: transparent;
    border: none;
    border-radius: 6px;
    color: var(--text-3);
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.pwd-toggle:hover {
    background: var(--input);
    color: var(--text);
}

/* =========================================================
   BUTTON - COMPACT
   ========================================================= */

.btn {
    width: 100%;
    height: 44px;
    margin-top: 16px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border: none;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 700;
    color: white;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    box-shadow: 0 4px 14px var(--primary-glow);
    transition: all 0.3s;
}

.btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 18px var(--primary-glow);
}

.btn:active:not(:disabled) {
    transform: scale(0.98);
}

.btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.btn-shine {
    position: absolute;
    inset: 0;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
    transform: translateX(-100%);
    transition: transform 0.6s;
}

.btn:hover:not(:disabled) .btn-shine {
    transform: translateX(100%);
}

.btn-content {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    position: relative;
    z-index: 1;
}

.btn-content i {
    font-size: 16px;
}

/* =========================================================
   COPYRIGHT - MOVED TO FORM
   ========================================================= */

.copyright {
    margin-top: 12px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
    text-align: center;
}

.copyright p {
    font-size: 12px;
    color: var(--text-3);
    line-height: 1.4;
}

/* =========================================================
   CONNECTION STATUS
   ========================================================= */

.status {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 14px;
    box-shadow: 0 4px 14px var(--shadow);
    display: flex;
    align-items: center;
    gap: 8px;
    z-index: 100;
    opacity: 0;
    transition: all 0.3s;
}

.status.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-3);
    transition: all 0.3s;
}

.dot.connecting {
    background: var(--warning);
    animation: blink 1.5s infinite;
}

.dot.connected {
    background: var(--success);
}

.dot.encrypted {
    background: var(--success);
    box-shadow: 0 0 8px var(--success);
}

.dot.error {
    background: var(--error);
}

@keyframes blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.text {
    font-size: 12px;
    font-weight: 500;
    color: var(--text);
}

.encrypt-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 10px;
    font-weight: 700;
    color: var(--success-text);
    background: var(--success-bg);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 4px;
}

/* =========================================================
   PAGE EXIT
   ========================================================= */

body.page-exit .card {
    animation: exit 0.4s ease forwards;
}

@keyframes exit {
    to {
        opacity: 0;
        transform: scale(0.95) translateY(-15px);
        filter: blur(6px);
    }
}

/* =========================================================
   RESPONSIVE - ALERT ADJUSTMENTS
   ========================================================= */

@media (max-width: 400px) {
    .main {
        max-width: 100%;
        padding: 12px;
    }
    
    .card {
        padding: 24px 20px 6px;
        border-radius: 14px;
    }
    
    .logo-box {
        width: 56px;
        height: 56px;
    }
    
    .logo-img {
        width: 53px;
        height: 53px;
    }
    
    .logo-fallback {
        font-size: 28px;
    }
    
    .theme-indicator {
        width: 22px;
        height: 22px;
    }
    
    .theme-indicator i {
        font-size: 12px;
    }
    
    .title {
        font-size: 20px;
    }
    
    .desc {
        font-size: 13px;
    }
    
    .tab {
        padding: 7px 8px;
        font-size: 12px;
    }
    
    .tab span {
        display: none;
    }
    
    .field {
        margin-bottom: 10px;
    }
    
    .input {
        height: 40px;
        font-size: 13px;
    }
    
    .btn {
        height: 42px;
        font-size: 13px;
    }
    
    .copyright {
        margin-top: 10px;
        padding-top: 6px;
    }
    
    .copyright p {
        font-size: 11px;
    }
    
    /* Smaller decorations on mobile */
    .decoration-item.small {
        font-size: 28px;
    }
    
    .decoration-item.medium {
        font-size: 36px;
    }
    
    .decoration-item.large {
        font-size: 48px;
    }
    
    /* Alert responsive adjustments for mobile */
    .alert-box.has-alert {
        max-height: 300px;
        margin-bottom: 12px;
    }
    
    .alert {
        padding: 10px 13px;
        font-size: 12px;
        line-height: 1.45;
        border-radius: 8px;
    }
}

@media (min-width: 500px) {
    .main {
        max-width: 380px;
    }
    
    .card {
        padding: 24px 28px 8px;
    }
    
    /* Alert adjustments for larger screens */
    .alert {
        padding: 12px 16px;
        font-size: 13.5px;
    }
    
    .alert-box.has-alert {
        margin-bottom: 16px;
    }
}

/* Tablet and larger screens */
@media (min-width: 768px) {
    .alert {
        max-width: 100%;
        word-wrap: break-word;
    }
}

/* Extra small screens (iPhone SE, etc) */
@media (max-width: 360px) {
    .alert {
        padding: 9px 12px;
        font-size: 11.5px;
        line-height: 1.4;
    }
    
    .alert-box.has-alert {
        max-height: 280px;
        margin-bottom: 10px;
    }
}

/* =========================================================
   ACCESSIBILITY
   ========================================================= */

@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .decoration-item {
        display: none !important;
    }
    
    /* Keep alert transitions smooth even with reduced motion */
    .alert-box,
    .alert {
        transition: opacity 0.2s ease, max-height 0.2s ease !important;
    }
}

.logo-section:focus-visible,
.tab:focus-visible,
.input:focus-visible,
.pwd-toggle:focus-visible,
.btn:focus-visible {
    outline: 0.1px solid var(--primary);
    outline-offset: 1px;
}

/* =========================================================
   PRINT
   ========================================================= */

@media print {
    .decorations,
    .grid-bg,
    .status {
        display: none !important;
    }
}