:root {
    --bg: #f5f6f8;
    --card: #ffffff;
    --text: #1d2433;
    --muted: #6b7280;
    --border: #e5e7eb;
    --accent: #2454ff;
    --accent-dark: #1638b3;
    --danger: #d64545;
    --danger-bg: #fdecec;
    --success: #1a8a4a;
    --success-bg: #e8f7ee;
    --warn-bg: #fff6e5;
    --warn: #a86400;
    --radius: 10px;
}

* { box-sizing: border-box; }

body {
    font-family: "Segoe UI", "BPG Arial", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    margin: 0;
    line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
    background: var(--card);
    border-bottom: 1px solid var(--border);
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 60px;
}

.topbar .brand { font-weight: 700; font-size: 18px; }

.topbar nav a {
    color: var(--text);
    margin-inline-start: 20px;
    font-size: 14px;
    font-weight: 500;
}
.topbar nav a.active { color: var(--accent); }

.topbar .logout { color: var(--muted); font-size: 13px; }

.container {
    max-width: 1100px;
    margin: 28px auto;
    padding: 0 20px;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 24px;
    margin-bottom: 20px;
}

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 17px; margin: 0 0 14px; }
.subtitle { color: var(--muted); font-size: 14px; margin-bottom: 20px; }

.stat-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}

.stat {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px 18px;
}
.stat .label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.stat .value { font-size: 24px; font-weight: 700; }
.stat.debt .value { color: var(--danger); }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}
th, td {
    text-align: right;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}
th:first-child, td:first-child, th:nth-child(2), td:nth-child(2) { text-align: right; }
th { color: var(--muted); font-weight: 600; font-size: 12px; letter-spacing: .03em; }
tr:hover td { background: #fafbfc; }

.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
}
.badge.unpaid { background: var(--danger-bg); color: var(--danger); }
.badge.paid { background: var(--success-bg); color: var(--success); }
.badge.overdue { background: var(--warn-bg); color: var(--warn); }

.btn {
    display: inline-block;
    background: var(--accent);
    color: #fff;
    border: none;
    padding: 9px 16px;
    border-radius: 8px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
}
.btn:hover { background: var(--accent-dark); text-decoration: none; }
.btn.secondary { background: #eef0f4; color: var(--text); }
.btn.secondary:hover { background: #e2e5eb; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.success { background: var(--success); }
.btn.danger { background: var(--danger); }
.btn.danger:hover { opacity: 0.9; }

form.inline { display: inline; }

.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px 20px;
}
.form-grid .full { grid-column: 1 / -1; }

label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 5px; color: var(--muted); }
input[type=text], input[type=password], input[type=number], input[type=email], input[type=date], select, textarea {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--border);
    border-radius: 7px;
    font-size: 14px;
    font-family: inherit;
    background: #fff;
    color: var(--text);
}
textarea { resize: vertical; min-height: 60px; }

.actions-row { margin-top: 18px; display: flex; gap: 10px; }

.alert {
    padding: 12px 16px;
    border-radius: 8px;
    font-size: 14px;
    margin-bottom: 18px;
}
.alert.success { background: var(--success-bg); color: var(--success); }
.alert.error { background: var(--danger-bg); color: var(--danger); }

.tag-company {
    display: inline-block;
    background: #eef0ff;
    color: var(--accent-dark);
    padding: 2px 8px;
    border-radius: 6px;
    font-size: 12px;
    font-weight: 600;
}

.login-wrap {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
}
.login-card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 36px 34px;
    width: 100%;
    max-width: 360px;
}
.login-card h1 { text-align: center; margin-bottom: 22px; }

.filters { display: flex; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; align-items: end; }
.filters .field { min-width: 140px; }

.empty-state { text-align: center; color: var(--muted); padding: 40px 0; }

.invoice-sheet {
    background: #fff;
    padding: 40px 48px;
    max-width: 820px;
    margin: 0 auto;
}
.invoice-sheet .inv-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 30px; }
.invoice-sheet .logo img { max-height: 70px; max-width: 220px; }
.invoice-sheet .inv-title { text-align: left; }
.invoice-sheet .inv-title h1 { font-size: 26px; margin-bottom: 4px; }
.invoice-sheet .parties { display: flex; justify-content: space-between; gap: 30px; margin-bottom: 26px; }
.invoice-sheet .party { flex: 1; }
.invoice-sheet .party h3 { font-size: 12px; color: var(--muted); margin-bottom: 8px; letter-spacing: .04em; }
.invoice-sheet .party p { margin: 2px 0; font-size: 14px; }
.invoice-sheet table.items { width: 100%; border-collapse: collapse; margin-bottom: 20px; }
.invoice-sheet table.items th { background: #f5f6f8; text-align: right; padding: 10px 12px; font-size: 12px; }
.invoice-sheet table.items td { padding: 12px; border-bottom: 1px solid var(--border); font-size: 14px; text-align: right; }
.invoice-sheet .totals { margin-inline-start: auto; width: 280px; }
.invoice-sheet .totals div { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; }
.invoice-sheet .totals .grand { font-weight: 700; font-size: 18px; border-top: 2px solid var(--text); margin-top: 6px; padding-top: 10px; }
.invoice-sheet .bank-box { margin-top: 30px; padding: 16px 18px; background: #f5f6f8; border-radius: 8px; font-size: 13px; }
.invoice-sheet .signature { margin-top: 40px; display: flex; justify-content: flex-end; align-items: center; position: relative; height: 100px; }
.invoice-sheet .signature .sig-img { max-height: 80px; position: relative; z-index: 1; }
.invoice-sheet .signature .stamp-img { max-height: 130px; position: relative; z-index: 2; margin-inline-start: -50px; mix-blend-mode: multiply; }
.invoice-sheet .signature .stamp-img:only-child { margin-inline-start: 0; }
.invoice-sheet .no-print { margin-bottom: 20px; }

@media print {
    .topbar, .no-print { display: none !important; }
    body { background: #fff; }
    .invoice-sheet { padding: 0; }
}

@media (max-width: 720px) {
    .form-grid { grid-template-columns: 1fr; }
    .invoice-sheet { padding: 24px; }
    .invoice-sheet .parties { flex-direction: column; }
}
