:root {
    --app-primary: #0f3d72;
    --app-primary-2: #1f5fa8;
    --app-accent: #0ea5a4;
    --app-soft: #eef4fb;
}

body {
    background: linear-gradient(180deg, #f5f7fb 0%, #eef3f8 100%);
    font-family: Tahoma, Arial, sans-serif;
    font-size: 18px;
    color: #16324f;
}

.app-navbar {
    background: linear-gradient(135deg, var(--app-primary), var(--app-primary-2));
}

.brand-logo {
    width: 48px;
    height: 48px;
    border-radius: 14px;
    background: #ffffff;
    object-fit: contain;
    padding: 6px;
}

.brand-company {
    font-size: 1rem;
    line-height: 1.1;
}

.brand-app {
    color: rgba(255,255,255,.82);
    font-size: .8rem;
}

.user-chip {
    border: 1px solid rgba(255,255,255,.2);
    border-radius: 12px;
    padding: 8px 12px;
    background: rgba(255,255,255,.08);
}

.card {
    border: none;
    border-radius: 18px;
    box-shadow: 0 8px 22px rgba(18, 43, 70, 0.08);
}

.card-title {
    font-size: 1.3rem;
    font-weight: bold;
}

.btn {
    border-radius: 12px;
    font-size: 17px;
    padding: 10px 16px;
}

.form-control,
.form-select {
    font-size: 17px;
    padding: 12px;
    border-radius: 12px;
    border: 1px solid #d5deea;
}

.form-check-input {
    width: 1.2rem;
    height: 1.2rem;
}

.form-check-label {
    padding-right: .35rem;
}

.table {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
}

.table td,
.table th {
    vertical-align: middle;
}

.big-action-btn {
    min-height: 90px;
    font-size: 22px;
    font-weight: bold;
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.stat-card {
    border-radius: 18px;
    padding: 20px;
    color: #fff;
}

.stat-blue {
    background: linear-gradient(135deg, #0d6efd, #4c8dff);
}

.stat-green {
    background: linear-gradient(135deg, #198754, #38b974);
}

.stat-orange {
    background: linear-gradient(135deg, #fd7e14, #ff9c4a);
}

.stat-slate {
    background: linear-gradient(135deg, #334155, #64748b);
}

.login-box {
    max-width: 560px;
    margin: 70px auto;
}

.login-brand {
    text-align: center;
    margin-bottom: 1.4rem;
}

.login-brand img {
    width: 72px;
    height: 72px;
    object-fit: contain;
    background: #fff;
    border-radius: 18px;
    padding: 10px;
    box-shadow: 0 8px 18px rgba(15,61,114,.12);
}

.summary-box {
    background: var(--app-soft);
    border-radius: 16px;
    padding: 16px;
}

.summary-box h6 {
    margin-bottom: 4px;
    color: #4b647e;
}

.summary-box .summary-value {
    font-size: 1.35rem;
    font-weight: 700;
}

.print-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 18px;
}

.print-header img {
    width: 60px;
    height: 60px;
    object-fit: contain;
    background: #fff;
    border-radius: 12px;
    padding: 6px;
}

@media print {
    .navbar,
    .btn,
    form,
    .no-print {
        display: none !important;
    }

    body {
        background: #fff;
        font-size: 14px;
    }

    .container {
        max-width: 100%;
        width: 100%;
    }

    .card {
        box-shadow: none;
        border: 1px solid #ddd;
    }
}

.stat-red { background: linear-gradient(135deg, #dc3545, #f86b7a); }
.stat-purple { background: linear-gradient(135deg, #6f42c1, #9b72e7); }
.small-money { font-size: 1.35rem; }
.timeline { border-right: 3px solid #dbe7f5; padding-right: 16px; }
.timeline-item { position: relative; background: #f8fbff; border: 1px solid #e3edf8; border-radius: 16px; padding: 14px; margin-bottom: 12px; }
.timeline-item:before { content: ''; position: absolute; right: -25px; top: 18px; width: 13px; height: 13px; border-radius: 50%; background: var(--app-primary); box-shadow: 0 0 0 4px #eef4fb; }
#calendar { background: #fff; border-radius: 18px; padding: 10px; }
.fc { font-family: Tahoma, Arial, sans-serif; }
.fc .fc-toolbar-title { font-size: 1.35rem; font-weight: 700; }
.fc-event { border: 0 !important; padding: 3px 6px; border-radius: 8px; }
.event-visit-scheduled { background: #0d6efd !important; }
.event-visit-done { background: #198754 !important; }
.event-visit-postponed { background: #fd7e14 !important; color: #111 !important; }
.event-visit-cancelled { background: #6c757d !important; }
.event-visit-missed { background: #dc3545 !important; }
.event-task-new { background: #0f3d72 !important; }
.event-task-in_progress { background: #0dcaf0 !important; color: #111 !important; }
.event-task-submitted { background: #ffc107 !important; color: #111 !important; }
.event-task-needs_revision { background: #dc3545 !important; }
.event-task-closed { background: #198754 !important; }
.event-task-cancelled { background: #6c757d !important; }
@media (max-width: 768px) {
    body { font-size: 16px; }
    .container-fluid { padding-right: 10px !important; padding-left: 10px !important; }
    .table { font-size: 14px; }
    .btn { font-size: 15px; padding: 8px 12px; }
    .stat-card h2 { font-size: 1.5rem; }
    .fc .fc-toolbar { flex-direction: column; gap: 10px; }
}


.invoice-paper {
    background: #fff;
    border-radius: 22px;
    overflow: hidden;
    border: 1px solid #e4edf7;
}
.invoice-topbar {
    background: linear-gradient(135deg, #0f3d72, #1f5fa8);
    color: #fff;
    padding: 24px;
}
.invoice-logo {
    width: 82px;
    height: 82px;
    object-fit: contain;
    background: #fff;
    border-radius: 18px;
    padding: 10px;
}
.invoice-meta-box {
    background: #f6f9fd;
    border: 1px solid #e4edf7;
    border-radius: 16px;
    padding: 14px;
}
.qr-box {
    width: 160px;
    min-height: 160px;
    background: #fff;
    border: 1px solid #d9e5f2;
    border-radius: 14px;
    padding: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.qr-box canvas, .qr-box img { max-width: 138px; max-height: 138px; }
@media print {
    .invoice-paper { border: none; border-radius: 0; }
    .invoice-topbar { color: #000; background: #f3f6fa !important; border-bottom: 2px solid #d9e5f2; }
    .qr-box { border: 1px solid #ccc; }
}

/* Invoice compact print layout - v3 */
.invoice-compact {
    max-width: 980px;
    margin: 0 auto;
    border-radius: 16px;
}
.invoice-compact .invoice-topbar {
    padding: 14px 18px;
}
.invoice-compact .invoice-logo {
    width: 62px;
    height: 62px;
    border-radius: 12px;
    padding: 6px;
}
.invoice-compact h2 { font-size: 1.45rem; }
.invoice-compact h3 { font-size: 1.25rem; }
.invoice-compact h5 { font-size: 1rem; margin-bottom: .45rem !important; }
.invoice-compact h6 { font-size: .95rem; }
.invoice-compact .p-4 { padding: 16px !important; }
.invoice-compact .invoice-meta-box {
    padding: 10px 12px;
    border-radius: 12px;
}
.invoice-compact .table {
    font-size: 13px;
    margin-bottom: 0;
}
.invoice-compact .table td,
.invoice-compact .table th {
    padding: 7px 8px;
}
.invoice-compact .summary-box {
    padding: 10px 12px;
    border-radius: 12px;
}
.invoice-compact .summary-box .summary-value {
    font-size: 1.05rem;
}
.invoice-compact .qr-box {
    width: 146px;
    min-height: 146px;
    padding: 8px;
    border-radius: 12px;
}
.invoice-compact .qr-box canvas,
.invoice-compact .qr-box img { max-width: 128px; max-height: 128px; }

@media print {
    @page { size: A4 portrait; margin: 8mm; }
    html, body { width: 210mm; min-height: 297mm; }
    body { background: #fff !important; font-size: 11.5px !important; color: #111 !important; }
    .container-fluid { padding: 0 !important; margin: 0 !important; width: 100% !important; }
    .invoice-compact {
        max-width: 100% !important;
        width: 100% !important;
        box-shadow: none !important;
        border: 1px solid #ddd !important;
        border-radius: 0 !important;
        page-break-inside: avoid;
        break-inside: avoid;
    }
    .invoice-compact .invoice-topbar {
        padding: 8px 10px !important;
        color: #000 !important;
        background: #f3f6fa !important;
        border-bottom: 1px solid #ccc !important;
    }
    .invoice-compact .invoice-logo { width: 44px !important; height: 44px !important; padding: 4px !important; }
    .invoice-compact h2 { font-size: 18px !important; margin: 0 0 2px !important; }
    .invoice-compact h3 { font-size: 16px !important; margin: 0 0 2px !important; }
    .invoice-compact h5, .invoice-compact h6 { font-size: 12px !important; margin-bottom: 4px !important; }
    .invoice-compact .p-4 { padding: 8px !important; }
    .invoice-compact .row { --bs-gutter-x: .45rem; --bs-gutter-y: .45rem; }
    .invoice-compact .mb-4 { margin-bottom: .45rem !important; }
    .invoice-compact .mb-3 { margin-bottom: .35rem !important; }
    .invoice-compact .invoice-meta-box { padding: 6px 8px !important; border-radius: 6px !important; }
    .invoice-compact .table { font-size: 10.5px !important; }
    .invoice-compact .table td, .invoice-compact .table th { padding: 4px 5px !important; }
    .invoice-compact .summary-box { padding: 6px 8px !important; border-radius: 6px !important; }
    .invoice-compact .summary-box .summary-value { font-size: 12px !important; }
    .invoice-compact .qr-box { width: 92px !important; min-height: 92px !important; padding: 4px !important; }
    .invoice-compact .qr-box canvas, .invoice-compact .qr-box img { max-width: 84px !important; max-height: 84px !important; }
}


/* v4 - iPhone / mobile compatibility improvements */
html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    -webkit-font-smoothing: antialiased;
}

img, svg, canvas {
    max-width: 100%;
    height: auto;
}

.navbar-toggler,
.btn,
a.btn,
.form-control,
.form-select,
.form-check-input {
    min-height: 44px;
    touch-action: manipulation;
}

input,
select,
textarea,
button {
    font-size: 16px !important; /* Prevents Safari iPhone auto-zoom on focus */
}

textarea {
    min-height: 110px;
}

.table-responsive {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: 14px;
}

.table-responsive > .table {
    margin-bottom: 0;
}

.mobile-table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    width: 100%;
}

.mobile-table-wrap > table {
    min-width: 760px;
}

.card-body {
    overflow-wrap: anywhere;
}

.badge {
    white-space: normal;
    line-height: 1.35;
}

.invoice-share-url {
    direction: ltr;
    text-align: center;
    word-break: break-all;
    font-size: 11px;
}

@media (max-width: 576px) {
    body {
        font-size: 15px;
        background: #f6f8fb;
    }

    .navbar-brand {
        max-width: calc(100vw - 86px);
        gap: .55rem !important;
    }

    .brand-logo {
        width: 40px;
        height: 40px;
        border-radius: 10px;
        padding: 5px;
    }

    .brand-company {
        font-size: .9rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 210px;
    }

    .brand-app {
        display: none;
    }

    .card {
        border-radius: 14px;
    }

    .card-body {
        padding: 14px !important;
    }

    .login-box {
        margin: 24px auto;
    }

    .login-brand img {
        width: 58px;
        height: 58px;
    }

    h1, .h1 { font-size: 1.55rem; }
    h2, .h2 { font-size: 1.35rem; }
    h3, .h3 { font-size: 1.18rem; }

    .big-action-btn {
        min-height: 70px;
        font-size: 17px;
    }

    .stat-card {
        padding: 14px;
    }

    .summary-box .summary-value {
        font-size: 1.08rem;
    }

    .invoice-paper {
        border-radius: 12px;
    }

    .invoice-compact {
        max-width: 100%;
        border-radius: 12px;
    }

    .invoice-compact .invoice-topbar {
        padding: 12px !important;
        gap: 10px !important;
    }

    .invoice-compact .invoice-logo {
        width: 50px;
        height: 50px;
    }

    .invoice-compact .p-4 {
        padding: 12px !important;
    }

    .invoice-compact .table {
        font-size: 12px;
    }

    .invoice-compact .qr-box {
        width: 120px;
        min-height: 120px;
        margin-inline: auto;
    }

    .invoice-compact .qr-box canvas,
    .invoice-compact .qr-box img {
        max-width: 108px;
        max-height: 108px;
    }

    #calendar {
        padding: 6px;
        border-radius: 12px;
    }

    .fc .fc-toolbar-title {
        font-size: 1.05rem;
    }

    .fc .fc-button {
        padding: .35rem .55rem;
        font-size: .78rem;
    }

    .fc .fc-daygrid-day-number {
        font-size: .82rem;
    }
}

@media (display-mode: standalone) {
    body {
        padding-top: env(safe-area-inset-top);
    }
}

/* v5 - Premium invoice print redesign */
.invoice-modern {
    max-width: 920px;
    overflow: hidden;
    background: #ffffff;
    border: 1px solid #dce6f1;
}

.invoice-brand-header {
    padding: 24px 24px 18px;
    background:
        radial-gradient(circle at 15% 15%, rgba(203, 161, 83, .12), transparent 26%),
        linear-gradient(135deg, #f8fafc 0%, #ffffff 45%, #eef5f8 100%);
    border-bottom: 4px solid #13284c;
    position: relative;
}

.invoice-brand-header::after {
    content: "";
    position: absolute;
    inset-inline: 14%;
    bottom: -4px;
    height: 4px;
    background: #cba153;
    border-radius: 99px;
}

.invoice-logo-main {
    width: 128px;
    max-height: 82px;
    object-fit: contain;
    display: block;
    margin: 0 auto;
}

.invoice-company-name {
    color: #13284c;
    font-size: 1.15rem;
    font-weight: 800;
    letter-spacing: .1px;
}

.invoice-title-main {
    color: #1b8092;
    font-size: 2rem;
    font-weight: 900;
    line-height: 1.2;
}

.invoice-body {
    background: #fff;
}

.invoice-small-card {
    height: 100%;
    background: #f8fafc;
    border: 1px solid #e2eaf3;
    border-radius: 14px;
    padding: 10px 12px;
}

.invoice-small-card span {
    display: block;
    color: #64748b;
    font-size: .82rem;
    margin-bottom: 3px;
}

.invoice-small-card strong {
    color: #13284c;
    font-size: .94rem;
    overflow-wrap: anywhere;
}

.invoice-modern .invoice-meta-box {
    border: 1px solid #e2eaf3;
    background: #ffffff;
    box-shadow: 0 8px 22px rgba(15, 23, 42, .04);
}

.invoice-customer-name-only {
    font-size: 1.1rem;
    font-weight: 800;
    color: #13284c;
    padding: 4px 0;
}

.invoice-table-wrap {
    border: 1px solid #dbe7f3;
    border-radius: 14px;
    overflow: hidden;
}

.invoice-table thead th {
    background: #13284c !important;
    color: #ffffff !important;
    border-color: #13284c !important;
    font-weight: 800;
}

.invoice-table tbody td {
    border-color: #e6edf5;
}

.invoice-modern .summary-box {
    border-color: #e2eaf3;
    background: #f8fafc;
}

.invoice-modern .summary-box-total {
    background: #13284c;
    color: #fff;
    border-color: #13284c;
}

.invoice-modern .summary-box-total h6,
.invoice-modern .summary-box-total .summary-value {
    color: #fff;
}

.invoice-modern .qr-box {
    width: 140px;
    min-height: 140px;
    border-color: #d8e3ef;
}

.invoice-notes-text {
    max-height: 120px;
    overflow: hidden;
}

@media print {
    @page { size: A4 portrait; margin: 7mm; }
    html, body { width: 210mm; min-height: 297mm; }
    body { background: #fff !important; font-size: 11px !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
    .no-print, .navbar, .app-navbar, .alert { display: none !important; }
    .container-fluid { padding: 0 !important; margin: 0 !important; width: 100% !important; max-width: 100% !important; }
    .invoice-modern {
        max-width: 100% !important;
        width: 100% !important;
        min-height: auto !important;
        border: 1px solid #d8dee8 !important;
        border-radius: 0 !important;
        box-shadow: none !important;
        page-break-inside: avoid;
        break-inside: avoid;
    }
    .invoice-brand-header {
        padding: 10px 14px 8px !important;
        border-bottom-width: 2px !important;
    }
    .invoice-brand-header::after { height: 2px !important; bottom: -2px !important; }
    .invoice-logo-main { width: 94px !important; max-height: 54px !important; }
    .invoice-company-name { font-size: 13px !important; margin-bottom: 1px !important; }
    .invoice-title-main { font-size: 22px !important; margin: 0 !important; }
    .invoice-body.p-4 { padding: 8px !important; }
    .invoice-info-row { margin-bottom: 6px !important; }
    .invoice-small-card { padding: 5px 7px !important; border-radius: 7px !important; }
    .invoice-small-card span { font-size: 9.5px !important; margin-bottom: 1px !important; }
    .invoice-small-card strong { font-size: 10px !important; }
    .invoice-modern .invoice-meta-box { padding: 6px 8px !important; border-radius: 7px !important; box-shadow: none !important; }
    .invoice-customer-name-only { font-size: 12px !important; }
    .invoice-modern h5, .invoice-modern h6 { font-size: 11.5px !important; margin-bottom: 4px !important; }
    .invoice-table { font-size: 9.7px !important; }
    .invoice-table td, .invoice-table th { padding: 3.5px 4px !important; }
    .invoice-table-wrap { margin-bottom: 6px !important; border-radius: 7px !important; }
    .invoice-modern .row { --bs-gutter-x: .45rem; --bs-gutter-y: .45rem; }
    .invoice-modern .mb-3 { margin-bottom: 6px !important; }
    .invoice-modern .summary-box { padding: 5px 7px !important; border-radius: 7px !important; }
    .invoice-modern .summary-box h6 { font-size: 10.5px !important; margin: 0 0 2px !important; }
    .invoice-modern .summary-box .summary-value { font-size: 11.5px !important; }
    .invoice-modern .qr-box { width: 88px !important; min-height: 88px !important; padding: 4px !important; border-radius: 7px !important; }
    .invoice-modern .qr-box canvas, .invoice-modern .qr-box img { max-width: 80px !important; max-height: 80px !important; }
    .invoice-qr-section .small { font-size: 8.5px !important; }
    .invoice-notes-text { max-height: 58px !important; overflow: hidden !important; }
}

@media (max-width: 576px) {
    .invoice-brand-header { padding: 18px 12px 14px; }
    .invoice-logo-main { width: 105px; max-height: 70px; }
    .invoice-company-name { font-size: 1rem; }
    .invoice-title-main { font-size: 1.55rem; }
    .invoice-small-card { padding: 9px 10px; }
    .invoice-modern .invoice-body.p-4 { padding: 12px !important; }
}
