/* ════════════════════════════════════════════════════════
   DocumentCare Web App — Complete UI Design System
   Clean, responsive, professional light-mode SPA
   ════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Plus+Jakarta+Sans:ital,wght@0,400;0,500;0,600;0,700;0,800;0,900;1,400&family=Inter:wght@400;500;600;700&display=swap');

/* ── TOKENS ─────────────────────────────────────────── */
:root {
  /* Brand */
  --blue:        #2563EB;
  --blue-dark:   #1D4ED8;
  --blue-pale:   #EFF6FF;
  --blue-mid:    #DBEAFE;
  --cyan:        #06B6D4;
  --green:       #10B981;
  --green-pale:  #ECFDF5;
  --red:         #EF4444;
  --red-pale:    #FEF2F2;
  --amber:       #F59E0B;
  --amber-pale:  #FFFBEB;
  --purple:      #8B5CF6;
  --purple-pale: #F5F3FF;

  /* Neutrals */
  --bg:          #F1F5F9;
  --surface:     #FFFFFF;
  --border:      #E2E8F0;
  --border-2:    #CBD5E1;
  --text:        #0F172A;
  --text-2:      #334155;
  --sub:         #64748B;
  --muted:       #94A3B8;
  --placeholder: #CBD5E1;

  /* Gradients */
  --grad: linear-gradient(135deg, #1D4ED8 0%, #2563EB 40%, #06B6D4 100%);

  /* Shadows */
  --shadow-xs:  0 1px 3px rgba(0,0,0,.06);
  --shadow-sm:  0 2px 8px rgba(0,0,0,.07);
  --shadow-md:  0 6px 24px rgba(0,0,0,.09);
  --shadow-lg:  0 16px 48px rgba(0,0,0,.12);
  --shadow-btn: 0 4px 14px rgba(37,99,235,.35);

  /* Border Radii */
  --r-sm:   8px;
  --r-md:   12px;
  --r-lg:   16px;
  --r-xl:   24px;
  --r-pill: 999px;

  /* Easing */
  --ease-spring: cubic-bezier(.34,1.56,.64,1);
  --ease-out:    cubic-bezier(.2,0,0,1);
}

/* ── RESET ──────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }
body {
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
h1,h2,h3,h4,h5,h6 {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
}
a { text-decoration: none; color: var(--blue); }

/* ── AUTH ───────────────────────────────────────────── */
#auth-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg,#EFF6FF 0%,#F0FDFA 100%);
  padding: 24px;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border-radius: var(--r-xl);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-lg);
  padding: 40px 36px;
  animation: popIn .4s var(--ease-spring);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 28px;
  justify-content: center;
}

.auth-brand .logo-icon {
  width: 44px; height: 44px;
  border-radius: var(--r-md);
  background: var(--grad);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; font-weight: 900; color: #fff;
  box-shadow: var(--shadow-btn);
}
.auth-brand .logo-name {
  font-family: 'Plus Jakarta Sans', sans-serif;
  font-size: 22px; font-weight: 800;
  color: var(--text);
}
.auth-brand .logo-name span { color: var(--blue); }

.auth-card h2 {
  font-size: 24px; font-weight: 800; text-align: center; margin-bottom: 6px;
}
.auth-card .auth-sub {
  text-align: center; color: var(--sub); font-size: 14px; margin-bottom: 28px;
}

.phone-row {
  display: flex;
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--bg);
  transition: border-color .2s, box-shadow .2s;
}
.phone-row:focus-within {
  border-color: var(--blue);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
.phone-cc {
  padding: 0 14px;
  display: flex; align-items: center;
  font-weight: 700; font-size: 14px; color: var(--blue);
  background: var(--blue-pale);
  border-right: 1.5px solid var(--border);
  white-space: nowrap;
}
.phone-row input {
  flex: 1; border: none; outline: none;
  background: transparent;
  padding: 12px 14px;
  font-size: 15px; font-weight: 500; color: var(--text);
}
.phone-row input::placeholder { color: var(--placeholder); }

/* ── FLOATING NAVBAR ───────────────────────────────── */
#main-layout { display: flex; flex-direction: column; min-height: 100vh; }

.app-header {
  position: fixed;
  inset-block-start: 12px;
  inset-inline-start: 50%;
  transform: translateX(-50%);
  width: calc(100% - 40px);
  max-width: 1180px;
  height: 60px;
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1.5px solid var(--border);
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-md);
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 16px;
  padding: 0 14px 0 16px;
  z-index: 1000;
}

/* left: logo + store */
.hdr-brand {
  display: flex; align-items: center; gap: 10px;
}
.hdr-logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: var(--grad);
  display: flex; align-items: center; justify-content: center;
  font-size: 17px; font-weight: 900; color: #fff;
  box-shadow: 0 3px 10px rgba(37,99,235,.3);
  flex-shrink: 0;
}
.hdr-store-wrap {
  display: flex; flex-direction: column;
}
.hdr-store-label { font-size: 10px; color: var(--muted); font-weight: 600; line-height: 1; }
#active-business-select {
  border: none; background: transparent; outline: none;
  font-size: 13px; font-weight: 700; color: var(--text);
  padding: 2px 0; cursor: pointer;
  max-width: 160px;
  /* No dropdown arrow needed here - custom */
  appearance: none;
  -webkit-appearance: none;
}

/* center: nav pills */
.hdr-nav {
  display: flex; justify-content: center;
  background: var(--bg);
  border-radius: var(--r-pill);
  padding: 4px;
  gap: 2px;
}
.pill-link {
  padding: 7px 16px;
  border-radius: var(--r-pill);
  font-size: 13px; font-weight: 600;
  font-family: 'Plus Jakarta Sans', sans-serif;
  color: var(--sub);
  text-decoration: none;
  transition: all .2s var(--ease-out);
  white-space: nowrap;
}
.pill-link:hover { color: var(--blue); background: rgba(37,99,235,.07); }
.pill-link.active {
  background: var(--surface);
  color: var(--blue);
  font-weight: 700;
  box-shadow: var(--shadow-xs);
}

/* right: user + logout */
.hdr-right { display: flex; align-items: center; gap: 8px; }
.hdr-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--blue-mid);
  color: var(--blue-dark);
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 800;
  cursor: pointer; flex-shrink: 0;
}
#header-user-name { font-size: 13px; font-weight: 700; color: var(--text); }
.btn-logout {
  padding: 6px 14px;
  border-radius: var(--r-pill);
  border: 1.5px solid var(--border);
  background: transparent;
  font-size: 12px; font-weight: 700;
  color: var(--sub); cursor: pointer;
  transition: all .2s;
}
.btn-logout:hover { border-color: var(--red); color: var(--red); background: var(--red-pale); }

/* ── MAIN CONTENT ───────────────────────────────────── */
.app-main {
  flex: 1;
  max-width: 1180px;
  width: 100%;
  margin: 0 auto;
  padding: 88px 20px 48px;
}

/* view management */
.view { display: none; }
.view.active-view { display: block; animation: fadeUp .28s var(--ease-out); }
.hidden { display: none !important; }

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes popIn {
  from { opacity: 0; transform: scale(.93); }
  to   { opacity: 1; transform: scale(1); }
}

/* ── PAGE HEADER ────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}
.page-header h2 { font-size: 22px; font-weight: 800; }
.page-header p  { font-size: 13px; color: var(--sub); margin-top: 2px; }

/* ── CARDS ──────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-xs);
}
.card-p  { padding: 20px; }
.card-p2 { padding: 24px; }

/* ── METRIC CARDS ───────────────────────────────────── */
.metrics-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
  margin-bottom: 24px;
}
.metric {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
  display: flex; align-items: center; gap: 16px;
  transition: transform .25s var(--ease-spring), box-shadow .25s;
}
.metric:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); }
.metric-icon {
  width: 48px; height: 48px; border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 22px; flex-shrink: 0;
}
.metric-body {}
.metric-label { font-size: 11px; font-weight: 700; color: var(--sub); text-transform: uppercase; letter-spacing: .5px; }
.metric-value { font-size: 20px; font-weight: 800; color: var(--text); font-family: 'Plus Jakarta Sans', sans-serif; margin-top: 2px; }
.metric-value.green { color: var(--green); }
.metric-value.red   { color: var(--red); }
.metric-value.amber { color: var(--amber); }
.metric-value.blue  { color: var(--blue); }

/* ── BUTTONS ────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 18px;
  border-radius: var(--r-md);
  font-size: 13px; font-weight: 700;
  font-family: 'Plus Jakarta Sans', sans-serif;
  border: 1.5px solid transparent;
  cursor: pointer; outline: none;
  transition: all .2s var(--ease-out);
  text-decoration: none; white-space: nowrap;
}
.btn-pill { border-radius: var(--r-pill); }
.btn-sm   { padding: 6px 12px; font-size: 12px; border-radius: var(--r-sm); }

.btn-primary {
  background: var(--grad); color: #fff;
  box-shadow: var(--shadow-btn);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 18px rgba(37,99,235,.4); }
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--blue-pale); color: var(--blue-dark);
  border-color: var(--blue-mid);
}
.btn-secondary:hover { background: var(--blue-mid); }

.btn-ghost {
  background: var(--surface); color: var(--sub);
  border-color: var(--border);
}
.btn-ghost:hover { border-color: var(--border-2); color: var(--text); background: var(--bg); }

.btn-link {
  background: none; border: none; padding: 0;
  color: var(--blue); font-size: 12px; font-weight: 700;
  cursor: pointer; font-family: 'Plus Jakarta Sans', sans-serif;
}
.btn-link:hover { text-decoration: underline; }

.btn-danger { background: var(--red-pale); color: var(--red); border-color: rgba(239,68,68,.2); }
.btn-danger:hover { background: var(--red); color: #fff; }

/* ── FORM CONTROLS ──────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 12px; font-weight: 700;
  color: var(--sub); margin-bottom: 6px;
  text-transform: uppercase; letter-spacing: .3px;
}
.form-label-row {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px;
}
.form-label-row .form-label { margin-bottom: 0; }

input[type=text], input[type=email], input[type=tel],
input[type=number], input[type=date], input[type=password],
textarea, select {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  font-size: 14px; font-family: 'Inter', sans-serif; font-weight: 500;
  color: var(--text); background: var(--bg);
  outline: none;
  transition: border-color .2s, box-shadow .2s, background .2s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--blue);
  background: var(--surface);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}
input::placeholder, textarea::placeholder { color: var(--placeholder); font-weight: 400; }
textarea { resize: vertical; }

select {
  appearance: none; -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748B' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 36px;
  cursor: pointer;
}

/* ── TABLES ─────────────────────────────────────────── */
.table-wrap { overflow-x: auto; border-radius: var(--r-lg); border: 1.5px solid var(--border); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th {
  padding: 12px 16px;
  text-align: left;
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .5px;
  color: var(--sub);
  background: var(--bg);
  border-bottom: 1.5px solid var(--border);
}
tbody td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--blue-pale); }

/* ── BADGES ─────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: var(--r-pill);
  font-size: 11px; font-weight: 700; white-space: nowrap;
}
.badge-blue   { background: var(--blue-mid);    color: #1E40AF; }
.badge-green  { background: var(--green-pale);  color: #065F46; }
.badge-red    { background: var(--red-pale);    color: #991B1B; }
.badge-amber  { background: var(--amber-pale);  color: #92400E; }
.badge-purple { background: var(--purple-pale); color: #5B21B6; }

/* ── INVOICE EDITOR SPECIFIC ────────────────────────── */
.inv-meta-grid {
  display: grid;
  grid-template-columns: 1fr 200px 200px;
  gap: 16px;
  margin-bottom: 24px;
}

/* line item row */
.item-row {
  display: grid;
  grid-template-columns: 2.5fr 90px 80px 110px 120px 36px;
  gap: 8px;
  align-items: start;
  padding: 14px 16px;
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--r-md);
  margin-bottom: 8px;
  transition: border-color .2s;
}
.item-row:hover { border-color: var(--border-2); }
.item-row input, .item-row select { font-size: 13px; padding: 8px 10px; }
.item-row select { padding-right: 28px; }

.item-row-label {
  font-size: 10px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .3px;
  margin-bottom: 4px;
}

.btn-remove-item {
  width: 32px; height: 32px; border-radius: 50%;
  border: none; background: var(--red-pale); color: var(--red);
  font-size: 14px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer; margin-top: 18px; flex-shrink: 0;
  transition: all .2s var(--ease-spring);
}
.btn-remove-item:hover { background: var(--red); color: #fff; transform: scale(1.1); }

/* item-row header (labels row) */
.item-row-header {
  display: grid;
  grid-template-columns: 2.5fr 90px 80px 110px 120px 36px;
  gap: 8px;
  padding: 0 16px;
  margin-bottom: 6px;
}
.item-row-header span {
  font-size: 10px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: .3px;
}

/* totals sidebar */
.totals-card {
  background: var(--bg);
  border: 1.5px solid var(--border);
  border-radius: var(--r-lg);
  padding: 20px;
}
.total-row {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 0;
  font-size: 14px; color: var(--sub);
  border-bottom: 1px solid var(--border);
}
.total-row:last-of-type { border-bottom: none; }
.total-row strong { color: var(--text); }
.total-grand {
  display: flex; justify-content: space-between; align-items: center;
  padding: 12px 0 0;
  margin-top: 8px;
  border-top: 2px solid var(--border);
  font-size: 17px; font-weight: 800; color: var(--text);
}
.total-grand .amount { color: var(--blue); }

/* bottom split grid */
.inv-bottom-grid {
  display: grid;
  grid-template-columns: 1fr 300px;
  gap: 20px;
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1.5px solid var(--border);
}

/* ── MODALS ─────────────────────────────────────────── */
.modal {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.45);
  backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  z-index: 2000; padding: 20px;
}
.modal-card {
  background: var(--surface);
  border-radius: var(--r-xl);
  border: 1.5px solid var(--border);
  box-shadow: var(--shadow-lg);
  padding: 28px;
  width: 100%;
  max-width: 480px;
  max-height: 90vh;
  overflow-y: auto;
  animation: popIn .3s var(--ease-spring);
}
.modal-card.wide { max-width: 680px; }
.modal-header { margin-bottom: 20px; }
.modal-header h3 { font-size: 18px; font-weight: 800; }
.modal-header p  { font-size: 13px; color: var(--sub); margin-top: 4px; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

/* ── SECTION DIVIDER ────────────────────────────────── */
.section-divider {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1.5px solid var(--border);
  margin-bottom: 16px;
}
.section-divider h3 { font-size: 15px; font-weight: 700; }

/* ── TOAST ──────────────────────────────────────────── */
#toast-container {
  position: fixed; top: 80px; right: 20px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 10px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: center; gap: 12px;
  min-width: 300px; max-width: 400px;
  padding: 14px 16px;
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  font-size: 13px; font-weight: 600; color: var(--text);
  animation: slideInRight .35s var(--ease-spring);
}
.toast.t-success { border-left: 4px solid var(--green); }
.toast.t-error   { border-left: 4px solid var(--red); }
.toast.t-warning { border-left: 4px solid var(--amber); }
.toast.t-info    { border-left: 4px solid var(--blue); }
.toast-icon { font-size: 18px; flex-shrink: 0; }
.toast-msg  { flex: 1; line-height: 1.4; }
.toast-close {
  background: none; border: none; color: var(--muted); cursor: pointer;
  font-size: 16px; line-height: 1; padding: 0;
}
.toast-close:hover { color: var(--text); }

@keyframes slideInRight {
  from { opacity:0; transform: translateX(48px) scale(.95); }
  to   { opacity:1; transform: translateX(0) scale(1); }
}
@keyframes fadeOut {
  to { opacity:0; transform: translateX(20px); }
}

/* ── UTILITY ────────────────────────────────────────── */
.mt-1  { margin-top: 4px;  }
.mt-2  { margin-top: 8px;  }
.mt-3  { margin-top: 12px; }
.mt-4  { margin-top: 16px; }
.mt-6  { margin-top: 24px; }
.mb-2  { margin-bottom: 8px;  }
.mb-4  { margin-bottom: 16px; }
.mb-6  { margin-bottom: 24px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.flex  { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.flex-center { display:flex; align-items:center; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.text-lg { font-size: 16px; }
.font-bold { font-weight: 700; }
.font-extrabold { font-weight: 800; }
.text-sub  { color: var(--sub); }
.text-muted { color: var(--muted); }
.text-blue  { color: var(--blue); }
.text-green { color: var(--green); }
.text-red   { color: var(--red); }
.w-full { width: 100%; }
.grid-2 { display:grid; grid-template-columns:1fr 1fr; gap:20px; }

/* ── PRINT ──────────────────────────────────────────── */
@media print {
  body * { visibility: hidden; }
  #printable-invoice-container,
  #printable-invoice-container * { visibility: visible; }
  #printable-invoice-container {
    position: fixed; inset: 0; width: 100%;
  }
}
