/* ======================================================
   1. Theme and Reset Section
========================================================= */
:root {
    --brand-blue: #1464a5;
    --brand-blue-dark: #0b4778;
    --brand-blue-light: #eef7ff;
    --text: #222222;
    --text-muted: #667085;
    --border: #d9dde3;
    --surface: #ffffff;
    --background: #f4f6f8;
    --shadow: 0 4px 18px rgba(16, 24, 40, 0.08);
    --radius: 10px;
}

* {
    box-sizing: border-box;
}

html {
    scroll-behavior: smooth;
}

body {
    margin: 0;
    min-width: 320px;
    font-family: Arial, Helvetica, sans-serif;
    color: var(--text);
    background: var(--background);
    line-height: 1.5;
}

img {
    max-width: 100%;
}

/* ======================================================
   2. Header and Main Navigation Section
========================================================= */
.topbar {
    position: sticky;
    top: 0;
    z-index: 1000;
    background: var(--surface);
    border-bottom: 4px solid var(--brand-blue);
    box-shadow: 0 2px 12px rgba(16, 24, 40, 0.08);
}

.topbar-inner {
    width: 100%;
    max-width: 1600px;
    min-height: 78px;
    margin: 0 auto;
    padding: 8px 22px;
    display: flex;
    align-items: center;
    gap: 22px;
}

.brand {
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    gap: 12px;
    color: #303030;
    text-decoration: none;
    font-weight: 700;
}

.brand img {
    width: auto;
    height: 58px;
}

.brand span {
    max-width: 245px;
    line-height: 1.2;
}

.main-nav {
    display: flex;
    align-items: center;
    gap: 3px;
    margin-left: auto;
}

.nav-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    min-height: 42px;
    padding: 9px 12px;
    border: 0;
    border-radius: 7px;
    color: #333333;
    background: transparent;
    text-decoration: none;
    font: inherit;
    font-size: 14px;
    font-weight: 700;
    white-space: nowrap;
    cursor: pointer;
}

.nav-link:hover,
.nav-link:focus-visible,
.nav-dropdown.is-open > .nav-link {
    color: var(--brand-blue);
    background: var(--brand-blue-light);
    outline: none;
}

.nav-dropdown {
    position: relative;
}

.dropdown-arrow {
    display: inline-block;
    font-size: 12px;
    transition: transform 0.18s ease;
}

.nav-dropdown.is-open .dropdown-arrow {
    transform: rotate(180deg);
}

.dropdown-menu {
    position: absolute;
    top: calc(100% + 7px);
    left: 0;
    z-index: 1100;
    display: none;
    min-width: 245px;
    padding: 7px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 9px;
    box-shadow: 0 16px 35px rgba(16, 24, 40, 0.17);
}

.dropdown-menu-right {
    right: 0;
    left: auto;
}

.nav-dropdown.is-open > .dropdown-menu {
    display: block;
}

.dropdown-menu a {
    display: block;
    padding: 10px 12px;
    border-radius: 6px;
    color: #333333;
    text-decoration: none;
    font-size: 14px;
    white-space: nowrap;
}

.dropdown-menu a:hover,
.dropdown-menu a:focus-visible {
    color: var(--brand-blue);
    background: var(--brand-blue-light);
    outline: none;
}

.user-chip {
    flex: 0 0 auto;
    display: flex;
    flex-direction: column;
    padding-left: 16px;
    border-left: 1px solid var(--border);
    font-size: 12px;
    color: var(--text-muted);
    line-height: 1.25;
}

.user-chip strong {
    max-width: 180px;
    overflow: hidden;
    color: #303030;
    font-size: 15px;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.nav-toggle {
    display: none;
    width: 44px;
    height: 42px;
    padding: 9px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: var(--surface);
    cursor: pointer;
}

.nav-toggle span {
    display: block;
    height: 2px;
    margin: 5px 0;
    background: #333333;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.nav-toggle.is-open span:nth-child(1) {
    transform: translateY(7px) rotate(45deg);
}

.nav-toggle.is-open span:nth-child(2) {
    opacity: 0;
}

.nav-toggle.is-open span:nth-child(3) {
    transform: translateY(-7px) rotate(-45deg);
}

/* ======================================================
   3. Main Content and Dashboard Section
========================================================= */
.container {
    width: min(1200px, 100%);
    margin: 24px auto;
    padding: 0 20px;
}

.container > h1 {
    margin: 0 0 20px;
    font-size: clamp(26px, 4vw, 36px);
    line-height: 1.15;
}

.cards {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 18px;
}

.card,
.panel,
.form-card,
.menu-card {
    background: var(--surface);
    border: 1px solid rgba(217, 221, 227, 0.7);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card {
    padding: 20px;
}

.card h2 {
    margin: 0 0 7px;
    color: #4b5563;
    font-size: 16px;
}

.card strong {
    color: var(--brand-blue);
    font-size: 38px;
    line-height: 1;
}

.panel,
.form-card {
    padding: 22px;
}

.dashboard-section {
    margin-top: 24px;
}

.section-heading {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
}

.section-heading h2,
.panel h2,
.form-card h2 {
    margin-top: 0;
}

.section-heading h2 {
    margin-bottom: 4px;
}

.section-heading p {
    margin: 0;
    color: var(--text-muted);
}

.menu-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 20px;
}

.menu-card {
    overflow: hidden;
}

.menu-card-heading {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 20px;
    border-bottom: 1px solid var(--border);
}

.menu-card-heading h2 {
    margin: 0 0 4px;
    font-size: 21px;
}

.menu-card-heading p {
    margin: 0;
    color: var(--text-muted);
    font-size: 14px;
}

.menu-card-icon {
    flex: 0 0 48px;
    width: 48px;
    height: 48px;
    display: grid;
    place-items: center;
    border-radius: 10px;
    color: #ffffff;
    background: var(--brand-blue);
    font-size: 15px;
    font-weight: 800;
    letter-spacing: 0.3px;
}

.menu-links {
    display: grid;
    gap: 1px;
    padding: 8px;
    background: #f7f8fa;
}

.menu-links a {
    display: flex;
    align-items: center;
    min-height: 43px;
    padding: 10px 12px;
    border-radius: 7px;
    color: #333333;
    background: var(--surface);
    text-decoration: none;
    font-weight: 700;
}

.menu-links a::after {
    content: ">";
    margin-left: auto;
    color: var(--brand-blue);
    font-weight: 800;
}

.menu-links a:hover,
.menu-links a:focus-visible {
    color: var(--brand-blue);
    background: var(--brand-blue-light);
    outline: none;
}

.empty-state {
    padding: 34px 18px;
    border: 1px dashed #c8cdd4;
    border-radius: 9px;
    text-align: center;
    background: #fafafa;
}

.empty-state h3 {
    margin: 0 0 7px;
}

.empty-state p {
    margin: 0;
    color: var(--text-muted);
}

/* ======================================================
   4. Buttons, Alerts and Form Controls Section
========================================================= */
.button,
button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 15px;
    border: 0;
    border-radius: 6px;
    color: #ffffff;
    background: var(--brand-blue);
    text-decoration: none;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.button:hover,
button:hover {
    filter: brightness(0.94);
}

.button.secondary,
button.secondary {
    background: #555555;
}

.button.danger,
button.danger {
    background: var(--brand-blue-dark);
}

.button.small,
button.small {
    min-height: 32px;
    padding: 6px 9px;
    font-size: 12px;
}

.alert {
    margin: 12px 0;
    padding: 12px;
    border-radius: 6px;
}

.alert.success {
    color: #176b31;
    background: #dff3e4;
}

.alert.error {
    color: var(--brand-blue-dark);
    background: #fde0e0;
}

.alert.warning {
    color: #664d03;
    background: #fff3cd;
}

label {
    display: block;
    margin-bottom: 12px;
    font-weight: 700;
}

input,
select,
textarea {
    width: 100%;
    min-height: 42px;
    margin-top: 5px;
    padding: 9px 10px;
    border: 1px solid #b9c0ca;
    border-radius: 5px;
    color: var(--text);
    background: #ffffff;
    font: inherit;
}

input:focus,
select:focus,
textarea:focus {
    border-color: var(--brand-blue);
    outline: 3px solid rgba(178, 14, 22, 0.12);
}

textarea {
    min-height: 90px;
    resize: vertical;
}

.grid-2 {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 16px;
}

.grid-3 {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 16px;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.actions form {
    margin: 0;
}

.item-row {
    display: grid;
    grid-template-columns: minmax(220px, 2fr) minmax(100px, 0.7fr) minmax(100px, 0.7fr) minmax(140px, 1fr) auto;
    gap: 10px;
    align-items: end;
    margin-bottom: 8px;
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: 7px;
    background: #fafafa;
}

/* ======================================================
   5. Tables Section
========================================================= */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--surface);
    -webkit-overflow-scrolling: touch;
}

.table-responsive table {
    min-width: 760px;
}

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
}

th,
td {
    padding: 11px 10px;
    border-bottom: 1px solid #e2e5e9;
    text-align: left;
    vertical-align: top;
}

th {
    color: #333333;
    background: #eef0f3;
    font-size: 15px;
}

tbody tr:hover {
    background: #fffafa;
}

tbody tr:last-child td {
    border-bottom: 0;
}

.status {
    font-weight: 700;
    text-transform: capitalize;
}

.status.invoiced,
.status.cancelled {
    color: var(--brand-blue-dark);
}

.status.delivered,
.status.issued,
.status.paid {
    color: #176b31;
}

.status.draft {
    color: #765a00;
}

/* ======================================================
   6. Login Screen Section
========================================================= */
.login-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 20px;
    background: linear-gradient(135deg, #e4f8ff, #9edff5);
}

.login-card {
    width: min(430px, 100%);
    padding: 32px;
    border-radius: 12px;
    background: #ffffff;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.33);
}

.login-card img {
    display: block;
    width: auto;
    height: 145px;
    margin: auto;
}

.login-card h1 {
    text-align: center;
    font-size: 22px;
}

/* ======================================================
   7. Printable Document Section
========================================================= */
.document {
    position: relative;
    max-width: 900px;
    margin: 0 auto;
    padding: 35px;
    background: #ffffff;
}

.doc-header {
    display: flex;
    justify-content: space-between;
    gap: 20px;
    padding-bottom: 15px;
    border-bottom: 3px solid var(--brand-blue);
}

.doc-header img {
    width: auto;
    height: 120px;
}

.doc-title {
    text-align: right;
}

.totals {
    width: min(360px, 100%);
    margin-left: auto;
}

.totals td {
    text-align: right;
    white-space: nowrap;
}

.invoice-delivery-row td {
    background: #f7f7f7;
    font-weight: 700;
}

.invoice-product-row td {
    font-size: 15px;
}

.invoice-product-row .item-description {
    padding-left: 24px;
}

.invoice-bank-details {
    width: min(440px, 100%);
    margin-top: 24px;
    text-align: left;
    break-inside: avoid;
    page-break-inside: avoid;
}

.invoice-bank-details h3 {
    margin-bottom: 8px;
}

.invoice-bank-details p {
    margin: 0;
    line-height: 1.5;
}

.delivery-items-table th,
.delivery-items-table td {
    font-size: 15px;
}

.number,
.centre {
    white-space: nowrap;
}

.number {
    text-align: right;
}

.centre {
    text-align: center;
}

.signature-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 30px;
    margin-top: 45px;
}

.signature-box {
    margin-top: 50px;
    padding-top: 8px;
    border-top: 1px solid #333333;
}

.site-footer {
    padding: 25px 20px;
    color: #666666;
    text-align: center;
}

/* ======================================================
   8. Desktop Dropdown Behaviour Section
========================================================= */
@media (min-width: 1101px) {
    .nav-dropdown:hover > .dropdown-menu,
    .nav-dropdown:focus-within > .dropdown-menu {
        display: block;
    }
}

/* ======================================================
   9. Tablet and Mobile Navigation Section
========================================================= */
@media (max-width: 1100px) {
    .topbar-inner {
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        gap: 10px 14px;
        padding: 8px 16px;
    }

    .brand span {
        max-width: none;
    }

    .nav-toggle {
        display: block;
    }

    .main-nav {
        grid-column: 1 / -1;
        display: none;
        width: 100%;
        margin: 0;
        padding: 8px 0 5px;
        border-top: 1px solid var(--border);
    }

    .main-nav.is-open {
        display: grid;
        gap: 4px;
    }

    .main-nav > .nav-link,
    .nav-dropdown,
    .nav-dropdown > .nav-link {
        width: 100%;
    }

    .main-nav > .nav-link,
    .nav-dropdown > .nav-link {
        justify-content: space-between;
        padding: 10px 12px;
        text-align: left;
    }

    .dropdown-menu,
    .dropdown-menu-right {
        position: static;
        width: 100%;
        min-width: 0;
        margin-top: 3px;
        padding: 5px 5px 5px 14px;
        border: 0;
        border-left: 3px solid var(--brand-blue);
        border-radius: 0;
        box-shadow: none;
        background: #fafafa;
    }

    .dropdown-menu a {
        white-space: normal;
    }

    .user-chip {
        grid-column: 1 / -1;
        padding: 7px 0 2px;
        border-top: 1px solid var(--border);
        border-left: 0;
    }

    .user-chip strong {
        max-width: 100%;
    }
}

/* ======================================================
   10. Small Screen Content Section
========================================================= */
@media (max-width: 800px) {
    .container {
        margin-top: 18px;
        padding: 0 14px;
    }

    .cards,
    .menu-grid,
    .grid-2,
    .grid-3,
    .signature-grid {
        grid-template-columns: 1fr;
    }

    .section-heading {
        flex-direction: column;
    }

    .section-heading .button {
        width: 100%;
    }

    .item-row {
        grid-template-columns: 1fr;
    }

    .item-row button {
        width: 100%;
    }

    .panel,
    .form-card,
    .card {
        padding: 16px;
    }

    .document {
        padding: 15px;
    }

    .doc-header {
        flex-direction: column;
    }

    .doc-title {
        text-align: left;
    }

    .doc-header img {
        height: 95px;
        align-self: flex-start;
    }

    .container > table,
    .form-card > table,
    .panel > table {
        display: block;
        width: 100%;
        overflow-x: auto;
        white-space: nowrap;
        -webkit-overflow-scrolling: touch;
    }
}

@media (max-width: 520px) {
    .brand img {
        height: 50px;
    }

    .brand span {
        font-size: 15px;
    }

    .login-card {
        padding: 22px;
    }

    .menu-card-heading {
        padding: 16px;
    }
}

/* ======================================================
   11. Print Section
========================================================= */
@media print {
    body {
        background: #ffffff;
    }

    .topbar,
    .site-footer,
    .no-print,
    body > main > h1 {
        display: none !important;
    }

    .container {
        max-width: none;
        margin: 0;
        padding: 0;
    }

    .document {
        max-width: none;
        padding: 10mm 12mm 32mm;
        box-shadow: none;
    }

    .document::after {
        content: "";
        position: fixed;
        right: 0;
        bottom: 0;
        left: 0;
        z-index: -1;
        height: 30mm;
        background: url('../img/letterhead-footer.png') bottom center / 100% auto no-repeat;
    }

    a {
        color: #000000;
        text-decoration: none;
    }

    table {
        font-size: 11px;
    }
}

/* ======================================================
   12. Statements and Reports Section
========================================================= */
.report-page {
    display: grid;
    gap: 22px;
}

.report-filters {
    margin-bottom: 0;
}

.report-sheet {
    overflow: hidden;
}

.report-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
    padding-bottom: 16px;
    border-bottom: 3px solid var(--brand-blue);
}

.report-heading img {
    width: auto;
    height: 96px;
}

.report-heading > div {
    text-align: right;
}

.report-heading h2,
.report-heading p {
    margin: 0 0 4px;
}

.report-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 24px;
    margin: 16px 0;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fafafa;
    font-size: 14px;
}

.report-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
    margin: 16px 0;
}

.report-summary-card {
    min-width: 0;
    padding: 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #ffffff;
}

.report-summary-card span {
    display: block;
    margin-bottom: 5px;
    color: #666666;
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.report-summary-card strong {
    display: block;
    overflow-wrap: anywhere;
    font-size: 19px;
}

.report-summary-total {
    border-color: var(--brand-blue);
    background: #fff8f8;
}

.report-actions {
    justify-content: flex-end;
    margin: 16px 0;
}

.report-table-wrap {
    margin-top: 12px;
}

.report-table {
    min-width: 900px;
    font-size: 15px;
}

.report-table th {
    white-space: nowrap;
}

.report-table td.numeric,
.report-table th.numeric {
    text-align: right;
    white-space: nowrap;
}

.report-table tfoot th {
    border-top: 2px solid #333333;
    background: #f4f4f4;
}

.report-note {
    margin: 14px 0 0;
    color: #666666;
    font-size: 12px;
}

@media (max-width: 900px) {
    .report-summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 600px) {
    .report-heading {
        align-items: flex-start;
        flex-direction: column;
    }

    .report-heading > div {
        text-align: left;
    }

    .report-heading img {
        height: 78px;
    }

    .report-summary-grid {
        grid-template-columns: 1fr;
    }
}

@media print {
    .report-page {
        display: block;
    }

    .report-sheet {
        padding: 0;
        border: 0;
        box-shadow: none;
    }

    .report-heading img {
        height: 75px;
    }

    .report-meta {
        margin: 10px 0;
        padding: 8px;
        font-size: 10px;
    }

    .report-summary-grid {
        grid-template-columns: repeat(7, minmax(0, 1fr));
        gap: 5px;
        margin: 10px 0;
    }

    .report-summary-card {
        padding: 7px;
        border-radius: 0;
    }

    .report-summary-card span {
        font-size: 8px;
    }

    .report-summary-card strong {
        font-size: 11px;
    }

    .report-table-wrap {
        overflow: visible;
    }

    .report-table {
        min-width: 0;
        width: 100%;
        font-size: 8px;
    }

    .report-table th,
    .report-table td {
        padding: 4px;
    }

    .report-note {
        font-size: 9px;
    }
}

/* ======================================================
   13. Document Email Module Section
========================================================= */
.email-module {
    display: grid;
    gap: 20px;
}

.document-type-tabs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    box-shadow: var(--shadow);
}

.document-type-tabs a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    padding: 9px 15px;
    border-radius: 7px;
    color: #333333;
    background: #f2f4f7;
    text-decoration: none;
    font-weight: 700;
}

.document-type-tabs a:hover,
.document-type-tabs a:focus-visible,
.document-type-tabs a.active {
    color: #ffffff;
    background: var(--brand-blue);
    outline: none;
}

.email-filter-form {
    margin: 0 0 18px;
    padding: 18px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fafafa;
}

.email-filter-actions {
    align-self: end;
    padding-bottom: 12px;
}

.email-document-table {
    min-width: 1080px;
}

.select-column {
    width: 72px;
    text-align: center;
}

.select-column input[type="radio"] {
    width: 19px;
    height: 19px;
    margin: 0;
    accent-color: var(--brand-blue);
}

.email-selection-actions {
    justify-content: flex-end;
    margin-top: 18px;
}

.missing-email {
    color: var(--brand-blue-dark);
    font-weight: 700;
}

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

.compact-list {
    margin: 8px 0 0;
    padding-left: 22px;
}

.alert.info {
    color: #174c72;
    border-color: #9cc9e6;
    background: #eef8ff;
}

.email-summary-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 12px;
}

.email-summary-grid > div {
    min-width: 0;
    padding: 13px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: #fafafa;
}

.email-summary-grid span {
    display: block;
    margin-bottom: 4px;
    color: var(--text-muted);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 0.03em;
    text-transform: uppercase;
}

.email-summary-grid strong {
    display: block;
    overflow-wrap: anywhere;
}

.email-compose-form textarea {
    min-height: 210px;
    resize: vertical;
}

.email-compose-form small,
.email-filter-form small {
    display: block;
    margin-top: 5px;
    color: var(--text-muted);
    font-weight: 400;
}

.email-attachment-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    margin: 16px 0 20px;
    padding: 15px;
    border: 1px solid #f0b9bc;
    border-left: 5px solid var(--brand-blue);
    border-radius: 8px;
    background: var(--brand-blue-light);
}

.email-attachment-card strong,
.email-attachment-card span {
    display: block;
}

.email-attachment-card span {
    margin-top: 3px;
    color: var(--text-muted);
    font-size: 15px;
}

.email-attachment-card a {
    flex: 0 0 auto;
    color: var(--brand-blue);
    font-weight: 700;
}

.email-result {
    display: inline-flex;
    align-items: center;
    min-height: 25px;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 700;
    text-transform: capitalize;
}

.email-result.sent {
    color: #176b31;
    background: #eaf7ee;
}

.email-result.failed {
    color: var(--brand-blue-dark);
    background: var(--brand-blue-light);
}

@media (max-width: 900px) {
    .email-summary-grid {
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
}

@media (max-width: 600px) {
    .document-type-tabs,
    .document-type-tabs a,
    .email-summary-grid {
        width: 100%;
    }

    .document-type-tabs {
        display: grid;
        grid-template-columns: 1fr;
    }

    .email-summary-grid {
        grid-template-columns: 1fr;
    }

    .email-attachment-card {
        align-items: flex-start;
        flex-direction: column;
    }

    .email-attachment-card a,
    .email-selection-actions button {
        width: 100%;
    }
}
