:root {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: #172033;
  background: #f1f5f9;
}
* { box-sizing: border-box; }
body { margin: 0; min-width: 0; }
.topbar { min-height: 68px; background: #172554; color: #fff; display: flex; align-items: center; padding: 0 32px; gap: 36px; position: sticky; top: 0; z-index: 10; }
.brand { font-size: 20px; font-weight: 800; white-space: nowrap; }
.brand.dark { color: #172554; }
.topbar nav { display: flex; gap: 22px; flex-wrap: wrap; }
.topbar a { color: #dbeafe; text-decoration: none; }
.topbar a.active, .topbar a:hover { color: #fff; text-decoration: underline; }
.page { width: 100%; max-width: none; margin: 30px auto; padding: 0 clamp(14px, 3vw, 48px); }
h1 { margin: 4px 0 24px; font-size: 32px; letter-spacing: -.02em; }
h2 { margin: 0; color: #172554; font-size: 19px; }
h3 { color: #334155; }
.eyebrow { margin: 0; color: #2563eb; text-transform: uppercase; font-size: 12px; font-weight: 800; letter-spacing: .08em; }
.cards { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; }
.card, .detail-card, .form-card { background: #fff; border: 1px solid #dbe3ee; border-radius: 12px; box-shadow: 0 4px 16px #0f172a0a; }
.card { padding: 24px; min-height: 125px; text-decoration: none; color: inherit; }
.card span { display: block; color: #64748b; margin-bottom: 18px; }
.card strong { font-size: 28px; }
.page-heading, .section-heading { display: flex; align-items: center; justify-content: space-between; gap: 20px; }
.page-heading { align-items: end; margin-bottom: 12px; }
.inline-form, .line-toolbar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
button, .button, select, textarea, input { border: 1px solid #cbd5e1; border-radius: 7px; padding: 10px 12px; background: #fff; font: inherit; }
button:not(:disabled), .button { background: #2563eb; color: #fff; border-color: #2563eb; cursor: pointer; text-decoration: none; display: inline-block; }
button:disabled { cursor: not-allowed; opacity: .55; }
.secondary-button { background: #475569 !important; border-color: #475569 !important; }
.danger-button { background: #dc2626 !important; border-color: #dc2626 !important; color: #fff !important; }
.button-small { padding: 8px 11px; font-size: 13px; font-weight: 700; }
.table-hint, .hint { margin: 0; color: #64748b; font-size: 13px; line-height: 1.45; }
.table-wrap { background: #fff; border: 1px solid #dbe3ee; border-radius: 12px; overflow: auto; max-width: 100%; box-shadow: 0 4px 16px #0f172a0a; }
table { width: 100%; border-collapse: collapse; table-layout: fixed; min-width: 920px; }
th, td { text-align: left; padding: 13px 15px; border-bottom: 1px solid #e2e8f0; white-space: normal; overflow-wrap: anywhere; word-break: break-word; vertical-align: top; }
th { position: relative; background: #eff6ff; color: #1e3a8a; font-size: 13px; cursor: pointer; user-select: none; }
th:hover { background: #dbeafe; }
tbody tr:last-child td { border-bottom: 0; }
.status { display: inline-block; background: #fef3c7; color: #92400e; padding: 4px 8px; border-radius: 999px; font-size: 12px; }
.status.archived { background: #e2e8f0; color: #475569; }
.payment-paid { color: #166534; font-weight: 700; }
.payment-partial { color: #92400e; font-weight: 700; }
.actions-column, .work-orders-table th:last-child, .work-orders-table td:last-child { width: 210px; min-width: 210px; }
.work-orders-table th:nth-child(7), .work-orders-table td:nth-child(7) { width: 125px; }
.work-orders-table th:nth-child(8), .work-orders-table td:nth-child(8) { width: 170px; }
.table-actions { display: flex; gap: 8px; align-items: flex-start; flex-wrap: wrap; white-space: normal; }
.table-actions .button { margin: 0; white-space: nowrap; }
.resize-handle { position: absolute; z-index: 2; top: 0; right: -4px; width: 9px; height: 100%; cursor: col-resize; }
.resize-handle:hover, .resize-handle.active { background: #93c5fd; }
.form-card { padding: 26px; display: grid; gap: 22px; max-width: none; }
.form-section { display: grid; gap: 14px; border-top: 1px solid #e2e8f0; padding-top: 20px; }
.form-section:first-of-type { border-top: 0; padding-top: 0; }
.form-card label, .login-card label { display: grid; gap: 6px; color: #334155; font-weight: 650; }
.form-card input, .form-card select, .form-card textarea, .login-card input { width: 100%; font-weight: 400; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.actions { display: flex; justify-content: flex-end; gap: 14px; align-items: center; padding-top: 4px; flex-wrap: wrap; }
.actions a { color: #475569; }
.actions a.button, .actions .button, .actions button { color: #fff !important; width: max-content; }
.associated-record { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: 8px; padding: 14px; }
.associated-record strong { color: #172554; }
.associated-record span { color: #64748b; }
.associated-record a { margin-left: auto; color: #2563eb; }
.detail-card { padding: 24px; margin: 0 0 18px; }
.detail-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 18px; }
.detail-grid > div { display: grid; gap: 5px; min-width: 0; }
.detail-grid span, .related-row span { color: #64748b; font-size: 13px; }
.detail-grid strong { font-weight: 400; overflow-wrap: anywhere; white-space: pre-wrap; }
.detail-wide { grid-column: 1 / -1; }
.related-list { display: grid; gap: 8px; margin-top: 16px; }
.related-row { display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 12px; border: 1px solid #e2e8f0; border-radius: 8px; }
.related-row > div { display: grid; gap: 4px; min-width: 0; }
.detail-text { margin-top: 18px; }
.detail-text h3 { font-size: 14px; margin: 18px 0 5px; }
.detail-text p { white-space: pre-wrap; margin: 0; }
.line-section { overflow: hidden; }
.line-table-wrap { overflow: auto; border: 1px solid #dbe3ee; border-radius: 8px; }
.line-table { min-width: 1260px; }
.line-table th, .line-table td { padding: 8px; }
.line-table input, .line-table select { padding: 7px 8px; font-size: 13px; min-width: 100px; }
.line-table input[type=datetime-local] { min-width: 170px; }
.line-table .short-input { min-width: 78px; width: 78px; }
.line-table .price-input { min-width: 95px; width: 95px; }
.line-table .tax-input { min-width: 65px; width: 65px; margin-top: 4px; }
.line-total { margin: 0; text-align: right; color: #475569; }
.remove-line { background: #dc2626 !important; border-color: #dc2626 !important; padding: 4px 10px; }
.upload-box { padding: 18px; border: 2px dashed #bfdbfe; border-radius: 10px; background: #eff6ff; }
.upload-actions { display: flex; gap: 12px; flex-wrap: wrap; margin-top: 12px; }
.upload-option { display: inline-flex !important; align-items: center; gap: 8px !important; background: #2563eb; color: #fff !important; border: 1px solid #2563eb; border-radius: 7px; padding: 10px 12px; cursor: pointer; }
.upload-option input { width: auto !important; display: none; }
.upload-option { appearance: none; font-weight: 650; }
.reference-columns { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.reference-columns > div { display: grid; gap: 8px; align-content: start; }
.reference-lines { display: grid; gap: 8px; }
.reference-line { display: flex; align-items: start; gap: 8px; }
.reference-line textarea { flex: 1; min-height: 44px; resize: vertical; }
.reference-line .remove-reference { white-space: nowrap; }
.reference-display { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-top: 16px; }
.reference-display > div { display: grid; gap: 5px; }
.reference-display span { color: #64748b; font-size: 13px; }
.reference-display strong { font-weight: 400; overflow-wrap: anywhere; white-space: pre-wrap; }
.camera-modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 18px; background: #020617aa; }
.camera-dialog { width: min(720px, 100%); max-height: 95vh; overflow: auto; display: grid; gap: 14px; padding: 18px; border-radius: 12px; background: #fff; box-shadow: 0 20px 80px #02061766; }
.camera-dialog video { display: block; width: 100%; max-height: 70vh; object-fit: contain; border-radius: 8px; background: #0f172a; }
.camera-actions { display: flex; justify-content: center; }
.camera-actions button { min-width: 140px; }
.attachment-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.attachment-grid a { display: grid; gap: 5px; color: #334155; text-decoration: none; font-size: 12px; min-width: 0; }
.attachment-grid img { width: 100%; height: 110px; object-fit: cover; border-radius: 8px; border: 1px solid #cbd5e1; }
.attachment-grid a span { overflow-wrap: anywhere; word-break: break-word; line-height: 1.25; }
.filter-bar { display: flex; gap: 10px; align-items: end; flex-wrap: wrap; background: #fff; border: 1px solid #dbe3ee; border-radius: 12px; padding: 14px; margin: 12px 0; }
.filter-bar label { display: grid; gap: 5px; font-size: 13px; color: #475569; }
.admin-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 18px; }
.admin-card { padding: 20px; }
.admin-card form { display: grid; gap: 10px; margin-top: 14px; }
.password-field { display: flex; align-items: stretch; gap: 6px; }
.password-field input { flex: 1; }
.password-toggle { min-width: 46px; padding: 8px 10px; }
.row-actions { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.checkbox-line { display: flex !important; align-items: center; gap: 8px !important; }
.button-stack { display: grid; gap: 10px; }
.totals-card .total-lines { display: grid; gap: 10px; max-width: 520px; margin-top: 14px; }
.total-lines > div { display: flex; justify-content: space-between; gap: 18px; border-bottom: 1px solid #e2e8f0; padding: 8px 0; }
.total-lines .grand-total { font-size: 20px; color: #172554; border-top: 2px solid #172554; border-bottom: 0; }
.print-page { background: #fff; color: #111; }
.print-sheet { max-width: 900px; margin: 0 auto; padding: 30px; }
.print-header { display: flex; justify-content: space-between; border-bottom: 2px solid #172554; padding-bottom: 16px; margin-bottom: 20px; }
.print-section { border: 1px solid #cbd5e1; padding: 14px; margin: 14px 0; }
.print-section h2 { font-size: 16px; border-bottom: 1px solid #cbd5e1; padding-bottom: 6px; }
.print-table { min-width: 0; }
.print-table th, .print-table td { padding: 7px; border: 1px solid #cbd5e1; }
.print-total { text-align: right; font-size: 18px; font-weight: 800; }
@media print { .no-print { display: none !important; } .print-sheet { padding: 0; } .print-section { break-inside: avoid; } }
.login-page { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #172554, #2563eb); }
.login-card { background: #fff; border-radius: 16px; padding: 34px; width: min(440px, calc(100% - 32px)); box-shadow: 0 20px 60px #02061755; display: grid; gap: 18px; }
.login-card form { display: grid; gap: 16px; }
.login-card button { border: 0; border-radius: 7px; padding: 12px; background: #2563eb; color: #fff; font-weight: 700; cursor: pointer; }
.error { padding: 10px 12px; border-radius: 7px; background: #fee2e2; color: #991b1b; }
.success { background: #dcfce7; color: #166534; border: 1px solid #86efac; padding: 12px; border-radius: 8px; }
.warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; padding: 12px; border-radius: 8px; margin-top: 18px; }
.login-links { text-align: center; }
p { line-height: 1.6; color: #475569; }
@media (max-width: 800px) {
  .topbar { height: auto; padding: 16px 18px; align-items: flex-start; flex-direction: column; gap: 14px; }
  .topbar nav { gap: 12px 18px; }
  .brand { font-size: 18px; }
  .page { margin: 22px auto; padding: 0 14px; }
  .page-heading, .section-heading { align-items: flex-start; flex-direction: column; }
  .cards, .form-grid, .admin-grid { grid-template-columns: 1fr; }
  .reference-columns, .reference-display { grid-template-columns: 1fr; }
  .form-card { padding: 18px; }
  .table-wrap { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; min-width: 0; }
  .data-table thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  .data-table tr { background: #fff; border: 1px solid #e2e8f0; border-radius: 10px; margin-bottom: 12px; padding: 8px 12px; }
  .data-table td { display: grid; grid-template-columns: minmax(105px, 34%) minmax(0, 1fr); gap: 12px; padding: 9px 0; border-bottom: 1px solid #eef2f7; }
  .data-table td:last-child { border-bottom: 0; }
  .data-table td::before { content: attr(data-label); font-weight: 700; color: #475569; }
  .data-table .table-actions { display: flex; justify-content: flex-start; gap: 8px; }
  .resize-handle { display: none; }
  .status { justify-self: start; }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-wide { grid-column: auto; }
  .detail-card { padding: 18px; }
  .related-row { align-items: flex-start; flex-direction: column; }
  .related-row .button { align-self: flex-end; }
  .associated-record a { margin-left: 0; }
  .line-toolbar { width: 100%; }
  .line-toolbar select { flex: 1; min-width: 230px; }
  .filter-bar label, .filter-bar select, .filter-bar button { width: 100%; }
  .actions { justify-content: flex-start; }
  .actions .button, .actions button { width: auto; }
  .print-sheet { padding: 14px; }
}
