:root {
    --bg: #f3f6f7;
    --surface: #ffffff;
    --ink: #10212b;
    --muted: #677c88;
    --line: #e2e9ed;
    --brand: #0f766e;
    --brand-dark: #0b5c56;
    --brand-soft: #e5f3f0;
    --blue: #1d4ed8;
    --blue-soft: #e8efff;
    --green: #047857;
    --green-soft: #e7f7f0;
    --amber: #b45309;
    --amber-soft: #fdf2e2;
    --red: #b91c1c;
    --red-soft: #fdeaea;
    --radius: 16px;
    --shadow: 0 10px 30px rgba(16, 33, 43, 0.06);
}

* {
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;
    background:
        radial-gradient(circle at 12% -10%, rgba(15, 118, 110, 0.08), transparent 40%),
        var(--bg);
    color: var(--ink);
    font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    min-height: 100vh;
}

a {
    color: var(--brand);
    text-decoration: none;
}

a:hover {
    color: var(--brand-dark);
}

h1, h2, h3 {
    margin: 0;
    line-height: 1.25;
    letter-spacing: -0.01em;
}

h1 {
    font-size: 1.7rem;
}

h2 {
    font-size: 1.1rem;
}

p {
    margin: 0;
}

code {
    background: #f1f5f7;
    border: 1px solid var(--line);
    border-radius: 6px;
    padding: 1px 5px;
    font-size: 0.82em;
}

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

.small {
    font-size: 0.82rem;
}

.mono {
    font-family: Consolas, "Courier New", monospace;
    font-size: 0.85rem;
}

.amount {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.amount-debt {
    color: var(--red);
}

.amount-credit {
    color: var(--green);
}

.nowrap {
    white-space: nowrap;
}

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

.link {
    font-size: 0.85rem;
    font-weight: 600;
}

.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 26px 22px 48px;
}

.topbar {
    position: sticky;
    top: 0;
    z-index: 20;
    background: rgba(255, 255, 255, 0.94);
    backdrop-filter: blur(10px);
    border-bottom: 1px solid var(--line);
}

.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 12px 22px;
    display: flex;
    align-items: center;
    gap: 22px;
    flex-wrap: wrap;
}

.brand,
.auth-brand {
    display: inline-flex;
    align-items: center;
    gap: 11px;
    color: var(--ink);
}

.brand:hover,
.auth-brand:hover {
    color: var(--ink);
}

.brand-mark {
    display: inline-grid;
    place-items: center;
    width: 42px;
    height: 42px;
    border-radius: 13px;
    background: linear-gradient(135deg, #14b8a6, var(--brand) 70%);
    color: #ffffff;
    font-size: 1.3rem;
    font-weight: 700;
    box-shadow: 0 8px 18px rgba(15, 118, 110, 0.28);
    flex: none;
}

.brand-text {
    display: flex;
    flex-direction: column;
    line-height: 1.15;
}

.brand-text strong {
    font-size: 0.98rem;
}

.brand-text small {
    color: var(--muted);
    font-size: 0.76rem;
    letter-spacing: 0.02em;
}

.nav {
    display: flex;
    align-items: center;
    gap: 4px;
    flex: 1;
    flex-wrap: wrap;
}

.nav-link {
    padding: 8px 13px;
    border-radius: 10px;
    color: var(--muted);
    font-size: 0.88rem;
    font-weight: 600;
    transition: background 0.15s, color 0.15s;
}

.nav-link:hover {
    background: #f0f4f5;
    color: var(--ink);
}

.nav-link.is-active {
    background: var(--brand-soft);
    color: var(--brand-dark);
}

.user-box {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-left: auto;
}

.user-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    line-height: 1.2;
}

.user-meta strong {
    font-size: 0.86rem;
}

.role-chip {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.page-head {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
    margin-bottom: 20px;
}

.page-head p {
    margin-top: 6px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
    gap: 14px;
    margin-bottom: 20px;
}

.stats-grid-3 {
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.stat-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 16px 18px;
    display: flex;
    flex-direction: column;
    gap: 3px;
    box-shadow: 0 2px 10px rgba(16, 33, 43, 0.03);
}

.stat-label {
    color: var(--muted);
    font-size: 0.72rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.stat-value {
    font-size: 1.42rem;
    font-variant-numeric: tabular-nums;
}

.stat-hint {
    color: var(--muted);
    font-size: 0.78rem;
}

.stat-brand {
    background: linear-gradient(135deg, #12857c, #0a5c56);
    border-color: transparent;
    box-shadow: 0 12px 26px rgba(15, 118, 110, 0.24);
}

.stat-brand .stat-label,
.stat-brand .stat-hint {
    color: rgba(255, 255, 255, 0.75);
}

.stat-brand .stat-value {
    color: #ffffff;
}

.grid {
    display: grid;
    gap: 20px;
}

.grid-main {
    grid-template-columns: minmax(0, 1.75fr) minmax(280px, 1fr);
    align-items: start;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
    min-width: 0;
}

.card + .card {
    margin-top: 20px;
}

.grid-main > .card + .card {
    margin-top: 0;
}

.card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    margin-bottom: 18px;
}

.grid-main > .card:first-child {
    order: 1;
}

.grid-main > aside {
    order: 2;
}

.alert {
    border: 1px solid transparent;
    border-radius: 12px;
    padding: 12px 15px;
    margin-bottom: 16px;
    font-size: 0.9rem;
}

.alert a {
    font-weight: 600;
    text-decoration: underline;
}

.alert-success {
    background: var(--green-soft);
    border-color: #bfe8d6;
    color: #065f46;
}

.alert-warning {
    background: var(--amber-soft);
    border-color: #f3d9ae;
    color: #92400e;
}

.alert-error {
    background: var(--red-soft);
    border-color: #f5c6c6;
    color: #991b1b;
}

.alert-info {
    background: #e9f2ff;
    border-color: #c8dcfa;
    color: #1e40af;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    border-radius: 999px;
    padding: 3px 9px;
    font-size: 0.72rem;
    font-weight: 700;
    white-space: nowrap;
}

.badge-ok {
    background: var(--green-soft);
    color: var(--green);
}

.badge-error {
    background: var(--red-soft);
    color: var(--red);
}

.badge-muted {
    background: #eef2f4;
    color: var(--muted);
}

.badge-pending {
    background: var(--amber-soft);
    color: var(--amber);
}

.badge-soft {
    background: var(--brand-soft);
    color: var(--brand-dark);
}

.badge-cash {
    background: var(--green-soft);
    color: var(--green);
}

.badge-card {
    background: var(--blue-soft);
    color: var(--blue);
}

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

.field {
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-width: 0;
}

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

.field label,
.field-label {
    font-size: 0.82rem;
    font-weight: 600;
    color: #334e5c;
}

.field-hint {
    color: var(--muted);
    font-size: 0.76rem;
}

.customer-search {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.search-input-wrap {
    position: relative;
}

.search-results {
    position: absolute;
    top: calc(100% + 6px);
    left: 0;
    right: 0;
    z-index: 40;
    background: #ffffff;
    border: 1px solid var(--line);
    border-radius: 12px;
    box-shadow: 0 18px 40px rgba(16, 33, 43, 0.16);
    max-height: 320px;
    overflow-y: auto;
    padding: 6px;
}

.search-result {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 14px;
    width: 100%;
    padding: 10px 12px;
    border: 0;
    border-radius: 9px;
    background: transparent;
    font: inherit;
    color: var(--ink);
    text-align: left;
    cursor: pointer;
}

.search-result:hover,
.search-result.is-active {
    background: var(--brand-soft);
}

.search-result-info,
.search-result-meta {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
}

.search-result-info strong {
    font-size: 0.9rem;
}

.search-result-meta {
    align-items: flex-end;
    text-align: right;
    color: var(--muted);
    font-size: 0.76rem;
    white-space: nowrap;
}

.search-result-meta strong {
    color: var(--ink);
    font-size: 0.83rem;
}

.search-empty {
    padding: 16px 12px;
    text-align: center;
    color: var(--muted);
    font-size: 0.84rem;
}

.selected-customer {
    display: flex;
    align-items: center;
    gap: 13px;
    padding: 14px 16px;
    border: 1.5px solid var(--brand);
    background: var(--brand-soft);
    border-radius: 12px;
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.08);
}

.selected-avatar {
    display: grid;
    place-items: center;
    width: 44px;
    height: 44px;
    flex: none;
    border-radius: 50%;
    background: var(--brand);
    color: #ffffff;
    font-size: 1.1rem;
    font-weight: 700;
    text-transform: uppercase;
}

.selected-info {
    display: flex;
    flex-direction: column;
    gap: 1px;
    min-width: 0;
    line-height: 1.3;
}

.selected-info strong {
    font-size: 0.98rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.selected-label {
    color: var(--brand-dark);
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.selected-customer .btn {
    margin-left: auto;
    flex: none;
}

.label-optional {
    color: var(--muted);
    font-weight: 400;
}

.section-title {
    font-size: 0.9rem;
    font-weight: 700;
    padding-top: 6px;
    border-top: 1px dashed var(--line);
    margin-top: 2px;
}

input[type="text"],
input[type="tel"],
input[type="password"],
input[type="number"],
input[type="search"],
input[type="date"],
select,
textarea {
    width: 100%;
    border: 1px solid #d6e0e5;
    border-radius: 10px;
    padding: 10px 12px;
    font: inherit;
    color: var(--ink);
    background: #fbfdfd;
    transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}

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

input:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--brand);
    background: #ffffff;
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.14);
}

input[readonly] {
    background: #f2f6f7;
    color: #40545f;
    font-weight: 600;
}

input:disabled,
select:disabled,
button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.check {
    display: inline-flex;
    align-items: center;
    gap: 9px;
    font-weight: 500 !important;
    font-size: 0.88rem !important;
}

.check input {
    width: 17px;
    height: 17px;
    accent-color: var(--brand);
}

.check-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
    gap: 8px;
}

.check-card {
    display: flex;
    align-items: center;
    gap: 9px;
    padding: 9px 12px;
    border: 1px solid var(--line);
    border-radius: 10px;
    background: #fbfdfd;
    cursor: pointer;
}

.check-card:hover {
    border-color: #c8d6dc;
    background: #ffffff;
}

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

.pay-option {
    position: relative;
    display: block;
    cursor: pointer;
}

.pay-option input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.pay-option-body {
    display: flex;
    flex-direction: column;
    gap: 2px;
    border: 1.5px solid #d6e0e5;
    border-radius: 12px;
    padding: 13px 15px 13px 44px;
    position: relative;
    transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
    background: #fbfdfd;
}

.pay-option-body::before {
    content: "";
    position: absolute;
    left: 15px;
    top: 50%;
    transform: translateY(-50%);
    width: 17px;
    height: 17px;
    border: 2px solid #b9c7ce;
    border-radius: 50%;
    background: #ffffff;
    transition: border-color 0.15s, box-shadow 0.15s;
}

.pay-option-body strong {
    font-size: 0.94rem;
}

.pay-option-body small {
    color: var(--muted);
    font-size: 0.78rem;
}

.pay-option input:checked + .pay-option-body {
    border-color: var(--brand);
    background: var(--brand-soft);
    box-shadow: 0 0 0 3px rgba(15, 118, 110, 0.1);
}

.pay-option input:checked + .pay-option-body::before {
    border-color: var(--brand);
    box-shadow: inset 0 0 0 4px #ffffff, inset 0 0 0 10px var(--brand);
}

.pay-option input:focus-visible + .pay-option-body {
    outline: 2px solid var(--brand);
    outline-offset: 2px;
}

.form-actions {
    flex-direction: row;
    align-items: center;
    gap: 14px;
    flex-wrap: wrap;
    padding-top: 2px;
}

.form-note {
    margin-top: 18px;
    padding-top: 14px;
    border-top: 1px dashed var(--line);
    color: var(--muted);
    font-size: 0.78rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    border: 1px solid transparent;
    border-radius: 10px;
    padding: 10px 16px;
    font: inherit;
    font-weight: 600;
    font-size: 0.88rem;
    cursor: pointer;
    white-space: nowrap;
    transition: background 0.15s, border-color 0.15s, color 0.15s, transform 0.05s;
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: var(--brand);
    color: #ffffff;
    box-shadow: 0 7px 16px rgba(15, 118, 110, 0.22);
}

.btn-primary:hover {
    background: var(--brand-dark);
    color: #ffffff;
}

.btn-ghost {
    background: #ffffff;
    border-color: #d6e0e5;
    color: #334e5c;
}

.btn-ghost:hover {
    background: #f4f8f9;
    border-color: #bccbd1;
    color: var(--ink);
}

.btn-sm {
    padding: 6px 11px;
    font-size: 0.78rem;
    border-radius: 8px;
}

.btn-danger {
    background: #fff5f5;
    border-color: #f3c6c6;
    color: var(--red);
}

.btn-danger:hover {
    background: var(--red);
    border-color: var(--red);
    color: #ffffff;
}

.btn-block {
    width: 100%;
}

.table-wrap {
    overflow-x: auto;
    margin: 0 -4px;
    padding: 0 4px;
}

table {
    width: 100%;
    border-collapse: collapse;
    min-width: 640px;
}

th {
    text-align: left;
    padding: 9px 12px;
    border-bottom: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.7rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    white-space: nowrap;
}

td {
    padding: 12px;
    border-bottom: 1px solid #edf2f4;
    vertical-align: middle;
    font-size: 0.88rem;
}

tbody tr:hover {
    background: #fafcfc;
}

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

.row-actions {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
}

.row-actions form {
    margin: 0;
}

.log-response {
    max-width: 340px;
    color: var(--muted);
    font-size: 0.78rem;
    word-break: break-word;
}

.filter-bar {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    align-items: end;
    margin-bottom: 18px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

.filter-bar-wide {
    grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
}

.filter-actions {
    display: flex;
    gap: 8px;
    align-items: end;
}

.pagination {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    margin-top: 16px;
}

.page-link {
    min-width: 34px;
    height: 34px;
    display: inline-grid;
    place-items: center;
    padding: 0 9px;
    border: 1px solid var(--line);
    border-radius: 8px;
    color: var(--muted);
    font-size: 0.82rem;
    font-weight: 600;
}

.page-link:hover {
    border-color: #bccbd1;
    color: var(--ink);
}

.page-link.is-active {
    background: var(--brand);
    border-color: var(--brand);
    color: #ffffff;
}

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

.timeline li {
    padding: 12px 0;
    border-bottom: 1px dashed var(--line);
}

.timeline li:first-child {
    padding-top: 0;
}

.timeline li:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.timeline-top {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
}

.timeline-top strong {
    font-size: 0.9rem;
}

.timeline-meta {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    color: var(--muted);
    font-size: 0.76rem;
    margin-top: 3px;
}

.empty-state {
    text-align: center;
    color: var(--muted);
    padding: 30px 16px;
    border: 1px dashed #d6e0e5;
    border-radius: 12px;
    background: #fbfdfd;
    font-size: 0.9rem;
}

.test-box {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
    margin-top: 18px;
    padding-top: 18px;
    border-top: 1px dashed var(--line);
}

.test-box p {
    margin-top: 3px;
}

.footer {
    border-top: 1px solid var(--line);
    margin-top: 10px;
    color: var(--muted);
    font-size: 0.78rem;
}

.footer-inner {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    flex-wrap: wrap;
    padding-top: 18px;
    padding-bottom: 22px;
}

.auth-body {
    display: grid;
    place-items: center;
    background:
        radial-gradient(circle at 15% 15%, rgba(20, 184, 166, 0.22), transparent 42%),
        radial-gradient(circle at 88% 85%, rgba(15, 118, 110, 0.18), transparent 48%),
        #eef3f4;
    padding: 30px 18px;
}

.auth-wrap {
    width: 100%;
    max-width: 430px;
}

.auth-brand {
    justify-content: center;
    margin-bottom: 20px;
}

.auth-card {
    padding: 30px;
}

.auth-card h1 {
    font-size: 1.45rem;
}

.auth-card > .muted {
    margin: 6px 0 20px;
    font-size: 0.88rem;
}

.stack {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.auth-foot {
    text-align: center;
    color: var(--muted);
    font-size: 0.78rem;
    margin-top: 18px;
}

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

    .nav {
        order: 3;
        flex-basis: 100%;
        overflow-x: auto;
        padding-bottom: 2px;
        flex-wrap: nowrap;
    }

    .nav-link {
        white-space: nowrap;
    }

    .user-box {
        margin-left: auto;
    }
}

@media (max-width: 640px) {
    .container {
        padding: 20px 14px 36px;
    }

    .topbar-inner {
        padding: 10px 14px;
        gap: 12px;
    }

    .brand-text small {
        display: none;
    }

    .card {
        padding: 18px;
    }

    .form-grid,
    .pay-options {
        grid-template-columns: minmax(0, 1fr);
    }

    .page-head {
        align-items: flex-start;
    }

    h1 {
        font-size: 1.45rem;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    }

    .stat-value {
        font-size: 1.2rem;
    }

    .user-meta {
        display: none;
    }

    .filter-actions {
        width: 100%;
    }

    .filter-actions .btn {
        flex: 1;
    }

    .form-actions .btn {
        width: 100%;
    }
}
