/* ============================================================
   Zaeger CRM — styles (mobile-first, responsive)
   ============================================================ */
:root {
  --blue: #4f46e5;
  --blue-dark: #4338ca;
  --bg: #f6f7fb;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #eaecf2;
  --danger: #dc2626;
  --green: #16a34a;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.04), 0 4px 12px rgba(16, 24, 40, 0.05);
}

* { 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);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--blue); }
h1, h2, h3, h4 { margin: 0 0 0.4rem; }
.muted { color: var(--muted); }
.small { font-size: 0.8rem; }

/* ---- Buttons ---- */
.btn {
  font: inherit;
  font-weight: 600;
  padding: 0.55rem 0.9rem;
  border-radius: 10px;
  border: 1px solid transparent;
  cursor: pointer;
  background: var(--card);
  color: var(--text);
  transition: background 0.15s, opacity 0.15s;
}
.btn:hover { opacity: 0.9; }
.btn--primary { background: var(--blue); color: #fff; }
.btn--primary:hover { background: var(--blue-dark); opacity: 1; }
.btn--ghost { background: transparent; border-color: var(--border); }
.btn--danger-ghost { background: transparent; color: var(--danger); border-color: transparent; }
.btn--block { width: 100%; }
.icon-btn {
  border: none; background: transparent; cursor: pointer;
  font-size: 0.9rem; color: var(--muted); padding: 0.25rem; border-radius: 6px;
}
.icon-btn:hover { background: var(--bg); }

/* ---- Inputs ---- */
input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 0.55rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
}
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}
label { display: block; font-weight: 600; font-size: 0.85rem; }
label input, label select, label textarea { margin-top: 0.3rem; font-weight: 400; }

/* ---- Centered (auth / setup) ---- */
.centered {
  min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 1rem;
}
.card {
  background: var(--card); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1.75rem;
}
.auth-card, .setup-card { width: 100%; max-width: 380px; text-align: center; }
.auth-card label { text-align: left; margin-top: 0.8rem; }
.btn--google { display: flex; align-items: center; justify-content: center; gap: 0.5rem; border: 1px solid var(--border); background: #fff; font-weight: 600; margin-top: 0.5rem; }
.btn--google:hover { background: var(--bg); }
.auth-fallback { margin-top: 1rem; text-align: left; }
.auth-fallback summary { cursor: pointer; text-align: center; }
.auth-fallback form { margin-top: 0.6rem; }
.auth-card .btn { margin-top: 1.2rem; }
.logo { font-size: 2.5rem; }
.auth-toggle { margin-top: 1rem; font-size: 0.9rem; }
.setup-card code {
  background: var(--bg); padding: 0.1rem 0.35rem; border-radius: 5px; font-size: 0.85em;
}

/* ---- Topbar ---- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  background: rgba(255, 255, 255, 0.85); backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border);
  padding: 0.7rem 1rem; padding-top: max(0.7rem, env(safe-area-inset-top));
}
.topbar__brand { font-weight: 800; font-size: 1.1rem; letter-spacing: -0.01em; display: flex; align-items: center; flex-shrink: 0; }
.topbar__logo { height: 30px; width: auto; max-width: 180px; display: block; }

/* ---- Global search ---- */
.topbar__search { position: relative; flex: 1; max-width: 440px; margin: 0 0.8rem; }
.topbar__search input { width: 100%; padding: 0.5rem 0.8rem; border-radius: 999px; background: var(--bg); border: 1px solid var(--border); }
.global-results {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; display: none;
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: 0 12px 32px rgba(16, 24, 40, 0.16); max-height: 70vh; overflow-y: auto; z-index: 50; padding: 0.4rem;
}
.global-results.open { display: block; }
.gr-group + .gr-group { border-top: 1px solid var(--border); margin-top: 0.3rem; padding-top: 0.3rem; }
.gr-title { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em; color: var(--muted); font-weight: 700; padding: 0.3rem 0.5rem 0.2rem; }
.gr-item { display: flex; align-items: center; gap: 0.6rem; width: 100%; border: none; background: none; font: inherit; text-align: left; padding: 0.45rem 0.5rem; border-radius: 8px; cursor: pointer; }
.gr-item:hover { background: var(--bg); }
.gr-ic { font-size: 1rem; flex-shrink: 0; }
.gr-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.gr-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.gr-right { flex-shrink: 0; }
.gr-empty { padding: 0.8rem; text-align: center; }
@media (max-width: 560px) { .topbar__search { margin: 0 0.4rem; } }
.topbar__user { display: flex; align-items: center; gap: 0.6rem; }

/* ---- Layout: left sidebar + content ---- */
.layout { display: flex; align-items: flex-start; }
.sidebar {
  width: 210px; flex-shrink: 0; padding: 0.9rem 0.6rem;
  display: flex; flex-direction: column; gap: 0.2rem;
  position: sticky; top: 52px; align-self: flex-start;
  border-right: 1px solid var(--border); min-height: calc(100vh - 52px);
  background: var(--card);
}
.navlink {
  display: flex; align-items: center; gap: 0.7rem; width: 100%;
  border: none; background: none; font: inherit; font-weight: 600;
  color: var(--muted); padding: 0.7rem 0.8rem; cursor: pointer;
  border-radius: 10px; text-align: left;
}
.navlink:hover { background: var(--bg); color: var(--text); }
.navlink--active { background: #eef2ff; color: var(--blue); }
.navlink__icon { font-size: 1.1rem; width: 1.3rem; text-align: center; flex-shrink: 0; }
.navlink__label { flex: 1; }
.pill {
  background: var(--bg); color: var(--muted); font-size: 0.72rem;
  padding: 0.05rem 0.45rem; border-radius: 999px;
}
.navlink--active .pill { background: #fff; color: var(--blue); }

/* ---- Content ---- */
.content { flex: 1; min-width: 0; max-width: 1000px; padding: 1rem 1.25rem; padding-bottom: 4rem; overflow-x: hidden; }
/* Prevent long text (emails, addresses, URLs) from pushing the layout wide */
.field__value, .mini-deal, .detail__notes p, .activity__body { overflow-wrap: anywhere; min-width: 0; }

/* Narrow screens: move the nav to a bottom tab bar (frees the full width) */
@media (max-width: 640px) {
  .layout { display: block; }
  .sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; top: auto;
    width: 100%; min-height: 0;
    flex-direction: row; gap: 0; padding: 0.2rem;
    padding-bottom: max(0.2rem, env(safe-area-inset-bottom));
    border-right: none; border-top: 1px solid var(--border);
    box-shadow: 0 -2px 12px rgba(16, 24, 40, 0.07); z-index: 40;
  }
  .navlink {
    flex: 1; min-width: 0; flex-direction: column; gap: 0.12rem;
    justify-content: center; padding: 0.3rem 0.1rem; border-radius: 8px;
  }
  .navlink__icon { font-size: 1.3rem; width: auto; }
  .navlink__label {
    display: block; flex: none; font-size: 0.58rem; line-height: 1; text-align: center;
    max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .navlink .pill { display: none; }
  .content { padding: 0.8rem; padding-bottom: 5rem; }
  .toast { bottom: calc(4.5rem + env(safe-area-inset-bottom)); }
}
.toolbar {
  display: flex; gap: 0.6rem; align-items: center; margin-bottom: 1rem; flex-wrap: wrap;
}
.toolbar .search { flex: 1; min-width: 160px; }
.empty {
  text-align: center; color: var(--muted); padding: 3rem 1rem;
  background: var(--card); border-radius: var(--radius); border: 1px dashed var(--border);
}
.empty--sm { padding: 0.8rem; border: none; background: transparent; }

/* ---- Contact cards ---- */
.cards { display: flex; flex-direction: column; gap: 0.6rem; }
.contact-card {
  display: flex; align-items: center; gap: 0.8rem; background: var(--card);
  padding: 0.8rem; border-radius: var(--radius); box-shadow: var(--shadow);
  cursor: pointer; transition: transform 0.1s;
}
.contact-card:hover { transform: translateY(-1px); }
.contact-card__main { flex: 1; min-width: 0; }
.contact-card__name { font-weight: 600; }
.contact-card__sub { font-size: 0.85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--blue), #7c3aed); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.9rem;
}
.avatar--lg { width: 60px; height: 60px; font-size: 1.3rem; }

/* ---- Status badges ---- */
.status {
  font-size: 0.72rem; font-weight: 700; padding: 0.2rem 0.55rem; border-radius: 999px;
  background: var(--bg); color: var(--muted); white-space: nowrap;
}
.status--lead { background: #fef9c3; color: #854d0e; }
.status--prospect { background: #dbeafe; color: #1e40af; }
.status--customer { background: #dcfce7; color: #166534; }
.status--inactive { background: #f1f5f9; color: #64748b; }

/* ---- Contact detail ---- */
.back { margin-bottom: 0.8rem; }
.detail { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.25rem; }
.detail__header { display: flex; align-items: center; gap: 1rem; flex-wrap: wrap; }
.detail__header h2 { margin: 0; }
.detail__actions { margin-left: auto; display: flex; gap: 0.4rem; }
.detail__fields {
  display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.8rem;
  margin: 1.2rem 0; padding: 1.2rem 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
}
.field__label { font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.03em; }
.field__value { margin-top: 0.15rem; }
.detail__notes { margin: 1rem 0; }
.detail__notes p { white-space: pre-wrap; }
.detail__section { margin-top: 1.5rem; }
.detail__section h4 { color: var(--muted); text-transform: uppercase; font-size: 0.78rem; letter-spacing: 0.03em; }
.mini-deal {
  display: flex; justify-content: space-between; padding: 0.5rem 0; border-bottom: 1px solid var(--border);
}

/* ---- Activities ---- */
.activity-form { display: flex; gap: 0.5rem; margin: 0.6rem 0 1rem; flex-wrap: wrap; }
.activity-form select { width: auto; }
.activity-form input { flex: 1; min-width: 140px; }
.activity-list { display: flex; flex-direction: column; gap: 0.5rem; }
.activity {
  display: flex; gap: 0.6rem; align-items: flex-start; background: var(--bg);
  padding: 0.6rem 0.7rem; border-radius: 10px;
}
.activity__icon { font-size: 1.1rem; }
.activity__body { flex: 1; }
.mention { color: var(--blue); font-weight: 600; background: #eff6ff; padding: 0 3px; border-radius: 4px; }
.auth-note { margin-top: 1rem; }

/* ---- Owner chips & assignment ---- */
.owner {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%; flex-shrink: 0;
  background: #e0e7ff; color: #3730a3; font-size: 0.68rem; font-weight: 700;
  border: none; cursor: default;
}
.owner--me { cursor: pointer; background: var(--blue); color: #fff; }
.deal-card__owner { display: flex; align-items: center; gap: 0.35rem; margin-top: 0.4rem; }

/* ---- Segmented toggle (Mine / Everyone) ---- */
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: 999px; padding: 2px; flex-shrink: 0; }
.seg__btn {
  border: none; background: none; font: inherit; font-size: 0.82rem; font-weight: 600;
  color: var(--muted); padding: 0.32rem 0.8rem; border-radius: 999px; cursor: pointer;
}
.seg__btn--active { background: var(--card); color: var(--blue); box-shadow: var(--shadow); }
.toolbar--right { justify-content: flex-end; }

/* ---- Contacts table ---- */
.table-wrap { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.table thead th {
  text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); font-weight: 700; padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--border); white-space: nowrap; background: #fbfbfe;
  position: sticky; top: 0;
}
.table tbody td { padding: 0.65rem 0.9rem; border-bottom: 1px solid var(--border); white-space: nowrap; vertical-align: middle; }
.td-strong { font-weight: 600; }
.widget__body--scroll { max-height: 340px; overflow-y: auto; }
.audit-entry { padding: 0.6rem 0; border-bottom: 1px solid var(--border); }
.audit-entry:last-child { border-bottom: none; }
.audit-meta { margin-bottom: 0.25rem; }
.audit-op { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); }
.audit-op--add { color: var(--green); }
.audit-op--del { color: var(--danger); }
.audit-changes { margin: 0.3rem 0 0; padding-left: 1rem; font-size: 0.88rem; }
.audit-changes li { margin: 0.15rem 0; overflow-wrap: anywhere; }
.pager { display: flex; align-items: center; justify-content: center; gap: 0.85rem; margin: 1rem 0 0.5rem; }
.pager button[disabled] { opacity: 0.4; cursor: default; }
.bf-voided td { opacity: 0.45; }
.void-badge { background: #fee2e2; color: #991b1b; font-size: 0.62rem; font-weight: 800; padding: 0.05rem 0.35rem; border-radius: 4px; vertical-align: middle; }
.void-banner { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; padding: 0.6rem 0.8rem; border-radius: 8px; font-weight: 600; margin-bottom: 0.8rem; }
.th-sort { cursor: pointer; user-select: none; }
.th-sort:hover { color: var(--text); }
.th-sort--active { color: var(--blue); }
.th-arrow { font-size: 0.7em; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { cursor: pointer; transition: background 0.12s; }
.table tbody tr:hover { background: #f7f7fd; }
.cell-name { display: flex; align-items: center; gap: 0.55rem; font-weight: 600; }
.cell-owner { text-align: right; }
.avatar--sm { width: 30px; height: 30px; font-size: 0.72rem; }
.table-count { margin-top: 0.6rem; padding-left: 0.2rem; }

/* ---- Detail: section head + small button ---- */
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; }
.btn--sm { padding: 0.35rem 0.65rem; font-size: 0.82rem; }
.ext-arrow { font-size: 0.85em; opacity: 0.6; }

/* ---- Invoice statuses ---- */
.status--paid { background: #dcfce7; color: #166534; }
.status--sent { background: #dbeafe; color: #1e40af; }
.status--draft { background: #f1f5f9; color: #64748b; }
.status--overdue { background: #fee2e2; color: #991b1b; }

/* ---- Inquiry statuses ---- */
.status--open { background: #fef9c3; color: #854d0e; }
.status--sourcing { background: #dbeafe; color: #1e40af; }
.status--matched { background: #ede9fe; color: #6d28d9; }
.status--fulfilled { background: #dcfce7; color: #166534; }
.status--closed { background: #f1f5f9; color: #64748b; }
.mini-deal[data-open-inq] { cursor: pointer; }
.mini-deal[data-open-inq]:hover { background: #f7f7fd; border-radius: 8px; }

/* ---- Stock matching ---- */
.stock-note { margin: -0.4rem 0 0.8rem; }
.match-chip { background: #dcfce7; color: #166534; font-size: 0.72rem; font-weight: 700; padding: 0.12rem 0.5rem; border-radius: 999px; }

/* ---- Inventory ---- */
.toolbar select { width: auto; flex-shrink: 0; }
.page-title__count { font-size: 0.9rem; font-weight: 600; margin-left: 0.3rem; }
/* Standard statuses: neutral, normal weight. Available = bold green, Sold = bold red. */
.inv-status { display: inline-block; font-size: 0.72rem; font-weight: 500; padding: 0.1rem 0.5rem; border-radius: 999px; background: #f1f5f9; color: #64748b; white-space: nowrap; }
.inv-status--avail { background: #dcfce7; color: #15803d; font-weight: 800; }
.inv-status--sold { background: #fee2e2; color: #b91c1c; font-weight: 800; }

/* ---- Deal stage badge (table view) ---- */
.deal-stage { display: inline-block; font-size: 0.72rem; font-weight: 700; padding: 0.12rem 0.55rem; border-radius: 999px; background: #eef2ff; color: #3730a3; white-space: nowrap; }
.deal-stage--won { background: #dcfce7; color: #166534; }
.deal-stage--lost { background: #f1f5f9; color: #64748b; }
.inq-match { margin-top: 1.2rem; border-top: 1px solid var(--border); padding-top: 1rem; }
.inq-match h4 { color: var(--muted); text-transform: uppercase; font-size: 0.78rem; letter-spacing: 0.03em; }
.stock-row { display: flex; align-items: center; gap: 0.7rem; padding: 0.55rem 0.2rem; border-bottom: 1px solid var(--border); }
.stock-row:last-child { border-bottom: none; }
.stock-row__main { flex: 1; min-width: 0; }
.stock-row__title { font-weight: 600; }
.stock-row__price { font-weight: 700; white-space: nowrap; }
.stock-row__price--within { color: var(--green); }

/* ---- Recent purchases ---- */
.invoice-row {
  display: flex; align-items: center; gap: 0.7rem; padding: 0.6rem 0.2rem;
  border-bottom: 1px solid var(--border); cursor: pointer;
}
.invoice-row:hover { background: #f7f7fd; }
.invoice-row:last-child { border-bottom: none; }
.invoice-row__main { flex: 1; min-width: 0; }
.invoice-row__num { font-weight: 600; }
.invoice-row__amount { font-weight: 700; color: var(--green); }

/* ---- Files ---- */
.file-row { display: flex; align-items: center; gap: 0.7rem; padding: 0.55rem 0.2rem; border-bottom: 1px solid var(--border); }
.file-row:last-child { border-bottom: none; }
.file-row__icon { font-size: 1.3rem; flex-shrink: 0; width: 46px; text-align: center; }
.file-thumb { width: 46px; height: 46px; object-fit: cover; border-radius: 8px; flex-shrink: 0; background: var(--bg); border: 1px solid var(--border); }
.file-thumb[data-full] { cursor: zoom-in; }
.hero-thumb { width: 100%; height: 100%; border-radius: 50%; border: none; object-fit: cover; }
.drag-grip { color: var(--muted); cursor: grab; flex-shrink: 0; font-size: 1.1rem; user-select: none; }
.file-row[draggable] { cursor: default; }
.file-row.dragging { opacity: 0.4; }
.file-reorder-hint { margin-bottom: 0.5rem; }

/* ---- Lightbox ---- */
.lightbox { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.88); display: flex; align-items: center; justify-content: center; z-index: 400; padding: 1rem; animation: fadeIn 0.15s ease; }
.lightbox img { max-width: 95vw; max-height: 92vh; object-fit: contain; border-radius: 8px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5); }
.lightbox__close { position: fixed; top: 1rem; right: 1rem; width: 42px; height: 42px; border-radius: 50%; border: none; background: rgba(255, 255, 255, 0.18); color: #fff; font-size: 1.2rem; cursor: pointer; }
.lightbox__close:hover { background: rgba(255, 255, 255, 0.3); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.file-row__main { flex: 1; min-width: 0; }
.file-row__name { font-weight: 600; overflow-wrap: anywhere; }

/* ---- Timeline ---- */
.timeline { position: relative; margin-top: 0.4rem; }
.timeline::before { content: ""; position: absolute; left: 14px; top: 8px; bottom: 8px; width: 2px; background: var(--border); }
.tl-item { display: flex; gap: 0.8rem; align-items: flex-start; position: relative; padding: 0.5rem 0; }
.tl-item__icon {
  width: 30px; height: 30px; border-radius: 50%; background: var(--card); border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center; font-size: 0.9rem; flex-shrink: 0; z-index: 1;
}
.tl-item__body { flex: 1; min-width: 0; }
.tl-item__head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.6rem; }
.tl-item__label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.04em; font-weight: 700; color: var(--muted); }
.tl-item__date { flex-shrink: 0; white-space: nowrap; }
.tl-item__content { margin-top: 0.1rem; overflow-wrap: anywhere; }
.tl-item__content a { font-weight: 600; }
.tl-snippet { margin-top: 0.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.section-head__actions { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: flex-end; }

/* ---- Google Calendar events ---- */
.gcal-event { padding: 0.5rem 0.2rem; border-bottom: 1px solid var(--border); }
.gcal-event:last-child { border-bottom: none; }
.gcal-event__title { font-weight: 600; }

/* ---- Pipeline board ---- */
.board {
  display: grid; grid-auto-flow: column; grid-auto-columns: minmax(220px, 1fr);
  gap: 0.8rem; overflow-x: auto; padding-bottom: 0.5rem;
}
.column { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); display: flex; flex-direction: column; }
.column__head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.7rem 0.8rem; font-weight: 700; border-bottom: 1px solid var(--border);
}
.column__body { padding: 0.6rem; display: flex; flex-direction: column; gap: 0.6rem; min-height: 60px; }
.deal-card { background: var(--bg); border-radius: 10px; padding: 0.7rem; border: 1px solid var(--border); }
.deal-card__title { font-weight: 600; }
.deal-card__value { color: var(--green); font-weight: 700; margin: 0.2rem 0; }
.deal-card__foot { display: flex; gap: 0.4rem; align-items: center; margin-top: 0.5rem; }
.stage-select { font-size: 0.8rem; padding: 0.3rem 0.4rem; }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.5);
  display: flex; align-items: flex-end; justify-content: center; z-index: 100;
}
.modal {
  background: var(--card); width: 100%; max-width: 520px;
  border-radius: var(--radius) var(--radius) 0 0; max-height: 92vh; overflow-y: auto;
  animation: slideUp 0.2s ease;
}
@keyframes slideUp { from { transform: translateY(30px); opacity: 0.6; } to { transform: translateY(0); opacity: 1; } }
.modal__head {
  display: flex; justify-content: space-between; align-items: center;
  padding: 1rem 1.2rem; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--card);
}
.modal__head h3 { margin: 0; }
.modal__body { padding: 1.2rem; }

/* ---- Forms in modal ---- */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
.form-grid .full { grid-column: 1 / -1; }
.form-actions { display: flex; gap: 0.5rem; align-items: center; margin-top: 0.5rem; }
.form-actions .spacer { flex: 1; }
.checkbox-row { display: flex; align-items: center; gap: 0.5rem; font-weight: 400; }
.checkbox-row input { width: auto; }

/* ---- Buy Form (Form 1) ---- */
.bf h2 { margin-bottom: 0.2rem; }
.bf-sec { margin: 1.4rem 0 0.6rem; color: var(--blue); border-bottom: 1px solid var(--border); padding-bottom: 0.3rem; text-transform: uppercase; font-size: 0.78rem; letter-spacing: 0.04em; }
.bf-goods-row { display: grid; grid-template-columns: 90px 1fr 130px 130px 110px 28px; gap: 0.4rem; margin-bottom: 0.4rem; align-items: center; }
.bf-goods-row input { width: 100%; }
.sigpad { width: 100%; max-width: 600px; height: 160px; border: 2px dashed var(--border); border-radius: 10px; background: #fff; touch-action: none; cursor: crosshair; display: block; }
.bf-date { display: inline-flex; flex-direction: column; font-weight: 600; font-size: 0.85rem; margin-top: 0.8rem; max-width: 200px; }
@media (max-width: 640px) {
  .bf-goods-row { grid-template-columns: 1fr 1fr; }
  .bf-goods-row .bf-g-remove { grid-column: 2; justify-self: end; }
}

/* ---- Inline quick-add customer ---- */
.quick-add { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 0.7rem; flex-basis: 100%; }
.quick-add__grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.quick-add__actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.6rem; }
@media (max-width: 520px) { .quick-add__grid { grid-template-columns: 1fr; } }

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translate(-50%, 1rem);
  background: var(--text); color: #fff; padding: 0.7rem 1.1rem; border-radius: 10px;
  box-shadow: var(--shadow); opacity: 0; transition: all 0.3s; z-index: 200; max-width: 90vw;
}
.toast--show { opacity: 1; transform: translate(-50%, 0); }
.toast--error { background: var(--danger); }
.toast--success { background: var(--green); }

/* ---- Responsive ---- */
@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
  .modal { border-radius: var(--radius); }
}
@media (max-width: 520px) {
  .hide-sm { display: none; }
  .form-grid { grid-template-columns: 1fr; }
  .detail__fields { grid-template-columns: 1fr; }
  .stats { grid-template-columns: 1fr 1fr; }
}

/* ---- Dashboard ---- */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.7rem; margin-bottom: 1rem; }
.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 1rem; text-align: left; cursor: pointer; font: inherit;
  transition: transform 0.1s;
}
.stat:hover { transform: translateY(-1px); }
.stat--alert { border-color: var(--danger); }
.stat__num { font-size: 1.5rem; font-weight: 800; }
.stat__num--green { color: var(--green); }
.stat__label { color: var(--muted); font-size: 0.8rem; margin-top: 0.2rem; }
.panel { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 1.1rem; margin-bottom: 1rem; }
.panel h4 { color: var(--muted); text-transform: uppercase; font-size: 0.78rem; letter-spacing: 0.03em; }
.bar-row { display: flex; align-items: center; gap: 0.6rem; margin: 0.5rem 0; }
.bar-row__label { width: 80px; font-size: 0.85rem; font-weight: 600; flex-shrink: 0; }
.bar-row__val { width: 110px; text-align: right; flex-shrink: 0; }
.bar { flex: 1; height: 10px; background: var(--bg); border-radius: 999px; overflow: hidden; }
.bar__fill { height: 100%; background: var(--blue); border-radius: 999px; min-width: 2px; }
.bar__fill--won { background: var(--green); }
.bar__fill--lost { background: #cbd5e1; }

/* ---- Dashboard widgets ---- */
.page-title { font-size: 1.4rem; font-weight: 800; margin: 0 0 1rem; letter-spacing: -0.01em; }
.widgets { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1rem; }
.widget {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); display: flex; flex-direction: column;
  min-height: 240px; overflow: hidden;
}
.widget__head {
  display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  padding: 0.8rem 1rem; border-bottom: 1px solid var(--border); font-weight: 700;
}
.widget__body { padding: 0.6rem 0.7rem; overflow-y: auto; flex: 1; }
.widget__body > .task { box-shadow: none; border: 1px solid var(--border); }
.w-row {
  display: flex; align-items: center; gap: 0.6rem; padding: 0.5rem 0.4rem;
  border-bottom: 1px solid var(--border); cursor: pointer; border-radius: 8px;
}
.w-row:last-child { border-bottom: none; }
.w-row:hover { background: #f7f7fd; }
.w-row__main { flex: 1; min-width: 0; }
.w-row__title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.transfer-dest { font-size: 0.72rem; font-weight: 700; padding: 0.1rem 0.55rem; border-radius: 999px; background: #fef3c7; color: #92400e; white-space: nowrap; flex-shrink: 0; }

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

/* ---- Tags ---- */
.tags { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-top: 0.35rem; }
.tags--lg { margin: 0.4rem 0 0.2rem; }
.tag { background: #ede9fe; color: #6d28d9; font-size: 0.72rem; font-weight: 600; padding: 0.12rem 0.5rem; border-radius: 999px; }
.tag-bar { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-bottom: 0.9rem; }
.tag-chip {
  border: 1px solid var(--border); background: var(--card); color: var(--muted);
  font: inherit; font-size: 0.8rem; font-weight: 600; padding: 0.3rem 0.7rem;
  border-radius: 999px; cursor: pointer;
}
.tag-chip--active { background: var(--blue); color: #fff; border-color: var(--blue); }

/* ---- Drag & drop ---- */
.deal-card { position: relative; cursor: grab; touch-action: none; }
.deal-card__edit { position: absolute; top: 0.4rem; right: 0.4rem; }
.deal-card.dragging { opacity: 0.35; }
.drag-ghost {
  position: fixed; transform: translate(-50%, -50%); pointer-events: none; z-index: 300;
  opacity: 0.95; box-shadow: 0 10px 28px rgba(15, 23, 42, 0.3); rotate: -2deg;
}
.column--over { outline: 2px dashed var(--blue); outline-offset: -3px; background: rgba(37, 99, 235, 0.04); }

/* ---- Tasks ---- */
.task-add { display: flex; gap: 0.5rem; margin-bottom: 1.2rem; flex-wrap: wrap; }
.task-add input[name="title"] { flex: 1; min-width: 160px; }
.task-add input[type="date"], .task-add select { width: auto; flex-shrink: 0; }
.task-group { margin-bottom: 1.3rem; }
.task-group h4 { color: var(--muted); text-transform: uppercase; font-size: 0.78rem; letter-spacing: 0.03em; margin-bottom: 0.5rem; }
.task-group--overdue { color: var(--danger); }
.task {
  display: flex; align-items: center; gap: 0.7rem; background: var(--card);
  border-radius: 10px; box-shadow: var(--shadow); padding: 0.7rem 0.8rem; margin-bottom: 0.5rem;
}
.task__check { width: 18px; height: 18px; flex-shrink: 0; }
.task__main { flex: 1; min-width: 0; }
.task__title { font-weight: 600; }
.task--done .task__title { text-decoration: line-through; color: var(--muted); }
.task__meta .overdue { color: var(--danger); font-weight: 700; }
.task-done { margin-top: 1rem; }
.task-done summary { cursor: pointer; color: var(--muted); font-weight: 600; margin-bottom: 0.6rem; }
