/* ==================== CSS RESET & VARIABLES ==================== */
:root {
    --primary: #10b981;
    --primary-dark: #059669;
    --primary-light: #34d399;
    
    --bg: #ffffff;
    --bg-secondary: #f9fafb;
    --bg-card: #ffffff;
    
    --text: #111827;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    
    --border: #e5e7eb;
    --border-light: #f3f4f6;
    
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #3b82f6;
    
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px rgba(0,0,0,0.1);
    
    --radius-sm: 6px;
    --radius: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    
    --transition: 0.2s ease;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --bg-secondary: #1e293b;
    --bg-card: #1e293b;
    --text: #f1f5f9;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: #334155;
    --border-light: #1e293b;
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-secondary);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

.hidden { display: none !important; }

/* ==================== AUTH PAGE ==================== */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg) 100%);
}

.auth-container {
    width: 100%;
    max-width: 400px;
}

.auth-card {
    background: var(--bg-card);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    padding: 2rem;
    border: 1px solid var(--border-light);
}

.auth-header {
    text-align: center;
    margin-bottom: 2rem;
}

.auth-logo {
    width: 64px;
    height: 64px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    border-radius: var(--radius-lg);
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    color: white;
}

.auth-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.25rem;
}

.auth-header p {
    color: var(--text-muted);
    font-size: 0.875rem;
}

.auth-form { display: none; }
.auth-form.active { display: block; }

.form-group {
    margin-bottom: 1.25rem;
}

.form-group label {
    display: block;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.input-icon {
    position: absolute;
    left: 12px;
    color: var(--text-muted);
    pointer-events: none;
}

.input-wrapper input {
    width: 100%;
    padding: 0.75rem 0.75rem 0.75rem 2.75rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9375rem;
    background: var(--bg);
    color: var(--text);
    transition: var(--transition);
}

.input-wrapper input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(16, 185, 129, 0.1);
}

.input-wrapper input::placeholder {
    color: var(--text-muted);
}

.toggle-password {
    position: absolute;
    right: 12px;
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: 4px;
    display: flex;
}

.toggle-password:hover {
    color: var(--text-secondary);
}

/* ==================== BUTTONS ==================== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    border-radius: var(--radius);
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: var(--transition);
}

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

.btn-primary:hover {
    background: var(--primary-dark);
}

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

.btn-success:hover {
    background: #059669;
}

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

.btn-danger:hover {
    background: #dc2626;
}

.btn-block {
    width: 100%;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.icon-btn:hover {
    background: var(--bg-secondary);
    color: var(--text);
}

/* ==================== AUTH MISC ==================== */
.auth-divider {
    display: flex;
    align-items: center;
    margin: 1.5rem 0;
    color: var(--text-muted);
    font-size: 0.875rem;
}

.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.auth-divider span {
    padding: 0 1rem;
}

.auth-footer {
    text-align: center;
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.auth-footer a {
    color: var(--primary);
    text-decoration: none;
    font-weight: 500;
}

.auth-footer a:hover {
    text-decoration: underline;
}

/* ==================== LOADING OVERLAY ==================== */
.loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.loading-overlay.active {
    display: flex;
}

.loading-spinner {
    background: var(--bg-card);
    padding: 2rem;
    border-radius: var(--radius-lg);
    text-align: center;
}

.loading-spinner .spinner {
    animation: spin 1s linear infinite;
    color: var(--primary);
}

.loading-spinner p {
    margin-top: 1rem;
    color: var(--text-secondary);
}

@keyframes spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* ==================== TOAST ==================== */
.toast {
    position: fixed;
    bottom: 2rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 0.875rem 1.5rem;
    border-radius: var(--radius);
    background: var(--text);
    color: var(--bg);
    font-size: 0.9375rem;
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 9999;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.success { background: var(--success); color: white; }
.toast.error { background: var(--danger); color: white; }
.toast.info { background: var(--info); color: white; }

/* ==================== DASHBOARD LAYOUT ==================== */
.dashboard {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.header {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 100;
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--primary);
    font-weight: 700;
    font-size: 1.25rem;
}

.header-actions {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.time-display {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-secondary);
    border-radius: var(--radius);
}

.icon-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.icon-btn.logout-btn:hover {
    background: var(--danger);
    color: white;
    border-color: var(--danger);
}

a.icon-btn {
    text-decoration: none;
}

/* ==================== MAIN CONTAINER ==================== */
.main-container {
    flex: 1;
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
    width: 100%;
}

/* ==================== STATUS BAR ==================== */
.status-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.75rem;
    margin-bottom: 1.5rem;
}

.status-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.status-item strong {
    color: var(--text);
}

/* ==================== SECTION TITLE ==================== */
.section-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 1rem;
}

/* ==================== SENSOR SECTION ==================== */
.sensor-section {
    margin-bottom: 2rem;
}

.sensor-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 1rem;
}

.sensor-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
    display: flex;
    gap: 1rem;
    transition: var(--transition);
}

.sensor-card:hover {
    box-shadow: var(--shadow-md);
}

.sensor-icon {
    width: 48px;
    height: 48px;
    border-radius: var(--radius);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.sensor-icon.soil { background: #dcfce7; color: #16a34a; }
.sensor-icon.temp { background: #fee2e2; color: #dc2626; }
.sensor-icon.humidity { background: #dbeafe; color: #2563eb; }
.sensor-icon.water { background: #e0e7ff; color: #4f46e5; }

[data-theme="dark"] .sensor-icon.soil { background: rgba(22, 163, 74, 0.2); }
[data-theme="dark"] .sensor-icon.temp { background: rgba(220, 38, 38, 0.2); }
[data-theme="dark"] .sensor-icon.humidity { background: rgba(37, 99, 235, 0.2); }
[data-theme="dark"] .sensor-icon.water { background: rgba(79, 70, 229, 0.2); }

.sensor-info {
    flex: 1;
    min-width: 0;
}

.sensor-info h3 {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
}

.sensor-value {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.5rem;
}

.sensor-value span {
    font-size: 0.875rem;
    font-weight: 400;
    color: var(--text-secondary);
}

.sensor-bar {
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: 0.5rem;
}

.sensor-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 2px;
    transition: width 0.5s ease;
}

.sensor-bar-fill.temp { background: #dc2626; }
.sensor-bar-fill.humidity { background: #2563eb; }
.sensor-bar-fill.water { background: #4f46e5; }

.sensor-status {
    font-size: 0.75rem;
    color: var(--text-muted);
}

/* ==================== CONTROL SECTION ==================== */
.control-section {
    margin-bottom: 2rem;
}

.control-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1rem;
}

.control-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 1.25rem;
}

.control-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
    color: var(--text);
}

.control-header h3 {
    font-size: 1rem;
    font-weight: 600;
}

.control-actions {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.control-actions .btn {
    flex: 1;
}

.control-status {
    font-size: 0.875rem;
    color: var(--text-secondary);
}

.control-status span {
    font-weight: 600;
    color: var(--text);
}

.timer-controls {
    display: flex;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 1rem;
}

.timer-input-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.timer-input-group input {
    width: 80px;
    padding: 0.5rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9375rem;
    background: var(--bg);
    color: var(--text);
}

.timer-input-group span {
    color: var(--text-secondary);
    font-size: 0.875rem;
}

.timer-display {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary);
    text-align: center;
    font-variant-numeric: tabular-nums;
}

/* ==================== FLOATING CHAT BUTTON ==================== */
.chat-fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 60px;
    height: 60px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    border: none;
    cursor: pointer;
    box-shadow: 0 4px 20px rgba(16, 185, 129, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
    z-index: 1000;
}

.chat-fab:hover {
    transform: scale(1.1);
    box-shadow: 0 6px 25px rgba(16, 185, 129, 0.5);
}

.chat-fab.active {
    background: var(--danger);
    box-shadow: 0 4px 20px rgba(239, 68, 68, 0.4);
}

.chat-fab .fab-icon-close { display: none; }
.chat-fab.active .fab-icon-chat { display: none; }
.chat-fab.active .fab-icon-close { display: block; }

/* ==================== CHAT POPUP ==================== */
.chat-popup {
    position: fixed;
    bottom: 100px;
    right: 24px;
    width: 380px;
    max-height: 520px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.15);
    display: flex;
    flex-direction: column;
    opacity: 0;
    visibility: hidden;
    transform: translateY(20px) scale(0.95);
    transition: all 0.3s ease;
    z-index: 999;
    overflow: hidden;
}

.chat-popup.active {
    opacity: 1;
    visibility: visible;
    transform: translateY(0) scale(1);
}

.chat-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1rem 1.25rem;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
}

.chat-popup-title {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.chat-popup-title h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.chat-popup-title span {
    font-size: 0.75rem;
    opacity: 0.8;
}

.chat-popup-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.chat-popup-close:hover {
    background: rgba(255, 255, 255, 0.3);
}

.chat-popup-messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    max-height: 280px;
    min-height: 200px;
}

.chat-popup-quick {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.chat-popup-form {
    display: flex;
    gap: 0.5rem;
    padding: 1rem;
    border-top: 1px solid var(--border);
}

.chat-popup-form input {
    flex: 1;
    padding: 0.75rem 1rem;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    font-size: 0.9375rem;
    background: var(--bg);
    color: var(--text);
}

.chat-popup-form input:focus {
    outline: none;
    border-color: var(--primary);
}

/* Chat message styles */
.chat-message {
    display: flex;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.chat-message.user {
    flex-direction: row-reverse;
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    color: var(--text-secondary);
}

.chat-message.bot .message-avatar {
    background: var(--primary);
    color: white;
}

.message-content {
    max-width: 75%;
    padding: 0.625rem 0.875rem;
    border-radius: var(--radius-lg);
    background: var(--bg-secondary);
    color: var(--text);
}

.chat-message.user .message-content {
    background: var(--primary);
    color: white;
}

.message-content p {
    font-size: 0.875rem;
    line-height: 1.5;
    margin: 0;
}

.quick-btn {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.5rem 0.75rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text-secondary);
    font-size: 0.75rem;
    cursor: pointer;
    transition: var(--transition);
}

.quick-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.send-btn {
    width: 44px;
    height: 44px;
    border-radius: var(--radius);
    background: var(--primary);
    color: white;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    flex-shrink: 0;
}

.send-btn:hover {
    background: var(--primary-dark);
}

/* Typing indicator */
.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 0.5rem 0;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { transform: translateY(0); }
    30% { transform: translateY(-4px); }
}

@media (max-width: 480px) {
    .chat-fab {
        bottom: 16px;
        right: 16px;
        width: 56px;
        height: 56px;
    }
    
    .chat-popup {
        bottom: 80px;
        right: 16px;
        left: 16px;
        width: auto;
        max-height: 70vh;
    }
}

/* ==================== FOOTER ==================== */
.footer {
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    padding: 1rem;
    text-align: center;
}

.footer p {
    font-size: 0.8125rem;
    color: var(--text-muted);
}

/* ==================== PROFILE PAGE ==================== */
.profile-page {
    max-width: 600px;
    margin: 0 auto;
}

.profile-header {
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 2rem;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    margin-bottom: 1.5rem;
}

.profile-avatar {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    flex-shrink: 0;
}

.profile-info h1 {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 0.25rem;
}

.profile-info p {
    color: var(--text-secondary);
    font-size: 0.9375rem;
}

.profile-section {
    margin-bottom: 1.5rem;
}

.profile-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    overflow: hidden;
}

.profile-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid var(--border);
}

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

.profile-item-icon {
    width: 40px;
    height: 40px;
    border-radius: var(--radius);
    background: var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    flex-shrink: 0;
}

.profile-item-content {
    flex: 1;
    min-width: 0;
}

.profile-item-content label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.125rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.profile-item-content p {
    font-size: 0.9375rem;
    color: var(--text);
    font-weight: 500;
    word-break: break-all;
}

.profile-item-content .device-id,
.profile-item-content .user-id {
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.8125rem;
    background: var(--bg-secondary);
    padding: 0.25rem 0.5rem;
    border-radius: var(--radius-sm);
    display: inline-block;
}

.profile-actions {
    display: flex;
    gap: 1rem;
}

.profile-actions .btn {
    flex: 1;
}

@media (max-width: 480px) {
    .profile-header {
        flex-direction: column;
        text-align: center;
    }
    
    .profile-actions {
        flex-direction: column;
    }
}

/* ==================== RESPONSIVE ==================== */
@media (max-width: 768px) {
    .header-content {
        padding: 0.5rem 0.75rem;
    }
    
    .time-display {
        display: none;
    }
    
    .user-btn span {
        display: none;
    }
    
    .main-container {
        padding: 1rem 0.75rem;
    }
    
    .sensor-grid,
    .control-grid {
        grid-template-columns: 1fr;
    }
    
    .status-bar {
        flex-direction: column;
    }
    
    .timer-controls {
        flex-direction: column;
        align-items: stretch;
    }
    
    .chatbot-messages {
        height: 250px;
    }
    
    .message-content {
        max-width: 85%;
    }
}

@media (max-width: 480px) {
    .auth-card {
        padding: 1.5rem;
    }
    
    .control-actions {
        flex-direction: column;
    }
}
