:root {
  --navy: #0f3c3a;
  --navy-dark: #0a2b29;
  --teal: #0e8074;
  --teal-dark: #0a6559;
  --teal-light: #e5f4f1;
  --accent: #0e8074;
  --accent-dark: #0a6559;
  --bg: #f6f8f8;
  --card: #ffffff;
  --border: #e2e8e7;
  --text: #1f2937;
  --muted: #6b7280;
  --danger: #dc2626;
  --success: #16a34a;
  --warn: #d97706;
  --sidebar-w: 216px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  /* The app shell below is pinned to exactly one viewport height and only
     .content scrolls internally — without this, a tall page pushes .app
     taller than the viewport and the whole page (topbar + sidebar included)
     scrolls with it, making the nav disappear as you scroll down. */
  height: 100vh;
  overflow: hidden;
}

.hidden { display: none !important; }
svg.icon { width: 18px; height: 18px; flex-shrink: 0; }

/* ---- Login ---- */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-dark) 100%);
}
.login-card {
  background: var(--card);
  padding: 40px;
  border-radius: 14px;
  width: 380px;
  box-shadow: 0 24px 64px rgba(0,0,0,0.28);
}
.login-logo { max-width: 160px; max-height: 70px; display: block; margin: 0 auto 16px; }
.login-card h1 { margin: 0 0 4px; font-size: 22px; color: var(--navy); text-align: center; letter-spacing: -0.2px; }
.login-card .muted { margin: 0 0 24px; color: var(--muted); font-size: 14px; text-align: center; }
.login-card label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0 4px; }
.login-card input { width: 100%; padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.login-card input:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-light); }
.error-text { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 16px; }

.google-signin-btn { display: flex; align-items: center; justify-content: center; gap: 10px; margin-top: 8px; }
.google-signin-btn .icon { flex-shrink: 0; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ---- App shell ---- */
.app { height: 100vh; display: flex; flex-direction: column; }

.topbar {
  height: 60px;
  background: #fff;
  color: var(--text);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 16px; letter-spacing: -0.2px; display: flex; align-items: center; gap: 10px; color: var(--navy); }
.brand svg { color: var(--teal); }
.topbar-logo { height: 30px; max-width: 120px; object-fit: contain; }
.settings-logo-preview { max-width: 200px; max-height: 90px; display: block; margin: 10px 0; border: 1px solid var(--border); border-radius: 8px; padding: 8px; background: #fff; }
.topbar-right { display: flex; align-items: center; gap: 14px; }

.user-chip { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--teal); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; letter-spacing: 0.3px; flex-shrink: 0;
}
.user-chip-text { display: flex; flex-direction: column; line-height: 1.25; }
.user-chip-name { font-size: 13px; font-weight: 600; color: var(--text); }
.user-chip-role { font-size: 11px; color: var(--muted); text-transform: capitalize; }

.layout { display: flex; flex: 1; min-height: 0; }

.sidebar {
  width: var(--sidebar-w);
  background: #fff;
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 16px 12px;
  flex-shrink: 0;
  gap: 2px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  text-align: left;
  background: none;
  border: none;
  padding: 10px 12px;
  font-size: 13.5px;
  color: #44514f;
  cursor: pointer;
  border-radius: 8px;
  font-family: inherit;
}
.nav-item svg { color: #7c8b89; }
.nav-item:hover { background: var(--bg); }
.nav-item.active { background: var(--teal-light); color: var(--teal-dark); font-weight: 600; }
.nav-item.active svg { color: var(--teal-dark); }

.content { flex: 1; padding: 28px 32px; overflow-y: auto; }

/* ---- Common elements ---- */
h2.page-title { margin: 0 0 4px; font-size: 21px; color: var(--navy); letter-spacing: -0.2px; }
.page-sub { color: var(--muted); font-size: 13px; margin-bottom: 22px; }

.toolbar { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; gap: 10px; flex-wrap: wrap; }
.toolbar-filters { display: flex; gap: 8px; flex-wrap: wrap; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  background: #fff;
  font-family: inherit;
}
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); }
.btn-secondary { background: #fff; border-color: var(--border); color: var(--text); }
.btn-secondary:hover { background: var(--bg); }
.btn-danger { background: #fff; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: #fdecec; }
.btn-ghost { background: transparent; border: none; color: inherit; }
.btn-ghost:hover { opacity: 0.7; }
.btn-block { width: 100%; margin-top: 18px; justify-content: center; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

select, input[type=text], input[type=number], input[type=date], input[type=datetime-local], input[type=email], input[type=password], textarea {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  width: 100%;
}
select:focus, input:focus, textarea:focus { outline: none; border-color: var(--teal); box-shadow: 0 0 0 3px var(--teal-light); }

.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  margin-bottom: 16px;
  box-shadow: 0 1px 2px rgba(16,25,23,0.03);
}

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 24px; }
.stat-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 18px; display: flex; align-items: flex-start; gap: 14px;
  box-shadow: 0 1px 2px rgba(16,25,23,0.03);
}
.stat-icon {
  width: 38px; height: 38px; border-radius: 10px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
}
.stat-icon svg { width: 19px; height: 19px; }
.stat-icon.teal { background: var(--teal-light); color: var(--teal-dark); }
.stat-icon.blue { background: #e8eefd; color: #2f6fed; }
.stat-icon.amber { background: #fef3c7; color: #b45309; }
.stat-icon.violet { background: #ede9fe; color: #6d28d9; }
.stat-card .stat-value { font-size: 24px; font-weight: 700; color: var(--navy); line-height: 1.2; }
.stat-card .stat-label { font-size: 12px; color: var(--muted); margin-top: 2px; }

table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: 10px; overflow: hidden; }
table th, table td { padding: 11px 14px; text-align: left; font-size: 13px; border-bottom: 1px solid var(--border); }
table th { background: #fafbfb; font-weight: 600; color: var(--muted); text-transform: uppercase; font-size: 10.5px; letter-spacing: 0.5px; }
table tr:last-child td { border-bottom: none; }
table tr:hover td { background: #fafbfb; }
.table-wrap { border: 1px solid var(--border); border-radius: 12px; overflow-x: auto; overflow-y: hidden; box-shadow: 0 1px 2px rgba(16,25,23,0.03); }
.actions-cell { white-space: nowrap; display: flex; gap: 6px; }

.badge { display: inline-block; padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-open, .badge-draft { background: #e0e7ff; color: #3730a3; }
.badge-closed, .badge-void { background: #f3f4f6; color: #6b7280; }
.badge-pending, .badge-sent { background: #fef3c7; color: #92400e; }
.badge-paid { background: #dcfce7; color: #166534; }
.badge-in-progress { background: #dbeafe; color: #1e40af; }
.badge-done { background: #dcfce7; color: #166534; }
.badge-high { background: #fee2e2; color: #991b1b; }
.badge-normal { background: #f3f4f6; color: #374151; }
.badge-low { background: #f3f4f6; color: #6b7280; }
.badge-success { background: #dcfce7; color: #166534; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-partial { background: #fef3c7; color: #92400e; }
.badge-social { background: #dbeafe; color: #1e40af; }
.badge-promotions { background: #fce7f3; color: #9d174d; }
.badge-updates { background: #ede9fe; color: #6d28d9; }
.badge-forums { background: #f3f4f6; color: #374151; }
.badge-overdue { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-restricted { background: #fee2e2; color: #991b1b; margin-left: 6px; }

.empty-state { text-align: center; padding: 50px 20px; color: var(--muted); }

/* ---- Modal ---- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(10, 20, 19, 0.5);
  display: flex; align-items: center; justify-content: center; z-index: 100;
  padding: 20px;
}
.modal {
  background: #fff; border-radius: 12px; width: 100%; max-width: 520px;
  max-height: 88vh; display: flex; flex-direction: column; overflow: hidden;
  box-shadow: 0 24px 64px rgba(0,0,0,0.25);
}
.modal.modal-wide { max-width: 860px; }
.modal-header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 16px; }
.modal-header .btn-ghost { font-size: 20px; line-height: 1; }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-body label { display: block; font-size: 12px; font-weight: 600; margin: 10px 0 4px; color: var(--muted); }
.modal-body .form-row { display: flex; gap: 12px; }
.modal-body .form-row > div { flex: 1; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; flex-wrap: wrap; }
.field-error { color: var(--danger); font-size: 12px; margin-top: 8px; }
/* .modal-body label (below) targets every <label>, including ones with this
   class, at equal-or-higher specificity — qualify with .modal-body so this
   reliably wins instead of silently losing to display:block. */
.modal-body .checkbox-row { display: flex; align-items: center; gap: 8px; margin-top: 10px; }
.modal-body .checkbox-row input { width: auto; }
.helper-text { font-size: 12px; color: var(--muted); margin-top: 4px; }

.search-result-row {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 8px; border-radius: 8px; cursor: pointer;
}
.search-result-row:hover { background: var(--teal-light); }
.search-result-row svg { color: var(--teal-dark); }
.search-result-title { font-size: 13px; font-weight: 600; color: var(--text); }
.search-result-sub { font-size: 12px; color: var(--muted); }

/* ---- Appointments (Google-Calendar-style grid) ---- */
.appt-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 10px; margin-bottom: 14px;
}
.appt-toolbar-left, .appt-toolbar-right { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.appt-range-label { font-weight: 600; margin-left: 6px; font-size: 14px; }

/* Month view */
.appt-month-grid { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: #fff; }
.appt-month-dow { display: grid; grid-template-columns: repeat(7, 1fr); background: var(--bg); border-bottom: 1px solid var(--border); }
.appt-month-dow > div { padding: 8px; text-align: center; font-size: 12px; font-weight: 600; color: var(--muted); }
.appt-month-days { display: grid; grid-template-columns: repeat(7, 1fr); grid-auto-rows: minmax(108px, 1fr); }
.appt-month-cell {
  border-right: 1px solid var(--border); border-bottom: 1px solid var(--border);
  padding: 6px; cursor: pointer; overflow: hidden; display: flex; flex-direction: column; gap: 4px;
}
.appt-month-cell:hover { background: var(--teal-light); }
.appt-month-cell:nth-child(7n) { border-right: none; }
.appt-month-cell.appt-dim { background: #fafbfb; }
.appt-month-cell.appt-dim .appt-month-daynum { color: var(--muted); }
.appt-month-daynum {
  font-size: 13px; font-weight: 600; width: 24px; height: 24px;
  display: flex; align-items: center; justify-content: center; border-radius: 50%;
}
.appt-month-daynum.appt-today { background: var(--teal); color: #fff; }
.appt-month-events { display: flex; flex-direction: column; gap: 2px; }
.appt-chip {
  background: var(--teal-light); color: var(--teal-dark); font-size: 11px; padding: 2px 6px;
  border-radius: 5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; cursor: grab;
}
.appt-chip:active { cursor: grabbing; }
.appt-more { font-size: 11px; color: var(--muted); cursor: pointer; padding: 0 6px; }
.appt-more:hover { text-decoration: underline; }
.appt-drop-target { background: var(--teal-light) !important; outline: 2px dashed var(--teal); outline-offset: -2px; }

/* Week / Day time grid */
.appt-timegrid { border: 1px solid var(--border); border-radius: 12px; overflow: hidden; background: #fff; }
.appt-timegrid-header { display: flex; border-bottom: 1px solid var(--border); background: var(--bg); }
.appt-timegrid-gutter { width: 56px; flex-shrink: 0; font-size: 11px; color: var(--muted); padding: 6px; }
.appt-timegrid-daylabel { flex: 1; text-align: center; padding: 8px 4px; font-size: 12px; font-weight: 600; color: var(--muted); border-left: 1px solid var(--border); }
.appt-timegrid-daylabel.appt-today { color: var(--teal-dark); }
.appt-daylabel-num { display: block; font-size: 15px; }
.appt-allday-row { display: flex; border-bottom: 1px solid var(--border); min-height: 30px; }
.appt-allday-cell { flex: 1; border-left: 1px solid var(--border); padding: 2px 4px; display: flex; flex-direction: column; gap: 2px; }
.appt-timegrid-body { display: flex; max-height: 620px; overflow-y: auto; position: relative; }
.appt-timegrid-gutter-col { width: 56px; flex-shrink: 0; }
.appt-hour-label { font-size: 11px; color: var(--muted); text-align: right; padding-right: 8px; box-sizing: border-box; transform: translateY(-6px); }
.appt-day-col { flex: 1; position: relative; border-left: 1px solid var(--border); user-select: none; }
.appt-slot { border-top: 1px solid #f0f2f2; box-sizing: border-box; }
.appt-slot:nth-child(odd) { border-top-color: var(--border); }
.appt-block {
  position: absolute; left: 2px; right: 2px; background: var(--teal); color: #fff; border-radius: 6px;
  padding: 2px 6px; font-size: 11px; overflow: hidden; cursor: grab; box-shadow: 0 1px 3px rgba(0,0,0,0.15); z-index: 2;
}
.appt-block:active { cursor: grabbing; }
.appt-block-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appt-block-time { font-size: 10px; opacity: 0.85; }
.appt-create-ghost {
  position: absolute; left: 2px; right: 2px; background: rgba(14,128,116,0.25);
  border: 1px dashed var(--teal); border-radius: 6px; z-index: 1; pointer-events: none;
}

/* Appointment form */
.appt-attendee-list {
  display: flex; flex-wrap: wrap; gap: 8px 16px; border: 1px solid var(--border);
  border-radius: 8px; padding: 10px; max-height: 140px; overflow-y: auto;
}
/* Higher specificity than the generic ".modal-body label" rule, which would
   otherwise force these into block display with the wrong size/color. */
.appt-attendee-list .appt-attendee-item { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 400; color: var(--text); margin: 0; }
.appt-attendee-list .appt-attendee-item input { width: auto; }

/* ---- Invoicing (Wave-style) ---- */
.inv-summary-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.inv-summary-card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px 18px; box-shadow: 0 1px 2px rgba(16,25,23,0.03);
}
.inv-summary-label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.4px; }
.inv-summary-value { font-size: 22px; font-weight: 700; color: var(--navy); margin-top: 6px; }
.inv-summary-card.inv-summary-danger .inv-summary-value { color: #c62828; }
.inv-summary-card.inv-summary-success .inv-summary-value { color: #2e7d32; }

/* Line-item editor: description | qty | rate | amount | remove-button */
.inv-lines-header, .inv-line-row {
  display: grid; grid-template-columns: 1fr 70px 90px 90px 32px; gap: 8px; align-items: center;
}
.inv-lines-header { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; padding: 0 2px; margin-top: 10px; }
.inv-line-row { margin-top: 6px; }
.inv-line-row input { margin: 0; }
.inv-li-amount { font-size: 13px; text-align: right; padding-right: 4px; color: var(--text); }
.inv-li-remove { padding: 0; width: 28px; height: 28px; line-height: 1; font-size: 16px; }

.inv-totals-box { max-width: 300px; margin-left: auto; margin-top: 16px; }
.inv-totals-box.inv-totals-box-preview { margin-top: 14px; }
.inv-totals-box > div { display: flex; justify-content: space-between; padding: 4px 2px; font-size: 13px; color: var(--muted); }
.inv-totals-box .inv-totals-grand { border-top: 1px solid var(--border); margin-top: 4px; padding-top: 8px; font-size: 15px; font-weight: 700; color: var(--navy); }

.inv-preview-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }

/* ---- Email: rich text compose ---- */
.rte-toolbar { display: flex; gap: 4px; margin-top: 4px; margin-bottom: 4px; flex-wrap: wrap; }
.rte-toolbar .rte-btn {
  padding: 4px 9px; font-size: 13px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--card); cursor: pointer; color: var(--text); line-height: 1.4;
}
.rte-toolbar .rte-btn:hover { background: var(--bg); }
.rte-editor {
  min-height: 160px; max-height: 320px; overflow: auto; border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 12px; font-size: 13.5px; line-height: 1.5; background: var(--card);
}
.rte-editor:focus { outline: none; border-color: var(--navy); }
.rte-editor ul, .rte-editor ol { margin: 6px 0; padding-left: 22px; }
.email-quote {
  margin: 6px 0 0; padding-left: 12px; border-left: 2px solid var(--border);
  color: var(--muted);
}

/* ---- Email: recipient autocomplete (To/Cc/Bcc) ---- */
.recipient-field { position: relative; }
.recipient-suggest {
  position: absolute; top: 100%; left: 0; right: 0; z-index: 50;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  margin-top: 4px; max-height: 220px; overflow-y: auto;
  box-shadow: 0 4px 16px rgba(16,25,23,0.08);
}
.recipient-suggest.hidden { display: none; }
.recipient-suggest-row { padding: 8px 12px; cursor: pointer; }
.recipient-suggest-row.active, .recipient-suggest-row:hover { background: var(--bg); }
.recipient-suggest-name { font-size: 13px; color: var(--text); font-weight: 500; }
.recipient-suggest-email { font-size: 12px; color: var(--muted); }

/* ---- Email: star toggle ---- */
.star-btn {
  background: none; border: none; cursor: pointer; font-size: 16px; line-height: 1;
  color: var(--muted); padding: 2px;
}
.star-btn.starred { color: #e0a80e; }

.inbox-unread-badge {
  display: inline-block; min-width: 18px; padding: 1px 6px; margin-left: 2px;
  border-radius: 10px; background: rgba(255,255,255,0.25); color: inherit;
  font-size: 11px; font-weight: 700; line-height: 16px; text-align: center;
}
.btn-secondary .inbox-unread-badge { background: var(--accent); color: #fff; }

/* ---- Notifications bell ---- */
.notif-bell-wrap { position: relative; }
.notif-bell-btn { position: relative; padding: 8px 10px; }
.notif-badge {
  position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 4px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: 10px; font-weight: 700;
  line-height: 18px; text-align: center; box-shadow: 0 0 0 2px #fff;
}
.notif-badge.hidden { display: none; }
.notif-dropdown {
  position: absolute; top: 100%; right: 0; z-index: 60; margin-top: 8px;
  width: 360px; max-height: 420px; overflow-y: auto;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 28px rgba(16,25,23,0.14);
}
.notif-dropdown.hidden { display: none; }
.notif-dropdown-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; border-bottom: 1px solid var(--border); font-weight: 600;
}
.notif-dropdown-header button { font-size: 12px; font-weight: 500; }
.notif-email-row {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; background: var(--teal-light);
}
.notif-email-row:hover { filter: brightness(0.97); }
.notif-item { display: flex; align-items: flex-start; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--border); cursor: pointer; }
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--bg); }
.notif-item.unread { background: #f0f9f7; }
.notif-item-seen { display: flex; align-items: center; padding-top: 2px; cursor: pointer; }
.notif-item-seen input[type="checkbox"] { width: 16px; height: 16px; cursor: pointer; accent-color: var(--accent); }
.notif-item-main { flex: 1; min-width: 0; }
.notif-item-title { font-size: 13px; color: var(--text); font-weight: 600; }
.notif-item.unread .notif-item-title::before { content: '\25CF'; color: var(--accent); font-size: 8px; margin-right: 6px; vertical-align: middle; }
.notif-item-body { font-size: 12px; color: var(--muted); margin-top: 2px; }
.conflict-results { margin: 6px 0 14px; padding: 10px 12px; background: #fffbeb; border: 1px solid var(--warn); border-radius: 8px; }
.conflict-results.hidden { display: none; }
.conflict-header { font-size: 13px; font-weight: 600; color: #92400e; margin-bottom: 6px; }
.conflict-item { font-size: 12.5px; color: #78350f; padding: 3px 0; }
.notif-item-time { font-size: 11px; color: var(--muted); margin-top: 4px; }
.notif-empty { padding: 24px 14px; text-align: center; color: var(--muted); font-size: 13px; }
.contact-doc-list { display: flex; flex-direction: column; gap: 4px; }
.contact-doc-item { font-size: 13px; color: var(--accent); text-decoration: none; padding: 4px 0; border-bottom: 1px solid var(--border); }
.contact-doc-item:last-child { border-bottom: none; }
.contact-doc-item:hover { text-decoration: underline; }
.client-detail-info p { margin: 4px 0; font-size: 13px; }
.client-row { cursor: pointer; }

/* ---- Email: attachments on a received message ---- */
.attachment-section { margin-top: 12px; }
.attachment-chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 6px; }
.attachment-chip {
  display: flex; align-items: center; gap: 8px; cursor: pointer;
  border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; background: var(--card);
}
.attachment-chip:hover { background: var(--bg); }
.attachment-chip-name { font-size: 13px; color: var(--text); }
.attachment-chip-download {
  color: var(--muted); text-decoration: none; font-size: 14px; padding: 0 2px;
}
.attachment-chip-download:hover { color: var(--navy); }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--navy-dark); color: #fff; padding: 10px 20px; border-radius: 8px;
  font-size: 13px; z-index: 200; box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.toast.error { background: var(--danger); }

@media (max-width: 800px) {
  .stat-grid, .inv-summary-grid { grid-template-columns: repeat(2, 1fr); }
  .sidebar { width: 160px; }
  .user-chip-text { display: none; }
}

/* ---- Mobile (phones, narrow tablets) ----
   Below this width there isn't room for a fixed left sidebar next to page
   content, so the sidebar becomes a horizontally-scrollable strip above the
   content instead of down the side. Modals become near-full-screen sheets
   (easier to fill out a form with an on-screen keyboard than a small
   centered popup), and anything laid out in side-by-side columns
   (form-row, detail-grid, toolbars) stacks vertically instead. */
@media (max-width: 640px) {
  .topbar { padding: 0 14px; }
  .brand span { display: none; } /* keep the logo/icon, drop the wordmark to save space */

  .layout { flex-direction: column; }
  .sidebar {
    width: 100%; flex-direction: row; overflow-x: auto; -webkit-overflow-scrolling: touch;
    padding: 8px 10px; gap: 4px; border-right: none; border-bottom: 1px solid var(--border);
  }
  .nav-item { flex-shrink: 0; white-space: nowrap; }

  .content { padding: 16px; }

  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar-filters { width: 100%; }
  .toolbar > .btn, .toolbar > a.btn { width: 100%; justify-content: center; }

  .detail-grid { grid-template-columns: 1fr; }

  .modal-body .form-row { flex-direction: column; gap: 0; }

  /* Anchor modals to the bottom of the screen as a full-width sheet rather
     than a small centered card — much easier to use one-handed and leaves
     room above for the on-screen keyboard. */
  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal { max-width: 100%; width: 100%; max-height: 94vh; border-radius: 14px 14px 0 0; }

  .appt-toolbar { justify-content: flex-start; }
  .appt-month-days { grid-auto-rows: minmax(70px, 1fr); }
  .appt-month-daynum { width: 20px; height: 20px; font-size: 12px; }

  table { min-width: 560px; } /* let .table-wrap's horizontal scroll kick in instead of squishing columns unreadably */
}

@media (max-width: 460px) {
  .stat-grid, .inv-summary-grid { grid-template-columns: 1fr; }

  /* The line-item editor's 5-column grid (description/qty/rate/amount/remove)
     has no room to breathe this narrow — drop the column header labels and
     let each line wrap onto multiple rows within the grid instead. */
  .inv-lines-header { display: none; }
  .inv-line-row {
    grid-template-columns: 1fr 1fr; grid-template-areas: "desc desc" "qty rate" "amount remove";
    gap: 4px 8px; padding-bottom: 10px; margin-bottom: 6px; border-bottom: 1px dashed var(--border);
  }
  .inv-line-row input:nth-child(1) { grid-area: desc; }
  .inv-line-row input:nth-child(2) { grid-area: qty; }
  .inv-line-row input:nth-child(3) { grid-area: rate; }
  .inv-li-amount { grid-area: amount; }
  .inv-li-remove { grid-area: remove; justify-self: end; }
}

/* ---- Numbered pager (Activity Log, etc.) ---- */
.pager {
  display: flex; align-items: center; gap: 4px; margin-top: 14px; flex-wrap: wrap;
}
.pager-ellipsis {
  color: var(--muted); padding: 0 4px; font-size: 13px;
}

/* ---- Detail pages (Matter Detail, Client Detail) ---- */
.back-link {
  display: inline-block; margin-bottom: 10px; font-size: 13px; color: var(--muted); text-decoration: none;
}
.back-link:hover { color: var(--navy); text-decoration: underline; }
.detail-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start;
}
.detail-list { margin: 6px 0 0 18px; padding: 0; font-size: 13px; }
.detail-list li { margin-bottom: 4px; }
