/* ===== Invoice System Stylesheet ===== */

/* ===== CSS Variables ===== */
:root {
    --white-color: #fff;
    --primary-color: #0b2545;
    --secondary-color: #2c3e50;
    --text-color: #1b344d;
    --light-text: #8f9eaf;
    --muted-text: #666;
    --border-color: #dee2e6;
    --box-bg-color: #f0f3f7;
    --danger-color: #dc3545;
    --success-color: #28a745;
    --font-main: 'Inter', sans-serif;
}

/* ===== Accessibility and UX Improvements ===== */

/* Focus Visible Styles for Keyboard Navigation */
:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 3px;
    box-shadow: 0 0 0 3px rgba(11, 37, 69, 0.25);
    border-radius: 2px;
    transition: outline-offset 0.2s ease;
}

.btn:focus-visible,
.form-control:focus-visible {
    outline: 3px solid var(--primary-color);
    outline-offset: 1px;
}

/* Allow focus outline but hide default browser outline */
:focus {
    outline: none;
}

/* Skip to content link for keyboard users */
.skip-to-content {
    position: absolute;
    left: 0;
    top: -50px;
    background: var(--primary-color);
    color: white;
    padding: 10px 15px;
    z-index: 1000;
    transition: top 0.3s ease;
    text-decoration: none;
    border-radius: 0 0 5px 0;
}

.skip-to-content:focus {
    top: 0;
}

/* Screen Reader Utility Classes */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

.sr-only-focusable:not(:focus) {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Enhanced Form Validation Feedback */
.invalid-feedback {
    display: none;
    width: 100%;
    margin-top: 0.25rem;
    font-size: 85%;
    color: var(--danger-color);
}

.valid-feedback {
    display: none;
    width: 100%;
    margin-top: 0.25rem;
    font-size: 85%;
    color: var(--success-color);
}

.form-control.is-invalid~.invalid-feedback,
.form-control.is-valid~.valid-feedback {
    display: block;
}

.form-control.is-valid {
    border-color: var(--success-color);
    padding-right: calc(1.5em + 0.75rem);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 8 8'%3e%3cpath fill='%2328a745' d='M2.3 6.73L.6 4.53c-.4-1.04.46-1.4 1.1-.8l1.1 1.4 3.4-3.8c.6-.63 1.6-.27 1.2.7l-4 4.6c-.43.5-.8.4-1.1.1z'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

/* Form field animations */
.form-control.is-invalid {
    animation: shake 0.5s ease-in-out;
}

@keyframes shake {

    0%,
    100% {
        transform: translateX(0);
    }

    20%,
    60% {
        transform: translateX(-5px);
    }

    40%,
    80% {
        transform: translateX(5px);
    }
}

/* Loading State Styles */
.loading {
    position: relative;
    pointer-events: none;
    opacity: 0.7;
}

.loading::after {
    content: "";
    position: absolute;
    top: calc(50% - 1rem);
    left: calc(50% - 1rem);
    width: 2rem;
    height: 2rem;
    border: 2px solid rgba(var(--primary-color), 0.2);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spinner 0.6s linear infinite;
}

@keyframes spinner {
    to {
        transform: rotate(360deg);
    }
}

.btn.loading {
    padding-right: 2.5rem;
}

.btn.loading::after {
    width: 1rem;
    height: 1rem;
    right: 1rem;
    left: auto;
    top: calc(50% - 0.5rem);
}

/* Better Error State Handling */
.error {
    color: var(--danger-color);
    border-color: var(--danger-color);
    background-color: rgba(220, 53, 69, 0.05);
}

.error-message {
    display: block;
    margin-top: 0.5rem;
    padding: 0.5rem 1rem;
    background-color: rgba(220, 53, 69, 0.1);
    border-left: 3px solid var(--danger-color);
    color: var(--danger-color);
    border-radius: 0 3px 3px 0;
}

/* Success indicator */
.success-message {
    display: block;
    margin-top: 0.5rem;
    padding: 0.5rem 1rem;
    background-color: rgba(40, 167, 69, 0.1);
    border-left: 3px solid var(--success-color);
    color: var(--success-color);
    border-radius: 0 3px 3px 0;
}

/* ARIA attributes styling */
[aria-invalid="true"] {
    border-color: var(--danger-color);
}

[aria-disabled="true"] {
    opacity: 0.6;
    cursor: not-allowed;
}

[role="alert"] {
    animation: fadeIn 0.3s ease-in-out;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Improved visibility for currently focused elements */
.form-control:focus,
.btn:focus,
a:focus {
    box-shadow: 0 0 0 3px rgba(11, 37, 69, 0.25);
}

/* Added touch target size for mobile */
@media (max-width: 768px) {

    .btn,
    .form-control,
    a,
    select,
    input[type="checkbox"],
    input[type="radio"] {
        min-height: 44px;
        min-width: 44px;
    }

    input[type="checkbox"],
    input[type="radio"] {
        transform: scale(1.2);
    }
}

/* ===== Base Styles ===== */
body {
    font-family: var(--font-main);
    line-height: 1.6;
    color: var(--text-color);
    background-color: #fff;
}

.container {
    max-width: 1140px;
    margin: 0 auto;
}

hr {
    border: 1px solid var(--light-text);
    margin-top: 50px;
    margin-bottom: 20px;
}

/* ===== Common Components ===== */
.logo-img {
    height: 80px;
    object-fit: contain;
}

.title-text {
    color: var(--light-text);
    font-size: 16px;
    font-weight: 500;
    margin-bottom: 10px;
}

/* Button Styles */
.btn {
    padding: 0.5rem 1rem;
    border-radius: 4px;
    font-weight: 500;
    text-decoration: none;
    display: inline-block;
    cursor: pointer;
    transition: all 0.3s ease;
}

.btn-primary {
    background-color: var(--primary-color);
    border: 1px solid var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background-color: var(--secondary-color);
    border-color: var(--secondary-color);
}

.btn-secondary {
    background-color: var(--light-text);
    border: 1px solid var(--light-text);
    color: white;
}

.btn-secondary:hover {
    background-color: #5a6268;
    border-color: #5a6268;
}

/* ===== Invoice Styles ===== */
.invoice {
    margin-bottom: 2rem;
}

/* Company Info */
.company-name {
    font-weight: 700;
    font-size: 20px;
    color: var(--text-color);
}

.company-address {
    font-size: 14px;
    color: var(--text-color);
}

.invoice-title {
    color: var(--text-color);
    font-size: 36px;
    font-weight: 700;
    line-height: 1;
}

.invoice-info {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-color);
}

/* Table Styles */
.table>:not(caption)>*>* {
    background-color: transparent !important;
}

.table thead tr {
    font-weight: 600;
    font-size: 16px;
    background-color: var(--box-bg-color);
    color: var(--all-text-color);
}

.table {
    width: 100%;
    margin-bottom: 1rem;
    margin-top: 2rem;
}

.table .item-details {
    border-bottom: 1px solid var(--light-text);
}

.table th,
.table td {
    padding: 12px;
    vertical-align: middle;
}

.table thead tr {
    font-weight: 600;
    font-size: 16px;
    background-color: var(--box-bg-color);
    color: var(--text-color);
}

thead th span {
    font-weight: 400;
    color: var(--light-text);
}

tbody tr {
    /* border-bottom: 1px solid var(--light-text); */
    font-size: 14px;
    font-weight: 400;
}

tbody,
td,
tfoot,
th,
thead,
tr {
    border-style: none;
}

tbody .details-text {
    border-bottom: 1px solid var(--light-text);
}

.table>:not(caption)>*>* {
    padding: .2rem .5rem;
}

tbody td:first-child,
tbody td:nth-child(2) {
    font-weight: 600;
}

tbody p {
    color: var(--light-text);
    font-weight: 400;
    font-size: 14px;
    margin-bottom: 0;
}

.text-start {
    text-align: left;
}

.text-end {
    text-align: right;
}

/* Total Section */
.btn-total {
    background-color: var(--primary-color);
    color: white;
    font-weight: 500;
    font-size: 18px;
    padding: 8px 10px 8px 100px;
    border-radius: 10px;
    border: none;
}

.total-words-text {
    font-size: 16px;
    font-weight: 500;
}

.total-words-text span {
    font-weight: 600;
}

.total-price-btn {
    background-color: var(--primary-color);
    color: var(--white-color);
    border-radius: 8px;
}

/* Bank Details */
.bank-details {
    margin-top: 2rem;
}

.bank-details-box {
    background-color: var(--box-bg-color);
    max-width: 60%;
    border-radius: 5px;
    border: 1px solid var(--border-color);
    padding: 1.5rem;
}

.bank-info p {
    font-size: 16px;
    margin-bottom: 0;
    color: var(--text-color);
}

.bank-info p span {
    font-weight: 600;
    color: var(--text-color);
}

/* Notes Section */
.notes {
    font-size: 14px;
    color: var(--text-color);
    margin-top: 1.5rem;
}

.notes p {
    color: var(--text-color);
    margin-bottom: 0.5rem;
    font-size: 16px;
    font-weight: 600;
}

.notes span {
    font-size: 14px;
    font-style: italic;
    color: var(--muted-text);
}

/* ===== Footer Styles ===== */
footer {
    font-size: 14px;
    color: var(--light-text);
    padding-top: 1rem;
    margin-top: 2rem;
    border-top: 1px solid var(--border-color);
}

footer i {
    margin-right: 5px;
    color: var(--primary-color);
}

footer p {
    margin-bottom: 0;
    color: var(--light-text);
    font-size: 16px;
}




/* ===== Form Styles ===== */
.form-section {
    background-color: var(--box-bg-color);
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 1.5rem;
    margin-bottom: 2rem;
}

.form-label {
    font-weight: 500;
    color: var(--text-color);
    margin-bottom: 0.5rem;
    display: block;
}

.form-control {
    display: block;
    width: 100%;
    padding: 0.375rem 0.75rem;
    font-size: 1rem;
    line-height: 1.5;
    color: var(--text-color);
    background-color: #fff;
    border: 1px solid var(--border-color);
    border-radius: 0.25rem;
    transition: border-color 0.15s ease-in-out, box-shadow 0.15s ease-in-out;
}

.form-control:focus {
    border-color: var(--primary-color);
    outline: 0;
    box-shadow: 0 0 0 0.25rem rgba(11, 37, 69, 0.25);
}

.form-control:disabled,
.form-control[readonly] {
    background-color: var(--box-bg-color);
    opacity: 1;
}

.form-control::placeholder {
    color: var(--light-text);
    opacity: 0.6;
}

.items-table th {
    background-color: var(--box-bg-color);
}

.add-item-btn {
    margin: 1rem 0;
}

.remove-item {
    color: var(--danger-color);
    cursor: pointer;
    transition: color 0.2s;
}

.remove-item:hover {
    color: #bd2130;
}

/* Form Validation */
.is-invalid {
    border-color: var(--danger-color);
    padding-right: calc(1.5em + 0.75rem);
    background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 12' width='12' height='12' fill='none' stroke='%23dc3545'%3e%3ccircle cx='6' cy='6' r='4.5'/%3e%3cpath stroke-linejoin='round' d='M5.8 3.6h.4L6 6.5z'/%3e%3ccircle cx='6' cy='8.2' r='.6' fill='%23dc3545' stroke='none'/%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right calc(0.375em + 0.1875rem) center;
    background-size: calc(0.75em + 0.375rem) calc(0.75em + 0.375rem);
}

/* ===== Utility Classes ===== */
/* Margin */
.mt-1 {
    margin-top: 0.25rem !important;
}

.mt-2 {
    margin-top: 0.5rem !important;
}

.mt-3 {
    margin-top: 1rem !important;
}

.mt-4 {
    margin-top: 1.5rem !important;
}

.mt-5 {
    margin-top: 3rem !important;
}

.mb-0 {
    margin-bottom: 0 !important;
}

.mb-1 {
    margin-bottom: 0.25rem !important;
}

.mb-2 {
    margin-bottom: 0.5rem !important;
}

.mb-3 {
    margin-bottom: 1rem !important;
}

.mb-4 {
    margin-bottom: 1.5rem !important;
}

.mb-5 {
    margin-bottom: 3rem !important;
}

.ms-2 {
    margin-left: 0.5rem !important;
}

.me-3 {
    margin-right: 1rem !important;
}

.me-5 {
    margin-right: 3rem !important;
}

.mx-4 {
    margin-left: 1.5rem !important;
    margin-right: 1.5rem !important;
}

/* Padding */
.p-3 {
    padding: 1rem !important;
}

/* Flexbox utilities */
.d-flex {
    display: flex !important;
}

.d-block {
    display: block !important;
}

.d-inline-block {
    display: inline-block !important;
}

.flex-wrap {
    flex-wrap: wrap !important;
}

.flex-nowrap {
    flex-wrap: nowrap !important;
}

.flex-column {
    flex-direction: column !important;
}

.flex-row {
    flex-direction: row !important;
}

.justify-content-between {
    justify-content: space-between !important;
}

.justify-content-end {
    justify-content: flex-end !important;
}

.justify-content-start {
    justify-content: flex-start !important;
}

.justify-content-center {
    justify-content: center !important;
}

.align-items-center {
    align-items: center !important;
}

.align-items-start {
    align-items: flex-start !important;
}

.align-items-end {
    align-items: flex-end !important;
}

.gap-1 {
    gap: 0.25rem !important;
}

.gap-2 {
    gap: 0.5rem !important;
}

.gap-3 {
    gap: 1rem !important;
}

.gap-4 {
    gap: 1.5rem !important;
}

.gap-5 {
    gap: 3rem !important;
}

/* Text alignment */
.text-end {
    text-align: right !important;
}

.text-start {
    text-align: left !important;
}

.text-center {
    text-align: center !important;
}

/* ===== Print Styles ===== */
@media print {

    /* Page setup */
    @page {
        size: A4;
        margin: 1.5cm;
        margin-bottom: 3cm;
    }

    @page :first {
        margin-top: 1cm;
    }

    @page :last {
        margin-bottom: 3cm;
    }

    /* Hide elements not meant for printing */
    .no-print {
        display: none !important;
    }

    /* Basic print styles */
    html,
    body {
        width: 210mm;
        height: 297mm;
        font-size: 12pt;
        line-height: 1.3;
        background: #fff !important;
        color: #000 !important;
        print-color-adjust: exact;
        -webkit-print-color-adjust: exact;
        margin: 0;
        padding: 0;
    }

    .container {
        width: 100%;
        max-width: none;
        padding: 0;
        margin: 0;
    }

    /* Page break control */
    .page-break-before {
        page-break-before: always;
    }

    .page-break-after {
        page-break-after: always;
    }

    .avoid-break,
    .invoice-title,
    .bank-details-box,
    .notes,
    .total-section,
    tbody tr {
        page-break-inside: avoid;
        break-inside: avoid;
    }

    /* Table print optimization */
    .table {
        width: 100%;
        border-collapse: collapse !important;
        break-inside: auto;
    }

    .table th,
    .table td {
        background-color: #fff !important;
        border-color: #000 !important;
    }

    /* Make table headers repeat on each page */
    thead {
        display: table-header-group;
    }

    tfoot {
        display: table-footer-group;
    }

    /* Control element appearance */
    .btn-total {
        border: 1px solid #000;
        background: none !important;
        color: #000 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    /* Footer positioning */
    footer {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        border-top: 1px solid #000;
        padding-top: 0.5cm;
        margin-top: 1cm;
    }

    /* Link handling */
    a {
        text-decoration: none !important;
        color: #000 !important;
    }

    a[href]::after {
        content: none !important;
    }

    /* Force background colors */
    * {
        -webkit-print-color-adjust: exact !important;
        print-color-adjust: exact !important;
    }
}

/* ===== Total Section Styles =====
@media (max-width: 992px) {
    .container {
        padding: 0 1rem;
    }
    
    .invoice-title {
        font-size: 28px;
    }
    
    .bank-details-box {
        max-width: 80%;
    }
}

/* Medium screens (tablets) */
@media (max-width: 768px) {

    /* Layout adjustments */
    .row {
        flex-direction: column;
    }

    .col-lg-6 {
        width: 100%;
    }

    /* Typography adjustments */
    .invoice-title {
        font-size: 24px;
        margin-top: 1.5rem;
    }

    .company-name {
        font-size: 16px;
    }

    .company-address {
        font-size: 13px;
    }

    /* Table responsiveness */
    .table-responsive {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        -ms-overflow-style: -ms-autohiding-scrollbar;
        margin-bottom: 1rem;
        border: 0;
    }

    /* Make first column sticky for better mobile scrolling */
    .table-responsive .table th:first-child,
    .table-responsive .table td:first-child {
        position: sticky;
        left: 0;
        background-color: #fff;
        z-index: 1;
    }

    /* Prevent text wrapping in most columns */
    .table th,
    .table td {
        padding: 8px;
        font-size: 14px;
        white-space: nowrap;
    }

    /* Allow text wrapping in description column */
    .table td:nth-child(2) {
        white-space: normal;
        min-width: 200px;
    }

    /* Footer adjustments */
    footer .d-flex {
        flex-direction: column;
        gap: 0.5rem;
    }

    footer p {
        font-size: 14px;
        margin-bottom: 0.5rem;
    }

    /* Total section */
    .btn-total {
        padding-left: 15px;
        text-align: center;
        margin-top: 1rem;
        width: 100%;
        justify-content: space-between;
    }

    /* Bank details */
    .bank-details-box {
        max-width: 100%;
    }
}

/* Small screens (mobile) */
@media (max-width: 576px) {

    /* Typography adjustments */
    .invoice-title {
        font-size: 22px;
    }

    /* Table handling */
    .table th,
    .table td {
        padding: 6px 4px;
        font-size: 12px;
    }

    /* Bank details */
    .bank-info p {
        display: flex;
        flex-wrap: wrap;
        margin-bottom: 0.5rem;
        padding: 0.25rem 0;
        /* Better touch targets */
    }

    .bank-info p span {
        min-width: 40%;
        margin-right: 0.5rem;
    }

    /* Form adjustments */
    .form-section {
        padding: 1rem;
    }

    .form-control {
        padding: 0.375rem 0.5rem;
        font-size: 16px;
        /* Prevent iOS zoom on focus */
        min-height: 44px;
        /* Better touch target */
    }

    .form-label {
        font-size: 14px;
        margin-bottom: 0.25rem;
    }

    /* Touch-friendly buttons */
    .btn {
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }

    /* Adjustment for total section */
    .btn-total {
        font-size: 16px;
        padding: 8px 15px;
    }
}

/* Very small screens (small mobile) */
@media (max-width: 400px) {

    /* Hide less important info */
    .hide-xs {
        display: none;
    }

    /* More compact layout */
    .invoice-title {
        font-size: 20px;
    }

    .btn-total {
        font-size: 16px;
        padding: 8px;
    }

    /* Smaller footer */
    footer p {
        font-size: 12px;
    }
}

/* High DPI Screen Optimizations */
@media (-webkit-min-device-pixel-ratio: 2),
(min-resolution: 192dpi) {

    /* Sharper images */
    .logo-img,
    .bank-logo-img {
        image-rendering: -webkit-optimize-contrast;
        image-rendering: crisp-edges;
    }

    /* Better text rendering */
    body {
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
    }
}