<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Share    <!-- Theme toggle button -->
    <button id="themeToggle" class="theme-toggle" title="Switch to dark mode">🌙</button>Admin Login</title>
    <link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
    
    <!-- Immediate theme application to prevent flash -->
    <script>
        (function() {
            function getCookie(name) {
                const nameEQ = name + "=";
                const ca = document.cookie.split(';');
                for (let i = 0; i < ca.length; i++) {
                    let c = ca[i];
                    while (c.charAt(0) === ' ') c = c.substring(1, c.length);
                    if (c.indexOf(nameEQ) === 0) return c.substring(nameEQ.length, c.length);
                }
                return null;
            }
            
            function getSystemTheme() {
                return window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
            }
            
            const savedTheme = getCookie('sharey-theme') || 'auto';
            let actualTheme;
            
            if (savedTheme === 'auto') {
                actualTheme = getSystemTheme();
            } else {
                actualTheme = savedTheme;
            }
            
            if (actualTheme === 'dark') {
                document.documentElement.setAttribute('data-theme', 'dark');
            }
        })();
    </script>
    
    <style>
        .login-container {
            display: flex;
            justify-content: center;
            align-items: center;
            min-height: 80vh;
            padding: 20px;
        }
        
        .login-box {
            background: var(--bg-secondary);
            border: 2px solid var(--border-color);
            border-radius: 12px;
            padding: 40px;
            max-width: 400px;
            width: 100%;
            text-align: center;
            box-shadow: 0 4px 20px var(--shadow);
        }
        
        .login-header {
            margin-bottom: 30px;
        }
        
        .login-icon {
            font-size: 3rem;
            margin-bottom: 15px;
            color: var(--border-color);
        }
        
        .login-title {
            color: var(--text-primary);
            margin: 0 0 10px 0;
            font-size: 1.8rem;
        }
        
        .login-subtitle {
            color: var(--text-secondary);
            margin: 0;
            font-size: 1rem;
        }
        
        .login-form {
            text-align: left;
        }
        
        .form-group {
            margin-bottom: 20px;
        }
        
        .form-label {
            display: block;
            margin-bottom: 8px;
            color: var(--text-primary);
            font-weight: bold;
        }
        
        .form-input {
            width: 100%;
            padding: 12px;
            border: 1px solid var(--border-color);
            border-radius: 6px;
            background: var(--bg-primary);
            color: var(--text-primary);
            font-size: 16px;
            box-sizing: border-box;
            transition: border-color 0.3s ease;
        }
        
        .form-input:focus {
            outline: none;
            border-color: var(--text-secondary);
        }
        
        .login-button {
            width: 100%;
            padding: 12px;
            background: var(--border-color);
            color: white;
            border: none;
            border-radius: 6px;
            font-size: 16px;
            font-weight: bold;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }
        
        .login-button:hover {
            background: var(--text-secondary);
        }
        
        .error-message {
            background: #f44336;
            color: white;
            padding: 12px;
            border-radius: 6px;
            margin-bottom: 20px;
            text-align: center;
        }
        
        .back-link {
            margin-top: 20px;
            text-align: center;
        }
        
        .back-link a {
            color: var(--text-secondary);
            text-decoration: none;
            font-size: 14px;
        }
        
        .back-link a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <!-- Theme toggle button -->
    <button id="themeToggle" class="theme-toggle" title="Switch to dark mode">�</button>
    
    <div class="container">
        <div class="login-container">
            <div class="login-box">
                <div class="login-header">
                    <div class="login-icon">🔐</div>
                    <h1 class="login-title">Admin Access</h1>
                    <p class="login-subtitle">Enter password to access admin panel</p>
                </div>
                
                {% if error %}
                <div class="error-message">
                    {{ error }}
                </div>
                {% endif %}
                
                <form method="POST" class="login-form">
                    <div class="form-group">
                        <label for="password" class="form-label">Password:</label>
                        <input type="password" id="password" name="password" class="form-input" required autocomplete="current-password">
                    </div>
                    
                    <button type="submit" class="login-button">🚪 Login</button>
                </form>
                
                <div class="back-link">
                    <a href="/">← Back to Sharey</a>
                </div>
            </div>
        </div>
    </div>

    <script src="{{ url_for('static', filename='script.js') }}"></script>
</body>
</html>
