/**
 * YNET+ Ops Portal - Mobile-First Styles
 */

/* ============================================================================
   CSS Variables
   ============================================================================ */

:root {
    /* Brand Colors */
    --primary: #13265C;
    --primary-light: #1e3a8a;
    --accent: #E63946;
    --accent-hover: #dc2f3e;

    /* Status Colors */
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #0891b2;

    /* Grays */
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;

    /* Layout */
    --header-height: 60px;
    --bottom-nav-height: 70px;
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
}

/* ============================================================================
   Base Styles
   ============================================================================ */

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

html, body {
    height: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--gray-100);
    color: var(--gray-900);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Prevent body scroll when modal is open */
body.modal-open {
    overflow: hidden;
}

/* ============================================================================
   Header
   ============================================================================ */

.ops-header {
    background: var(--primary);
    color: white;
    padding: 12px 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: var(--header-height);
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo {
    display: flex;
    align-items: center;
    gap: 8px;
}

.logo-badge {
    background: white;
    color: var(--primary);
    padding: 4px 10px;
    border-radius: 6px;
    font-weight: 700;
    font-size: 14px;
}

.logo-badge .plus {
    color: var(--accent);
}

.logo-suffix {
    font-weight: 500;
    font-size: 14px;
}

.header-title {
    font-size: 16px;
    font-weight: 600;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.env-badge {
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
}

.env-development { background: #fef3c7; color: #92400e; }
.env-staging { background: #cffafe; color: #0e7490; }
.env-production { background: #d1fae5; color: #065f46; }
.env-docker { background: #e9d5ff; color: #7c3aed; }

.role-badge {
    background: rgba(255,255,255,0.2);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 12px;
    text-transform: capitalize;
}

/* ============================================================================
   Main Content Area
   ============================================================================ */

.main-content {
    padding-top: var(--header-height);
    padding-bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom));
    min-height: 100vh;
}

.page-content {
    padding: 16px;
}

/* ============================================================================
   Stats Bar
   ============================================================================ */

.stats-bar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
    padding: 16px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}

.stat-item {
    text-align: center;
}

.stat-value {
    font-size: 28px;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 11px;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* ============================================================================
   Tab Navigation
   ============================================================================ */

.tab-nav {
    display: flex;
    background: white;
    border-bottom: 1px solid var(--gray-200);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.tab-nav::-webkit-scrollbar {
    display: none;
}

.tab-btn {
    flex: 1;
    min-width: max-content;
    padding: 14px 16px;
    border: none;
    background: none;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-500);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    white-space: nowrap;
    transition: all 0.2s;
}

.tab-btn.active {
    color: var(--primary);
    border-bottom-color: var(--primary);
}

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

/* ============================================================================
   Order Cards
   ============================================================================ */

.order-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.order-card {
    background: white;
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
    border: 1px solid var(--gray-200);
}

.order-card.priority {
    border-left: 4px solid var(--accent);
}

.order-card.building {
    border-left: 4px solid var(--warning);
    background: #fffbeb;
}

.order-card.ready {
    border-left: 4px solid var(--success);
}

.order-card.out-for-delivery {
    border-left: 4px solid var(--info);
}

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

.order-ref {
    font-size: 18px;
    font-weight: 700;
    color: var(--primary);
}

.order-client {
    font-size: 14px;
    color: var(--gray-700);
    margin-top: 2px;
}

/* Status Badges */
.status-badge {
    padding: 4px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.status-badge.new { background: #dbeafe; color: #1d4ed8; }
.status-badge.in-progress { background: #fef3c7; color: #b45309; }
.status-badge.building { background: #fed7aa; color: #c2410c; }
.status-badge.ready { background: #d1fae5; color: #047857; }
.status-badge.out-for-delivery { background: #cffafe; color: #0891b2; }
.status-badge.delivered { background: #e5e7eb; color: #374151; }

.order-details {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 6px 12px;
    font-size: 13px;
    color: var(--gray-600);
}

.order-details .label {
    color: var(--gray-500);
}

.order-due {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--gray-100);
    font-size: 13px;
}

.order-due.urgent {
    color: var(--danger);
    font-weight: 600;
}

.order-address {
    display: flex;
    align-items: flex-start;
    gap: 6px;
    margin-top: 12px;
    padding-top: 12px;
    border-top: 1px solid var(--gray-100);
    font-size: 13px;
    color: var(--gray-600);
}

/* ============================================================================
   Bottom Navigation
   ============================================================================ */

#bottomNav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    border-top: 1px solid var(--gray-200);
    display: flex;
    padding: 8px 0;
    padding-bottom: calc(8px + var(--safe-area-bottom));
    z-index: 100;
}

.nav-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 8px;
    text-decoration: none;
    color: var(--gray-500);
    font-size: 11px;
    transition: color 0.2s;
}

.nav-tab svg {
    width: 24px;
    height: 24px;
}

.nav-tab.active {
    color: var(--primary);
}

.nav-tab:hover {
    color: var(--primary);
}

/* ============================================================================
   Floating Action Button (FAB)
   ============================================================================ */

.fab {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom) + 16px);
    right: 16px;
    width: 64px;
    height: 64px;
    background: var(--accent);
    border: none;
    border-radius: 50%;
    color: white;
    font-size: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 20px rgba(230, 57, 70, 0.4);
    cursor: pointer;
    z-index: 50;
    transition: transform 0.2s, box-shadow 0.2s;
}

.fab:active {
    transform: scale(0.95);
}

.fab svg {
    width: 28px;
    height: 28px;
}

/* ============================================================================
   Scanner Screen
   ============================================================================ */

.scanner-container {
    padding: 20px;
}

.scanner-viewfinder {
    background: var(--gray-900);
    border-radius: 16px;
    overflow: hidden;
    position: relative;
    aspect-ratio: 1;
}

#scanner-region {
    width: 100%;
    height: 100%;
}

.scanner-hint {
    text-align: center;
    margin-top: 24px;
}

.scanner-hint h3 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
}

.scanner-hint p {
    font-size: 14px;
    color: var(--gray-500);
}

/* ============================================================================
   Modal
   ============================================================================ */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    display: flex;
    align-items: flex-end;
    justify-content: center;
    z-index: 200;
    padding: 20px;
}

.modal-overlay.hidden {
    display: none;
}

.modal-content {
    background: white;
    border-radius: 20px 20px 0 0;
    width: 100%;
    max-width: 500px;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

@keyframes slideUp {
    from { transform: translateY(100%); }
    to { transform: translateY(0); }
}

.modal-header {
    padding: 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: sticky;
    top: 0;
    background: white;
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: var(--gray-100);
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-body {
    padding: 20px;
}

.modal-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 20px;
    border-top: 1px solid var(--gray-200);
}

/* ============================================================================
   Buttons
   ============================================================================ */

.btn {
    padding: 14px 24px;
    border-radius: 12px;
    font-size: 16px;
    font-weight: 600;
    border: none;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s;
}

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

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

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

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

.btn-secondary {
    background: var(--gray-200);
    color: var(--gray-700);
}

.btn-secondary:hover {
    background: var(--gray-300);
}

.btn-full {
    width: 100%;
}

.btn-lg {
    padding: 18px 32px;
    font-size: 18px;
}

/* ============================================================================
   Scan Result
   ============================================================================ */

.scan-result-order {
    text-align: center;
    padding: 20px 0;
}

.scan-result-order .ref {
    font-size: 32px;
    font-weight: 700;
    color: var(--primary);
}

.scan-result-order .client {
    font-size: 16px;
    color: var(--gray-600);
    margin-top: 4px;
}

.scan-result-details {
    background: var(--gray-50);
    border-radius: 12px;
    padding: 16px;
    margin: 16px 0;
}

.scan-result-details .row {
    display: flex;
    justify-content: space-between;
    padding: 10px 0;
    border-bottom: 1px solid var(--gray-200);
}

.scan-result-details .row:last-child {
    border-bottom: none;
}

.scan-result-details .label {
    color: var(--gray-500);
}

.scan-result-details .value {
    font-weight: 600;
    text-align: right;
}

.action-preview {
    background: #fef3c7;
    border: 1px solid var(--warning);
    border-radius: 12px;
    padding: 16px;
    margin: 16px 0;
    text-align: center;
}

.action-preview .action-label {
    font-size: 12px;
    color: #92400e;
    text-transform: uppercase;
    font-weight: 600;
}

.action-preview .action-text {
    font-size: 20px;
    font-weight: 700;
    color: #78350f;
    margin-top: 4px;
}

.action-preview .role-text {
    font-size: 14px;
    color: #92400e;
    margin-top: 4px;
}

/* ============================================================================
   Signature Capture
   ============================================================================ */

.signature-container {
    padding: 20px;
}

.signature-order-info {
    text-align: center;
    margin-bottom: 24px;
}

.signature-order-info .ref {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary);
}

.signature-order-info .address {
    color: var(--gray-600);
    margin-top: 4px;
}

.signature-pad-wrapper {
    background: white;
    border: 2px dashed var(--gray-300);
    border-radius: 12px;
    height: 200px;
    margin-bottom: 16px;
    position: relative;
    overflow: hidden;
}

.signature-pad-wrapper.has-signature {
    border-style: solid;
    border-color: var(--success);
}

#signatureCanvas {
    width: 100%;
    height: 100%;
    display: block;
}

.signature-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--gray-400);
    pointer-events: none;
}

.signature-placeholder.hidden {
    display: none;
}

.signature-placeholder svg {
    width: 48px;
    height: 48px;
    margin-bottom: 8px;
}

.signature-actions {
    display: flex;
    gap: 12px;
    margin-bottom: 16px;
}

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

/* ============================================================================
   GPS Status
   ============================================================================ */

.gps-status {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    border-radius: 12px;
    margin-bottom: 16px;
}

.gps-status.acquiring {
    background: #fef3c7;
    color: #92400e;
}

.gps-status.success {
    background: #d1fae5;
    color: #065f46;
}

.gps-status.error {
    background: #fee2e2;
    color: #991b1b;
}

.gps-status svg {
    width: 24px;
    height: 24px;
}

.gps-info {
    flex: 1;
}

.gps-label {
    font-weight: 600;
    font-size: 14px;
}

.gps-coords {
    font-size: 12px;
    opacity: 0.8;
}

/* ============================================================================
   Form Inputs
   ============================================================================ */

.form-group {
    margin-bottom: 16px;
}

.form-label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 6px;
}

.form-input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--gray-300);
    border-radius: 10px;
    font-size: 16px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(19, 38, 92, 0.1);
}

.form-input::placeholder {
    color: var(--gray-400);
}

/* ============================================================================
   Success Screen
   ============================================================================ */

.success-screen {
    text-align: center;
    padding: 60px 20px;
}

.success-icon {
    width: 100px;
    height: 100px;
    background: #d1fae5;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 24px;
}

.success-icon svg {
    width: 48px;
    height: 48px;
    color: var(--success);
}

.success-title {
    font-size: 24px;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 8px;
}

.success-message {
    color: var(--gray-600);
    margin-bottom: 32px;
}

.success-details {
    background: var(--gray-50);
    border-radius: 12px;
    padding: 16px;
    text-align: left;
    margin-bottom: 32px;
}

/* ============================================================================
   Empty State
   ============================================================================ */

.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-500);
}

.empty-state svg {
    width: 64px;
    height: 64px;
    margin-bottom: 16px;
    color: var(--gray-300);
}

.empty-state h3 {
    font-size: 18px;
    color: var(--gray-700);
    margin-bottom: 8px;
}

/* ============================================================================
   Loading State
   ============================================================================ */

.loading {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--gray-200);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

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

/* ============================================================================
   Profile Menu
   ============================================================================ */

#profileMenu {
    position: fixed;
    bottom: calc(var(--bottom-nav-height) + var(--safe-area-bottom) + 8px);
    right: 16px;
    background: white;
    border-radius: 12px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    min-width: 200px;
    z-index: 150;
}

#profileMenu.hidden {
    display: none;
}

.profile-menu-content {
    padding: 12px;
}

.profile-info {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
}

.profile-avatar {
    width: 40px;
    height: 40px;
    background: var(--primary);
    color: white;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
}

.profile-name {
    font-weight: 600;
    font-size: 14px;
}

.profile-role {
    font-size: 12px;
    color: var(--gray-500);
    text-transform: capitalize;
}

.profile-divider {
    height: 1px;
    background: var(--gray-200);
    margin: 8px 0;
}

.profile-menu-item {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px;
    border: none;
    background: none;
    border-radius: 8px;
    cursor: pointer;
    font-size: 14px;
    color: var(--gray-700);
    transition: background 0.2s;
}

.profile-menu-item:hover {
    background: var(--gray-100);
}

.profile-menu-item svg {
    width: 18px;
    height: 18px;
}

/* ============================================================================
   Login Page
   ============================================================================ */

.login-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
}

.login-card {
    background: white;
    border-radius: 20px;
    padding: 40px 32px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.login-logo {
    text-align: center;
    margin-bottom: 32px;
}

.login-logo .logo-badge {
    font-size: 24px;
    padding: 8px 16px;
}

.login-title {
    text-align: center;
    font-size: 24px;
    font-weight: 700;
    color: var(--gray-900);
    margin-bottom: 8px;
}

.login-subtitle {
    text-align: center;
    color: var(--gray-500);
    margin-bottom: 32px;
}

.login-error {
    background: #fee2e2;
    color: #991b1b;
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 14px;
}

.login-error.hidden {
    display: none;
}

/* ============================================================================
   Delivery Header
   ============================================================================ */

.delivery-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    color: white;
    padding: 24px 20px;
    text-align: center;
}

.delivery-date {
    font-size: 14px;
    opacity: 0.8;
}

.delivery-title {
    font-size: 24px;
    font-weight: 700;
    margin: 8px 0;
}

.delivery-stats {
    display: flex;
    justify-content: center;
    gap: 32px;
    margin-top: 20px;
}

.delivery-stat {
    text-align: center;
}

.delivery-stat .number {
    font-size: 32px;
    font-weight: 700;
}

.delivery-stat .label {
    font-size: 12px;
    opacity: 0.8;
}

/* ============================================================================
   Utilities
   ============================================================================ */

.hidden {
    display: none !important;
}

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

.text-success {
    color: var(--success);
}

.text-danger {
    color: var(--danger);
}

.text-warning {
    color: var(--warning);
}

.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
