:root {
    --primary: #2B6CB0;
    --navy: #1a365d;
    --accent: #E67E22;
    --bg: #0f1419;
    --surface: #1a2332;
    --text: #e8eef4;
    --muted: #94a3b8;
    --border: #2d3a4f;
    --success: #22c55e;
    --error: #ef4444;
}

* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    overflow-x: hidden;
}

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

.brand a {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: #fff;
    text-decoration: none;
    font-weight: 700;
}
.logo-sm { height: 40px; }
.main-nav a { color: #fff; font-weight: 500; }
.user-menu a { color: #fff; }
.inline-form { display: inline; margin: 0; }
.btn-link {
    background: none; border: none; color: var(--accent);
    cursor: pointer; font: inherit; padding: 0;
}

.container { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }

h1 { margin-top: 0; color: #fff; }

.alert {
    padding: 0.75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
}
.alert-success { background: rgba(34,197,94,0.15); border: 1px solid var(--success); }
.alert-error { background: rgba(239,68,68,0.15); border: 1px solid var(--error); }
.alert-warning { background: rgba(230,126,34,0.15); border: 1px solid var(--accent); }

.btn {
    display: inline-block;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    border: none;
    cursor: pointer;
    font-size: 0.95rem;
    text-decoration: none;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: #2563a8; text-decoration: none; }
.btn-secondary { background: var(--surface); color: #fff; border: 1px solid var(--border); }
.btn-danger { background: #b91c1c; color: #fff; }
.btn-sm { padding: 0.25rem 0.5rem; font-size: 0.85rem; }
.btn-block { width: 100%; }

.toolbar { display: flex; gap: 1rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap; }
.search-form { display: flex; gap: 0.5rem; }
.search-form input { padding: 0.5rem; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); color: var(--text); }

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border-radius: 8px;
    overflow: hidden;
}
th, td { padding: 0.65rem 0.75rem; text-align: left; border-bottom: 1px solid var(--border); }
th { background: var(--navy); color: #fff; font-weight: 600; }
tr:hover td { background: rgba(43,108,176,0.08); }

.form-card, .panel {
    background: var(--surface);
    padding: 1.25rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    margin-bottom: 1.5rem;
}
.panel-heading {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}
.panel-heading h2 {
    margin: 0;
    font-size: 1.15rem;
}
.panel-heading h2 small {
    font-weight: normal;
    font-size: 0.85rem;
}
.btn-expand .btn-expand-icon {
    display: inline-block;
    min-width: 1rem;
    font-weight: 700;
    font-size: 1.1rem;
    line-height: 1;
}
.collapsible-form {
    margin-top: 0.75rem;
}
.collapsible-form .form-card {
    margin-bottom: 0;
}
.detail-list-items {
    margin: 0 0 0.5rem;
    padding-left: 1.25rem;
}
.detail-list-items li {
    margin-bottom: 0.5rem;
}
.detail-list-item .detail-list-summary {
    margin-bottom: 0.25rem;
}
.item-actions {
    display: inline;
    margin-left: 0.35rem;
}
.item-actions .inline-form {
    display: inline;
}
.item-actions .btn-link + .inline-form,
.item-actions .inline-form + .btn-link {
    margin-left: 0.35rem;
}
.form-hint {
    font-size: 0.85rem;
    margin: 0.25rem 0 0;
}
label { display: block; margin-bottom: 1rem; font-weight: 500; color: var(--text); }
input, select, textarea {
    display: block;
    width: 100%;
    margin-top: 0.25rem;
    padding: 0.5rem;
    border: 1px solid #94a3b8;
    border-radius: 6px;
    background: #fff;
    color: #111827;
}
input:focus, select:focus, textarea:focus {
    outline: 2px solid var(--primary);
    border-color: var(--primary);
}
/* Readable inputs inside tables (invoice lines, etc.) */
.line-items-table input,
.line-items-table select,
.line-items-table textarea,
.form-card input,
.form-card select,
.form-card textarea,
.panel input,
.panel select,
.panel textarea {
    background: #fff !important;
    color: #111827 !important;
}
.line-items-table th {
    background: #1a365d;
    color: #fff;
}
.line-items-table td {
    background: #f8fafc;
    color: #111827;
}
.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 1rem; }
.form-actions { margin-top: 1rem; display: flex; gap: 0.5rem; flex-wrap: wrap; }

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 1rem;
    margin-top: 1.5rem;
}
.module-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1.25rem;
    color: inherit;
    text-decoration: none;
    transition: border-color 0.2s;
}
.module-card:hover {
    border-color: var(--accent);
    text-decoration: none;
}
.module-card h2 { margin: 0 0 0.5rem; color: var(--accent); }
.module-card p { margin: 0; color: var(--muted); font-size: 0.9rem; }

.text-muted { color: var(--muted); }
.badge {
    display: inline-block;
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    background: var(--navy);
}
.badge-converted { background: #64748b; }

.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #0f1419 0%, var(--navy) 100%);
}
.login-card {
    background: var(--surface);
    padding: 2rem;
    border-radius: 12px;
    width: 100%;
    max-width: 400px;
    border: 1px solid var(--border);
    text-align: center;
}
.login-logo { max-width: 280px; margin-bottom: 1rem; }
.login-card h1 { font-size: 1.25rem; margin: 0; }
.login-card .subtitle { color: var(--muted); margin-bottom: 1.5rem; }
.logo-fallback { font-size: 1.5rem; font-weight: bold; color: var(--primary); }

.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; }

/* ——— App header / navigation ——— */
.topbar {
    display: flex;
    background: var(--navy);
    border-bottom: 3px solid var(--accent);
    position: sticky;
    top: 0;
    z-index: 200;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    padding: 0;
}
.topbar-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    padding: 0.65rem 1rem;
    position: relative;
    z-index: 1;
}
.brand { min-width: 0; flex-shrink: 1; }
.brand-text {
    font-size: 1rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
/* Mobile-first nav: hidden until menu opened */
.nav-toggle {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    padding: 10px;
    border: 1px solid rgba(255,255,255,0.25);
    border-radius: 8px;
    background: rgba(0,0,0,0.2);
    cursor: pointer;
    flex-shrink: 0;
    -webkit-tap-highlight-color: transparent;
    touch-action: manipulation;
    color: #fff;
    font: inherit;
}
.nav-toggle-bar {
    display: block;
    height: 2px;
    width: 100%;
    background: #fff;
    border-radius: 1px;
    pointer-events: none;
}
.nav-panel {
    display: none;
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    width: 100%;
    padding: 0.5rem 0.75rem 0.75rem;
    border-top: 1px solid rgba(255,255,255,0.1);
    max-height: min(70vh, calc(100dvh - 4rem));
    overflow-x: hidden;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.app-header.nav-open .nav-panel {
    display: flex;
}
.main-nav {
    display: flex;
    flex-direction: column;
    gap: 0;
    width: 100%;
}
.main-nav a {
    display: block;
    text-decoration: none;
    padding: 0.85rem 0.75rem;
    min-height: 44px;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    font-size: 1rem;
    white-space: normal;
}
.main-nav a:hover { text-decoration: none; opacity: 0.9; }
.user-menu {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 0.25rem;
    width: 100%;
    padding: 0.75rem 0 0;
    border-top: 1px solid rgba(255,255,255,0.15);
    color: var(--muted);
}
.user-menu a,
.user-menu .btn-link {
    display: block;
    padding: 0.75rem;
    min-height: 44px;
    text-align: left;
}
.user-name {
    padding: 0.5rem 0.75rem;
    font-size: 0.9rem;
}
.logo-sm { height: 32px; }

/* ——— Mobile layout ——— */
@media (max-width: 768px) {
    .detail-grid { grid-template-columns: 1fr; }

    .container {
        padding: 1rem 0.75rem;
        padding-bottom: calc(1rem + env(safe-area-inset-bottom));
        max-width: 100%;
    }

    h1 { font-size: 1.35rem; }

    .toolbar {
        flex-direction: column;
        align-items: stretch;
        gap: 0.5rem;
    }
    .toolbar .btn,
    .toolbar a.btn {
        width: 100%;
        text-align: center;
        min-height: 44px;
        display: flex;
        align-items: center;
        justify-content: center;
    }
    .toolbar .inline-form { display: block; width: 100%; }
    .toolbar .inline-form .btn { width: 100%; }

    .search-form {
        flex-direction: column;
        width: 100%;
    }
    .search-form input { width: 100%; font-size: 16px; min-height: 44px; }

    .form-row { grid-template-columns: 1fr; }

    .form-actions { flex-direction: column; }
    .form-actions .btn { width: 100%; text-align: center; min-height: 44px; }

    .btn { min-height: 44px; display: inline-flex; align-items: center; justify-content: center; }

    input, select, textarea { font-size: 16px; min-height: 44px; }
    textarea { min-height: 5rem; }

    .tabs {
        flex-wrap: nowrap;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 0.35rem;
        padding-bottom: 0.25rem;
        margin-bottom: 1rem;
    }
    .tabs a {
        flex-shrink: 0;
        padding: 0.65rem 0.85rem;
        font-size: 0.9rem;
        border-radius: 6px;
    }

    .card-grid { grid-template-columns: 1fr; }
    .module-card { padding: 1rem; min-height: 44px; }

    .table-scroll {
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        margin-bottom: 1rem;
        border-radius: 8px;
    }
    .table-scroll table { margin-bottom: 0; min-width: 520px; }

    .container > table,
    .panel > table,
    .form-card > table {
        display: block;
        width: 100%;
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
    }

    th, td { padding: 0.5rem; font-size: 0.875rem; }

    .line-items-table { font-size: 0.85rem; }
    .line-items-table input,
    .line-items-table select { min-width: 64px; font-size: 16px; }

    .totals-box { max-width: 100%; margin-left: 0; }

    .login-card { margin: 1rem; padding: 1.5rem; }
}

/* Wide desktop: horizontal nav, no hamburger */
@media (min-width: 1101px) {
    .topbar {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        padding: 0.5rem 1rem;
        gap: 0.5rem 1rem;
    }
    .topbar-inner {
        flex: 0 0 auto;
        padding: 0;
    }
    .topbar .logo-sm { height: 40px; }
    .topbar .nav-toggle { display: none !important; }
    .topbar .nav-panel {
        display: flex !important;
        flex: 1 1 400px;
        flex-direction: row;
        align-items: center;
        justify-content: flex-end;
        min-width: 0;
        padding: 0;
        border: none;
        max-height: none;
        overflow: visible;
        gap: 0.75rem;
    }
    .topbar.app-header.nav-open .nav-panel,
    .topbar.app-header:not(.nav-open) .nav-panel {
        display: flex !important;
    }
    .topbar .main-nav {
        flex-direction: row;
        flex-wrap: wrap;
        flex: 1;
        min-width: 0;
        justify-content: flex-end;
        gap: 0.15rem 0.35rem;
        width: auto;
    }
    .topbar .main-nav a {
        display: inline-block;
        font-size: 0.8125rem;
        padding: 0.35rem 0.45rem;
        min-height: 0;
        border-bottom: none;
        white-space: nowrap;
    }
    .topbar .user-menu {
        flex-direction: row;
        flex-shrink: 0;
        align-items: center;
        width: auto;
        padding: 0;
        border: none;
        font-size: 0.8125rem;
        gap: 0.5rem;
    }
    .topbar .user-menu a,
    .topbar .user-menu .btn-link {
        display: inline;
        padding: 0;
        min-height: 0;
        text-align: inherit;
    }
    .topbar .user-name { padding: 0; }
}

.line-items-table input, .line-items-table select {
    margin: 0;
    min-width: 80px;
}
.totals-box {
    max-width: 320px;
    margin-left: auto;
    background: #f0f4f8;
    border: 2px solid var(--navy);
    padding: 1rem;
    border-radius: 8px;
    color: #111827;
}
.totals-box dl { display: grid; grid-template-columns: 1fr auto; gap: 0.25rem 1rem; margin: 0; }
.totals-box dt { color: #334155; font-weight: 600; }
.totals-box dd { margin: 0; text-align: right; font-weight: 700; color: #000; }
.tax-note { font-size: 0.85rem; color: #334155; margin-top: 0.5rem; }

.tabs { display: flex; gap: 0.5rem; margin-bottom: 1rem; }
.tabs a {
    padding: 0.5rem 1rem;
    background: var(--surface);
    border-radius: 6px 6px 0 0;
    color: var(--muted);
}
.tabs a.active { background: var(--navy); color: #fff; }

/* Legacy print rules moved to public/assets/css/print.css */
