/* WebXperts CRM */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand: #0f1923;
  --brand2: #1a2735;
  --blue: #3b82f6;
  --blue-d: #2563eb;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --ink: #0f172a;
  --ink2: #334155;
  --muted: #64748b;
  --border: #e2e8f0;
  --bg: #f1f5f9;
  --white: #ffffff;
  --surface: #f8fafc;
  --ff: 'DM Sans', system-ui, sans-serif;
}

html, body { height: 100%; font-family: var(--ff); background: var(--bg); color: var(--ink); }

/* ── LOGIN ── */
body.page-login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(ellipse at 50% 0%, rgba(59,130,246,.25) 0%, transparent 70%), var(--brand);
  overflow-y: auto;
}
.login-wrap { display: flex; flex-direction: column; align-items: center; padding: 24px; width: 100%; }
.login-card {
  background: var(--brand2);
  border: 1px solid rgba(255,255,255,.08);
  border-radius: 20px;
  padding: 40px 44px;
  width: 100%;
  max-width: 420px;
  box-shadow: 0 24px 60px rgba(0,0,0,.4);
}
.login-brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 20px; font-weight: 500; color: #fff; margin-bottom: 28px;
}
.login-brand strong { font-weight: 800; }
.login-card h1 { font-size: 26px; font-weight: 800; color: #fff; margin-bottom: 6px; letter-spacing: -.4px; }
.login-sub { color: rgba(255,255,255,.45); font-size: 14px; margin-bottom: 24px; }
.login-error {
  background: rgba(239,68,68,.15); border: 1px solid rgba(239,68,68,.35);
  color: #fca5a5; padding: 10px 14px; border-radius: 10px;
  font-size: 13.5px; font-weight: 600; margin-bottom: 18px;
}
.form-field { margin-bottom: 16px; }
.form-field label {
  display: block; font-size: 11.5px; font-weight: 700;
  color: rgba(255,255,255,.4); text-transform: uppercase;
  letter-spacing: .6px; margin-bottom: 7px;
}
.form-field input, .form-field select, .form-field textarea {
  width: 100%;
  background: rgba(255,255,255,.06);
  border: 1.5px solid rgba(255,255,255,.1);
  border-radius: 10px; padding: 12px 14px;
  font-size: 14px; font-family: var(--ff); color: #fff; outline: none;
  transition: border-color .15s, background .15s;
}
.form-field input::placeholder { color: rgba(255,255,255,.22); }
.form-field input:focus { border-color: var(--blue); background: rgba(59,130,246,.08); }
.remember {
  display: flex; align-items: center; gap: 8px;
  color: rgba(255,255,255,.5); font-size: 13px; cursor: pointer; margin-bottom: 22px;
}
.remember input { width: auto; accent-color: var(--blue); }
.login-btn {
  width: 100%; background: var(--blue); color: #fff; border: none;
  border-radius: 12px; padding: 14px; font-size: 15px; font-weight: 700;
  font-family: var(--ff); cursor: pointer; transition: background .15s, transform .1s;
  box-shadow: 0 4px 16px rgba(59,130,246,.35);
}
.login-btn:hover { background: var(--blue-d); transform: translateY(-1px); }
.login-footer { color: rgba(255,255,255,.2); font-size: 12px; margin-top: 20px; }

/* ── APP LAYOUT ── */
body:not(.page-login) { overflow: hidden; }
.app-layout { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

.sidebar {
  width: 220px; flex-shrink: 0;
  background: var(--brand);
  display: flex; flex-direction: column;
  height: 100vh; height: 100dvh; overflow: hidden; z-index: 100;
  transition: transform .25s;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px; font-size: 17px; font-weight: 500; color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.07); flex-shrink: 0;
}
.sidebar-brand strong { font-weight: 800; }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 8px; display: flex; flex-direction: column; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 10px; border-radius: 10px;
  color: rgba(255,255,255,.5); text-decoration: none;
  font-size: 13.5px; font-weight: 600; transition: all .12s;
}
.nav-link:hover { background: rgba(255,255,255,.07); color: rgba(255,255,255,.9); }
.nav-link.active { background: rgba(59,130,246,.2); color: #60a5fa; }
.nav-link svg { width: 17px; height: 17px; flex-shrink: 0; }

/* Unread leads count badge */
.nav-badge {
  margin-left: auto;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  border-radius: 10px;
  padding: 2px 7px;
  min-width: 20px;
  text-align: center;
  line-height: 1.3;
  box-shadow: 0 1px 2px rgba(0,0,0,0.2);
}
.nav-link.active .nav-badge { background: #fff; color: #ef4444; }

/* Lead row visual states */
.lead-row-new { background: rgba(239, 68, 68, 0.04); border-left: 3px solid #ef4444; cursor: pointer; }
.lead-row-new td:first-child { padding-left: calc(14px - 3px); }
.lead-row-new strong::before {
  content: '';
  display: inline-block;
  width: 8px;
  height: 8px;
  background: #ef4444;
  border-radius: 50%;
  margin-right: 7px;
  vertical-align: middle;
  margin-bottom: 2px;
}
.data-table tbody tr { cursor: pointer; }
.data-table tbody tr:hover { background: rgba(59, 130, 246, 0.04); }
.sidebar-footer {
  padding: 10px; border-top: 1px solid rgba(255,255,255,.07);
  display: flex; align-items: center; gap: 8px; flex-shrink: 0;
}
.user-avatar {
  width: 32px; height: 32px; border-radius: 8px;
  background: linear-gradient(135deg, #3b82f6, #1d4ed8);
  display: grid; place-items: center;
  font-size: 13px; font-weight: 800; color: #fff; flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 700; color: rgba(255,255,255,.9); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: rgba(255,255,255,.3); }
.logout-btn {
  display: grid; place-items: center; width: 28px; height: 28px;
  border-radius: 8px; color: rgba(255,255,255,.3); text-decoration: none;
  transition: all .15s; flex-shrink: 0;
}
.logout-btn:hover { background: rgba(239,68,68,.15); color: #f87171; }

.app-body { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.topbar {
  height: 52px; background: var(--white);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 20px; gap: 12px; flex-shrink: 0;
}
.menu-btn { display: none; background: none; border: none; cursor: pointer; color: var(--muted); padding: 6px; border-radius: 8px; }
.menu-btn:hover { background: var(--surface); }
.topbar-title { font-size: 15px; font-weight: 800; color: var(--ink); letter-spacing: -.3px; }
.page-content { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.sidebar-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 99; }

/* ── INNER CONTENT ── */
.content-inner { padding: 24px; max-width: 1200px; }
.page-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 22px; gap: 12px; flex-wrap: wrap;
}
.page-header h1 { font-size: 22px; font-weight: 800; letter-spacing: -.4px; }
.toolbar { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; flex-wrap: wrap; }

/* ── BUTTONS ── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px; border-radius: 10px;
  font-size: 13.5px; font-weight: 700; cursor: pointer; border: none;
  font-family: var(--ff); transition: all .15s; text-decoration: none; line-height: 1;
}
.btn-primary { background: var(--blue); color: #fff; box-shadow: 0 2px 8px rgba(59,130,246,.3); }
.btn-primary:hover { background: var(--blue-d); transform: translateY(-1px); }
.btn-ghost { background: transparent; border: 1.5px solid var(--border); color: var(--muted); }
.btn-ghost:hover { border-color: var(--blue); color: var(--blue); }
.btn-danger { background: var(--red); color: #fff; }
.btn-danger:hover { background: #dc2626; }
.btn-sm { padding: 6px 12px; font-size: 12.5px; border-radius: 8px; }

/* ── STATS ── */
.stats-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 22px; }
.stat-card { background: var(--white); border: 1px solid var(--border); border-radius: 16px; padding: 18px; }
.loading-card { display: flex; align-items: center; justify-content: center; min-height: 90px; }
.stat-icon { font-size: 24px; margin-bottom: 10px; }
.stat-label { font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 22px; font-weight: 800; color: var(--ink); margin-top: 4px; font-variant-numeric: tabular-nums; }

/* ── CARD ── */
.card { background: var(--white); border: 1px solid var(--border); border-radius: 16px; padding: 20px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.card-header h3 { font-size: 14.5px; font-weight: 700; }
.two-col { display: grid; grid-template-columns: 1.6fr 1fr; gap: 16px; }

/* ── TABLE ── */
.table-wrap { border-radius: 16px; border: 1px solid var(--border); overflow: hidden; background: var(--white); }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: left; padding: 11px 16px;
  color: var(--muted); font-size: 11.5px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .5px;
  background: var(--surface); border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); color: var(--ink2); vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table tr:hover td { background: var(--surface); }
.amount { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ── BADGES ── */
.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 20px; font-size: 11.5px; font-weight: 700; }
.badge-active, .badge-paid  { background: #d1fae5; color: #065f46; }
.badge-prospect             { background: #ede9fe; color: #5b21b6; }
.badge-draft                { background: var(--surface); color: var(--muted); border: 1px solid var(--border); }
.badge-sent                 { background: #dbeafe; color: #1e40af; }
.badge-overdue              { background: #fee2e2; color: #991b1b; }
.badge-inactive, .badge-archived { background: #f1f5f9; color: #64748b; border: 1px solid var(--border); }

/* ── SEARCH ── */
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--white); border: 1.5px solid var(--border);
  border-radius: 10px; padding: 0 12px; min-width: 220px;
}
.search-box:focus-within { border-color: var(--blue); }
.search-box input { all: unset; padding: 9px 0; font-size: 14px; width: 100%; color: var(--ink); }
.select-input {
  border: 1.5px solid var(--border); border-radius: 10px;
  padding: 9px 12px; font-size: 13.5px; font-family: var(--ff);
  background: var(--white); color: var(--ink); cursor: pointer; outline: none;
}
.select-input:focus { border-color: var(--blue); }

/* ── FORMS (light modal) ── */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.form-field.full { grid-column: 1 / -1; }
.modal .form-field label {
  display: block; font-size: 11.5px; font-weight: 700;
  color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 6px;
}
.modal .form-field input,
.modal .form-field select,
.modal .form-field textarea {
  width: 100%; border: 1.5px solid var(--border); border-radius: 10px;
  padding: 10px 13px; font-size: 14px; font-family: var(--ff);
  color: var(--ink); background: var(--white); outline: none; transition: border-color .15s;
}
.modal .form-field input:focus,
.modal .form-field select:focus,
.modal .form-field textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(59,130,246,.1); }
.modal .form-field textarea { resize: vertical; min-height: 80px; }

/* ── MODAL ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); backdrop-filter: blur(4px);
  z-index: 1000; display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal {
  background: var(--white); border-radius: 20px;
  box-shadow: 0 24px 60px rgba(0,0,0,.2);
  width: 100%; max-width: 600px; max-height: 90vh; overflow-y: auto;
  animation: modal-in .2s ease;
}
.modal-lg { max-width: 820px; }
@keyframes modal-in { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--white); z-index: 1;
}
.modal-header h2 { font-size: 17px; font-weight: 800; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 18px; width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center; }
.modal-close:hover { background: var(--surface); color: var(--ink); }
.modal-body { padding: 22px; }
.modal-footer {
  display: flex; justify-content: flex-end; align-items: center; gap: 10px;
  padding: 14px 22px; border-top: 1px solid var(--border);
  position: sticky; bottom: 0; background: var(--white);
}

/* ── INVOICE LINE ITEMS (modal) ── */
.inv-line-header {
  display: grid; grid-template-columns: 3fr .8fr 1fr 1fr .3fr;
  gap: 8px; padding: 4px; font-size: 11px; font-weight: 700;
  color: var(--muted); text-transform: uppercase; letter-spacing: .4px;
}
.inv-line-header span:nth-child(2),
.inv-line-header span:nth-child(3),
.inv-line-header span:nth-child(4) { text-align: right; }
.inv-line-row {
  display: grid; grid-template-columns: 3fr .8fr 1fr 1fr .3fr;
  gap: 8px; align-items: center; margin-bottom: 6px;
}
.inv-line-desc, .inv-line-price, .inv-line-qty {
  width: 100%; border: 1.5px solid var(--border); border-radius: 8px;
  padding: 9px 10px; font-size: 14px; font-family: var(--ff);
  color: var(--ink); background: var(--white); outline: none;
  box-sizing: border-box;
}
.inv-line-desc:focus, .inv-line-price:focus, .inv-line-qty:focus { border-color: var(--blue); }
.inv-line-qty { text-align: center; cursor: pointer; }
.inv-line-price { text-align: right; }
.inv-line-total { text-align: right; font-weight: 600; font-size: 14px; font-variant-numeric: tabular-nums; }
.inv-line-remove { background: none; border: none; color: #cbd5e1; cursor: pointer; font-size: 18px; padding: 0; }
.inv-line-remove:hover { color: var(--red); }

/* ── OLD INVOICE ITEMS (keep for compat) ── */
.items-section { margin-bottom: 0; }
.inv-totals { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; padding: 14px 0 0; }
.totals-row { display: flex; gap: 48px; font-size: 13.5px; color: var(--ink2); }
.total-row { font-size: 17px; font-weight: 800; color: var(--ink); padding-top: 8px; border-top: 1.5px solid var(--border); margin-top: 4px; }
.totals-row span:last-child { min-width: 100px; text-align: right; font-variant-numeric: tabular-nums; }

/* ── UTILITY ── */
.spinner { width: 24px; height: 24px; border: 3px solid var(--border); border-top-color: var(--blue); border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.empty-state { padding: 60px 24px; text-align: center; color: var(--muted); font-size: 14px; }
.empty-msg { padding: 24px; text-align: center; color: var(--muted); font-size: 13.5px; }
.muted { color: var(--muted); }

/* ── LIST ROW (dashboard) ── */
.list-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.list-row:last-child { border-bottom: none; }

/* ── TOASTS ── */
#toasts { position: fixed; bottom: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column-reverse; gap: 8px; pointer-events: none; }
.toast { background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 13.5px; font-weight: 600; box-shadow: 0 8px 24px rgba(0,0,0,.2); animation: toast-in .2s ease; max-width: 300px; pointer-events: all; }
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }
@keyframes toast-in { from { transform: translateY(8px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

/* ── INVOICE ACTION BUTTONS ── */
.inv-actions { text-align: right; white-space: nowrap; }

/* Mobile cards: hidden on desktop */
.inv-cards-mobile { display: none; }
.inv-table-desktop { display: block; }

/* ── INVOICE CARD (mobile) ── */
.inv-card {
  display: flex; align-items: center; gap: 10px; padding: 12px 14px;
  border-bottom: 1px solid var(--border); cursor: pointer; transition: background .1s;
}
.inv-card:active { background: var(--surface); }
.inv-card:last-child { border-bottom: none; }
.inv-card-check { flex-shrink: 0; }
.inv-card-check input { width: 18px; height: 18px; }
.inv-card-body { flex: 1; min-width: 0; }
.inv-card-top { display: flex; align-items: center; gap: 6px; font-size: 13.5px; }
.inv-card-mid { font-size: 14px; color: var(--ink2); margin: 3px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.inv-card-bot { display: flex; align-items: center; justify-content: space-between; }

/* ── XERO DROPDOWN ── */
.xero-dd-opt {
  padding: 10px 14px; font-size: 13px; font-weight: 600; color: var(--ink2);
  cursor: pointer; white-space: nowrap; transition: background .1s;
}
.xero-dd-opt:hover { background: #eff6ff; color: #1a73e8; }
.xero-dd-opt:not(:last-child) { border-bottom: 1px solid var(--border); }

/* ── RESPONSIVE ── */
@media (max-width: 768px) {
  .menu-btn { display: grid; }
  .sidebar { position: fixed; top: 0; left: 0; bottom: 0; transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); box-shadow: 4px 0 40px rgba(0,0,0,.4); }
  .sidebar-overlay.show { display: block; }
  .content-inner { padding: 12px; padding-bottom: 80px; }
  .page-content { padding-bottom: env(safe-area-inset-bottom, 0px); }
  .two-col { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }

  /* Tables: keep for other pages */
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .data-table th, .data-table td { padding: 9px 8px; font-size: 12px; overflow: hidden; text-overflow: ellipsis; }
  .data-table .btn-sm { padding: 4px 7px; font-size: 10.5px; }

  /* Clients: hide cols to fit */
  .data-table .col-email,
  .data-table .col-city,
  .data-table .col-mrr,
  .data-table .col-report { display: none; }

  /* Invoices: hide cols to fit */
  .data-table .col-exgst,
  .data-table .col-gst,
  .data-table .col-balance,
  .data-table .col-date { display: none; }

  /* Bulk select bar */
  .bulk-bar {
    position: sticky; bottom: 0; left: 0; right: 0; z-index: 50;
    background: var(--ink); color: #fff; padding: 12px 16px;
    border-radius: 12px; margin: 8px 0 0; box-shadow: 0 -4px 20px rgba(0,0,0,.2);
    display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  }

  /* Modal full-screen on mobile */
  .modal-overlay { padding: 0; align-items: stretch; }
  .modal, .modal-lg { max-width: 100%; max-height: 100vh; border-radius: 0; }
  .modal-body { padding: 16px; }
  .modal-header { padding: 14px 16px; }

  /* Modal footer: wrap buttons */
  .modal-footer { flex-wrap: wrap; gap: 8px; padding: 12px 16px; }
  .modal-footer .btn { font-size: 12px; padding: 8px 12px; }

  /* Invoice line items: stack on mobile */
  .inv-line-header { display: none; }
  .inv-line-row {
    grid-template-columns: 1fr;
    gap: 6px; padding: 12px; margin-bottom: 10px;
    border: 1.5px solid var(--border); border-radius: 10px;
    background: var(--surface); position: relative;
  }
  .inv-line-desc { font-size: 15px; padding: 12px; min-height: 48px; }
  .inv-line-qty, .inv-line-price {
    display: inline-block; width: calc(50% - 4px);
    font-size: 15px; padding: 10px 12px;
  }
  .inv-line-qty { margin-right: 8px; }
  .inv-col-total { display: none; }
  .inv-line-remove {
    position: absolute; top: 10px; right: 10px; font-size: 20px;
    width: 28px; height: 28px; display: grid; place-items: center; color: var(--muted);
  }

  /* Invoice totals */
  .inv-totals { min-width: auto !important; width: 100%; }
  .totals-row { gap: 16px; font-size: 13px; width: 100%; justify-content: space-between; }

  /* Page header */
  .page-header h1 { font-size: 18px; }

  /* Toolbar filters */
  .toolbar { gap: 8px; }
  .toolbar .select-input { min-width: 80px; font-size: 12.5px; padding: 8px 10px; }
  .toolbar .form-input { width: 100% !important; font-size: 13px; }
  #inv-summary { font-size: 11px; gap: 8px !important; flex-wrap: wrap; }

  /* Action buttons: hide text on mobile, keep icons */
  .inv-cards-mobile { display: block; }
  .inv-table-desktop { display: none; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* Xero dropdown on mobile */
  .xero-dd { position: fixed !important; bottom: 0 !important; left: 0 !important; right: 0 !important;
    top: auto !important; border-radius: 12px 12px 0 0 !important; min-width: 100% !important; }
  .xero-dd-opt { padding: 14px 20px; font-size: 15px; }
}

/* Bulk bar always visible */
.bulk-bar {
  position: sticky; bottom: 0; left: 0; right: 0; z-index: 50;
  background: var(--ink); color: #fff; padding: 10px 16px;
  border-radius: 12px; margin: 8px 0 0; box-shadow: 0 -4px 20px rgba(0,0,0,.2);
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.bulk-bar .btn { font-size: 12px; padding: 6px 12px; border-radius: 8px; }
.bulk-bar .btn-xero-draft { background: #1e3a5f; color: #93c5fd; }
.bulk-bar .btn-xero-approve { background: #1e3a5f; color: #60a5fa; }
.bulk-bar .btn-xero-send { background: #1a73e8; color: #fff; }
.bulk-bar .bulk-count { font-size: 13px; font-weight: 700; }
.bulk-bar .bulk-close { background: none; border: none; color: #94a3b8; cursor: pointer; font-size: 18px; margin-left: auto; }

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}
