/* Sales & Commission Log — mobile-first, zero build */
:root {
  --teal: #0f766e;
  --teal-dark: #0b5e57;
  --teal-light: #e6f4f2;
  --ink: #1a1a1a;
  --muted: #666;
  --border: #ddd;
  --bg: #f7f7f5;
  --card: #fff;
  --danger: #b91c1c;
  --danger-bg: #fef2f2;
  --radius: 12px;
  --shadow: 0 1px 4px rgba(0, 0, 0, .08);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--ink);
  line-height: 1.5;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
h1 { font-size: 1.25rem; margin: 0; line-height: 1.2; }
h2 { font-size: 1.25rem; margin: 0 0 .5rem; }
h3 { font-size: 1rem; margin: 0 0 .75rem; }
p { margin: 0 0 .75rem; }
.hidden { display: none !important; }

/* ---------- Header / top nav (desktop) ---------- */
.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-inner {
  max-width: 960px;
  margin: 0 auto;
  padding: .75rem 1rem;
  display: flex;
  align-items: center;
  gap: 1rem;
}
.brand { display: flex; align-items: center; gap: .6rem; flex: 1; min-width: 0; }
.brand-mark {
  width: 36px; height: 36px; flex: none;
  display: grid; place-items: center;
  background: var(--teal); color: #fff;
  border-radius: 10px; font-weight: 700; font-size: 1.25rem;
}
.brand-sub { margin: 0; font-size: .8rem; color: var(--muted); }
/* Top nav is hidden on mobile — the bottom bar is the nav there. */
.topnav { display: none; gap: .25rem; }
.refresh-btn {
  min-height: 44px; padding: .5rem .75rem;
  border: 1px solid var(--border); border-radius: 10px;
  background: #fff; color: var(--ink); cursor: pointer; font-size: .9rem;
}
.refresh-btn:active { background: var(--teal-light); }
.sync-state { font-size: .8rem; color: var(--muted); margin-left: .25rem; }

/* ---------- Layout ---------- */
.container { max-width: 960px; margin: 0 auto; padding: 1rem 1rem 2rem; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.hint { color: var(--muted); font-size: .9rem; }
.optional { color: var(--muted); font-weight: 400; }

/* ---------- Forms ---------- */
.field { margin-bottom: 1rem; }
.field label { display: block; font-weight: 600; margin-bottom: .35rem; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: .75rem; }
input, select, textarea {
  width: 100%; min-height: 44px;
  padding: .6rem .75rem;
  font: inherit; font-size: 1rem;
  border: 1px solid var(--border); border-radius: 10px;
  background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--teal); outline-offset: 1px; border-color: var(--teal);
}
textarea { resize: vertical; min-height: 44px; }
.colleague-row { display: flex; gap: .5rem; }
.colleague-row select { flex: 1; min-width: 0; }
.add-colleague { display: flex; gap: .5rem; margin-top: .5rem; }
.add-colleague input { flex: 1; min-width: 0; }

/* % quick-calc helper — fills commission, field stays manually editable */
.pct-helper { display: flex; align-items: center; flex-wrap: wrap; gap: .4rem; margin-top: .5rem; }
.pct-label { font-size: .9rem; color: var(--muted); }
.pct-chip {
  min-width: 44px; min-height: 44px; padding: .4rem .7rem;
  border: 1px solid var(--border); border-radius: 999px;
  background: #fff; cursor: pointer; font-size: .9rem;
}
.pct-chip:active, .pct-chip.active { background: var(--teal-light); border-color: var(--teal); }
.pct-custom { display: flex; align-items: center; gap: .25rem; }
.pct-custom input { width: 72px; text-align: right; }
.form-error { color: var(--danger); font-size: .9rem; }

/* ---------- Buttons ---------- */
.btn {
  min-height: 44px; padding: .65rem 1rem;
  border-radius: 10px; border: 1px solid transparent;
  font: inherit; font-size: 1rem; font-weight: 600;
  cursor: pointer; display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
}
.btn:disabled { opacity: .6; cursor: wait; }
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:active { background: var(--teal-dark); }
.btn-secondary { background: #fff; border-color: var(--border); color: var(--ink); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--ink); font-size: .9rem; white-space: nowrap; }
.btn-small { min-height: 44px; padding: .4rem .7rem; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-spinner {
  width: 16px; height: 16px; flex: none;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  border-radius: 50%; animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Bottom nav (mobile) ---------- */
.bottomnav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex;
  background: var(--card);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
}
.bottomnav .nav-btn, .topnav .nav-btn {
  flex: 1; min-height: 56px;
  border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 1rem; font-weight: 600; color: var(--muted);
}
.topnav .nav-btn { flex: none; min-height: 44px; padding: .5rem 1rem; border-radius: 10px; }
.nav-btn.active { color: var(--teal); background: var(--teal-light); }

/* ---------- Loading / error / empty ---------- */
.loading { text-align: center; padding: 2rem 0; color: var(--muted); }
.spinner {
  width: 28px; height: 28px; margin: 0 auto .75rem;
  border: 3px solid var(--border); border-top-color: var(--teal);
  border-radius: 50%; animation: spin .8s linear infinite;
}
.skeleton {
  height: 72px; border-radius: var(--radius);
  background: linear-gradient(90deg, #eee, #f6f6f6, #eee);
  margin: .75rem 0;
}
.error-banner {
  background: var(--danger-bg); border: 1px solid #fecaca;
  border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem;
}
.empty-state { color: var(--muted); text-align: center; padding: 2rem 1rem; }

/* ---------- Filters / KPIs / charts ---------- */
.filters {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.preset-row { display: flex; flex-wrap: wrap; gap: .5rem; margin-bottom: 1rem; }
.preset-btn {
  min-height: 44px; padding: .5rem .9rem;
  border: 1px solid var(--border); border-radius: 999px;
  background: #fff; cursor: pointer; font-size: .9rem;
}
.preset-btn.active { background: var(--teal); color: #fff; border-color: var(--teal); }
.kpis { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; margin-bottom: 1rem; }
.kpi-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: .9rem .75rem; box-shadow: var(--shadow);
}
.kpi-label { display: block; font-size: .8rem; color: var(--muted); margin-bottom: .25rem; }
.kpi-value { font-size: 1.05rem; word-break: break-word; }
.charts { display: grid; gap: 1rem; margin-bottom: 1rem; }
.chart-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow);
}
.chart-wrap { position: relative; width: 100%; height: 240px; }
.empty-chart { color: var(--muted); text-align: center; margin: .5rem 0 0; }
.records-heading { margin-top: 1.5rem; }

/* ---------- Records: mobile cards ---------- */
.cards-list { display: grid; gap: .75rem; }
.record-card {
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 1rem; box-shadow: var(--shadow);
}
.record-head { display: flex; justify-content: space-between; gap: .5rem; margin-bottom: .5rem; }
.record-date { font-weight: 600; }
.badge {
  background: var(--teal-light); color: var(--teal-dark);
  border-radius: 999px; padding: .15rem .6rem; font-size: .85rem; font-weight: 600;
  white-space: nowrap;
}
.record-amounts { display: flex; gap: 1.25rem; margin-bottom: .5rem; }
.record-amounts span { display: block; font-size: .8rem; color: var(--muted); }
.record-amounts strong { font-size: 1rem; }
.record-remarks { color: var(--muted); font-size: .9rem; margin-bottom: .75rem; word-break: break-word; }
.record-actions { display: flex; gap: .5rem; }
.record-actions .btn { flex: 1; }

/* Desktop table is hidden on mobile. */
.table-wrap { display: none; }

/* ---------- Modals ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: flex-end; justify-content: center;
}
.modal-backdrop { position: absolute; inset: 0; background: rgba(0,0,0,.5); }
.modal-card {
  position: relative; width: 100%; max-width: 520px; max-height: 92vh; overflow: auto;
  background: #fff; border-radius: 16px 16px 0 0; padding: 1.25rem;
  padding-bottom: calc(1.25rem + env(safe-area-inset-bottom));
}
.modal-card-small { max-width: 420px; }
.modal-text { color: var(--muted); }
.modal-actions { display: flex; gap: .5rem; justify-content: flex-end; margin-top: 1rem; }
.modal-actions .btn { flex: 1; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 60;
  background: var(--ink); color: #fff;
  padding: .75rem 1.25rem; border-radius: 999px;
  font-size: .95rem; max-width: calc(100vw - 2rem); text-align: center;
  box-shadow: 0 4px 16px rgba(0,0,0,.25);
}
.toast.error { background: var(--danger); }

/* ---------- Desktop >= 768px ---------- */
@media (min-width: 768px) {
  body { padding-bottom: 0; }
  .bottomnav { display: none; }
  .topnav { display: flex; }
  .toast { bottom: 2rem; }
  .charts { grid-template-columns: 1fr 1fr; }
  .cards-list { display: none; }
  .table-wrap { display: block; overflow-x: auto; }
  .records-table {
    width: 100%; border-collapse: collapse;
    background: var(--card); border: 1px solid var(--border);
    border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  }
  .records-table th, .records-table td {
    text-align: left; padding: .75rem; border-bottom: 1px solid var(--border);
    vertical-align: top;
  }
  .records-table th { background: #fafafa; font-size: .9rem; white-space: nowrap; }
  .records-table td { font-size: .95rem; }
  .records-table tr:last-child td { border-bottom: 0; }
  .sort-btn {
    border: 0; background: none; cursor: pointer;
    font: inherit; font-weight: 700; padding: 0; min-height: 44px;
  }
  .modal { align-items: center; padding: 1rem; }
  .modal-card { border-radius: 16px; padding-bottom: 1.25rem; }
  .modal-actions .btn { flex: none; }
  .kpi-value { font-size: 1.35rem; }
}
