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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Prevent horizontal scrolling on mobile */
    overflow-x: hidden;
}

/* Improve mobile scrolling */
html {
    scroll-behavior: smooth;
}

/* Prevent zoom on input focus for iOS */
@media screen and (max-width: 768px) {
    input, textarea, select {
        font-size: 16px !important;
    }
}

/* Header */
.header {
    background: linear-gradient(135deg, #4CAF50, #45a049);
    color: white;
    padding: 1rem 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

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

.logo {
    width: 40px;
    height: 40px;
    border-radius: 8px;
}

.header h1 {
    font-size: 1.5rem;
    font-weight: 600;
}

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

.status-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #ffc107;
    animation: pulse 2s infinite;
}

.status-dot.connected {
    background-color: #28a745;
    animation: none;
}

.status-dot.error {
    background-color: #dc3545;
    animation: none;
}

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

/* Buttons */
.btn {
    padding: 0.5rem 1rem;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.9rem;
    font-weight: 500;
    transition: all 0.2s;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
}

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

.btn-primary {
    background-color: #4CAF50;
    color: white;
}

.btn-primary:hover:not(:disabled) {
    background-color: #45a049;
}

.btn-secondary {
    background-color: rgba(255,255,255,0.2);
    color: white;
    border: 1px solid rgba(255,255,255,0.3);
}

.btn-secondary:hover:not(:disabled) {
    background-color: rgba(255,255,255,0.3);
}

.btn-outline {
    background-color: transparent;
    color: #666;
    border: 1px solid #ddd;
}

.btn-outline:hover:not(:disabled) {
    background-color: #f8f9fa;
    border-color: #adb5bd;
}

/* Back Button Specific Styles */
#back-btn {
    background-color: #f8f9fa;
    color: #333;
    border: 1px solid #dee2e6;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    min-width: 100px;
    justify-content: center;
}

#back-btn:hover:not(:disabled) {
    background-color: #e9ecef;
    border-color: #adb5bd;
    transform: translateY(-1px);
}

#back-btn:active {
    transform: translateY(0);
}

.back-icon {
    font-size: 1.1em;
    margin-right: 0.25rem;
}

.back-text {
    font-weight: 500;
}

/* Mobile-specific back button styles */
@media (max-width: 480px) {
    #back-btn {
        width: 100%;
        justify-content: center;
        padding: 0.875rem 1rem;
        font-size: 1rem;
        margin-bottom: 0.5rem;
    }

    .back-icon {
        font-size: 1.2em;
    }
}

/* Main Content */
.main-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* Mobile-First Base Styles */
@media (max-width: 480px) {
    .main-content {
        padding: 1rem 0.5rem;
    }
}

.view {
    display: none;
}

.view.active {
    display: block;
}

/* Dashboard */
.dashboard-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    flex-wrap: wrap;
    gap: 1rem;
}

.dashboard-header h2 {
    color: #333;
    font-size: 1.8rem;
}

.filters {
    display: flex;
    gap: 1rem;
    align-items: center;
}

.filter-select, .search-input {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.9rem;
}

.search-input {
    min-width: 250px;
}

/* Orders Container */
.orders-container {
    display: grid;
    gap: 1rem;
    grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
}

.order-card {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    transition: all 0.2s;
    border-left: 4px solid #4CAF50;
}

/* Mobile touch interactions */
@media (max-width: 768px) {
    .order-card {
        padding: 1rem;
    }
}

.order-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 1rem;
}

.order-number {
    font-weight: 600;
    color: #333;
    font-size: 1.1rem;
    position: relative;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Unread Message Indicators */
.unread-indicator {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    animation: pulse 2s infinite;
}

.customer-unread {
    background-color: #ff4444;
    box-shadow: 0 0 6px rgba(255, 68, 68, 0.6);
}

.seller-unread {
    background-color: #2196F3;
    box-shadow: 0 0 6px rgba(33, 150, 243, 0.6);
}

.unread-count {
    background-color: #ff4444;
    color: white;
    font-size: 0.75rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    margin-left: 0.5rem;
    min-width: 18px;
    text-align: center;
    line-height: 1.2;
}

.order-card.has-unread {
    border-left-color: #ff4444;
    background: linear-gradient(135deg, #fff 0%, #fff9f9 100%);
}

@keyframes pulse {
    0% {
        transform: scale(1);
        opacity: 1;
    }
    50% {
        transform: scale(1.2);
        opacity: 0.7;
    }
    100% {
        transform: scale(1);
        opacity: 1;
    }
}

.order-status {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 500;
    text-transform: capitalize;
}

.status-confirmed { background-color: #e3f2fd; color: #1976d2; }
.status-preparing { background-color: #fff3e0; color: #f57c00; }
.status-ready { background-color: #e8f5e8; color: #388e3c; }
.status-out_for_delivery { background-color: #f3e5f5; color: #7b1fa2; }
.status-delivered { background-color: #e0f2f1; color: #00695c; }
.status-cancelled { background-color: #ffebee; color: #d32f2f; }

.order-info {
    margin-bottom: 1rem;
}

.customer-name {
    font-weight: 500;
    color: #666;
    margin-bottom: 0.5rem;
}

.order-total {
    font-size: 1.2rem;
    font-weight: 600;
    color: #4CAF50;
}

.last-message {
    background-color: #f8f9fa;
    padding: 0.75rem;
    border-radius: 8px;
    margin-top: 1rem;
    border-left: 3px solid #4CAF50;
}

.message-preview {
    font-size: 0.9rem;
    color: #666;
    margin-bottom: 0.5rem;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.message-time {
    font-size: 0.8rem;
    color: #999;
}

/* Loading */
.loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem;
    color: #666;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 4px solid #f3f3f3;
    border-top: 4px solid #4CAF50;
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1rem;
}

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

/* Mobile-First Responsive Design */

/* Small Mobile Devices (320px - 480px) */
@media (max-width: 480px) {
    .main-content {
        padding: 1rem 0.5rem;
    }

    .header-content {
        flex-direction: column;
        gap: 0.75rem;
        text-align: center;
        padding: 0 0.5rem;
    }

    .header h1 {
        font-size: 1.25rem;
    }

    .logo {
        width: 32px;
        height: 32px;
    }

    .header-actions {
        flex-direction: column;
        gap: 0.5rem;
        width: 100%;
    }

    .btn {
        min-height: 44px; /* Better touch target */
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }

    .dashboard-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1rem;
    }

    .dashboard-header h2 {
        font-size: 1.5rem;
        text-align: center;
    }

    .filters {
        flex-direction: column;
        align-items: stretch;
        gap: 0.75rem;
    }

    .filter-select, .search-input {
        width: 100%;
        min-height: 44px;
        font-size: 1rem; /* Better readability on mobile */
    }

    .orders-container {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }

    .order-card {
        padding: 1rem;
        margin: 0;
    }

    .order-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .order-number {
        font-size: 1rem;
        font-weight: 600;
    }

    .order-status {
        align-self: flex-end;
        margin-top: -1.5rem;
    }

    .order-info {
        flex-direction: column;
        gap: 0.25rem;
    }

    /* Chat View Mobile Styles */
    .chat-header {
        flex-direction: column;
        gap: 1rem;
        padding: 0.75rem;
    }

    .order-info {
        text-align: center;
    }

    .order-actions {
        flex-direction: column;
        gap: 0.75rem;
        width: 100%;
    }

    .status-select {
        width: 100%;
        min-height: 44px;
        font-size: 1rem;
    }

    .chat-container {
        height: calc(100vh - 280px); /* Adjust for mobile header */
        border-radius: 8px;
    }

    .messages-container {
        padding: 0.75rem;
    }

    .message {
        max-width: 85%;
        font-size: 0.9rem;
    }

    .message-input-container {
        padding: 0.75rem;
    }

    #message-input {
        font-size: 1rem; /* Prevent zoom on iOS */
        min-height: 44px;
    }

    .input-actions {
        margin-top: 0.5rem;
    }

    /* Toast notifications for mobile */
    .toast-container {
        top: 10px;
        right: 10px;
        left: 10px;
        max-width: none;
    }

    .toast {
        min-width: auto;
        width: 100%;
    }
}

/* Medium Mobile Devices (481px - 768px) */
@media (min-width: 481px) and (max-width: 768px) {
    .header-content {
        flex-direction: row;
        flex-wrap: wrap;
        justify-content: space-between;
        align-items: center;
    }

    .header-actions {
        flex-direction: row;
        gap: 0.75rem;
    }

    .dashboard-header {
        flex-direction: column;
        align-items: stretch;
        gap: 1.5rem;
    }

    .filters {
        flex-direction: row;
        flex-wrap: wrap;
        gap: 1rem;
    }

    .search-input {
        flex: 1;
        min-width: 200px;
    }

    .orders-container {
        grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
    }

    .chat-header {
        flex-wrap: wrap;
        gap: 1rem;
    }

    .order-actions {
        flex-direction: row;
        gap: 0.75rem;
    }

    .chat-container {
        height: calc(100vh - 240px);
    }
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 4rem 2rem;
    color: #666;
}

.empty-state h3 {
    margin-bottom: 1rem;
    color: #333;
}

.empty-state p {
    margin-bottom: 2rem;
}

/* Error State */
.error-state {
    text-align: center;
    padding: 4rem 2rem;
    color: #dc3545;
}

.error-state h3 {
    margin-bottom: 1rem;
}

.error-state p {
    margin-bottom: 2rem;
}

/* Chat View */
.chat-header {
    background: white;
    padding: 1rem;
    border-radius: 12px;
    margin-bottom: 1rem;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.order-info h3 {
    margin-bottom: 0.25rem;
    color: #333;
}

.order-info span {
    color: #666;
    font-size: 0.9rem;
}

.order-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.status-select {
    padding: 0.5rem;
    border: 1px solid #ddd;
    border-radius: 6px;
    font-size: 0.9rem;
}

.chat-container {
    background: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    height: 70vh;
    display: flex;
    flex-direction: column;
}

.messages-container {
    flex: 1;
    padding: 1rem;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.message {
    max-width: 70%;
    padding: 0.75rem 1rem;
    border-radius: 18px;
    position: relative;
}

.message.seller {
    align-self: flex-end;
    background-color: #4CAF50;
    color: white;
    border-bottom-right-radius: 6px;
}

.message.customer {
    align-self: flex-start;
    background-color: #f1f3f4;
    color: #333;
    border-bottom-left-radius: 6px;
}

.message.system {
    align-self: center;
    background-color: #e3f2fd;
    color: #1976d2;
    font-style: italic;
    text-align: center;
    border-radius: 20px;
    max-width: 80%;
}

.message-content {
    margin-bottom: 0.25rem;
    word-wrap: break-word;
}

.message-time {
    font-size: 0.75rem;
    opacity: 0.7;
}

.message-input-container {
    border-top: 1px solid #eee;
    padding: 1rem;
}

.message-input-wrapper {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

#message-input {
    border: 1px solid #ddd;
    border-radius: 20px;
    padding: 0.75rem 1rem;
    resize: none;
    font-family: inherit;
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}

#message-input:focus {
    border-color: #4CAF50;
}

.input-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.char-count {
    font-size: 0.8rem;
    color: #666;
}

.char-count.warning {
    color: #f57c00;
}

.char-count.error {
    color: #d32f2f;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: white;
    border-radius: 12px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-header {
    padding: 1rem;
    border-bottom: 1px solid #eee;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-close {
    background: none;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    color: #666;
}

.modal-body {
    padding: 1rem;
}

/* Order Details Modal Styles */
.order-details-content {
    max-width: 100%;
}

.detail-section {
    margin-bottom: 1.5rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid #eee;
}

.detail-section:last-child {
    border-bottom: none;
    margin-bottom: 0;
}

.detail-section h4 {
    margin: 0 0 1rem 0;
    color: #333;
    font-size: 1.1rem;
    font-weight: 600;
}

.detail-row {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.75rem;
    gap: 1rem;
}

.detail-row:last-child {
    margin-bottom: 0;
}

.detail-label {
    font-weight: 500;
    color: #666;
    min-width: 120px;
    flex-shrink: 0;
}

.detail-value {
    color: #333;
    text-align: right;
    flex: 1;
    word-break: break-word;
}

.detail-value.total-price {
    font-weight: 600;
    font-size: 1.1rem;
    color: #4CAF50;
}

/* Items List Styles */
.items-list {
    background: #f8f9fa;
    border-radius: 8px;
    padding: 1rem;
}

.order-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid #e9ecef;
}

.order-item:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.item-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.item-name {
    font-weight: 500;
    color: #333;
}

.item-quantity {
    font-size: 0.9rem;
    color: #666;
}

.item-price {
    font-weight: 600;
    color: #4CAF50;
}

.no-items {
    color: #666;
    font-style: italic;
    margin: 0;
    text-align: center;
    padding: 1rem;
}

/* Order Actions Styles */
.order-actions {
    display: flex;
    gap: 0.5rem;
    margin-top: 1rem;
    padding-top: 1rem;
    border-top: 1px solid #eee;
}

.btn-small {
    padding: 0.5rem 1rem;
    font-size: 0.9rem;
    flex: 1;
}

/* Mobile Responsive for Modal */
@media (max-width: 768px) {
    .modal-content {
        width: 95%;
        max-height: 90vh;
        margin: 1rem;
    }

    .detail-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    .detail-label {
        min-width: auto;
    }

    .detail-value {
        text-align: left;
    }

    .order-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .item-price {
        align-self: flex-end;
    }

    .order-actions {
        flex-direction: column;
    }

    .btn-small {
        flex: none;
    }
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.toast {
    background: white;
    border-radius: 8px;
    padding: 1rem;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
    border-left: 4px solid #4CAF50;
    min-width: 300px;
    animation: slideIn 0.3s ease;
}

.toast.error {
    border-left-color: #dc3545;
}

.toast.warning {
    border-left-color: #ffc107;
}

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

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-width: 400px;
}

.toast {
    background: white;
    border-radius: 12px;
    padding: 1rem 1.5rem;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
    border-left: 4px solid #4CAF50;
    display: flex;
    align-items: center;
    gap: 1rem;
    transform: translateX(100%);
    opacity: 0;
    transition: all 0.3s ease;
    position: relative;
    overflow: hidden;
}

.toast.show {
    transform: translateX(0);
    opacity: 1;
}

.toast.hide {
    transform: translateX(100%);
    opacity: 0;
}

.toast-icon {
    font-size: 1.5rem;
    flex-shrink: 0;
}

.toast-content {
    flex: 1;
}

.toast-title {
    font-weight: 600;
    color: #333;
    margin-bottom: 0.25rem;
    font-size: 0.95rem;
}

.toast-message {
    color: #666;
    font-size: 0.85rem;
    line-height: 1.4;
}

.toast-close {
    background: none;
    border: none;
    font-size: 1.2rem;
    color: #999;
    cursor: pointer;
    padding: 0;
    width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.toast-close:hover {
    color: #666;
}

/* Toast Types */
.toast.success {
    border-left-color: #4CAF50;
}

.toast.info {
    border-left-color: #2196F3;
}

.toast.warning {
    border-left-color: #FF9800;
}

.toast.error {
    border-left-color: #f44336;
}

/* Toast Progress Bar */
.toast-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: rgba(76, 175, 80, 0.3);
    width: 100%;
    transform-origin: left;
}

.toast-progress::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: #4CAF50;
    width: 100%;
    transform: scaleX(1);
    transform-origin: left;
    animation: toast-progress 5s linear forwards;
}

.toast.info .toast-progress::after {
    background: #2196F3;
}

.toast.warning .toast-progress::after {
    background: #FF9800;
}

.toast.error .toast-progress::after {
    background: #f44336;
}

@keyframes toast-progress {
    from {
        transform: scaleX(1);
    }
    to {
        transform: scaleX(0);
    }
}
