:root {
    --bg: #f4f6fa;
    --surface: #ffffff;
    --border: #e3e7ef;
    --text: #1b2332;
    --muted: #6b7687;
    --accent: #4f46e5;
    --accent-dark: #4338ca;
    --accent-soft: #eef0fe;
    --green: #0f8a52;
    --green-soft: #e4f6ec;
    --amber: #a8690a;
    --amber-soft: #fdf3e0;
    --red: #c0392f;
    --red-soft: #fdeceb;
    --radius: 10px;
    --shadow: 0 1px 2px rgba(20, 30, 50, .06), 0 4px 16px rgba(20, 30, 50, .05);
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: "Segoe UI", system-ui, -apple-system, Roboto, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
}

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

h1, h2, h3 { margin: 0 0 .5rem; line-height: 1.25; font-weight: 650; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

.muted { color: var(--muted); font-size: .875rem; }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.center { text-align: center; }

/* ------------------------------------------------------------- shell ----- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 230px;
    flex: 0 0 230px;
    background: #171e2e;
    color: #c6cddc;
    padding: 1.25rem 0;
    display: flex;
    flex-direction: column;
}

.sidebar .brand {
    padding: 0 1.25rem 1.1rem;
    border-bottom: 1px solid #27304a;
    margin-bottom: 1rem;
}
.sidebar .brand img {
    display: block;
    width: 100%;
    max-width: 150px;
    height: auto;
}

.sidebar nav { display: flex; flex-direction: column; gap: 2px; padding: 0 .6rem; }

.sidebar nav a {
    color: #c6cddc;
    padding: .55rem .7rem;
    border-radius: 7px;
    font-size: .925rem;
}
.sidebar nav a:hover { background: #222b42; color: #fff; text-decoration: none; }
.sidebar nav a.active { background: var(--accent); color: #fff; }

.sidebar .sidebar-foot {
    margin-top: auto;
    padding: 1rem 1.25rem 0;
    border-top: 1px solid #27304a;
    font-size: .825rem;
}
.sidebar .sidebar-foot a { color: #8e9ab2; }

.main { flex: 1 1 auto; min-width: 0; padding: 1.75rem 2rem 3rem; }

.page-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1.25rem;
}

/* ------------------------------------------------------------- cards ----- */

.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.25rem;
    margin-bottom: 1.25rem;
}
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }

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

.stat {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1.1rem 1.25rem;
}
.stat .label {
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .06em;
    color: var(--muted);
    font-weight: 600;
}
.stat .value { font-size: 1.6rem; font-weight: 680; margin-top: .3rem; }
.stat .sub { font-size: .8rem; color: var(--muted); margin-top: .15rem; }

/* ------------------------------------------------------------ tables ----- */

.table-wrap { overflow-x: auto; }

table.data { width: 100%; border-collapse: collapse; }
table.data th, table.data td {
    padding: .7rem .75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
}
table.data th {
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    font-weight: 650;
    white-space: nowrap;
}
table.data tbody tr:last-child td { border-bottom: 0; }
table.data tbody tr:hover { background: #fafbfe; }
table.data td.money, table.data th.money { text-align: right; white-space: nowrap; }

.empty { padding: 2.5rem 1rem; text-align: center; color: var(--muted); }

/* ------------------------------------------------------------ badges ----- */

.badge {
    display: inline-block;
    padding: .2rem .55rem;
    border-radius: 999px;
    font-size: .75rem;
    font-weight: 650;
    white-space: nowrap;
}
.badge-paid    { background: var(--green-soft); color: var(--green); }
.badge-partial { background: var(--amber-soft); color: var(--amber); }
.badge-pending { background: #eef1f6; color: var(--muted); }
.badge-overdue { background: var(--red-soft); color: var(--red); }

/* ------------------------------------------------------------ buttons ---- */

.btn {
    display: inline-block;
    padding: .5rem .9rem;
    border-radius: 7px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: .9rem;
    font-weight: 550;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    line-height: 1.4;
}
.btn:hover { background: #f7f8fc; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-danger { color: var(--red); border-color: #f0c7c3; background: #fff; }
.btn-danger:hover { background: var(--red-soft); }
.btn-sm { padding: .3rem .6rem; font-size: .82rem; }
.btn-block { display: block; width: 100%; text-align: center; }
.btn-link { border: 0; background: none; color: var(--accent); padding: .2rem; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ------------------------------------------------------------- forms ----- */

label { display: block; margin-bottom: .9rem; font-size: .875rem; font-weight: 600; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], select, textarea {
    width: 100%;
    padding: .5rem .65rem;
    margin-top: .3rem;
    font: inherit;
    font-weight: 400;
    color: var(--text);
    background: #fff;
    border: 1px solid #cfd6e4;
    border-radius: 7px;
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--accent-soft);
    border-color: var(--accent);
}
textarea { resize: vertical; min-height: 70px; }
input[readonly] { background: #f4f6fa; color: var(--muted); }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 0 1rem; }

.inline-check {
    display: flex;
    align-items: flex-start;
    gap: .55rem;
    font-weight: 600;
    margin-bottom: .75rem;
}
.inline-check input { width: auto; margin: .25rem 0 0; }

/* ------------------------------------------------------- item editor ----- */

table.items { width: 100%; border-collapse: collapse; }
table.items th {
    font-size: .74rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--muted);
    font-weight: 650;
    text-align: left;
    padding: 0 .4rem .4rem;
}
table.items td { padding: .25rem .4rem .5rem; vertical-align: top; }
table.items input, table.items textarea { margin-top: 0; }
table.items .col-qty { width: 90px; }
table.items .col-price { width: 130px; }
table.items .col-total { width: 120px; }
table.items .col-remove { width: 44px; }
.row-remove {
    border: 0;
    background: none;
    color: var(--muted);
    font-size: 1.25rem;
    line-height: 1;
    cursor: pointer;
    padding: .45rem .35rem;
    border-radius: 6px;
}
.row-remove:hover { color: var(--red); background: var(--red-soft); }

.totals-box { margin-left: auto; width: min(340px, 100%); margin-top: 1rem; }
.totals-box .row {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    padding: .4rem 0;
    font-size: .925rem;
}
.totals-box .row.grand {
    border-top: 2px solid var(--text);
    margin-top: .35rem;
    padding-top: .6rem;
    font-size: 1.1rem;
    font-weight: 700;
}
.totals-box .row.due { color: var(--accent); font-weight: 650; }

/* ------------------------------------------------------------ alerts ----- */

.alert {
    padding: .75rem .9rem;
    border-radius: 8px;
    margin-bottom: 1rem;
    font-size: .9rem;
    border: 1px solid transparent;
}
.alert-success { background: var(--green-soft); color: #0b6c41; border-color: #bfe6d1; }
.alert-error   { background: var(--red-soft);   color: #96281b; border-color: #f3c9c4; }
.alert-info    { background: var(--accent-soft); color: #3d35bd; border-color: #d2d5fb; }
.alert-warn    { background: var(--amber-soft); color: #8a5608; border-color: #f0ddb8; }

/* -------------------------------------------------------- copy field ----- */

.copy-field { display: flex; gap: .5rem; align-items: center; }
.copy-field input {
    margin-top: 0;
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace;
    font-size: .8rem;
}

/* ------------------------------------------------------- auth screens ---- */

.auth-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1.5rem;
}
.auth-card {
    width: 100%;
    max-width: 400px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 1.75rem;
}
.auth-card h1 { margin-bottom: 1rem; }

.auth-logo { margin-bottom: 1.5rem; }
.auth-logo img {
    display: block;
    width: 170px;
    max-width: 65%;
    height: auto;
}

/* ------------------------------------------------------- invoice logo ---- */

.invoice-logo { margin-bottom: .9rem; }
.invoice-logo img {
    display: block;
    width: 160px;
    max-width: 55%;
    height: auto;
}
.invoice-logo.center-logo { display: flex; justify-content: center; margin-bottom: 1.5rem; }

/* --------------------------------------------------- public invoice ------ */

.invoice-page { max-width: 820px; margin: 0 auto; padding: 2rem 1.25rem 4rem; }

.invoice-sheet {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: var(--shadow);
    padding: 2rem;
}

.invoice-top {
    display: flex;
    justify-content: space-between;
    gap: 1.5rem;
    flex-wrap: wrap;
    padding-bottom: 1.5rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
}
.invoice-top .meta { text-align: right; }
.invoice-top .meta div { font-size: .875rem; }

.party { font-size: .9rem; }
.party strong { display: block; font-size: 1rem; margin-bottom: .15rem; }

.pay-panel {
    margin-top: 1.5rem;
    background: var(--accent-soft);
    border: 1px solid #d2d5fb;
    border-radius: var(--radius);
    padding: 1.25rem;
}
.pay-panel h3 { margin-bottom: .75rem; }
.amount-field { display: flex; gap: .5rem; align-items: stretch; }
.amount-field .prefix {
    display: flex;
    align-items: center;
    padding: 0 .7rem;
    background: #fff;
    border: 1px solid #cfd6e4;
    border-right: 0;
    border-radius: 7px 0 0 7px;
    font-weight: 650;
    color: var(--muted);
}
.amount-field input { border-radius: 0 7px 7px 0; margin-top: 0; }

.quick-amounts { display: flex; gap: .4rem; flex-wrap: wrap; margin-top: .6rem; }

@media (max-width: 760px) {
    .shell { flex-direction: column; }
    .sidebar { width: auto; flex: none; padding-bottom: .75rem; }
    .sidebar nav { flex-direction: row; overflow-x: auto; }
    .sidebar .sidebar-foot { margin-top: .75rem; }
    .main { padding: 1.25rem 1rem 2.5rem; }
    .invoice-sheet { padding: 1.25rem; }
    .invoice-top .meta { text-align: left; }
}

@media print {
    .sidebar, .pay-panel, .btn, .no-print { display: none !important; }
    body { background: #fff; }
    .invoice-sheet { border: 0; box-shadow: none; padding: 0; }
}
