/* Global Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #f5f5f5;
    color: #333;
    line-height: 1.6;
}

a {
    color: #007bff;
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* Navigation */
.navbar {
    background-color: #2c3e50;
    color: white;
    padding: 0.75rem 0;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.navbar-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.5rem 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: nowrap;
}

.navbar-brand {
    font-size: 1.5rem;
    font-weight: bold;
    margin-right: auto;
}

.navbar-menu {
    display: flex;
    list-style: none;
    gap: 2rem;
    align-items: center;
}

.navbar-menu a {
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    transition: background-color 0.3s;
}

.navbar-menu a:hover {
    background-color: #34495e;
    text-decoration: none;
}

.logout-btn {
    background-color: #e74c3c;
    padding: 0.5rem 1rem;
    border-radius: 4px;
    cursor: pointer;
    border: none;
    color: white;
    font-size: 1rem;
    min-height: 44px;
    min-width: 44px;
    /* Mobile touch target */
    white-space: nowrap;
}

.logout-btn:hover {
    background-color: #c0392b;
}

/* Mobile Menu Toggle */
.menu-toggle {
    display: none;
    background: none;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem 0.75rem;
    min-height: 44px;
    min-width: 44px;
    flex-grow: 0;
    margin-left: auto;
}

.menu-toggle:active {
    opacity: 0.8;
}

/* Container */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

/* Cards */
.card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    padding: 1.5rem;
    margin-bottom: 1.5rem;
}

.card-title {
    font-size: 1.5rem;
    margin-bottom: 1rem;
    color: #2c3e50;
    border-bottom: 2px solid #007bff;
    padding-bottom: 0.5rem;
}

/* Forms */
.form-group {
    margin-bottom: 1.5rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 600;
    color: #2c3e50;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.875rem;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 16px; /* Prevents iOS auto-zoom */
    min-height: 44px; /* Mobile touch target */
    font-family: inherit;
    transition: border-color 0.3s;
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: #007bff;
    box-shadow: 0 0 5px rgba(0,123,255,0.25);
}

.form-group textarea {
    resize: vertical;
    min-height: 100px;
}

/* Buttons */
.btn {
    padding: 0.875rem 1.5rem;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px; /* Prevents iOS auto-zoom */
    font-weight: 600;
    transition: all 0.3s;
    display: inline-block;
    min-height: 44px; /* Mobile touch target */
    min-width: 44px; /* Mobile touch target */
    vertical-align: middle;
    text-align: center;
}

.btn-primary {
    background-color: #007bff;
    color: white;
}

.btn-primary:hover {
    background-color: #0056b3;
}

.btn-success {
    background-color: #28a745;
    color: white;
}

.btn-success:hover {
    background-color: #218838;
}

.btn-danger {
    background-color: #dc3545;
    color: white;
}

.btn-danger:hover {
    background-color: #c82333;
}

.btn-warning {
    background-color: #ffc107;
    color: #333;
}

.btn-warning:hover {
    background-color: #e0a800;
}

.btn-secondary {
    background-color: #6c757d;
    color: white;
}

.btn-secondary:hover {
    background-color: #5a6268;
}

.btn-sm {
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    min-height: 36px;
    min-width: 36px;
    white-space: nowrap;
}

.btn-block {
    width: 100%;
    margin-top: 1rem;
}

.btn-group {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

/* Tables */
.table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 1rem;
}

.table thead {
    background-color: #f8f9fa;
}

.table th,
.table td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid #dee2e6;
}

.table th {
    font-weight: 600;
    color: #2c3e50;
}

.table tbody tr:hover {
    background-color: #f8f9fa;
}

.table-striped tbody tr:nth-child(odd) {
    background-color: #f8f9fa;
}

/* Table Column Widths */
.table th:nth-child(1),
.table td:nth-child(1) {
    width: 15%;
    min-width: 80px;
}

.table th:nth-child(2),
.table td:nth-child(2) {
    width: 25%;
    min-width: 120px;
}

.table th:nth-child(3),
.table td:nth-child(3) {
    width: 20%;
    min-width: 100px;
}

.table th:last-child,
.table td:last-child {
    width: 40%;
    min-width: 150px;
    text-align: center;
}

/* Responsive Tables */
.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    margin: 1rem 0;
}

.table-responsive .table {
    min-width: 600px;
}

/* Alerts */
.alert {
    padding: 1rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    border-left: 4px solid;
}

.alert-success {
    background-color: #d4edda;
    border-color: #28a745;
    color: #155724;
}

.alert-error,
.alert-danger {
    background-color: #f8d7da;
    border-color: #dc3545;
    color: #721c24;
}

.alert-warning {
    background-color: #fff3cd;
    border-color: #ffc107;
    color: #856404;
}

.alert-info {
    background-color: #d1ecf1;
    border-color: #17a2b8;
    color: #0c5460;
}

/* Dashboard Stats */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: white;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.1);
    padding: 1.5rem;
    border-top: 4px solid #007bff;
}

.stat-card.success {
    border-top-color: #28a745;
}

.stat-card.danger {
    border-top-color: #dc3545;
}

.stat-card.warning {
    border-top-color: #ffc107;
}

.stat-value {
    font-size: 2.5rem;
    font-weight: bold;
    color: #2c3e50;
    margin: 1rem 0;
}

.stat-label {
    color: #000000;
    font-size: 0.9rem;
}

/* Modal */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0,0,0,0.5);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.modal-content {
    background-color: white;
    margin: 5% auto;
    padding: 2rem;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 4px 12px rgba(0,0,0,0.3);
    animation: slideIn 0.3s ease-out;
    max-height: 90vh;
    overflow-y: auto;
}

@keyframes slideIn {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    border-bottom: 1px solid #dee2e6;
    padding-bottom: 1rem;
}

.modal-title {
    font-size: 1.5rem;
    font-weight: bold;
}

.close {
    font-size: 1.5rem;
    font-weight: bold;
    cursor: pointer;
    color: #aaa;
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close:hover {
    color: #000;
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    margin-top: 1.5rem;
    border-top: 1px solid #dee2e6;
    padding-top: 1rem;
}

/* Login Page */
.login-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 1rem;
}

.login-box {
    background: white;
    border-radius: 8px;
    box-shadow: 0 8px 24px rgba(0,0,0,0.2);
    padding: 2.5rem 2rem;
    width: 100%;
    max-width: 400px;
}

.login-title {
    text-align: center;
    font-size: 1.8rem;
    margin-bottom: 0.5rem;
    color: #2c3e50;
}

.login-subtitle {
    text-align: center;
    color: #666;
    margin-bottom: 2rem;
    font-size: 0.9rem;
}

/* Loading spinner */
.spinner {
    border: 4px solid #f3f3f3;
    border-top: 4px solid #007bff;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 2rem auto;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* Utility classes */
.text-center {
    text-align: center;
}

.text-right {
    text-align: right;
}

.mt-1 { margin-top: 0.5rem; }
.mt-2 { margin-top: 1rem; }
.mt-3 { margin-top: 1.5rem; }
.mt-4 { margin-top: 2rem; }

.mb-1 { margin-bottom: 0.5rem; }
.mb-2 { margin-bottom: 1rem; }
.mb-3 { margin-bottom: 1.5rem; }
.mb-4 { margin-bottom: 2rem; }

.p-1 { padding: 0.5rem; }
.p-2 { padding: 1rem; }
.p-3 { padding: 1.5rem; }
.p-4 { padding: 2rem; }

.hidden {
    display: none;
}

.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
}

/* ===== MOBILE RESPONSIVE STYLES ===== */

/* Base Responsive Typography */
html {
    font-size: 16px;
}

/* Tablet */
@media (max-width: 768px) {
    html {
        font-size: 15px;
    }
    
    .navbar-brand {
        font-size: 1.2rem;
    }
    
    .navbar-menu {
        gap: 0.5rem;
    }
    
    .container {
        padding: 1rem;
    }
    
    .card {
        padding: 1.25rem;
        margin-bottom: 1rem;
    }
    
    .card-title {
        font-size: 1.3rem;
    }
    
    /* Mobile Navigation */
    .menu-toggle {
        display: block;
    }
    
    .navbar-menu {
        display: none;
        width: 100%;
        flex-direction: column;
        gap: 0.5rem;
        margin-top: 0.75rem;
        order: 3;
        background-color: rgba(0,0,0,0.1);
        padding: 0.5rem;
        border-radius: 4px;
    }
    
    .navbar-menu.active {
        display: flex;
    }
    
    .navbar-menu li {
        width: 100%;
    }
    
    .navbar-menu a {
        display: block;
        text-align: center;
        padding: 0.875rem;
        margin: 0.25rem 0;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    
    /* Mobile Forms */
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px; /* Prevent iOS zoom */
        padding: 0.875rem;
    }
    
    /* Stack grid layouts */
    [style*="grid-template-columns"] {
        grid-template-columns: 1fr !important;
        gap: 1rem !important;
    }
    
    /* Mobile Tables */
    .table th,
    .table td {
        padding: 0.75rem;
        font-size: 0.9rem;
    }
    
    /* Mobile Stats */
    .stats-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 1rem;
    }
    
    .stat-value {
        font-size: 2rem;
    }
    
    /* Mobile Modal */
    .modal-content {
        width: 95%;
        margin: 10% auto;
        padding: 1.5rem;
    }
    
    .modal-header {
        flex-wrap: wrap;
    }
    
    .modal-title {
        font-size: 1.3rem;
    }
    
    /* Mobile Login */
    .login-box {
        padding: 2rem 1.5rem;
        margin: 1rem;
        width: calc(100% - 2rem);
    }
    
    .login-title {
        font-size: 1.5rem;
    }
    
    /* Mobile Buttons */
    .btn-group {
        flex-direction: column;
    }
    
    .btn-group .btn {
        width: 100%;
    }
}

/* Mobile Phones */
@media (max-width: 480px) {
    html {
        font-size: 14px;
    }
    
    .navbar-container {
        padding: 0.5rem 0.5rem;
    }
    
    .navbar-brand {
        font-size: 1rem;
    }
    
    .navbar-menu {
        gap: 0.25rem;
    }
    
    .container {
        padding: 0.75rem;
    }
    
    .card {
        padding: 1rem;
        margin-bottom: 0.75rem;
    }
    
    .card-title {
        font-size: 1.1rem;
        margin-bottom: 0.75rem;
    }
    
    /* Single column stats */
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 0.75rem;
    }
    
    .stat-card {
        padding: 1rem;
    }
    
    .stat-value {
        font-size: 1.8rem;
        margin: 0.5rem 0;
    }
    
    .stat-label {
        font-size: 0.85rem;
    }
    
    /* Mobile Tables */
    .table-responsive .table {
        min-width: 500px;
    }
    
    .table th,
    .table td {
        padding: 0.75rem 0.5rem;
        font-size: 0.875rem;
    }
    
    /* Mobile Form Inputs */
    .form-group {
        margin-bottom: 1.25rem;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 16px !important;
        padding: 0.875rem;
        min-height: 44px;
    }
    
    /* Mobile Button Sizes */
    .btn {
        padding: 0.875rem 1rem;
        font-size: 0.9rem;
        width: 100%;
        margin-bottom: 0.5rem;
    }

    .btn-sm {
        width: auto;
        padding: 0.5rem 0.75rem;
    }
    
    .btn-group {
        flex-direction: column;
    }
    
    .btn-group .btn {
        width: 100%;
    }

    /* Mobile Grid Layout - Stack on small screens */
    [style*="grid-template-columns: 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }

    [style*="grid-template-columns: 1fr 1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
    
    /* Mobile Modal */
    .modal-content {
        width: 96%;
        padding: 1.25rem;
        margin: 5% auto;
    }
    
    .modal-header {
        margin-bottom: 1rem;
    }
    
    .modal-title {
        font-size: 1.2rem;
    }
    
    .close {
        font-size: 1.25rem;
    }
    
    /* Mobile Loading Spinner */
    .spinner {
        width: 30px;
        height: 30px;
        border-width: 3px;
    }
    
    /* Utility classes adjustments */
    .mt-1 { margin-top: 0.375rem; }
    .mt-2 { margin-top: 0.75rem; }
    .mt-3 { margin-top: 1rem; }
    .mt-4 { margin-top: 1.5rem; }
    
    .mb-1 { margin-bottom: 0.375rem; }
    .mb-2 { margin-bottom: 0.75rem; }
    .mb-3 { margin-bottom: 1rem; }
    .mb-4 { margin-bottom: 1.5rem; }

/* Very Small Phones */
@media (max-width: 360px) {
    .btn {
        font-size: 0.875rem;
        padding: 0.75rem 0.875rem;
    }
    
    .form-group input,
    .form-group select,
    .form-group textarea {
        font-size: 14px !important;
        padding: 0.75rem;
        min-height: 44px;
    }
    
    .stat-value {
        font-size: 1.5rem;
    }
    
    .navbar-brand {
        font-size: 0.9rem;
    }
    
    .card-title {
        font-size: 1rem;
    }
    
    .login-box {
        padding: 1.5rem 1.25rem;
    }
    
    .login-title {
        font-size: 1.3rem;
    }
}

/* Tablet Landscape / Small Desktop */
@media (min-width: 769px) and (max-width: 1024px) {
    .container {
        padding: 1.5rem;
    }
    
    .stats-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .navbar-menu {
        gap: 1rem;
    }
}

/* Landscape Mode */
@media (max-height: 500px) and (orientation: landscape) {
    .login-box {
        padding: 1.5rem;
        max-height: 90vh;
        overflow-y: auto;
    }
    
    .navbar {
        padding: 0.5rem 0;
    }
    
    .modal-content {
        max-height: 80vh;
        margin: 2% auto;
    }
}

/* High Density Displays */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .btn {
        border-width: 0.5px;
    }
}

/* Print Styles */
@media print {
    .navbar,
    .btn,
    .no-print {
        display: none !important;
    }
    
    .container {
        padding: 0;
    }
    
    .card {
        box-shadow: none;
        border: 1px solid #ddd;
        page-break-inside: avoid;
    }
    
    .table {
        page-break-inside: avoid;
    }
}

/* Toast Notifications */
.toast {
    position: fixed;
    top: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: #28a745;
    color: white;
    padding: 1rem 2rem;
    border-radius: 4px;
    z-index: 9999;
    box-shadow: 0 2px 10px rgba(0,0,0,0.2);
    max-width: 90vw;
    text-align: center;
    animation: slideDown 0.3s ease;
}

.toast-error {
    background: #dc3545;
}

.toast-warning {
    background: #ffc107;
    color: #333;
}

.toast-info {
    background: #17a2b8;
}

@keyframes slideDown {
    from { top: -100px; opacity: 0; }
    to { top: 20px; opacity: 1; }
}

@keyframes slideUp {
    from { top: 20px; opacity: 1; }
    to { top: -100px; opacity: 0; }
}

@media (max-width: 768px) {
    .toast {
        top: 10px;
        padding: 0.75rem 1rem;
        font-size: 0.9rem;
    }
}

/* Safe Area Insets for Notched Phones */
.safe-area-padding {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
}

/* Mobile Action Bar */
.mobile-action-bar {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    padding: 0.75rem 1rem;
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    z-index: 1000;
    gap: 0.5rem;
}

@media (max-width: 768px) {
    .mobile-action-bar {
        display: flex;
    }
    
    body.with-action-bar {
        padding-bottom: 70px;
    }
}

/* Delivery Page Mobile Styles */
@media (max-width: 768px) {
    .customer-delivery-item {
        grid-template-columns: 1fr !important;
        padding: 1rem !important;
    }
    
    .customer-info-delivery {
        margin: 0.5rem 0;
    }
    
    .checkbox-large {
        width: 30px !important;
        height: 30px !important;
    }
    
    .input-group-inline {
        margin: 0.5rem 0;
    }
    
    .summary-grid {
        grid-template-columns: 1fr !important;
    }
}

/* Prevent iOS zoom on input focus */
input[type="color"],
input[type="date"],
input[type="datetime"],
input[type="datetime-local"],
input[type="email"],
input[type="month"],
input[type="number"],
input[type="password"],
input[type="search"],
input[type="tel"],
input[type="text"],
input[type="time"],
input[type="url"],
input[type="week"],
select:focus,
textarea {
    font-size: 16px !important;
}

/* Accessibility & Mobile Optimization */
/* Better focus states for keyboard navigation */
button:focus,
a:focus,
input:focus,
select:focus,
textarea:focus {
    outline: 2px solid #007bff;
    outline-offset: 2px;
}

/* Improve readability on small screens */
@media (max-width: 480px) {
    body {
        line-height: 1.7;
    }
    
    h1, h2, h3, h4, h5, h6 {
        margin-bottom: 0.75rem;
        line-height: 1.3;
    }
}

/* Smooth scrolling for better UX */
html {
    scroll-behavior: smooth;
}

/* Reduce motion for users who prefer it */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
}