:root {
    --bg: #f4efe5;
    --ink: #1f2430;
    --card: rgba(255, 255, 255, 0.75);
    --accent: #006d77;
    --accent-2: #f4a261;
    --ok: #2a9d8f;
    --error: #c1121f;
    --line: rgba(31, 36, 48, 0.16);
}

* {
    box-sizing: border-box;
}

html,
body {
    width: 100%;
}

body {
    margin: 0;
    color: var(--ink);
    font-family: 'Manrope', sans-serif;
    background: radial-gradient(circle at 10% 10%, #ffd7a8 0%, #f4efe5 45%, #d8f3dc 100%);
    min-height: 100vh;
}

.bg-orb {
    position: fixed;
    width: 340px;
    height: 340px;
    border-radius: 50%;
    z-index: -1;
    filter: blur(30px);
    opacity: 0.38;
}

.orb-1 {
    background: #ffb703;
    top: -120px;
    right: -80px;
}

.orb-2 {
    background: #0a9396;
    left: -120px;
    bottom: -100px;
}

.topbar {
    display: flex;
    gap: 12px;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    border-bottom: 1px solid var(--line);
    backdrop-filter: blur(12px);
    background: rgba(255, 255, 255, 0.9);
    position: sticky;
    top: 0;
    left: 0;
    right: 0;
    width: 100%;
    z-index: 300;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 8px;
    text-decoration: none;
}

.topbar-logo {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

.topbar h1 {
    margin: 0;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 1.18rem;
}

.topbar a {
    color: var(--ink);
    text-decoration: none;
}

.topbar nav {
    display: flex;
    margin-left: auto;
    justify-content: flex-end;
    flex-wrap: nowrap;
    gap: 8px;
    overflow-x: auto;
    scrollbar-width: thin;
    padding-bottom: 2px;
}

.topbar-tools {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    margin-left: 10px;
}

.topbar-tools label {
    font-size: 0.82rem;
    font-weight: 700;
    color: rgba(31, 36, 48, 0.84);
}

.topbar-tools select {
    width: 130px;
    border-radius: 999px;
    padding: 7px 10px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.95);
    font-size: 0.84rem;
}

.topbar nav a {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.95);
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.9rem;
    padding: 8px 12px;
    white-space: nowrap;
}

.topbar nav .logout-form {
    margin: 0;
}

.topbar nav .nav-link-button {
    display: inline-flex;
    align-items: center;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.95);
    border-radius: 999px;
    font-weight: 700;
    font-size: 0.9rem;
    padding: 8px 12px;
    white-space: nowrap;
    color: var(--ink);
}

.topbar nav a:hover {
    background: #e9f5f6;
}

.topbar nav .nav-link-button:hover {
    background: #e9f5f6;
}

.topbar nav a.active {
    background: #006d77;
    border-color: #006d77;
    color: #fff;
}

.content-wrap {
    padding: 18px;
    display: grid;
    gap: 20px;
    overflow-x: hidden;
}

.card {
    background: var(--card);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 18px;
    box-shadow: 0 8px 30px rgba(21, 31, 45, 0.08);
    animation: fadeUp 0.6s ease;
    overflow-x: hidden;
}

@keyframes fadeUp {
    from {
        opacity: 0;
        transform: translateY(10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.section-head h2 {
    margin: 0;
}

.section-head p,
.muted {
    margin: 8px 0 0;
    color: rgba(31, 36, 48, 0.8);
}

.grid-form {
    margin-top: 16px;
    display: grid;
    gap: 12px;
}

.cols-1 {
    grid-template-columns: 1fr;
}

.cols-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.cols-4 {
    grid-template-columns: repeat(4, minmax(0, 1fr));
}

label {
    display: grid;
    gap: 6px;
    font-weight: 600;
}

input,
textarea,
select,
button {
    font: inherit;
}

input,
textarea,
select {
    width: 100%;
    border-radius: 10px;
    border: 1px solid var(--line);
    padding: 10px 12px;
    background: #fff;
}

button {
    border: 0;
    padding: 10px 16px;
    border-radius: 10px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-weight: 700;
}

button.secondary {
    background: #6c757d;
}

.actions {
    display: flex;
    gap: 10px;
}

.table-toolbar {
    display: flex;
    justify-content: flex-start;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px;
    margin: 12px 0;
}

.table-toolbar label {
    display: flex;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    font-weight: 600;
    white-space: nowrap;
}

.table-toolbar input {
    width: 150px;
}

.inline-stack {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

.icon-btn {
    width: 42px;
    padding: 0;
    border-radius: 10px;
    background: var(--accent-2);
    color: #1f2430;
}

.inline-icons {
    display: inline-flex;
    gap: 6px;
}

.mini-icon-btn {
    width: 26px;
    height: 26px;
    padding: 0;
    border-radius: 7px;
    font-size: 0.78rem;
    line-height: 1;
    background: #2a9d8f;
    color: #fff;
}

.th-print-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 2px 5px;
    margin-left: 4px;
    border-radius: 5px;
    font-size: 0.72rem;
    line-height: 1;
    background: rgba(255,255,255,0.25);
    color: inherit;
    border: 1px solid rgba(255,255,255,0.4);
    cursor: pointer;
    vertical-align: middle;
}

.th-print-btn:hover {
    background: rgba(255,255,255,0.45);
}

tfoot .totals-row td {
    background: #f0f8f7;
    font-weight: 600;
    border-top: 2px solid var(--line);
    white-space: nowrap;
}

.full-row {
    grid-column: 1 / -1;
}

.table-wrap {
    width: 100%;
    overflow: auto;
    border: 1px solid var(--line);
    border-radius: 12px;
    max-width: 100%;
    max-height: calc(100vh - 250px);
    background: #fff;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
}

.table-wrap.compact {
    max-height: 460px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 1500px;
    background: #fff;
}

.table-fit {
    min-width: 100%;
}

.inline-toggle-form {
    display: inline-flex;
    gap: 10px;
    align-items: center;
}

th,
td {
    border: 1px solid var(--line);
    padding: 7px 8px;
    text-align: center;
    white-space: nowrap;
    font-size: 0.84rem;
}

.installments-cell {
    text-align: left;
    min-width: 140px;
}

.installment-item {
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 2px 0;
}

.installment-num {
    display: inline-block;
    font-size: 0.7rem;
    font-weight: 700;
    color: #006d77;
    background: #e0f4f5;
    border-radius: 4px;
    padding: 1px 5px;
    white-space: nowrap;
    line-height: 1.4;
}

.installment-amt {
    font-weight: 600;
    white-space: nowrap;
}

.installment-none {
    color: #aaa;
    font-style: italic;
    font-size: 0.85rem;
}

thead th {
    background: #e9f5f6;
    font-family: 'Space Grotesk', sans-serif;
    position: sticky;
    top: 0;
    z-index: 2;
}

thead tr:first-child th {
    top: 0;
}

thead tr:nth-child(2) th {
    top: 36px;
}

tbody tr:nth-child(even) {
    background: #fcfdfd;
}

tbody tr:hover {
    background: #f2fafb;
}

.empty-row {
    text-align: center;
    color: rgba(31, 36, 48, 0.65);
    padding: 20px;
}

.message-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.message {
    margin-bottom: 8px;
    border-radius: 10px;
    padding: 10px 12px;
}

.message.success {
    background: rgba(42, 157, 143, 0.18);
    border: 1px solid rgba(42, 157, 143, 0.4);
}

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

.auth-card {
    max-width: 460px;
    margin: 10vh auto 0;
}

.split {
    display: grid;
    grid-template-columns: 1.1fr 1.4fr;
    gap: 16px;
}

.inline-checkbox {
    align-items: center;
    grid-auto-flow: column;
    justify-content: start;
    gap: 8px;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.35);
    display: none;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 1000;
}

.modal.show {
    display: flex;
}

.modal-content {
    width: 100%;
    max-width: 560px;
    background: #fff;
    border-radius: 14px;
    border: 1px solid var(--line);
    padding: 16px;
    max-height: calc(100vh - 48px);
    overflow: auto;
}

.modal-close-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    border-radius: 999px;
    padding: 0;
    font-size: 1.25rem;
    line-height: 1;
    background: #6c757d;
    color: #fff;
}

.modal-content {
    position: relative;
}

#entry-create-modal .modal-content {
    width: min(980px, 96vw);
    max-width: 980px;
}

@media (max-width: 980px) {
    .topbar {
        flex-direction: column;
        align-items: stretch;
        gap: 10px;
        padding: 10px 12px;
    }

    .topbar-tools {
        margin-left: 0;
    }

    .topbar nav {
        justify-content: flex-start;
    }

    .topbar nav a {
        padding: 7px 10px;
        font-size: 0.84rem;
    }

    .topbar nav .nav-link-button {
        padding: 7px 10px;
        font-size: 0.84rem;
    }

    .cols-4,
    .cols-2,
    .split {
        grid-template-columns: 1fr;
    }

    .content-wrap {
        padding: 14px;
    }

    table {
        min-width: 1240px;
    }

    .table-wrap {
        max-height: calc(100vh - 230px);
    }
}

/* ---- Entry create modal compact layout ---- */
.modal-content-wide {
    width: min(1060px, 96vw);
    max-width: 1060px;
    max-height: calc(100vh - 36px);
}

.entry-form-row1 {
    display: grid;
    grid-template-columns: 180px 1fr 1fr;
    gap: 10px;
    margin-bottom: 10px;
}

.entry-form-row-installment {
    display: grid;
    grid-template-columns: minmax(260px, 480px);
    margin-bottom: 14px;
}

.entry-name-row {
    display: flex;
    gap: 6px;
    align-items: stretch;
}

.entry-name-select {
    flex: 1;
    min-width: 0;
}

.entry-installment-inline {
    display: flex;
    gap: 6px;
    align-items: stretch;
}

.entry-installment-inline input[type="number"] {
    min-width: 160px;
}

.entry-installment-inline .icon-btn {
    flex-shrink: 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    font-size: 1.15rem;
}

.installment-total-inline {
    display: grid;
    gap: 4px;
    min-width: 170px;
}

.installment-total-inline span {
    font-size: 0.8rem;
    font-weight: 700;
    color: rgba(31, 36, 48, 0.8);
    line-height: 1;
}

.installment-total-inline input[readonly] {
    background: #f3fbfb;
    font-weight: 700;
}

button.danger {
    background: #c1121f;
}

button.danger:hover {
    background: #a30f1a;
}

.additional-installments-list {
    display: grid;
    gap: 6px;
    margin-top: 6px;
}

.additional-installment-row {
    display: flex;
    flex-wrap: nowrap;
    gap: 0;
    align-items: center;
}

.additional-installment-row input[type="number"] {
    border-radius: 0;
    border-right: none;
}

.additional-installment-row input[type="number"]:first-of-type {
    border-radius: 6px 0 0 6px;
}

.additional-installment-row input[type="number"]:last-of-type {
    border-radius: 0 6px 6px 0;
    border-right: 1px solid var(--line);
}

.additional-installment-remove {
    padding: 4px 10px;
    font-size: 0.8rem;
    margin-left: 6px;
    white-space: nowrap;
}

.entry-form-compact {
    display: grid;
    grid-template-columns: repeat(3, minmax(240px, 1fr));
    gap: 12px;
    align-items: stretch;
}

.compact-group {
    border: 1px solid var(--line);
    border-radius: 12px;
    overflow: hidden;
    min-height: 124px;
}

.compact-group-commission {
    max-width: none;
}

.compact-group-header {
    background: #e9f5f6;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.88rem;
    font-weight: 700;
    padding: 8px 10px;
    text-align: center;
    border-bottom: 1px solid var(--line);
}

.compact-group-body {
    display: flex;
    flex-wrap: wrap;
    gap: 0;
    height: calc(100% - 40px);
}

.compact-label {
    display: flex;
    flex-direction: column;
    gap: 6px;
    font-weight: 600;
    font-size: 0.9rem;
    padding: 10px;
    flex: 1;
}

.compact-label + .compact-label {
    border-left: 1px solid var(--line);
}

.compact-label input {
    padding: 10px 10px;
    font-size: 0.95rem;
    border-radius: 8px;
}

.compact-group-commission .compact-label {
    font-size: 0.82rem;
}

.compact-group-commission .compact-label input {
    max-width: 92px;
    font-size: 0.86rem;
    padding: 8px 8px;
}

.compact-group-lorry .lorry-toggle-row {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.78rem;
    font-weight: 700;
    padding: 8px 10px;
    border-top: 1px solid var(--line);
    background: #f5fbfb;
}

.compact-group-lorry .lorry-toggle-row input {
    width: 16px;
    height: 16px;
    margin: 0;
}

.compact-group-unloading {
    grid-column: auto;
    max-width: none;
}

.compact-group-grand-summary {
    max-width: none;
}

.compact-group-other {
    max-width: none;
    grid-column: 1 / -1;
}

.entry-payment-row {
    margin-top: 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px;
    background: #f7fcfc;
    display: grid;
    gap: 8px;
}

.entry-payment-row-title {
    font-family: 'Space Grotesk', sans-serif;
    font-weight: 700;
    font-size: 0.9rem;
}

.entry-payment-line {
    display: grid;
    grid-template-columns: minmax(180px, 240px) minmax(220px, 320px);
    gap: 8px;
}

.entry-payment-mode-inline {
    display: flex;
    gap: 6px;
    align-items: stretch;
}

.entry-payment-mode-inline .icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    font-size: 1.15rem;
    flex-shrink: 0;
}

.entry-payment-summary {
    display: grid;
    grid-template-columns: repeat(2, minmax(180px, 240px));
    gap: 10px;
}

.entry-payment-summary input[readonly] {
    background: #f3fbfb;
    font-weight: 700;
}

.entry-live-summary {
    margin-top: 14px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: #fbfefe;
    padding: 12px;
}

.entry-live-summary h4 {
    margin: 0 0 10px;
    font-family: 'Space Grotesk', sans-serif;
    font-size: 0.98rem;
}

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

.entry-live-summary-grid input[readonly] {
    background: #f3fbfb;
    font-weight: 700;
}

@media (max-width: 700px) {
    .entry-form-row1 {
        grid-template-columns: 1fr 1fr;
    }

    .entry-form-row-installment {
        grid-template-columns: 1fr;
    }

    .entry-form-compact {
        grid-template-columns: 1fr;
    }

    .entry-installment-inline {
        flex-wrap: wrap;
    }

    .installment-total-inline {
        min-width: 0;
        width: 100%;
    }

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

    .compact-group-commission {
        max-width: none;
    }

    .compact-group-unloading {
        grid-column: auto;
    }

    .entry-payment-line,
    .entry-payment-summary {
        grid-template-columns: 1fr;
    }
}

/* ---- Date picker with calendar button ---- */
.date-dmy-wrap {
    position: relative;
    display: flex;
    align-items: stretch;
}

.date-dmy-wrap input.date-dmy {
    border-radius: 10px 0 0 10px;
    border-right: none;
    flex: 1;
    min-width: 0;
}

.date-cal-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    flex-shrink: 0;
    padding: 0;
    background: var(--accent);
    color: #fff;
    border: 1px solid var(--accent);
    border-radius: 0 10px 10px 0;
    cursor: pointer;
}

.date-cal-btn:hover {
    background: #005a62;
    border-color: #005a62;
}

.date-hidden-picker {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 1px;
    height: 1px;
    top: 0;
    left: 0;
    padding: 0;
    border: none;
    overflow: hidden;
}
