/* ---------- Base ---------- */
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background: #f4f5f7;
    color: #2d3748;
    font-size: 14px;
    line-height: 1.5;
}
a { color: #2563eb; text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0 0 4px; }
h3 { margin: 0; }

/* ---------- Navbar ---------- */
.navbar { background: #1a1a2e; color: #fff; }
.navbar-inner {
    max-width: 1100px; margin: 0 auto; padding: 0 20px;
    display: flex; align-items: center; justify-content: space-between; height: 56px;
}
.navbar-brand { color: #fff; font-weight: 700; font-size: 18px; }
.navbar-brand:hover { text-decoration: none; }
.navbar-links a { color: #cbd5e0; margin-left: 20px; font-size: 14px; }
.navbar-links a:hover { color: #fff; text-decoration: none; }
.navbar-links a.active { color: #fff; font-weight: 600; }
.navbar-logout { color: #fca5a5 !important; }

/* ---------- Layout ---------- */
.container { max-width: 1100px; margin: 24px auto; padding: 0 20px; }
.site-footer { text-align: center; color: #a0aec0; font-size: 12px; padding: 20px; }
.page-head {
    display: flex; align-items: center; justify-content: space-between;
    margin-bottom: 18px; flex-wrap: wrap; gap: 10px;
}
.muted { color: #718096; }
.small { font-size: 12px; }

/* ---------- Cards ---------- */
.card {
    background: #fff; border: 1px solid #e2e8f0; border-radius: 8px;
    padding: 18px; margin-bottom: 18px;
}
.card-title { font-size: 15px; margin-bottom: 14px; color: #1a1a2e; }
.card-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 14px; }
.readonly-block { background: #f7fafc; border: 1px solid #edf2f7; border-radius: 6px; padding: 12px; line-height: 1.5; }

/* ---------- Grid ---------- */
.grid { display: grid; gap: 14px; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 760px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* ---------- Fields ---------- */
.field { margin-bottom: 12px; }
.field label { display: block; font-weight: 600; font-size: 12px; margin-bottom: 4px; color: #4a5568; }
input[type=text], input[type=password], input[type=number], input[type=date],
select, textarea {
    width: 100%; padding: 8px 10px; border: 1px solid #cbd5e0; border-radius: 6px;
    font-size: 14px; font-family: inherit; background: #fff; color: #2d3748;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: #2563eb; box-shadow: 0 0 0 2px rgba(37,99,235,.15); }
textarea { resize: vertical; }
textarea.mono { font-family: "SFMono-Regular", Menlo, Consolas, monospace; font-size: 12.5px; }
input[type=file] { padding: 4px; }
.radio-group label { display: block; font-weight: 400; margin-bottom: 4px; }

/* ---------- Buttons ---------- */
.btn {
    display: inline-block; padding: 8px 16px; border-radius: 6px; border: 1px solid transparent;
    font-size: 14px; font-weight: 600; cursor: pointer; text-align: center; line-height: 1.2;
}
.btn:hover { text-decoration: none; opacity: .92; }
.btn-primary { background: #2563eb; color: #fff; }
.btn-success { background: #059669; color: #fff; }
.btn-danger  { background: #dc2626; color: #fff; }
.btn-secondary { background: #edf2f7; color: #2d3748; border-color: #cbd5e0; }
.btn-block { width: 100%; }
.btn-small { padding: 5px 10px; font-size: 12.5px; }

/* ---------- Flash ---------- */
.flash { padding: 12px 16px; border-radius: 6px; margin-bottom: 16px; font-size: 14px; }
.flash-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.flash-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.flash-info    { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid #e2e8f0; border-radius: 8px; overflow: hidden; }
.data-table th { text-align: left; padding: 10px 12px; background: #f7fafc; font-size: 12px; color: #4a5568; border-bottom: 1px solid #e2e8f0; }
.data-table td { padding: 10px 12px; border-bottom: 1px solid #edf2f7; }
.data-table tbody tr:hover, .data-table tbody tr:hover { background: #f9fafb; }
.data-table .num { text-align: right; }
.data-table .empty { text-align: center; color: #a0aec0; padding: 24px; }
.actions-col { white-space: nowrap; }
.link-action { margin-right: 10px; font-size: 13px; }
.link-button { background: none; border: none; padding: 0; cursor: pointer; color: #2563eb; font-size: 13px; font-family: inherit; }
.link-button.danger { color: #dc2626; }
.inline-form { display: inline; margin: 0; }

/* ---------- Badges ---------- */
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .3px; }
.badge-status-draft { background: #e2e8f0; color: #4a5568; }
.badge-status-sent  { background: #dbeafe; color: #1e40af; }
.badge-status-paid  { background: #d1fae5; color: #065f46; }
.badge-status-cancelled { background: #fee2e2; color: #991b1b; }
.badge-type-proforma { background: #ffedd5; color: #9a3412; }
.badge-type-tax { background: #dbeafe; color: #1e40af; }

/* ---------- Filter bar ---------- */
.filter-bar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filter-bar input, .filter-bar select { width: auto; flex: 0 0 auto; }
.filter-bar input[name=search] { min-width: 220px; }

/* ---------- Login ---------- */
.login-body { background: #1a1a2e; display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login-card { background: #fff; padding: 32px; border-radius: 10px; width: 340px; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.login-card h1 { text-align: center; margin-bottom: 2px; }
.login-sub { text-align: center; color: #718096; margin-top: 0; margin-bottom: 20px; }

/* ---------- Invoice form: type toggle ---------- */
.type-toggle { display: flex; gap: 12px; margin-bottom: 18px; }
.type-option {
    flex: 1; border: 2px solid #cbd5e0; border-radius: 8px; padding: 14px; text-align: center;
    cursor: pointer; font-weight: 600; position: relative;
}
.type-option input { position: absolute; opacity: 0; }
.type-option.selected { border-color: #2563eb; background: #eff6ff; color: #1e40af; }

/* ---------- Sections & items ---------- */
.inv-section {
    border: 1px solid #e2e8f0; border-radius: 8px; margin-bottom: 14px; background: #fbfcfd;
}
.inv-section-head {
    display: flex; gap: 10px; align-items: center; padding: 10px 12px;
    background: #f0f2f5; border-bottom: 1px solid #e2e8f0; border-radius: 8px 8px 0 0;
}
.inv-section-head input { flex: 1; font-weight: 600; }
.items-table { width: 100%; border-collapse: collapse; }
.items-table th { font-size: 11px; color: #4a5568; text-align: left; padding: 6px 8px; }
.items-table td { padding: 4px 6px; vertical-align: top; }
.items-table .th-num, .items-table .th-drag { width: 26px; }
.items-table .th-amount, .items-table .th-price, .items-table .th-qty { text-align: right; }
.items-table input, .items-table textarea { padding: 6px 8px; font-size: 13px; }
.items-table textarea { min-height: 34px; }
.item-amount { text-align: right; font-weight: 600; padding-right: 8px; white-space: nowrap; }
.drag-handle { cursor: move; color: #a0aec0; user-select: none; text-align: center; }
.row-index { text-align: center; color: #718096; }
.btn-remove-row, .btn-remove-section {
    background: none; border: none; color: #dc2626; cursor: pointer; font-size: 16px; line-height: 1; padding: 4px 6px;
}
.section-foot { padding: 8px 12px; text-align: right; border-top: 1px solid #e2e8f0; }
.section-subtotal-val { font-weight: 700; }
.section-actions { padding: 8px 12px; }
.sortable-ghost { opacity: .4; }
tr.dragging { background: #eef2ff; }

/* ---------- Totals card ---------- */
.totals-card .totals-row { display: flex; justify-content: space-between; padding: 6px 0; border-bottom: 1px solid #edf2f7; }
.totals-card .totals-row.grand { font-size: 18px; font-weight: 700; border-bottom: none; border-top: 2px solid #1a1a2e; margin-top: 6px; padding-top: 10px; }
.vat-field { max-width: 160px; }

/* ---------- Form actions ---------- */
.form-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 6px; margin-bottom: 30px; }

/* ---------- Invoice view ---------- */
.action-buttons { display: flex; gap: 10px; }
.action-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.invoice-preview { background: #fff; border: 1px solid #e2e8f0; border-radius: 8px; padding: 30px; }
.num { text-align: right; }
