/* ============================================================
   SimpleInvoice — Mobile-first CSS
   ============================================================ */

:root {
    --red:       #CE1126;
    --red-dark:  #A50D1E;
    --black:     #1A1A1A;
    --white:     #FFFFFF;
    --concrete:  #F4F4F5;
    --steel:     #E2E2E2;
    --dust:      #6B7280;
    --green:     #16A34A;
    --font-head: 'Barlow Condensed', sans-serif;
    --font-body: 'Barlow', sans-serif;
    --font-mono: 'JetBrains Mono', monospace;
    --radius: 6px;
    --shadow: 0 1px 4px rgba(0,0,0,.08);
}

*, *::before, *::after { box-sizing: border-box; }

html { font-size: 16px; }

body {
    font-family: var(--font-body);
    background: var(--concrete);
    color: var(--black);
    margin: 0;
    padding: 0;
    line-height: 1.5;
}

/* ── Nav ── */
.nav {
    background: var(--black);
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    max-width: 1100px;
    margin: 0 auto;
    padding: 0 16px;
    height: 52px;
}
.nav-brand {
    font-family: var(--font-head);
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--white);
    text-decoration: none;
    letter-spacing: .03em;
    text-transform: uppercase;
}
.nav-links {
    display: flex;
    gap: 4px;
    align-items: center;
}
.nav-link {
    color: rgba(255,255,255,.75);
    text-decoration: none;
    font-size: .875rem;
    font-weight: 500;
    padding: 6px 10px;
    border-radius: var(--radius);
    transition: color .15s, background .15s;
}
.nav-link:hover { color: var(--white); background: rgba(255,255,255,.08); }
.nav-link--active { color: var(--white); }
.nav-link--logout { color: rgba(255,255,255,.45); }
.nav-link--logout:hover { color: #f87171; background: rgba(248,113,113,.1); }

/* ── Main ── */
.main {
    max-width: 900px;
    margin: 0 auto;
    padding: 24px 16px 48px;
}

/* ── Cards ── */
.card {
    background: var(--white);
    border: 1px solid var(--steel);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}
.card--muted { background: var(--concrete); }
.card--table { padding: 0; overflow: hidden; }
.mb-4 { margin-bottom: 20px; }

/* ── Page header ── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-header__left {
    display: flex;
    align-items: center;
    gap: 10px;
}
.page-header__actions {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}
.page-title {
    font-family: var(--font-head);
    font-size: 1.6rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
}
.section-title {
    font-family: var(--font-head);
    font-size: 1rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--dust);
    margin: 0 0 16px;
}

/* ── Buttons ── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-family: var(--font-body);
    font-size: .875rem;
    font-weight: 600;
    padding: 9px 18px;
    border-radius: var(--radius);
    border: 1.5px solid transparent;
    cursor: pointer;
    text-decoration: none;
    white-space: nowrap;
    transition: background .15s, border-color .15s, color .15s;
}
.btn-primary {
    background: var(--red);
    color: var(--white);
    border-color: var(--red);
}
.btn-primary:hover { background: var(--red-dark); border-color: var(--red-dark); }
.btn-secondary {
    background: var(--white);
    color: var(--black);
    border-color: var(--steel);
}
.btn-secondary:hover { border-color: #aaa; }
.btn-full { width: 100%; justify-content: center; }
.btn-sm { padding: 6px 12px; font-size: .8125rem; }

/* ── Forms ── */
.form-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group--full { grid-column: 1 / -1; }
label {
    font-size: .8125rem;
    font-weight: 600;
    color: var(--dust);
    text-transform: uppercase;
    letter-spacing: .03em;
}
input[type="text"],
input[type="email"],
input[type="number"],
input[type="date"],
input[type="password"],
input[type="file"],
select,
textarea {
    font-family: var(--font-body);
    font-size: .9375rem;
    border: 1.5px solid var(--steel);
    border-radius: var(--radius);
    padding: 9px 12px;
    background: var(--white);
    color: var(--black);
    width: 100%;
    transition: border-color .15s, box-shadow .15s;
    -webkit-appearance: none;
    appearance: none;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--red);
    box-shadow: 0 0 0 3px rgba(206,17,38,.12);
}
input[type="file"] { padding: 7px 10px; }
textarea { resize: vertical; min-height: 80px; }
.field-hint { font-size: .8rem; color: var(--dust); margin: 4px 0 0; }
.required { color: var(--red); }
.form-actions {
    display: flex;
    gap: 10px;
    justify-content: flex-end;
    margin-top: 8px;
    flex-wrap: wrap;
}

/* ── Line Items ── */
#line-items { display: flex; flex-direction: column; gap: 8px; }
.line-item {
    display: grid;
    grid-template-columns: 1fr 130px 32px;
    gap: 8px;
    align-items: center;
}
.line-item input { margin: 0; }
.btn-remove-item {
    background: none;
    border: none;
    color: var(--dust);
    font-size: 1.2rem;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: var(--radius);
    line-height: 1;
    transition: color .15s, background .15s;
}
.btn-remove-item:hover { color: var(--red); background: rgba(206,17,38,.08); }
.mt-2 { margin-top: 8px; }

/* ── Totals block ── */
.totals-block {
    max-width: 380px;
    margin-left: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
.totals-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
}
.totals-label { font-size: .9rem; color: var(--dust); }
.totals-value { font-family: var(--font-mono); font-size: .9375rem; }
.totals-input {
    font-family: var(--font-mono) !important;
    width: 130px !important;
    text-align: right;
}
.totals-row--grand {
    border-top: 2px solid var(--black);
    padding-top: 10px;
    margin-top: 4px;
}
.totals-row--grand .totals-label { font-weight: 700; font-size: 1rem; color: var(--black); }
.grand-total-display { font-size: 1.1rem; font-weight: 700; }
.mono { font-family: var(--font-mono); }

/* ── Badges ── */
.badge {
    display: inline-block;
    font-size: .75rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .04em;
    padding: 2px 8px;
    border-radius: 20px;
}
.badge--draft { background: #F4F4F5; color: var(--dust); border: 1px solid var(--steel); }
.badge--final { background: #DCFCE7; color: #166534; border: 1px solid #BBF7D0; }

/* ── Alerts ── */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: .9rem;
    margin-bottom: 16px;
    border: 1px solid transparent;
}
.alert-error { background: #FEF2F2; border-color: #FECACA; color: #991B1B; }
.alert-success { background: #F0FDF4; border-color: #BBF7D0; color: #166534; }

/* ── Dashboard Table ── */
.search-bar {
    padding: 16px;
    border-bottom: 1px solid var(--steel);
}
.search-bar input { max-width: 340px; }
.table-wrap { overflow-x: auto; }
.invoice-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}
.invoice-table th {
    background: var(--concrete);
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--dust);
    padding: 10px 16px;
    text-align: left;
    font-weight: 600;
    border-bottom: 1px solid var(--steel);
    white-space: nowrap;
}
.invoice-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--steel);
    vertical-align: middle;
}
.invoice-table tr:last-child td { border-bottom: none; }
.invoice-table tr:hover td { background: var(--concrete); }
.col-amount { text-align: right; }
.col-actions { white-space: nowrap; text-align: right; }

.action-link {
    background: none;
    border: none;
    font-family: var(--font-body);
    font-size: .8125rem;
    font-weight: 500;
    color: var(--dust);
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    text-decoration: none;
    transition: color .15s, background .15s;
}
.action-link:hover { color: var(--black); background: var(--steel); }
.action-link--danger:hover { color: var(--red); background: rgba(206,17,38,.08); }

/* ── Empty state ── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--dust);
}
.empty-state__msg { font-size: 1rem; margin-bottom: 20px; }

/* ── Settings: Logo preview ── */
.logo-preview { margin-bottom: 10px; }
.logo-img { max-width: 200px; max-height: 80px; border: 1px solid var(--steel); border-radius: var(--radius); padding: 8px; background: var(--white); }
.logo-hint { font-size: .8rem; color: var(--dust); margin: 4px 0; }

/* ── Business header on form ── */
.biz-header { display: flex; gap: 16px; align-items: flex-start; }
.biz-logo { max-width: 100px; max-height: 60px; object-fit: contain; }
.biz-info { display: flex; flex-direction: column; font-size: .875rem; gap: 2px; }
.biz-info strong { font-size: 1rem; }

/* ── Invoice preview (view page) ── */
.invoice-preview { padding: 32px; }
.inv-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 24px; gap: 16px; }
.inv-logo-biz { display: flex; flex-direction: column; gap: 8px; }
.inv-logo { max-width: 160px; max-height: 70px; object-fit: contain; }
.inv-biz { display: flex; flex-direction: column; font-size: .875rem; gap: 2px; }
.inv-biz-name { font-size: 1.1rem; font-weight: 700; }
.inv-meta { text-align: right; }
.inv-meta-row { margin-bottom: 6px; }
.inv-meta-label { font-size: .75rem; text-transform: uppercase; color: var(--dust); display: block; }
.inv-meta-val { font-size: .9375rem; font-weight: 600; }
.inv-section { margin: 20px 0; }
.inv-section-title {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--dust);
    font-weight: 700;
    margin: 0 0 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid var(--steel);
}
.inv-work-desc { font-size: .9375rem; line-height: 1.6; white-space: pre-wrap; }
.inv-items-table {
    width: 100%;
    border-collapse: collapse;
    font-size: .9rem;
}
.inv-items-table th {
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .04em;
    color: var(--dust);
    padding: 8px 12px;
    text-align: left;
    border-bottom: 2px solid var(--steel);
}
.inv-items-table td { padding: 8px 12px; border-bottom: 1px solid var(--steel); }
.inv-items-table tr:last-child td { border-bottom: none; }
.text-right { text-align: right !important; }
.inv-totals { margin-left: auto; max-width: 280px; margin-top: 12px; }
.inv-totals-row {
    display: flex;
    justify-content: space-between;
    padding: 5px 0;
    font-size: .9rem;
    color: var(--dust);
}
.inv-totals-row--grand {
    border-top: 2px solid var(--black);
    margin-top: 6px;
    padding-top: 8px;
    font-weight: 700;
    font-size: 1.05rem;
    color: var(--black);
}
.inv-notes { color: var(--dust); font-size: .875rem; }

/* ── Login page ── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--concrete);
}
.login-wrap { width: 100%; max-width: 380px; padding: 16px; }
.login-card {
    background: var(--white);
    border: 1px solid var(--steel);
    border-radius: var(--radius);
    padding: 32px 28px;
    box-shadow: var(--shadow);
}
.login-title {
    font-family: var(--font-head);
    font-size: 1.75rem;
    font-weight: 700;
    text-align: center;
    margin: 0 0 24px;
    text-transform: uppercase;
    letter-spacing: .05em;
}

/* ── Responsive ── */
@media (max-width: 600px) {
    .nav-links { gap: 0; }
    .nav-link { padding: 6px 7px; font-size: .8rem; }
    .form-grid { grid-template-columns: 1fr; }
    .form-group--full { grid-column: 1; }
    .line-item { grid-template-columns: 1fr 100px 28px; }
    .invoice-preview { padding: 16px; }
    .inv-header { flex-direction: column; }
    .inv-meta { text-align: left; }
    .page-header { flex-direction: column; align-items: flex-start; }
    .invoice-table th, .invoice-table td { padding: 8px 10px; }
    .col-actions { white-space: normal; }
}
