/* ============ Root / Reset ============ */
:root {
  --brand-red: #a01c1c;
  --brand-dark: #58595b;
  --brand-orange: #f7941d;
  --table-blue: #dbe6f0;
  --table-blue-dark: #c3d6e8;
  --table-gray: #d9d9d9;
  --border-color: #333;
  --page-bg: #f2f2f0;
  --danger: #c0392b;
  --success: #1e8449;
  --warn-bg: #fdecea;
  font-size: 15px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  font-family: 'Segoe UI', Arial, Helvetica, sans-serif;
  background: var(--page-bg);
  color: #1a1a1a;
  -webkit-tap-highlight-color: transparent;
  overflow-x: hidden;
  width: 100%;
}

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

a { color: inherit; text-decoration: none; }

.hidden { display: none !important; }

/* ============ Login Screen ============ */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #2b2b2d 0%, #1c1c1e 100%);
  padding: 20px;
}

.login-card {
  background: #fff;
  border-radius: 12px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.35);
  text-align: center;
}

.login-card img.login-logo {
  max-width: 220px;
  margin-bottom: 24px;
}

.login-card h1 {
  font-size: 20px;
  margin: 0 0 6px;
  color: var(--brand-dark);
}

.login-card p.subtitle {
  color: #777;
  font-size: 13px;
  margin: 0 0 24px;
}

.field-group {
  text-align: left;
  margin-bottom: 16px;
}

.field-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: #555;
  margin-bottom: 5px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.field-group input, .field-group select, .field-group textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
  background: #fff;
}

.field-group input:focus, .field-group select:focus, .field-group textarea:focus {
  outline: none;
  border-color: var(--brand-red);
  box-shadow: 0 0 0 3px rgba(160,28,28,0.12);
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 6px;
  padding: 11px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.05s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: var(--brand-red);
  color: #fff;
  width: 100%;
}
.btn-primary:hover { background: #861414; }

.btn-secondary {
  background: #eee;
  color: #333;
}
.btn-secondary:hover { background: #e0e0e0; }

.btn-outline {
  background: transparent;
  border: 1.5px solid var(--brand-red);
  color: var(--brand-red);
}
.btn-outline:hover { background: rgba(160,28,28,0.06); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #166a3a; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #9c2c20; }

.btn-sm { padding: 6px 12px; font-size: 12.5px; }

.login-error {
  color: var(--danger);
  font-size: 13px;
  margin-top: 10px;
  min-height: 18px;
}

.login-hint {
  margin-top: 18px;
  font-size: 11.5px;
  color: #999;
}

/* ============ App Shell ============ */
.app-header {
  background: #fff;
  border-bottom: 1px solid #e2e2e2;
  padding: 10px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
}

.app-header .logo-wrap img {
  height: 40px;
  display: block;
}

.app-header .user-info {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
  color: #555;
}

.app-header .user-info .user-badge {
  background: var(--table-blue);
  padding: 5px 10px;
  border-radius: 20px;
  font-weight: 600;
  color: var(--brand-dark);
}

.app-main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 20px;
}

/* ============ Dashboard ============ */
.dashboard-toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 18px;
}

.dashboard-toolbar .search-box {
  flex: 1;
  min-width: 220px;
  max-width: 380px;
}

.dashboard-toolbar .search-box input {
  width: 100%;
  padding: 10px 14px;
  border-radius: 20px;
  border: 1px solid #ccc;
}

.status-filters {
  display: flex;
  gap: 8px;
}

.status-chip {
  border: 1px solid #ccc;
  background: #fff;
  padding: 6px 14px;
  border-radius: 20px;
  font-size: 12.5px;
  cursor: pointer;
  color: #555;
}
.status-chip.active {
  background: var(--brand-dark);
  color: #fff;
  border-color: var(--brand-dark);
}

.report-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.report-card {
  background: #fff;
  border-radius: 10px;
  padding: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.07);
  border-left: 5px solid #ccc;
  display: flex;
  flex-direction: column;
  gap: 8px;
  cursor: pointer;
  transition: box-shadow 0.15s ease, transform 0.1s ease;
}
.report-card:hover { box-shadow: 0 6px 16px rgba(0,0,0,0.12); transform: translateY(-1px); }

.report-card.status-draft { border-left-color: #999; }
.report-card.status-sent { border-left-color: var(--success); }
.report-card.status-resent { border-left-color: var(--brand-orange); }

.report-card .rc-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.report-card h3 {
  margin: 0;
  font-size: 15px;
  color: #222;
}

.report-card .rc-meta {
  font-size: 12.5px;
  color: #777;
  line-height: 1.5;
}

.badge {
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  padding: 3px 9px;
  border-radius: 20px;
  letter-spacing: 0.03em;
}
.badge.status-draft { background: #eee; color: #666; }
.badge.status-sent { background: #e3f5e9; color: var(--success); }
.badge.status-resent { background: #fff1de; color: #b06a00; }

.report-card .rc-actions {
  display: flex;
  gap: 6px;
  margin-top: 6px;
  flex-wrap: wrap;
}

.empty-state {
  text-align: center;
  padding: 60px 20px;
  color: #999;
}
.empty-state img { width: 80px; opacity: 0.4; margin-bottom: 14px; }

.fab {
  position: fixed;
  bottom: 26px;
  right: 26px;
  width: 58px;
  height: 58px;
  border-radius: 50%;
  background: var(--brand-red);
  color: #fff;
  font-size: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 6px 18px rgba(160,28,28,0.4);
  cursor: pointer;
  border: none;
  z-index: 90;
}
.fab:hover { background: #861414; }

/* ============ Toast ============ */
.toast-container {
  position: fixed;
  top: 18px;
  right: 18px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.toast {
  background: #2b2b2d;
  color: #fff;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 13.5px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
  min-width: 220px;
  animation: toastIn 0.25s ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: #2b6cb0; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(30px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ============ Report Form Toolbar ============ */
.form-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
  gap: 10px;
}

.form-toolbar .left { display: flex; gap: 10px; align-items: center; }
.form-toolbar .right { display: flex; gap: 8px; flex-wrap: wrap; }

.status-pill {
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}
.status-pill.status-draft { background: #eee; color: #666; }
.status-pill.status-sent { background: #e3f5e9; color: var(--success); }
.status-pill.status-resent { background: #fff1de; color: #b06a00; }

/* ============ Report Document (matches original layout) ============ */
.doc-wrapper {
  background: #fff;
  border: 1px solid #999;
  padding: 14px;
  max-width: 1050px;
  margin: 0 auto;
  box-shadow: 0 2px 14px rgba(0,0,0,0.08);
}

.doc-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-bottom: 2px solid #333;
  padding-bottom: 10px;
  margin-bottom: 10px;
  gap: 14px;
  flex-wrap: wrap;
}

.doc-header .logo-block img { height: 62px; }

.doc-header .cert-badges {
  display: flex;
  gap: 8px;
  align-items: center;
}
.doc-header .cert-badges .cert {
  border: 1px solid #999;
  font-size: 9px;
  text-align: center;
  padding: 4px 8px;
  border-radius: 4px;
  color: #444;
  min-width: 60px;
  background: #fafafa;
}
.cert.bafe { background: #a01c1c; color: #fff; border-color: #a01c1c; font-weight: 700; }
.cert.ukas { background: #1c2a70; color: #fff; border-color: #1c2a70; font-weight: 700; }

.doc-title {
  font-size: 16px;
  font-weight: 700;
  margin: 6px 0 10px;
  color: #222;
}

table.doc-table {
  width: 100%;
  border-collapse: collapse;
  margin-bottom: 8px;
  font-size: 12px;
}
table.doc-table th, table.doc-table td {
  border: 1px solid #7c7c7c;
  padding: 4px 6px;
  vertical-align: middle;
}
table.doc-table th {
  background: var(--table-blue);
  font-weight: 700;
  text-align: left;
  white-space: nowrap;
}
table.doc-table td.label-cell {
  background: var(--table-blue);
  font-weight: 700;
  white-space: nowrap;
}
table.doc-table td input, table.doc-table td select, table.doc-table td textarea {
  width: 100%;
  border: none;
  background: transparent;
  padding: 2px 3px;
  font-size: 12px;
  font-family: inherit;
}
table.doc-table td input:focus, table.doc-table td select:focus, table.doc-table td textarea:focus {
  outline: 1.5px solid var(--brand-red);
  background: #fff8f0;
}
table.doc-table td textarea {
  resize: vertical;
  min-height: 26px;
}

.section-title-bar {
  background: #eee;
  font-weight: 700;
  font-size: 12px;
  padding: 4px 8px;
  border: 1px solid #7c7c7c;
  margin-top: 10px;
  margin-bottom: 0;
}

.yn-select {
  font-weight: 600;
}
.yn-select.val-YES { color: var(--success); }
.yn-select.val-NO { color: var(--danger); }

.two-col-tables {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.two-col-tables > div { flex: 1; min-width: 0; }

.doc-footer-note {
  font-size: 10.5px;
  color: #555;
  margin: 6px 0;
  line-height: 1.4;
}

.remedials-flag {
  background: var(--warn-bg) !important;
  color: var(--danger);
  font-weight: 700;
}
.remedials-flag select,
.remedials-flag input {
  background: var(--warn-bg) !important;
  color: var(--danger) !important;
  font-weight: 700;
}

.continuation-table td, .continuation-table th {
  font-size: 11px;
  height: 22px;
}
.continuation-table td.row-num {
  width: 24px;
  background: var(--table-blue);
  font-weight: 700;
  text-align: center;
}

.sig-canvas-wrap {
  border: 1px dashed #999;
  height: 46px;
  display: flex;
  align-items: center;
  padding: 0 6px;
}
.sig-canvas-wrap input {
  border: none;
  width: 100%;
  font-style: italic;
  font-size: 14px;
}

.remove-row-btn {
  background: var(--danger);
  color: #fff;
  border: none;
  border-radius: 3px;
  width: 20px;
  height: 20px;
  line-height: 1;
  cursor: pointer;
  font-size: 12px;
}

.add-row-btn {
  margin-top: 6px;
}

/* ============ History Log ============ */
.history-log {
  margin-top: 16px;
  background: #fafafa;
  border: 1px solid #ddd;
  border-radius: 8px;
  padding: 12px 16px;
}
.history-log h4 { margin: 0 0 8px; font-size: 13px; color: #444; }
.history-item {
  font-size: 12.5px;
  padding: 6px 0;
  border-bottom: 1px solid #eee;
  display: flex;
  justify-content: space-between;
  color: #555;
}
.history-item:last-child { border-bottom: none; }

/* ============ Modal ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 20px;
}
.modal-box {
  background: #fff;
  border-radius: 10px;
  padding: 26px;
  max-width: 420px;
  width: 100%;
  text-align: center;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.modal-box h3 { margin: 0 0 10px; }
.modal-box p { color: #666; font-size: 14px; margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: center; }

/* ============ Print / PDF ============ */
@media print {
  body * { visibility: hidden; }
  #printArea, #printArea * { visibility: visible; }
  #printArea {
    position: absolute;
    left: 0; top: 0;
    width: 100%;
  }
  .doc-wrapper { box-shadow: none; border: none; max-width: 100%; }
  @page { size: A4; margin: 10mm; }
}

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

/* Report document keeps its exact desktop layout/fidelity but becomes
   horizontally scrollable on narrow screens instead of squishing/breaking */
#printArea {
  width: 100%;
}

@media (max-width: 900px) {
  #printArea {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 6px;
  }
  .doc-wrapper {
    min-width: 720px;
  }
}

@media (max-width: 720px) {
  html { font-size: 14px; }

  .app-main { padding: 12px; }

  /* ---- Header ---- */
  .app-header {
    padding: 8px 12px;
    flex-wrap: wrap;
    gap: 8px;
  }
  .app-header .logo-wrap img { height: 32px; }
  .app-header .user-info { gap: 8px; font-size: 12px; }
  .app-header .user-info .user-badge { padding: 4px 8px; }

  /* ---- Dashboard toolbar ---- */
  .dashboard-toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }
  .dashboard-toolbar .search-box { max-width: 100%; }
  .status-filters {
    flex-wrap: wrap;
    gap: 6px;
  }
  .status-chip { padding: 6px 12px; font-size: 12px; }

  /* ---- Report grid ---- */
  .report-grid { grid-template-columns: 1fr; }

  /* ---- Report form toolbar ---- */
  .form-toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .form-toolbar .left { justify-content: space-between; }
  .form-toolbar .right {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    width: 100%;
  }
  .form-toolbar .right .btn { width: 100%; margin: 0; }

  /* ---- FAB ---- */
  .fab {
    bottom: 18px;
    right: 18px;
    width: 52px;
    height: 52px;
    font-size: 24px;
  }

  /* ---- Modal ---- */
  .modal-box { padding: 20px; max-width: 92vw; }

  /* ---- Toasts ---- */
  .toast-container {
    top: auto;
    bottom: 18px;
    left: 12px;
    right: 12px;
  }
  .toast { min-width: 0; width: 100%; }

  /* ---- Login ---- */
  .login-card { padding: 30px 22px; }
}

@media (max-width: 420px) {
  .form-toolbar .right { grid-template-columns: 1fr; }
  .app-header .user-info .user-badge { display: none; }
}

/* ============ Signatures (drawn) ============ */
.sig-canvas-wrap {
  position: relative;
  height: 70px;
  padding: 0;
  display: block;
  background: #fff;
}
.sig-canvas-wrap canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
}
.sig-canvas-wrap .sig-img {
  display: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.sig-canvas-wrap .sig-clear {
  position: absolute;
  top: 2px;
  right: 2px;
  font-size: 10px;
  padding: 1px 6px;
  border: 1px solid #bbb;
  border-radius: 3px;
  background: #f7f7f7;
  color: #555;
  cursor: pointer;
}
.sig-canvas-wrap .sig-clear:hover { background: #eee; }

/* ============ PDF mode: hide editing chrome, show signature images ============ */
#printArea.pdf-mode .remove-row-btn,
#printArea.pdf-mode .add-row-btn,
#printArea.pdf-mode .sig-clear,
#printArea.pdf-mode .no-pdf { display: none !important; }
#printArea.pdf-mode .sig-canvas-wrap canvas { display: none; }
#printArea.pdf-mode .sig-canvas-wrap .sig-img { display: block; }
#printArea.pdf-mode .sig-canvas-wrap .sig-img.empty { display: none; }

/* ============ Send-to row above the document ============ */
.send-to-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 0 0 10px;
  font-size: 13px;
  color: #444;
}
.send-to-row label { font-weight: 600; white-space: nowrap; }
.send-to-row input {
  flex: 1;
  min-width: 220px;
  padding: 7px 10px;
  border: 1px solid #ccc;
  border-radius: 6px;
  font-size: 14px;
}

/* ============ Sync / offline indicator ============ */
.sync-pill {
  font-size: 12px;
  padding: 3px 10px;
  border-radius: 999px;
  background: #fff3cd;
  color: #7a5b00;
  border: 1px solid #ffe08a;
  white-space: nowrap;
}
.sync-pill.offline { background: #eee; color: #444; border-color: #ccc; }
.sync-pill.error { background: #fde2e2; color: #8a1c1c; border-color: #f5b5b5; }
.sync-pill.hidden { display: none; }


/* ============ Navigation ============ */
.main-nav {
  display: flex;
  gap: 4px;
  padding: 0 16px;
  background: #fff;
  border-bottom: 1px solid #e3e3e3;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.main-nav::-webkit-scrollbar { display: none; }
.main-nav a {
  padding: 12px 14px;
  font-size: 14px;
  font-weight: 600;
  color: #555;
  text-decoration: none;
  border-bottom: 3px solid transparent;
  white-space: nowrap;
}
.main-nav a.active { color: var(--primary, #a01c1c); border-bottom-color: var(--primary, #a01c1c); }
.main-nav a:hover { color: #222; }

/* ============ Generic pages ============ */
.view-page { max-width: 1100px; margin: 0 auto; }
.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  margin: 0 0 14px;
}
.page-head h2 { margin: 0; font-size: 20px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.muted { color: #666; font-size: 13px; }
.muted.warn { color: #8a5a00; }
.crumbs { font-size: 13px; margin-bottom: 8px; }
.crumbs a { color: var(--primary, #a01c1c); text-decoration: none; }
.card {
  background: #fff;
  border: 1px solid #e3e3e3;
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 14px;
}
.card h3 { margin: 0 0 10px; font-size: 15px; }
.card-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 12px; }
.empty-note { color: #777; font-size: 14px; padding: 18px 0; text-align: center; }

.data-table { width: 100%; border-collapse: collapse; font-size: 14px; background: #fff; }
.data-table th, .data-table td { padding: 9px 10px; border-bottom: 1px solid #eee; text-align: left; vertical-align: top; }
.data-table th { font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: #666; background: #fafafa; }
.data-table tr.clickable { cursor: pointer; }
.data-table tr.clickable:hover td { background: #fcf7f7; }
.data-table td.num, .data-table th.num { text-align: right; white-space: nowrap; }
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid #e3e3e3; border-radius: 10px; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 700; background: #eee; color: #444; }
.badge.status-draft { background: #eee; color: #444; }
.badge.status-sent { background: #e3f1ff; color: #114b8a; }
.badge.status-resent { background: #e3f1ff; color: #114b8a; }
.badge.status-accepted, .badge.status-paid, .badge.status-complete, .badge.status-booked { background: #e2f6e9; color: #146c2e; }
.badge.status-declined, .badge.status-void, .badge.status-cancelled, .badge.status-overdue { background: #fde2e2; color: #8a1c1c; }
.badge.status-invoiced { background: #ede7f6; color: #4527a0; }
.badge.status-due { background: #fff3cd; color: #7a5b00; }
.badge.status-ok { background: #e2f6e9; color: #146c2e; }
.badge.status-none { background: #f1f1f1; color: #777; }

/* ============ Forms ============ */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px 14px; }
.form-grid .wide { grid-column: 1 / -1; }
.fm-field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: #444; }
.fm-field span { font-weight: 600; }
.fm-field input, .fm-field select, .fm-field textarea {
  padding: 8px 10px; border: 1px solid #ccc; border-radius: 6px; font-size: 14px; font-family: inherit; background: #fff;
}
.fm-field input:focus, .fm-field select:focus, .fm-field textarea:focus { outline: 2px solid rgba(160,28,28,0.25); border-color: var(--primary, #a01c1c); }
.fm-check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.modal-box.modal-form { max-width: 640px; text-align: left; }
.modal-box.modal-form h3 { margin-bottom: 14px; }
.modal-box.modal-form .modal-actions { justify-content: flex-end; margin-top: 6px; }
.send-status { min-height: 18px; }
.search-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 12px; }
.search-row input { flex: 1; min-width: 200px; padding: 8px 10px; border: 1px solid #ccc; border-radius: 6px; font-size: 14px; }

/* line items editor */
.items-table input { width: 100%; padding: 6px 8px; border: 1px solid #ddd; border-radius: 4px; font-size: 14px; }
.items-table td.num input { text-align: right; }
.items-table .totals td { font-weight: 600; border-bottom: none; }
.items-table .grand td { font-size: 16px; }
.detail-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 20px; font-size: 14px; }
.detail-grid dt { font-size: 12px; text-transform: uppercase; color: #777; letter-spacing: 0.03em; }
.detail-grid dd { margin: 2px 0 0; }
.inline-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* ============ Calendar ============ */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal-head h3 { margin: 0; font-size: 17px; }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal-dow { font-size: 11px; text-transform: uppercase; color: #777; text-align: center; padding: 4px 0; }
.cal-day {
  min-height: 74px; background: #fff; border: 1px solid #e6e6e6; border-radius: 6px; padding: 4px; font-size: 12px; cursor: pointer;
  display: flex; flex-direction: column; gap: 2px;
}
.cal-day.other { opacity: 0.45; }
.cal-day.today { border-color: var(--primary, #a01c1c); }
.cal-day.selected { background: #fff5f5; }
.cal-day .d { font-weight: 700; color: #444; }
.cal-job { font-size: 11px; padding: 1px 4px; border-radius: 3px; background: #e3f1ff; color: #114b8a; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.cal-job.complete { background: #e2f6e9; color: #146c2e; }
.cal-job.cancelled { background: #f1f1f1; color: #888; text-decoration: line-through; }
.job-list { margin-top: 14px; }
.job-row { display: flex; justify-content: space-between; gap: 10px; align-items: center; padding: 10px 0; border-bottom: 1px solid #eee; flex-wrap: wrap; }
.job-row .who { font-size: 14px; }
.job-row .who strong { display: block; }
@media (max-width: 720px) {
  .cal-day { min-height: 54px; }
  .cal-job { display: none; }
  .cal-day .dots { display: flex; gap: 2px; flex-wrap: wrap; }
  .cal-day .dot { width: 6px; height: 6px; border-radius: 50%; background: #114b8a; display: inline-block; }
  .form-grid { grid-template-columns: 1fr; }
}
@media (min-width: 721px) { .cal-day .dots { display: none; } }

/* ============ Quote / invoice PDF ============ */
.doc-print { position: absolute; left: -12000px; top: 0; width: 794px; }
.pd-doc { width: 794px; padding: 28px 34px; background: #fff; color: #222; font-family: Arial, Helvetica, sans-serif; font-size: 13px; box-sizing: border-box; }
.pd-head { display: flex; justify-content: space-between; gap: 20px; border-bottom: 3px solid #a01c1c; padding-bottom: 14px; margin-bottom: 18px; }
.pd-brand { display: flex; gap: 14px; align-items: flex-start; }
.pd-brand img { width: 120px; height: auto; }
.pd-company { font-size: 12px; line-height: 1.45; }
.pd-title h1 { margin: 0 0 8px; font-size: 26px; color: #a01c1c; text-align: right; letter-spacing: 0.02em; }
.pd-meta { border-collapse: collapse; font-size: 12px; margin-left: auto; }
.pd-meta th { text-align: left; padding: 2px 10px 2px 0; color: #666; font-weight: 600; white-space: nowrap; }
.pd-meta td { padding: 2px 0; }
.pd-parties { display: flex; gap: 24px; margin-bottom: 18px; }
.pd-parties > div { flex: 1; background: #f7f7f7; border-radius: 6px; padding: 10px 12px; line-height: 1.45; }
.pd-parties h4, .pd-notes h4, .pd-pay h4 { margin: 0 0 6px; font-size: 11px; text-transform: uppercase; color: #777; letter-spacing: 0.05em; }
.pd-ref { margin: 0 0 12px; }
.pd-items { width: 100%; border-collapse: collapse; margin-bottom: 18px; }
.pd-items th { background: #a01c1c; color: #fff; text-align: right; padding: 7px 8px; font-size: 12px; }
.pd-items th.desc { text-align: left; }
.pd-items td { padding: 7px 8px; border-bottom: 1px solid #e5e5e5; text-align: right; vertical-align: top; }
.pd-items td.desc { text-align: left; width: 55%; }
.pd-items tfoot td { border-bottom: none; font-weight: 600; }
.pd-items tfoot tr.grand td { font-size: 15px; border-top: 2px solid #a01c1c; }
.pd-notes { margin-bottom: 16px; line-height: 1.5; }
.pd-pay { background: #f7f7f7; border-radius: 6px; padding: 10px 12px; margin-bottom: 16px; }
.pd-pay .pd-meta { margin-left: 0; }
.pd-paid { background: #e2f6e9; color: #146c2e; border-radius: 6px; padding: 10px 12px; margin-bottom: 16px; font-weight: 600; }
.pd-footer { font-size: 11px; color: #666; border-top: 1px solid #ddd; padding-top: 10px; line-height: 1.5; }

/* ============ Settings ============ */
.settings-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.settings-tabs button { border: 1px solid #ddd; background: #fff; padding: 8px 12px; border-radius: 999px; font-size: 13px; cursor: pointer; }
.settings-tabs button.active { background: var(--primary, #a01c1c); color: #fff; border-color: var(--primary, #a01c1c); }
.email-status { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }


/* ============ Phone layouts ============ */
@media (max-width: 720px) {
  /* Lists become labelled rows instead of wide tables */
  .data-table.stack thead { display: none; }
  .data-table.stack tbody tr { display: block; padding: 10px 12px; border-bottom: 1px solid #eee; }
  .data-table.stack tbody tr:last-child { border-bottom: none; }
  .data-table.stack tbody td { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; border: none; padding: 3px 0; text-align: right; }
  .data-table.stack tbody td::before { content: attr(data-label); color: #777; font-size: 11px; text-transform: uppercase; letter-spacing: 0.03em; flex: 0 0 36%; text-align: left; padding-top: 2px; }
  .data-table.stack tbody td[data-label=""] { justify-content: flex-start; padding-top: 8px; }
  .data-table.stack tbody td[data-label=""]::before { display: none; }
  .data-table.stack tbody td.num { text-align: right; }
  .data-table.stack tbody td > .cell { flex: 1 1 auto; min-width: 0; }
  .data-table.stack tbody td[data-label=""] > .cell { width: 100%; }
  .data-table.stack tbody td[data-label=""] .inline-actions .btn { flex: 1 1 auto; }

  /* Quote / invoice lines: description on its own row, numbers underneath */
  .items-table thead { display: none; }
  .items-table tbody tr { display: flex; flex-wrap: wrap; gap: 6px 8px; align-items: flex-end; padding: 10px 0; border-bottom: 1px solid #eee; }
  .items-table tbody td { display: block; border: none; padding: 0; flex: 1 1 60px; }
  .items-table tbody td:first-child { flex: 0 0 100%; }
  .items-table tbody td[data-label]::before { content: attr(data-label); display: block; font-size: 10px; color: #777; text-transform: uppercase; letter-spacing: 0.03em; margin-bottom: 2px; }
  .items-table tbody td.line { flex: 1 1 80px; text-align: right; font-weight: 600; padding-bottom: 7px; }
  .items-table tbody td.line::before { content: 'Line'; display: block; font-size: 10px; color: #777; text-transform: uppercase; font-weight: 400; margin-bottom: 4px; }
  .items-table tbody td:last-child { flex: 0 0 28px; padding-bottom: 6px; }
  .items-table tfoot tr { display: flex; justify-content: space-between; padding: 3px 0; }
  .items-table tfoot td { border: none; padding: 2px 0; }
  .items-table tfoot td:last-child:empty { display: none; }

  .page-head .actions { width: 100%; }
  .page-head .actions .btn { flex: 1 1 auto; }
  .detail-grid { grid-template-columns: 1fr 1fr; }
  .card-grid { grid-template-columns: 1fr; }
  .main-nav a { padding: 12px 11px; font-size: 13.5px; }
}
