/* ============================================================
   SỔ NỢ — Vietnamese Ledger Book
   Aesthetic: Industrial Utilitarian + Editorial
   Inspiration: Paper ledger books used by Vietnamese shop owners
   ============================================================ */

/* ---- Import: Be Vietnam Pro (Vietnamese-optimized) + DM Mono for numbers ---- */
@import url('https://fonts.googleapis.com/css2?family=Be+Vietnam+Pro:ital,wght@0,300;0,400;0,500;0,600;0,700;0,800;1,400&family=DM+Mono:wght@400;500&display=swap');

/* ---- Reset ---- */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    /* Paper & Ink */
    --paper: #faf8f5;
    --paper-warm: #f5f0e8;
    --paper-line: #e8e0d4;
    --ink: #1a1714;
    --ink-light: #3d3830;
    --ink-faded: #7a7268;
    --ink-ghost: #b0a898;
    --ink-whisper: #d4cdc2;

    /* Red Ink — the core accent (like red pen on a ledger) */
    --red: #c0392b;
    --red-deep: #96281b;
    --red-light: #f8e8e6;
    --red-glow: rgba(192, 57, 43, 0.08);

    /* Blue Ink — secondary */
    --blue: #2471a3;
    --blue-light: #e8f0f7;

    /* Green Ink — payments/success */
    --green: #1e8449;
    --green-light: #e6f3ec;

    /* Amber — invoices/warnings */
    --amber: #b7950b;
    --amber-light: #fdf6e3;

    /* Violet — personal/home */
    --violet: #6c3483;
    --violet-light: #f0e8f5;

    /* Spacing rhythm: 4px base */
    --sp-1: 4px;
    --sp-2: 8px;
    --sp-3: 12px;
    --sp-4: 16px;
    --sp-5: 20px;
    --sp-6: 24px;
    --sp-8: 32px;
    --sp-10: 40px;
    --sp-12: 48px;

    /* Type scale */
    --text-xs: 11px;
    --text-sm: 13px;
    --text-base: 15px;
    --text-lg: 17px;
    --text-xl: 20px;
    --text-2xl: 26px;
    --text-3xl: 34px;

    /* Radius — subtle, not bubbly */
    --radius: 6px;
    --radius-lg: 10px;

    /* Shadows — warm, not cold */
    --shadow-sm: 0 1px 2px rgba(26,23,20,0.04);
    --shadow: 0 1px 4px rgba(26,23,20,0.06), 0 1px 2px rgba(26,23,20,0.04);
    --shadow-md: 0 4px 12px rgba(26,23,20,0.07), 0 1px 3px rgba(26,23,20,0.04);
    --shadow-up: 0 -2px 8px rgba(26,23,20,0.05);
}

/* ---- Base ---- */
body {
    font-family: 'Be Vietnam Pro', -apple-system, sans-serif;
    background: var(--paper);
    color: var(--ink);
    line-height: 1.65;
    -webkit-font-smoothing: antialiased;
    font-size: var(--text-base);
}

.container {
    max-width: 880px;
    margin: 0 auto;
    padding: 0 var(--sp-5);
}

a {
    color: var(--blue);
    text-decoration: none;
    transition: color 0.15s;
}
a:hover { color: var(--red); text-decoration: none; }

::selection {
    background: var(--red);
    color: #fff;
}

/* ============ NAVBAR ============ */
.navbar {
    background: var(--ink);
    padding: 0;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-content {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 54px;
}

.nav-brand {
    font-size: var(--text-lg);
    font-weight: 700;
    color: var(--paper);
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    letter-spacing: -0.3px;
}
.nav-brand:hover { color: var(--paper-warm); text-decoration: none; }

.nav-icon {
    font-size: 22px;
    opacity: 0.85;
}

.nav-links {
    display: flex;
    gap: 2px;
}

.nav-link {
    padding: var(--sp-2) var(--sp-3);
    border-radius: var(--radius);
    color: var(--ink-ghost);
    font-size: var(--text-sm);
    font-weight: 500;
    transition: all 0.15s;
    letter-spacing: 0.1px;
}
.nav-link:hover {
    color: var(--paper);
    background: rgba(255,255,255,0.08);
    text-decoration: none;
}
.nav-link.active {
    color: var(--paper);
    background: rgba(255,255,255,0.12);
    font-weight: 600;
}

/* ============ MAIN CONTENT ============ */
.main-content {
    padding-top: var(--sp-8);
    padding-bottom: 100px;
    min-height: calc(100vh - 54px - 52px);
}

/* ============ ALERTS ============ */
.alert {
    padding: var(--sp-3) var(--sp-4);
    border-radius: var(--radius);
    margin-bottom: var(--sp-6);
    font-size: var(--text-sm);
    font-weight: 500;
    transition: all 0.3s;
    border-left: 3px solid;
}
.alert-success {
    background: var(--green-light);
    color: var(--green);
    border-left-color: var(--green);
}
.alert-error {
    background: var(--red-light);
    color: var(--red);
    border-left-color: var(--red);
}

/* ============ PAGE HEADER ============ */
.page-header {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    margin-bottom: var(--sp-8);
    flex-wrap: wrap;
    gap: var(--sp-4);
    padding-bottom: var(--sp-5);
    border-bottom: 2px solid var(--ink);
}
.page-title {
    font-size: var(--text-2xl);
    font-weight: 800;
    color: var(--ink);
    letter-spacing: -0.5px;
    line-height: 1.2;
}
.page-subtitle {
    font-size: var(--text-sm);
    color: var(--ink-faded);
    margin-top: var(--sp-1);
    font-weight: 400;
}

/* ============ SEARCH BAR ============ */
.search-bar {
    display: flex;
    gap: var(--sp-2);
    margin-bottom: var(--sp-6);
}
.search-input {
    flex: 1;
    padding: 10px var(--sp-4);
    border: 2px solid var(--paper-line);
    border-radius: var(--radius);
    font-size: var(--text-base);
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
    background: #fff;
    color: var(--ink);
}
.search-input:focus {
    border-color: var(--ink);
}
.search-input::placeholder {
    color: var(--ink-ghost);
}

/* ============ SUMMARY CARDS ============ */
.summary-cards {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--sp-4);
    margin-bottom: var(--sp-8);
}

.summary-card {
    background: #fff;
    border-radius: var(--radius-lg);
    padding: var(--sp-5);
    border: 1px solid var(--paper-line);
    position: relative;
    overflow: hidden;
}
.summary-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--paper-line);
}
.summary-card:first-child::before { background: var(--red); }
.summary-card:nth-child(2)::before { background: var(--blue); }
.summary-card:nth-child(3)::before { background: var(--amber); }

.summary-card .label {
    font-size: var(--text-xs);
    color: var(--ink-faded);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: var(--sp-2);
}
.summary-card .value {
    font-family: 'DM Mono', monospace;
    font-size: var(--text-xl);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    letter-spacing: -0.5px;
}
.summary-card .value.text-danger { color: var(--red); }
.summary-card .value.text-success { color: var(--green); }
.summary-card .value.text-warning { color: var(--amber); }
.summary-card .value.text-primary { color: var(--blue); }
.summary-card .sub {
    font-size: var(--text-xs);
    color: var(--ink-ghost);
    margin-top: var(--sp-1);
}
.summary-card .sub a {
    color: var(--ink-faded);
    font-weight: 500;
}
.summary-card .sub a:hover { color: var(--red); }

/* ============ FILTER TABS ============ */
.filter-tabs {
    display: flex;
    gap: var(--sp-1);
    margin-bottom: var(--sp-4);
    border-bottom: 1px solid var(--paper-line);
    padding-bottom: 0;
}
.filter-tab {
    padding: var(--sp-2) var(--sp-4);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--ink-faded);
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: -1px;
    border-radius: 0;
}
.filter-tab:hover {
    color: var(--ink);
    text-decoration: none;
}
.filter-tab.active {
    color: var(--ink);
    border-bottom-color: var(--red);
    font-weight: 600;
    background: none;
}

/* ============ CARDS ============ */
.card {
    background: #fff;
    border-radius: var(--radius-lg);
    border: 1px solid var(--paper-line);
    overflow: hidden;
}

.card-header {
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--paper-line);
    font-weight: 600;
    font-size: var(--text-base);
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: var(--paper-warm);
}

.card-body {
    padding: var(--sp-6);
}

/* ============ CUSTOMER LIST ============ */
.customer-list {
    display: flex;
    flex-direction: column;
}

.customer-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--sp-4) var(--sp-5);
    border-bottom: 1px solid var(--paper-line);
    transition: background 0.1s;
    cursor: pointer;
    text-decoration: none;
    color: inherit;
}
.customer-item:last-child { border-bottom: none; }
.customer-item:hover {
    background: var(--paper-warm);
    text-decoration: none;
}

.customer-info {
    flex: 1;
    min-width: 0;
}
.customer-name {
    font-weight: 600;
    font-size: var(--text-base);
    color: var(--ink);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.customer-sub {
    font-size: var(--text-sm);
    color: var(--ink-faded);
    margin-top: 2px;
    display: flex;
    gap: var(--sp-3);
    flex-wrap: wrap;
}

.customer-debt {
    text-align: right;
    min-width: 130px;
    padding-left: var(--sp-4);
}
.debt-amount {
    font-family: 'DM Mono', monospace;
    font-size: var(--text-base);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}
.debt-amount.positive { color: var(--red); }
.debt-amount.zero { color: var(--green); }
.debt-amount.negative { color: var(--blue); }

/* ============ TRANSACTION TIMELINE ============ */
.timeline {
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
}

.timeline-item {
    display: flex;
    gap: var(--sp-4);
    padding: var(--sp-4) var(--sp-5);
    background: #fff;
    border-radius: var(--radius);
    border: 1px solid var(--paper-line);
    transition: border-color 0.15s;
}
.timeline-item:hover {
    border-color: var(--ink-whisper);
}

.timeline-date {
    min-width: 56px;
    text-align: center;
    flex-shrink: 0;
    padding-top: 2px;
}
.timeline-date .day {
    font-family: 'DM Mono', monospace;
    font-size: var(--text-xl);
    font-weight: 500;
    color: var(--ink);
    line-height: 1;
}
.timeline-date .month {
    font-size: var(--text-xs);
    color: var(--ink-ghost);
    margin-top: 2px;
    font-weight: 500;
}

.timeline-content {
    flex: 1;
    min-width: 0;
}

.timeline-header {
    display: flex;
    align-items: center;
    gap: var(--sp-2);
    flex-wrap: wrap;
    margin-bottom: var(--sp-1);
}

.timeline-amount {
    font-family: 'DM Mono', monospace;
    font-size: var(--text-lg);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
}

.timeline-note {
    font-size: var(--text-sm);
    color: var(--ink-faded);
    margin-top: var(--sp-1);
    white-space: pre-line;
    line-height: 1.6;
}

.timeline-actions {
    display: flex;
    align-items: flex-start;
    opacity: 0;
    transition: opacity 0.15s;
}
.timeline-item:hover .timeline-actions {
    opacity: 1;
}

/* ============ BADGES ============ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 1px 8px;
    border-radius: 3px;
    font-size: var(--text-xs);
    font-weight: 600;
    white-space: nowrap;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}
.badge.type-debt {
    background: var(--red-light);
    color: var(--red);
}
.badge.type-payment {
    background: var(--green-light);
    color: var(--green);
}
.badge.type-invoice {
    background: var(--amber-light);
    color: var(--amber);
}
.badge.target-home {
    background: var(--violet-light);
    color: var(--violet);
}
.badge.target-company {
    background: var(--blue-light);
    color: var(--blue);
}

/* ============ BUTTONS ============ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--sp-2);
    padding: 9px 18px;
    border-radius: var(--radius);
    font-size: var(--text-sm);
    font-weight: 600;
    font-family: inherit;
    border: none;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
    line-height: 1.4;
    letter-spacing: 0.1px;
}
.btn:hover { text-decoration: none; transform: translateY(-1px); }
.btn:active { transform: translateY(0); }

.btn-primary {
    background: var(--ink);
    color: var(--paper);
}
.btn-primary:hover {
    background: var(--ink-light);
    color: var(--paper);
}

.btn-success {
    background: var(--green);
    color: #fff;
}
.btn-success:hover { background: #196f3d; color: #fff; }

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

.btn-warning {
    background: var(--amber);
    color: #fff;
}
.btn-warning:hover { background: #9a7d0a; color: #fff; }

.btn-outline {
    background: transparent;
    color: var(--ink-faded);
    border: 1.5px solid var(--paper-line);
}
.btn-outline:hover {
    border-color: var(--ink-whisper);
    color: var(--ink);
    background: var(--paper-warm);
}

.btn-sm {
    padding: 5px 12px;
    font-size: var(--text-xs);
}

.btn-lg {
    padding: 13px 28px;
    font-size: var(--text-base);
}

.btn-icon {
    padding: 5px 7px;
    font-size: 15px;
    background: none;
    border: none;
    color: var(--ink-ghost);
    cursor: pointer;
    border-radius: var(--radius);
    transition: all 0.15s;
}
.btn-icon:hover {
    background: var(--red-light);
    color: var(--red);
}

.btn-group {
    display: flex;
    gap: var(--sp-2);
    flex-wrap: wrap;
}

/* ============ FORMS ============ */
.form-group {
    margin-bottom: var(--sp-5);
}
.form-label {
    display: block;
    font-size: var(--text-sm);
    font-weight: 600;
    color: var(--ink);
    margin-bottom: var(--sp-2);
}
.form-hint {
    font-size: var(--text-xs);
    color: var(--ink-ghost);
    font-weight: 400;
    margin-left: var(--sp-2);
}

.form-control {
    width: 100%;
    padding: 10px var(--sp-3);
    border: 2px solid var(--paper-line);
    border-radius: var(--radius);
    font-size: var(--text-base);
    font-family: inherit;
    outline: none;
    transition: border-color 0.15s;
    background: #fff;
    color: var(--ink);
}
.form-control:focus {
    border-color: var(--ink);
}
.form-control::placeholder {
    color: var(--ink-ghost);
}

textarea.form-control {
    resize: vertical;
    min-height: 88px;
    line-height: 1.6;
}

.money-input {
    font-family: 'DM Mono', monospace;
    font-weight: 500;
    letter-spacing: 0.5px;
}

select.form-control {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%237a7268' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 12px center;
    padding-right: 36px;
}

.radio-group {
    display: flex;
    gap: var(--sp-3);
    flex-wrap: wrap;
}

.radio-card {
    flex: 1;
    min-width: 120px;
}
.radio-card input[type="radio"] { display: none; }
.radio-card label {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 10px var(--sp-4);
    border: 2px solid var(--paper-line);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: var(--text-sm);
    font-weight: 500;
    transition: all 0.15s;
    text-align: center;
    color: var(--ink-faded);
}
.radio-card label:hover {
    border-color: var(--ink-whisper);
    color: var(--ink);
}
.radio-card input[type="radio"]:checked + label {
    border-color: var(--ink);
    background: var(--ink);
    color: var(--paper);
}
.radio-card.type-debt input[type="radio"]:checked + label {
    border-color: var(--red);
    background: var(--red);
    color: #fff;
}
.radio-card.type-payment input[type="radio"]:checked + label {
    border-color: var(--green);
    background: var(--green);
    color: #fff;
}
.radio-card.type-invoice input[type="radio"]:checked + label {
    border-color: var(--amber);
    background: var(--amber);
    color: #fff;
}

/* ============ DEBT SUMMARY ============ */
.debt-summary {
    background: #fff;
    border-radius: var(--radius-lg);
    padding: var(--sp-6);
    margin-bottom: var(--sp-6);
    border: 1px solid var(--paper-line);
    position: relative;
}
.debt-summary::after {
    content: '';
    position: absolute;
    bottom: 0;
    left: var(--sp-6);
    right: var(--sp-6);
    height: 1px;
    background: repeating-linear-gradient(90deg, var(--paper-line) 0, var(--paper-line) 4px, transparent 4px, transparent 8px);
}

.debt-summary .debt-total {
    font-family: 'DM Mono', monospace;
    font-size: var(--text-3xl);
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    letter-spacing: -1px;
}
.debt-summary .debt-total.positive { color: var(--red); }
.debt-summary .debt-total.zero { color: var(--green); }

.debt-breakdown {
    display: flex;
    gap: var(--sp-8);
    margin-top: var(--sp-4);
    font-size: var(--text-sm);
    color: var(--ink-faded);
}
.debt-breakdown span {
    font-family: 'DM Mono', monospace;
    font-weight: 500;
    color: var(--ink);
}

.progress-bar {
    width: 100%;
    height: 4px;
    background: var(--paper-line);
    border-radius: 2px;
    margin-top: var(--sp-4);
    overflow: hidden;
}
.progress-bar .fill {
    height: 100%;
    background: var(--green);
    border-radius: 2px;
    transition: width 0.4s ease;
}

/* ============ CUSTOMER DETAIL HEADER ============ */
.customer-header {
    background: #fff;
    border-radius: var(--radius-lg);
    padding: var(--sp-6);
    margin-bottom: var(--sp-6);
    border: 1px solid var(--paper-line);
}
.customer-header .name {
    font-size: var(--text-2xl);
    font-weight: 800;
    letter-spacing: -0.5px;
    line-height: 1.2;
}
.customer-header .contacts {
    display: flex;
    gap: var(--sp-2);
    margin-top: var(--sp-3);
    flex-wrap: wrap;
}
.customer-header .contact-badge {
    padding: 3px 10px;
    background: var(--paper-warm);
    border-radius: 3px;
    font-size: var(--text-sm);
    color: var(--ink-faded);
    font-weight: 500;
}
.customer-header .phones {
    margin-top: var(--sp-3);
    font-size: var(--text-sm);
    color: var(--ink-faded);
}
.customer-header .phones a {
    color: var(--blue);
    font-weight: 600;
    font-family: 'DM Mono', monospace;
}
.customer-header .phones a:hover { color: var(--red); }

/* ============ EMPTY STATE ============ */
.empty-state {
    text-align: center;
    padding: var(--sp-12) var(--sp-5);
    color: var(--ink-ghost);
}
.empty-state .icon {
    font-size: 40px;
    margin-bottom: var(--sp-3);
    opacity: 0.5;
}
.empty-state .text {
    font-size: var(--text-base);
    margin-bottom: var(--sp-5);
    color: var(--ink-faded);
}

/* ============ FOOTER ============ */
.footer {
    background: transparent;
    border-top: 1px solid var(--paper-line);
    padding: var(--sp-4) 0;
    text-align: center;
    font-size: var(--text-xs);
    color: var(--ink-ghost);
    letter-spacing: 0.5px;
}

/* ============ FAB ============ */
.fab {
    position: fixed;
    bottom: 24px;
    right: 24px;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: var(--red);
    color: #fff;
    font-size: 26px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 16px rgba(192,57,43,0.3);
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    z-index: 50;
    text-decoration: none;
}
.fab:hover {
    background: var(--red-deep);
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(192,57,43,0.35);
    color: #fff;
    text-decoration: none;
}

/* ============ RESPONSIVE ============ */
@media (max-width: 640px) {
    .container { padding: 0 var(--sp-4); }
    .nav-content { height: 48px; }
    .nav-brand { font-size: var(--text-base); }
    .nav-link { padding: var(--sp-1) var(--sp-2); font-size: var(--text-xs); }
    .main-content { padding-top: var(--sp-5); }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        padding-bottom: var(--sp-4);
        margin-bottom: var(--sp-5);
    }
    .page-title { font-size: var(--text-xl); }

    .summary-cards {
        grid-template-columns: 1fr;
        gap: var(--sp-3);
    }
    .summary-card { padding: var(--sp-4); }
    .summary-card .value { font-size: var(--text-lg); }

    .customer-item {
        padding: var(--sp-3) var(--sp-4);
        flex-wrap: wrap;
        gap: var(--sp-2);
    }
    .customer-debt { text-align: left; min-width: auto; padding-left: 0; }

    .timeline-item {
        flex-direction: column;
        gap: var(--sp-2);
        padding: var(--sp-3) var(--sp-4);
    }
    .timeline-date {
        text-align: left;
        display: flex;
        align-items: baseline;
        gap: var(--sp-2);
        min-width: auto;
    }
    .timeline-date .day { font-size: var(--text-base); }
    .timeline-amount { font-size: var(--text-base); }
    .timeline-actions { opacity: 1; }

    .debt-summary { padding: var(--sp-4); }
    .debt-summary .debt-total { font-size: var(--text-2xl); }
    .debt-breakdown { flex-direction: column; gap: var(--sp-1); }

    .radio-group { flex-direction: column; }
    .btn-group { flex-direction: column; }
    .btn-group .btn { width: 100%; }

    .filter-tabs {
        overflow-x: auto;
        flex-wrap: nowrap;
        -webkit-overflow-scrolling: touch;
    }

    .customer-header .name { font-size: var(--text-xl); }
    .customer-header { padding: var(--sp-4); }
}

@media (max-width: 420px) {
    .summary-cards { grid-template-columns: 1fr; }
    .nav-links { gap: 0; }
}
