/* Verifactis — app.css */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --color-primary:    #2563eb;
    --color-primary-h:  #1d4ed8;
    --color-danger:     #dc2626;
    --color-warning:    #d97706;
    --color-success:    #16a34a;
    --color-text:       #111827;
    --color-muted:      #6b7280;
    --color-border:     #e5e7eb;
    --color-bg:         #f9fafb;
    --color-card:       #ffffff;
    --nav-h:            56px;
    --radius:           6px;
    --shadow:           0 1px 3px rgba(0,0,0,.1);
}

body { font-family: system-ui, -apple-system, sans-serif; font-size: 15px; color: var(--color-text); background: var(--color-bg); }

/* Nav */
.navbar { position: sticky; top: 0; z-index: 100; height: var(--nav-h); display: flex; align-items: center; gap: 1.5rem; padding: 0 1.5rem; background: #fff; border-bottom: 1px solid var(--color-border); box-shadow: var(--shadow); }
.brand-link { font-size: 1.2rem; font-weight: 700; color: var(--color-primary); text-decoration: none; }
.navbar-nav { display: flex; list-style: none; gap: .25rem; flex: 1; }
.nav-link { padding: .4rem .75rem; border-radius: var(--radius); text-decoration: none; color: var(--color-text); font-size: .9rem; transition: background .15s; }
.nav-link:hover, .nav-link.active { background: var(--color-bg); color: var(--color-primary); }
.navbar-user { display: flex; align-items: center; gap: 1rem; margin-left: auto; }
.user-name { font-size: .875rem; color: var(--color-muted); }

/* Main */
.main-content { max-width: 1100px; margin: 0 auto; padding: 1.5rem 1.5rem 4rem; }
.page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1.5rem; flex-wrap: wrap; gap: .75rem; }
.page-header h1 { font-size: 1.5rem; font-weight: 700; }
.page-subtitle { color: var(--color-muted); font-size: .9rem; }
.page-actions { display: flex; gap: .5rem; flex-wrap: wrap; }

/* Cards */
.card { background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.card + .card, .mt-3 { margin-top: 1rem; }
.mt-2 { margin-top: .5rem; }
.mt-4 { margin-top: 1.5rem; }
.card-title { font-size: 1rem; font-weight: 600; margin-bottom: 1rem; }
.card--error { border-color: var(--color-danger); }

/* Alerts */
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; display: flex; align-items: center; gap: 1rem; }
.alert-success { background: #f0fdf4; border: 1px solid #bbf7d0; color: #166534; }
.alert-error   { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.alert-info    { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: .375rem; padding: .5rem 1rem; border-radius: var(--radius); font-size: .875rem; font-weight: 500; cursor: pointer; text-decoration: none; border: 1px solid transparent; transition: background .15s, border-color .15s; }
.btn-primary   { background: var(--color-primary); color: #fff; } .btn-primary:hover { background: var(--color-primary-h); }
.btn-secondary { background: #fff; border-color: var(--color-border); color: var(--color-text); } .btn-secondary:hover { background: var(--color-bg); }
.btn-danger    { background: var(--color-danger); color: #fff; } .btn-danger:hover { background: #b91c1c; }
.btn-sm { padding: .3rem .65rem; font-size: .8rem; }

/* Stats */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; margin-bottom: 1.5rem; }
.stat-card { background: var(--color-card); border: 1px solid var(--color-border); border-radius: var(--radius); padding: 1.25rem; box-shadow: var(--shadow); }
.stat-card--highlight { border-color: var(--color-primary); }
.stat-card--warning { border-color: var(--color-warning); }
.stat-value { font-size: 1.75rem; font-weight: 700; margin-bottom: .25rem; }
.stat-label { font-size: .8rem; color: var(--color-muted); text-transform: uppercase; letter-spacing: .05em; }

/* Section */
.section { margin-top: 1.5rem; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: .75rem; }
.section-header h2 { font-size: 1.1rem; font-weight: 600; }
.link-more { display: inline-block; margin-top: .75rem; font-size: .875rem; color: var(--color-primary); text-decoration: none; }

/* Tables */
.table { width: 100%; border-collapse: collapse; font-size: .875rem; }
.table th, .table td { padding: .625rem .75rem; border-bottom: 1px solid var(--color-border); text-align: left; }
.table th { font-weight: 600; color: var(--color-muted); font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; background: var(--color-bg); }
.table tbody tr:hover { background: #f8fafc; }
.text-right { text-align: right; }
.table-actions { display: flex; gap: .375rem; justify-content: flex-end; }
.row--error td { background: #fff5f5; }
.row--rejected td { background: #fff5f5; }
.row--accepted td { background: #f0fdf4; }

/* Badges */
.badge { display: inline-block; padding: .2rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 600; }
.badge--draft     { background: #f3f4f6; color: #374151; }
.badge--pending   { background: #fef9c3; color: #854d0e; }
.badge--submitted { background: #dbeafe; color: #1e40af; }
.badge--accepted  { background: #dcfce7; color: #166534; }
.badge--rejected  { background: #fee2e2; color: #991b1b; }
.badge--error     { background: #fee2e2; color: #991b1b; }
.badge--lg { font-size: .875rem; padding: .3rem .75rem; }

/* Forms */
.form-row { display: flex; gap: .75rem; flex-wrap: wrap; margin-bottom: .75rem; }
.form-group { display: flex; flex-direction: column; gap: .3rem; flex: 1; min-width: 160px; }
.form-group--wide { flex: 2; min-width: 240px; }
.form-group--small { flex: 0 0 120px; min-width: 100px; }
.form-group--check { flex: 0 0 auto; min-width: 140px; justify-content: flex-end; }
label { font-size: .8rem; font-weight: 500; color: var(--color-muted); }
input[type=text], input[type=email], input[type=date], input[type=number], input[type=password], select, textarea {
    padding: .45rem .6rem; border: 1px solid var(--color-border); border-radius: var(--radius);
    font-size: .875rem; color: var(--color-text); background: #fff; width: 100%;
    transition: border-color .15s; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 2px rgba(37,99,235,.15); }
textarea { resize: vertical; }
.checkbox-label { display: flex; align-items: center; gap: .4rem; font-size: .875rem; font-weight: 400; color: var(--color-text); cursor: pointer; }
input[type=checkbox] { width: 16px; height: 16px; }
.form-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }

/* DL */
.dl-horizontal { display: grid; grid-template-columns: auto 1fr; gap: .3rem .75rem; font-size: .875rem; }
.dl-horizontal dt { color: var(--color-muted); font-weight: 500; white-space: nowrap; }
.dl-horizontal dd { }

/* Filters */
.filters-bar { display: flex; align-items: center; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.filters-form { display: flex; gap: .5rem; flex-wrap: wrap; }
.status-summary { display: flex; gap: .375rem; flex-wrap: wrap; margin-left: auto; }

/* Invoice lines */
.line-row { display: grid; grid-template-columns: 3fr 1fr 1.2fr .8fr .8fr 1fr auto; gap: .375rem; align-items: center; margin-bottom: .375rem; }
.line-row--header { font-size: .75rem; font-weight: 600; color: var(--color-muted); }
.col-remove button { padding: .3rem .5rem; }

/* Invoice totals */
.invoice-totals { display: flex; justify-content: flex-end; }
.totals-dl { display: grid; grid-template-columns: auto auto; gap: .2rem .75rem; text-align: right; }
.totals-dl__total { font-size: 1.1rem; font-weight: 700; border-top: 1px solid var(--color-border); padding-top: .25rem; }

/* Detail grid */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
@media (max-width: 640px) { .detail-grid { grid-template-columns: 1fr; } }
.table--lines tfoot tr td { border-top: 1px solid var(--color-border); }
.tfoot-total td { border-top: 2px solid var(--color-border); }
.error-pre { font-size: .8rem; background: #fef2f2; padding: .75rem; border-radius: var(--radius); white-space: pre-wrap; }
.qr-section { display: flex; justify-content: flex-start; }

/* Modals */
.modal { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; }
.modal.hidden { display: none; }
.modal-overlay { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.modal-content { position: relative; background: var(--color-card); border-radius: var(--radius); padding: 1.5rem; max-width: 640px; width: 95%; max-height: 90vh; overflow-y: auto; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.modal-header h2 { font-size: 1.1rem; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 1.5rem; cursor: pointer; color: var(--color-muted); line-height: 1; }

/* Misc */
.empty-state { color: var(--color-muted); font-size: .9rem; padding: 2rem 0; text-align: center; }
.text-success { color: var(--color-success); }
.text-muted { color: var(--color-muted); font-size: .875rem; }
code { font-family: monospace; font-size: .8rem; background: #f3f4f6; padding: .1rem .35rem; border-radius: 3px; }
.hidden { display: none !important; }

/* Trial banner */
.trial-banner { background: #fffbeb; border-bottom: 1px solid #fde68a; color: #92400e; text-align: center; padding: .5rem 1rem; font-size: .875rem; font-weight: 500; }
.trial-banner-link { color: #92400e; font-weight: 700; text-decoration: underline; }

/* ==========================================
   Responsive / Mobile
   ========================================== */

/* Horizontal-scroll wrapper for wide tables */
.table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Hamburger toggle button — hidden on desktop */
.nav-toggle {
    display: none;
    background: none;
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    cursor: pointer;
    padding: .3rem .45rem;
    line-height: 1;
    color: var(--color-text);
    flex-shrink: 0;
}

@media (max-width: 768px) {
    /* Main content padding */
    .main-content { padding: 1rem 1rem 3rem; }

    /* Navbar — hamburger layout */
    .nav-toggle { display: flex; align-items: center; justify-content: center; }
    .navbar {
        flex-wrap: wrap;
        height: auto;
        min-height: var(--nav-h);
        padding: 0 1rem;
        column-gap: .75rem;
        row-gap: 0;
    }
    .navbar-brand { flex: 1; display: flex; align-items: center; min-height: var(--nav-h); }
    .navbar-nav {
        display: none;
        order: 10;
        width: 100%;
        flex-direction: column;
        gap: 0;
        border-top: 1px solid var(--color-border);
        padding: .375rem 0;
    }
    .navbar-user {
        display: none;
        order: 11;
        width: 100%;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        gap: .5rem;
        border-top: 1px solid var(--color-border);
        padding: .375rem 0 .625rem;
    }
    .navbar.nav-open .navbar-nav,
    .navbar.nav-open .navbar-user { display: flex; }
    .navbar-nav .nav-link { display: block; padding: .5rem .5rem; }
    .user-name { font-size: .8rem; }

    /* Page header */
    .page-header { flex-direction: column; align-items: flex-start; }
    .page-header h1 { font-size: 1.25rem; }
    .page-actions { flex-wrap: wrap; }

    /* Filters */
    .filters-bar { flex-direction: column; align-items: stretch; gap: .5rem; }
    .filters-form { flex-direction: column; }
    .filters-form > * { width: 100%; }
    .status-summary { margin-left: 0; }

    /* Stats grid — 2 columns */
    .stats-grid { grid-template-columns: 1fr 1fr; }

    /* Cards */
    .card { padding: 1rem; }

    /* Forms — single column */
    .form-row { flex-direction: column; gap: .5rem; }
    .form-group--small,
    .form-group--wide { flex: 1 1 auto; min-width: 0; }
    .form-group--check { justify-content: flex-start; }
    .form-actions { flex-direction: column; align-items: stretch; }
    .form-actions .btn { justify-content: center; }

    /* Prevent iOS zoom on input focus */
    input[type=text], input[type=email], input[type=date],
    input[type=number], input[type=password], select, textarea { font-size: 16px; }

    /* Invoice line rows — 2-column grid */
    .line-row {
        grid-template-columns: 1fr 1fr;
        background: var(--color-bg);
        border: 1px solid var(--color-border);
        border-radius: var(--radius);
        padding: .625rem;
        margin-bottom: .625rem;
    }
    .line-row--header { display: none; }
    .line-row .col-desc { grid-column: 1 / -1; }
    .line-row .col-remove { justify-self: end; }

    /* DL horizontal — single column */
    .dl-horizontal { grid-template-columns: 1fr; }
    .dl-horizontal dt {
        white-space: normal;
        margin-top: .375rem;
        font-size: .72rem;
        text-transform: uppercase;
        letter-spacing: .05em;
    }
    .dl-horizontal dt:first-child { margin-top: 0; }

    /* Detail grid — already handled at 640px, extend to 768 */
    .detail-grid { grid-template-columns: 1fr; }

    /* Modals — near full-width */
    .modal-content { padding: 1rem; width: calc(100% - 1.5rem); }

    /* Trial banner */
    .trial-banner { font-size: .8rem; padding: .375rem 1rem; }
}

@media (max-width: 480px) {
    /* Stats grid — single column on very small screens */
    .stats-grid { grid-template-columns: 1fr; }
}
