/* HandUp - Mobile-First Stylesheet */

/* CSS Reset and Base Styles */
* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    /* Color Palette */
    --primary-color: #007bff;
    --primary-dark: #0056b3;
    --secondary-color: #6c757d;
    --success-color: #28a745;
    --danger-color: #dc3545;
    --warning-color: #ffc107;
    --info-color: #17a2b8;
    
    /* Neutral Colors */
    --white: #ffffff;
    --gray-50: #f8f9fa;
    --gray-100: #e9ecef;
    --gray-200: #dee2e6;
    --gray-300: #ced4da;
    --gray-400: #adb5bd;
    --gray-500: #6c757d;
    --gray-600: #495057;
    --gray-700: #343a40;
    --gray-800: #212529;
    --gray-900: #000000;
    
    /* Message Colors */
    --message-sent-bg: var(--primary-color);
    --message-received-bg: var(--gray-100);
    --message-urgent-bg: #fff3cd;
    --message-urgent-border: var(--warning-color);
    
    /* Typography */
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-size-xs: 0.75rem;   /* 12px */
    --font-size-sm: 0.875rem;  /* 14px */
    --font-size-base: 1rem;    /* 16px */
    --font-size-lg: 1.125rem;  /* 18px */
    --font-size-xl: 1.25rem;   /* 20px */
    --font-size-2xl: 1.5rem;   /* 24px */
    
    /* Spacing */
    --spacing-xs: 0.25rem;  /* 4px */
    --spacing-sm: 0.5rem;   /* 8px */
    --spacing-md: 1rem;     /* 16px */
    --spacing-lg: 1.5rem;   /* 24px */
    --spacing-xl: 2rem;     /* 32px */
    --spacing-2xl: 3rem;    /* 48px */
    
    /* Layout */
    --border-radius: 0.5rem;
    --border-radius-sm: 0.25rem;
    --border-radius-lg: 0.75rem;
    --border-width: 1px;
    
    /* Shadows */
    --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);
    
    /* Z-index */
    --z-modal: 1000;
    --z-toast: 1100;
    --z-header: 100;
    --z-input: 10;
    
    /* Transitions */
    --transition: all 0.2s ease-in-out;
    --transition-fast: all 0.1s ease-in-out;
}

/* Base HTML and Body */
html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    font-size: var(--font-size-base);
    line-height: 1.5;
    color: var(--gray-800);
    background-color: var(--gray-50);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Accessibility */
*:focus {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Button focus for touch devices */
@media (hover: none) and (pointer: coarse) {
    *:focus {
        outline: none;
    }
}

/* Modal Styles */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    padding: var(--spacing-md);
    overflow: hidden;
}

/* Add subtle background pattern to modal */
.modal::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    opacity: 0.1;
    background-image: 
        radial-gradient(circle at 20% 80%, rgba(255,255,255,0.1) 0%, transparent 50%),
        radial-gradient(circle at 80% 20%, rgba(255,255,255,0.1) 0%, transparent 50%);
    pointer-events: none;
}

.modal-content {
    background: var(--white);
    border-radius: var(--border-radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 400px;
    max-height: 90vh;
    overflow-y: auto;
    position: relative;
    z-index: 1;
}

.modal-header {
    padding: var(--spacing-lg);
    border-bottom: var(--border-width) solid var(--gray-200);
    text-align: center;
}

.modal-header h2 {
    font-size: var(--font-size-xl);
    color: var(--gray-800);
    margin-bottom: var(--spacing-sm);
    font-weight: 600;
}

.modal-header p {
    color: var(--gray-600);
    font-size: var(--font-size-sm);
}

.modal-body {
    padding: var(--spacing-lg);
}

/* Form Styles */
.form-group {
    margin-bottom: var(--spacing-lg);
}

.form-group label {
    display: block;
    margin-bottom: var(--spacing-sm);
    font-weight: 500;
    color: var(--gray-700);
    font-size: var(--font-size-sm);
}

.form-group input,
.form-group textarea {
    width: 100%;
    padding: var(--spacing-md);
    border: var(--border-width) solid var(--gray-300);
    border-radius: var(--border-radius);
    font-size: 16px; /* Prevents zoom on iOS */
    font-family: inherit;
    transition: var(--transition);
    background: var(--white);
}

.form-group input:focus,
.form-group textarea:focus {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

/* Username Input with Prefix */
.username-input-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    border: var(--border-width) solid var(--gray-300);
    border-radius: var(--border-radius);
    background: var(--white);
    transition: var(--transition);
}

.username-input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

.username-prefix {
    padding: var(--spacing-md) 0 var(--spacing-md) var(--spacing-md);
    font-weight: 600;
    color: var(--primary-color);
    font-size: 16px;
    user-select: none;
}

.username-input-wrapper input {
    border: none !important;
    box-shadow: none !important;
    padding-left: var(--spacing-xs);
    flex: 1;
}

.input-hint {
    display: block;
    margin-top: var(--spacing-xs);
    font-size: var(--font-size-xs);
    color: var(--gray-500);
    font-style: italic;
}

/* Error Messages */
.error-message {
    color: var(--danger-color);
    font-size: var(--font-size-sm);
    margin-top: var(--spacing-xs);
    display: none;
}

.error-message.show {
    display: block;
}

/* Button Styles */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md) var(--spacing-lg);
    border: none;
    border-radius: var(--border-radius);
    font-size: var(--font-size-base);
    font-weight: 500;
    text-decoration: none;
    cursor: pointer;
    transition: var(--transition);
    min-height: 44px; /* Touch target */
    min-width: 44px;
    touch-action: manipulation;
}

.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

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

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

.btn-primary:active {
    transform: translateY(1px);
}

.btn-icon {
    padding: var(--spacing-sm);
    background: transparent;
    border: none;
    border-radius: var(--border-radius-sm);
    cursor: pointer;
    color: var(--gray-600);
    transition: var(--transition);
    min-height: 44px;
    min-width: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-icon:hover {
    background-color: var(--gray-100);
    color: var(--gray-800);
}

/* Chat Container */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh; /* Dynamic viewport height */
    max-height: 100vh;
    max-height: 100dvh;
    background: var(--white);
}

/* Chat Header */
.chat-header {
    background: var(--white);
    border-bottom: var(--border-width) solid var(--gray-200);
    padding: var(--spacing-md);
    position: sticky;
    top: 0;
    z-index: var(--z-header);
    box-shadow: var(--shadow-sm);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: var(--spacing-sm);
}

.chat-title {
    font-size: var(--font-size-lg);
    font-weight: 600;
    color: var(--primary-color);
}

.user-info {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.username {
    font-size: var(--font-size-sm);
    color: var(--gray-600);
    font-weight: 500;
}

/* Connection Status */
.connection-status {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    font-size: var(--font-size-xs);
    color: var(--gray-500);
}

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success-color);
    animation: pulse 2s infinite;
}

.status-indicator.disconnected {
    background: var(--danger-color);
    animation: none;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* Multi-Tab Warning */
.multi-tab-warning {
    background: var(--warning-color);
    color: var(--gray-800);
    padding: var(--spacing-sm) var(--spacing-md);
    font-size: var(--font-size-xs);
    font-weight: 600;
    text-align: center;
    border-bottom: 1px solid rgba(0,0,0,0.1);
    animation: slideDown 0.3s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Messages Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    scroll-behavior: smooth;
    background: var(--gray-50);
}

.messages-list {
    padding: var(--spacing-md);
    min-height: 100%;
    display: flex;
    flex-direction: column;
}

/* Loading Indicator */
.loading-indicator {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-xl);
    color: var(--gray-500);
    font-size: var(--font-size-sm);
}

.spinner {
    width: 24px;
    height: 24px;
    border: 2px solid var(--gray-200);
    border-top: 2px solid var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: var(--spacing-sm);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Date Separator */
.date-separator {
    display: flex;
    align-items: center;
    margin: var(--spacing-lg) 0;
    text-align: center;
}

.date-separator::before,
.date-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--gray-300);
}

.date-separator span {
    padding: 0 var(--spacing-md);
    font-size: var(--font-size-xs);
    color: var(--gray-500);
    background: var(--gray-50);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Message Styles */
.message {
    display: flex;
    margin-bottom: var(--spacing-sm);
    animation: slideIn 0.3s ease-out;
}

.message--sent {
    justify-content: flex-end;
}

.message--received {
    justify-content: flex-start;
}

.message--lecturer {
    justify-content: center;
}

.message--system {
    justify-content: center;
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.message__content {
    max-width: 80%;
    display: flex;
    flex-direction: column;
}

.message__bubble {
    padding: var(--spacing-md);
    border-radius: var(--border-radius-lg);
    word-wrap: break-word;
    position: relative;
    box-shadow: var(--shadow-sm);
}

.message__bubble--sent {
    background: var(--message-sent-bg);
    color: var(--white);
    border-bottom-right-radius: var(--border-radius-sm);
}

.message__bubble--received {
    background: var(--message-received-bg);
    color: var(--gray-800);
    border-bottom-left-radius: var(--border-radius-sm);
}

.message__bubble--lecturer {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: var(--white);
    border-radius: var(--border-radius-lg);
    font-weight: 500;
    box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
    max-width: 90%;
}

.message__bubble--urgent {
    background: var(--message-urgent-bg);
    border: var(--border-width) solid var(--message-urgent-border);
    color: var(--gray-800);
}

.message__meta {
    display: flex;
    align-items: center;
    gap: var(--spacing-xs);
    margin-top: var(--spacing-xs);
    font-size: var(--font-size-xs);
    color: var(--gray-500);
}

.message--sent .message__meta {
    justify-content: flex-end;
}

.message--received .message__meta {
    justify-content: flex-start;
}

.message__username {
    font-weight: 500;
    color: var(--gray-600);
}

.message__username--lecturer {
    font-weight: 700;
    color: #667eea;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-size: 0.8rem;
}

.message--lecturer .message__meta {
    justify-content: center;
    color: var(--gray-600);
}

.message__time {
    color: var(--gray-500);
}

.message__type-badge {
    background: var(--warning-color);
    color: var(--gray-800);
    padding: 2px 6px;
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-xs);
    font-weight: 500;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Message Input Container */
.message-input-container {
    background: var(--white);
    border-top: var(--border-width) solid var(--gray-200);
    padding: var(--spacing-md);
    position: sticky;
    bottom: 0;
    z-index: var(--z-input);
}

/* Message Type Selector */
.message-type-selector {
    display: flex;
    gap: var(--spacing-xs);
    margin-bottom: var(--spacing-md);
}

.type-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm) var(--spacing-md);
    border: var(--border-width) solid var(--gray-300);
    background: var(--white);
    color: var(--gray-600);
    border-radius: var(--border-radius);
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    min-height: 44px;
}

.type-btn:hover {
    background: var(--gray-50);
    border-color: var(--gray-400);
}

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

.type-btn svg {
    width: 16px;
    height: 16px;
}

/* Lecturer Options */
.lecturer-options {
    display: flex;
    gap: var(--spacing-xs);
    margin-bottom: var(--spacing-md);
    padding: var(--spacing-sm);
    background: var(--gray-50);
    border-radius: var(--border-radius);
}

.lecturer-type-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-xs);
    padding: var(--spacing-sm);
    border: none;
    background: transparent;
    color: var(--gray-600);
    border-radius: var(--border-radius-sm);
    font-size: var(--font-size-sm);
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    min-height: 36px;
}

.lecturer-type-btn:hover {
    background: var(--white);
}

.lecturer-type-btn--active {
    background: var(--white);
    color: var(--primary-color);
    box-shadow: var(--shadow-sm);
}

.lecturer-type-btn svg {
    width: 14px;
    height: 14px;
}

/* Message Form */
.message-form {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.message-input-wrapper {
    display: flex;
    align-items: flex-end;
    gap: var(--spacing-sm);
    background: var(--white);
    border: var(--border-width) solid var(--gray-300);
    border-radius: var(--border-radius-lg);
    padding: var(--spacing-sm);
    transition: var(--transition);
}

.message-input-wrapper:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(0, 123, 255, 0.1);
}

#messageInput {
    flex: 1;
    border: none;
    background: transparent;
    resize: none;
    font-size: 16px; /* Prevents zoom on iOS */
    font-family: inherit;
    line-height: 1.4;
    min-height: 20px;
    max-height: 100px;
    padding: var(--spacing-sm) 0;
}

#messageInput:focus {
    outline: none;
}

#messageInput::placeholder {
    color: var(--gray-400);
}

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

.send-btn:disabled {
    background: var(--gray-300);
    cursor: not-allowed;
}

.send-btn:not(:disabled):hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.send-btn:not(:disabled):active {
    transform: scale(0.95);
}

.send-btn svg {
    color: var(--white);
}

/* Message Meta */
.message-meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: var(--font-size-xs);
    color: var(--gray-500);
}

.character-count {
    font-weight: 500;
}

.character-count.warning {
    color: var(--warning-color);
}

.character-count.danger {
    color: var(--danger-color);
}

.message-type-label {
    font-weight: 500;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: var(--spacing-md);
    right: var(--spacing-md);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
    max-width: calc(100vw - 2rem);
}

.toast {
    background: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow-md);
    padding: var(--spacing-md);
    border-left: 4px solid var(--success-color);
    animation: slideInRight 0.3s ease-out;
    min-width: 280px;
}

.toast--error {
    border-left-color: var(--danger-color);
}

.toast--warning {
    border-left-color: var(--warning-color);
}

@keyframes slideInRight {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

.toast__content {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.toast__icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.toast__message {
    flex: 1;
    font-size: var(--font-size-sm);
    color: var(--gray-800);
}

/* Responsive Design */
@media (min-width: 768px) {
    .chat-container {
        max-width: 600px;
        margin: 0 auto;
        border-left: var(--border-width) solid var(--gray-200);
        border-right: var(--border-width) solid var(--gray-200);
        height: 100vh;
    }
    
    .message__content {
        max-width: 70%;
    }
    
    .toast-container {
        right: 50%;
        transform: translateX(50%);
    }
}

@media (min-width: 1024px) {
    .chat-container {
        max-width: 800px;
    }
    
    .message__content {
        max-width: 60%;
    }
}

/* Dark mode support (future) */
@media (prefers-color-scheme: dark) {
    /* Will be implemented later if needed */
}

/* Reduced motion support */
@media (prefers-reduced-motion: reduce) {
    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* High contrast mode support */
@media (prefers-contrast: high) {
    .btn {
        border: 2px solid currentColor;
    }
    
    .message__bubble {
        border: 1px solid currentColor;
    }
}
