/**
 * COTG PWA Styles
 * Mobile-first Police Citation Application
 */

:root {
    --qt-primary: #003366;
    --qt-secondary: #0066cc;
    --qt-success: #28a745;
    --qt-danger: #dc3545;
    --qt-warning: #ffc107;
    --qt-info: #17a2b8;
    --qt-bg: #f0f4f8;
    --qt-white: #ffffff;
    --qt-text: #333333;
    --qt-text-muted: #6c757d;
    --qt-border: #dee2e6;
    --qt-header-height: 56px;
    --qt-tab-height: 48px;
    --qt-action-height: 60px;
    --qt-ticket-bar-height: 36px;
}

* {
    box-sizing: border-box;
}

html, body {
    height: 100%;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--qt-bg);
    color: var(--qt-text);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ================================
   PWA INSTALL GATE
   ================================ */
#pwa-install-gate {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 9999;
    background: linear-gradient(135deg, var(--qt-primary) 0%, var(--qt-secondary) 100%);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.install-gate-container {
    text-align: center;
    color: var(--qt-white);
    max-width: 400px;
}

.install-gate-content {
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border-radius: 16px;
    padding: 2.5rem 2rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
}

.install-gate-icon {
    font-size: 4rem;
    display: block;
    margin-bottom: 0.5rem;
}

.install-gate-desc {
    font-size: 1.1rem;
    opacity: 0.9;
    margin-bottom: 1.5rem;
}

.install-gate-info {
    font-size: 0.95rem;
    margin-bottom: 1.5rem;
    line-height: 1.5;
}

.install-instructions {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 1rem;
    margin-top: 1rem;
    text-align: left;
}

.install-instructions .text-muted {
    color: rgba(255, 255, 255, 0.7) !important;
}

/* ================================
   SYNC STATUS INDICATOR
   ================================ */
.sync-indicator {
    font-size: 0.7rem;
    padding: 2px 8px;
    border-radius: 12px;
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-right: 8px;
}

.sync-indicator.online {
    background: rgba(40, 167, 69, 0.3);
    color: #90ee90;
}

.sync-indicator.offline {
    background: rgba(220, 53, 69, 0.3);
    color: #ff9999;
}

.sync-indicator.pending {
    background: rgba(255, 193, 7, 0.3);
    color: #ffeb99;
    animation: pulse-sync 2s ease-in-out infinite;
}

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

/* ================================
   LOGIN SCREEN
   ================================ */
#login-screen {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, var(--qt-primary) 0%, var(--qt-secondary) 100%);
    padding: 1rem;
}

.login-container {
    background: var(--qt-white);
    border-radius: 12px;
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

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

.login-header i {
    font-size: 4rem;
    color: var(--qt-primary);
}

.login-header h1 {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--qt-primary);
    margin: 0.5rem 0 0.25rem;
}

.login-header p {
    color: var(--qt-text-muted);
    margin: 0;
}

#login-form .form-label {
    font-weight: 600;
    color: var(--qt-text);
}

#login-form .btn-primary {
    background-color: var(--qt-primary);
    border-color: var(--qt-primary);
    padding: 0.75rem;
    font-weight: 600;
}

#login-form .btn-primary:hover {
    background-color: var(--qt-secondary);
    border-color: var(--qt-secondary);
}

/* ================================
   APP HEADER
   ================================ */
.app-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--qt-header-height);
    background: var(--qt-primary);
    color: var(--qt-white);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    z-index: 1000;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.header-left {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.header-left i {
    font-size: 1.5rem;
}

.app-title {
    font-size: 1.25rem;
    font-weight: 700;
}

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

.badge-info {
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.2);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
}

#btn-logout {
    padding: 0.25rem 0.5rem;
}

/* ================================
   TICKET INFO BAR
   ================================ */
.ticket-info-bar {
    position: fixed;
    top: var(--qt-header-height);
    left: 0;
    right: 0;
    height: var(--qt-ticket-bar-height);
    background: var(--qt-secondary);
    color: var(--qt-white);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 1rem;
    font-size: 0.875rem;
    z-index: 999;
}

#ticket-number {
    font-weight: 600;
}

#ticket-status {
    font-size: 0.75rem;
}

/* ================================
   TAB NAVIGATION
   ================================ */
.tab-nav {
    position: fixed;
    top: calc(var(--qt-header-height) + var(--qt-ticket-bar-height));
    left: 0;
    right: 0;
    height: var(--qt-tab-height);
    background: var(--qt-white);
    border-bottom: 1px solid var(--qt-border);
    z-index: 998;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

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

.tab-nav .nav {
    display: flex;
    flex-wrap: nowrap;
    padding: 0.5rem;
    gap: 0.25rem;
}

.tab-nav .nav-link {
    white-space: nowrap;
    padding: 0.375rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--qt-text-muted);
    background: transparent;
    border-radius: 20px;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.tab-nav .nav-link i {
    font-size: 0.9rem;
}

.tab-nav .nav-link.active {
    background: var(--qt-primary);
    color: var(--qt-white);
}

/* ================================
   TAB CONTENT
   ================================ */
.tab-content {
    position: fixed;
    top: calc(var(--qt-header-height) + var(--qt-ticket-bar-height) + var(--qt-tab-height));
    left: 0;
    right: 0;
    bottom: var(--qt-action-height);
    overflow-y: auto;
    padding: 1rem;
    background: var(--qt-bg);
    -webkit-overflow-scrolling: touch;
}

/* ================================
   FORM SECTIONS
   ================================ */
.form-section {
    background: var(--qt-white);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.section-title {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--qt-primary);
    margin-bottom: 0.75rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--qt-primary);
}

.form-label {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--qt-text);
    margin-bottom: 0.25rem;
}

.form-label.required::after {
    content: ' *';
    color: var(--qt-danger);
}

/* Vehicle-required class - shows asterisk by default, can be toggled via JS */
.form-label.vehicle-required::after {
    content: ' *';
    color: var(--qt-danger);
}

.form-label.vehicle-required.not-required::after {
    content: '';
}

.form-control, .form-select {
    font-size: 0.9rem;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
}

.form-control:focus, .form-select:focus {
    border-color: var(--qt-secondary);
    box-shadow: 0 0 0 0.2rem rgba(0, 102, 204, 0.25);
}

.form-check-label {
    font-size: 0.85rem;
}

.btn-group .btn {
    font-size: 0.8rem;
    padding: 0.375rem 0.5rem;
}

/* ================================
   ACTION BAR
   ================================ */
.action-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    height: var(--qt-action-height);
    background: var(--qt-white);
    border-top: 1px solid var(--qt-border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    padding: 0.5rem;
    z-index: 1000;
}

.action-bar .btn {
    flex: 1;
    max-width: 80px;
    display: flex;
    flex-direction: column;
    align-items: center;
    font-size: 0.7rem;
    padding: 0.25rem;
    gap: 0.125rem;
}

.action-bar .btn i {
    font-size: 1.25rem;
}

/* ================================
   VIOLATIONS LIST
   ================================ */
#violations-list {
    min-height: 60px;
}

.violation-item {
    background: var(--qt-bg);
    border-radius: 6px;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.violation-item .violation-info {
    flex: 1;
}

.violation-item .violation-code {
    font-weight: 700;
    color: var(--qt-primary);
}

.violation-item .violation-desc {
    font-size: 0.85rem;
    color: var(--qt-text);
}

.violation-item .violation-type {
    font-size: 0.75rem;
    padding: 0.125rem 0.5rem;
    border-radius: 10px;
}

.violation-item .violation-type.type-violation {
    background: var(--qt-danger);
    color: white;
}

.violation-item .violation-type.type-warning {
    background: var(--qt-warning);
    color: black;
}

.violation-item .violation-type.type-verbal {
    background: var(--qt-info);
    color: white;
}

.violation-item .btn-remove {
    padding: 0.25rem 0.5rem;
    font-size: 0.75rem;
}

/* ================================
   SIGNATURE PAD
   ================================ */
.signature-pad-container {
    position: relative;
    background: #f8f9fa;
    border: 2px dashed var(--qt-border);
    border-radius: 8px;
    padding: 0.5rem;
}

.signature-pad {
    width: 100%;
    height: 150px;
    background: var(--qt-white);
    border-radius: 4px;
    touch-action: none;
}

.signature-pad-container button {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
}

/* ================================
   MEDIA UPLOAD
   ================================ */
.media-upload-area {
    background: var(--qt-bg);
    border: 2px dashed var(--qt-border);
    border-radius: 8px;
    padding: 2rem 1rem;
    text-align: center;
    cursor: pointer;
    transition: border-color 0.3s, background-color 0.3s;
}

.media-upload-area:hover, .media-upload-area:active {
    border-color: var(--qt-secondary);
    background: rgba(0, 102, 204, 0.05);
}

.media-upload-area i {
    font-size: 2.5rem;
    color: var(--qt-text-muted);
    display: block;
    margin-bottom: 0.5rem;
}

.media-upload-area p {
    margin: 0;
    font-size: 0.85rem;
    color: var(--qt-text-muted);
}

#license-photo-preview,
#violator-photo-preview {
    position: relative;
    text-align: center;
}

#license-photo-preview img,
#violator-photo-preview img {
    max-height: 200px;
    border-radius: 8px;
}

#license-photo-preview button,
#violator-photo-preview button {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
}

#other-photos-preview .other-photo-item {
    position: relative;
}

#other-photos-preview img {
    width: 100%;
    height: 80px;
    object-fit: cover;
    border-radius: 6px;
}

#other-photos-preview .btn-remove-photo {
    position: absolute;
    top: 2px;
    right: 2px;
    padding: 0.125rem 0.25rem;
    font-size: 0.65rem;
}

/* ================================
   DASHBOARD
   ================================ */
#dashboard-screen {
    padding-top: var(--qt-header-height);
    min-height: 100vh;
    background: var(--qt-bg);
}

#dashboard-screen h4 {
    color: var(--qt-primary);
    font-weight: 700;
}

.dashboard-card {
    background: var(--qt-white);
    border-radius: 12px;
    padding: 1.5rem 1rem;
    text-align: center;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
}

.dashboard-card:hover,
.dashboard-card:active {
    transform: translateY(-2px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
}

.dashboard-card i {
    font-size: 2.5rem;
    color: var(--qt-primary);
}

.dashboard-card span {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--qt-text);
}

#admin-menu .dashboard-card {
    background: linear-gradient(135deg, #f8f9fa 0%, #e9ecef 100%);
}

#admin-menu .dashboard-card i {
    color: var(--qt-secondary);
}

/* Demo citation card */
.dashboard-card-demo {
    background: linear-gradient(135deg, #fff3cd 0%, #ffeeba 100%) !important;
    border: 1px solid #ffc107;
}

.dashboard-card-demo i {
    color: #856404 !important;
}

.dashboard-card-demo span {
    color: #856404;
}

.dashboard-card-nib {
    background: linear-gradient(135deg, #e8d5f5 0%, #d4b8e8 100%) !important;
    border: 1px solid #9b59b6;
}

.dashboard-card-nib i {
    color: #6c3483 !important;
}

.dashboard-card-nib span {
    color: #6c3483;
}

/* ================================
   NIB DATA MANAGER
   ================================ */

.dm-table {
    font-size: 13px;
}

.dm-table th {
    text-transform: capitalize;
    white-space: nowrap;
    font-size: 11px;
    background: #f8f9fa;
}

.dm-table td {
    vertical-align: middle;
    max-width: 200px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dm-actions {
    white-space: nowrap;
}

.dm-actions .btn {
    padding: 2px 6px;
    font-size: 12px;
}

/* ================================
   REFERENCE DATA MANAGER
   ================================ */
#ref-data-screen .table th {
    font-size: 0.8rem;
    white-space: nowrap;
}

#ref-data-screen .table td {
    font-size: 0.85rem;
    vertical-align: middle;
}

#ref-data-screen .table td strong {
    color: var(--qt-primary);
}

#ref-data-screen .progress {
    border-radius: 0;
}

#ref-data-summary .badge {
    font-size: 0.75rem;
    font-weight: 500;
}

/* Citation screen adjustments when not at top level */
#citation-screen .ticket-info-bar {
    position: fixed;
    top: var(--qt-header-height);
}

#citation-screen .tab-nav {
    top: calc(var(--qt-header-height) + var(--qt-ticket-bar-height));
}

#citation-screen .tab-content {
    top: calc(var(--qt-header-height) + var(--qt-ticket-bar-height) + var(--qt-tab-height));
}

/* ================================
   LOADING OVERLAY
   ================================ */
#loading-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

/* ================================
   TOAST NOTIFICATIONS
   ================================ */
.toast-container .toast {
    min-width: 280px;
}

/* ================================
   MODAL ADJUSTMENTS
   ================================ */
.modal-content {
    border-radius: 12px;
}

.modal-header {
    background: var(--qt-primary);
    color: var(--qt-white);
    border-radius: 12px 12px 0 0;
}

.modal-header .btn-close {
    filter: brightness(0) invert(1);
}

/* ================================
   UTILITY CLASSES
   ================================ */
.text-primary {
    color: var(--qt-primary) !important;
}

.bg-primary {
    background-color: var(--qt-primary) !important;
}

/* ================================
   RESPONSIVE ADJUSTMENTS
   ================================ */
@media (min-width: 576px) {
    .tab-content {
        padding: 1.5rem;
    }

    .form-section {
        padding: 1.5rem;
    }

    .tab-nav .nav-link {
        padding: 0.5rem 1rem;
        font-size: 0.85rem;
    }

    .action-bar .btn {
        max-width: 100px;
        font-size: 0.8rem;
    }
}

@media (min-width: 768px) {
    .form-section .row {
        --bs-gutter-x: 1rem;
    }
}

@media (min-width: 992px) {
    .tab-content {
        max-width: 800px;
        margin: 0 auto;
    }
}

/* ================================
   INNER SCREENS (My Citations, Search, Profile, Admin)
   ================================ */
.inner-screen {
    padding-top: var(--qt-header-height);
    min-height: 100vh;
    background: var(--qt-bg);
}

.screen-container {
    padding: 1rem;
    max-width: 800px;
    margin: 0 auto;
}

.screen-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding: 0.5rem 0;
}

.screen-header h5 {
    margin: 0;
    font-weight: 700;
    color: var(--qt-primary);
}

/* ================================
   CITATION LIST ITEMS
   ================================ */
.citation-list-item {
    background: var(--qt-white);
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-bottom: 0.5rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.citation-list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.citation-list-header strong {
    color: var(--qt-primary);
    font-size: 0.95rem;
}

.citation-list-body {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1rem;
}

.citation-list-detail {
    font-size: 0.8rem;
    color: var(--qt-text);
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.citation-list-detail i {
    color: var(--qt-text-muted);
    font-size: 0.75rem;
}

.citation-list-footer {
    font-size: 0.75rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--qt-border);
}

.citation-list-actions {
    display: flex;
    gap: 0.25rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--qt-border);
}

/* ================================
   STAT CARDS (Profile/Reports)
   ================================ */
.stat-card {
    background: var(--qt-bg);
    border-radius: 8px;
    padding: 0.75rem 0.5rem;
}

.stat-number {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--qt-primary);
    line-height: 1;
}

.stat-label {
    font-size: 0.7rem;
    color: var(--qt-text-muted);
    margin-top: 0.25rem;
}

/* ================================
   ADMIN TABLE STYLES
   ================================ */
.inner-screen .table {
    font-size: 0.85rem;
}

.inner-screen .table th {
    font-weight: 600;
    color: var(--qt-primary);
    border-bottom-width: 2px;
}

.inner-screen .table td {
    vertical-align: middle;
}

/* ================================
   FORM VALIDATION
   ================================ */
.is-invalid {
    border-color: var(--qt-danger) !important;
    box-shadow: 0 0 0 0.2rem rgba(220, 53, 69, 0.25) !important;
}

.invalid-feedback {
    font-size: 0.75rem;
    color: var(--qt-danger);
    margin-top: 0.125rem;
}

/* ================================
   PRINT STYLES
   ================================ */
@media print {
    .app-header,
    .tab-nav,
    .action-bar,
    #loading-overlay {
        display: none !important;
    }

    .tab-content {
        position: static;
        overflow: visible;
    }
}

/* ================================
   SAFE AREA INSETS (iOS)
   ================================ */
@supports (padding-top: env(safe-area-inset-top)) {
    .app-header {
        padding-top: env(safe-area-inset-top);
        height: calc(var(--qt-header-height) + env(safe-area-inset-top));
    }

    .action-bar {
        padding-bottom: env(safe-area-inset-bottom);
        height: calc(var(--qt-action-height) + env(safe-area-inset-bottom));
    }

    .tab-content {
        top: calc(var(--qt-header-height) + var(--qt-ticket-bar-height) + var(--qt-tab-height) + env(safe-area-inset-top));
        bottom: calc(var(--qt-action-height) + env(safe-area-inset-bottom));
    }
}
