/* ==========================================================
   360 Degree M - v91 Premium CRM layer
   Direction: calm "ink & indigo" workspace. Hairline borders, soft depth,
   tabular figures, generous touch targets, bottom-sheet modals on phones.
   Loaded last; refines tokens and components without changing markup.
   ========================================================== */
:root {
  --purple: #5B43E6;            /* white-on-purple >= 6:1 (AA) */
  --purple-dark: #4631C9;
  --purple-light: rgba(91, 67, 230, .09);
  --purple-glow: rgba(91, 67, 230, .22);
  --bg: #F4F5F9;
  --card: #FFFFFF;
  --card-hover: #FAFAFD;
  --text: #12121C;
  --text2: #50506A;
  --text3: #6E6E86;             /* >= 4.5:1 on white */
  --border: #E4E5EF;
  --border2: #EEEFF6;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(18, 18, 40, .04), 0 1px 1px rgba(18, 18, 40, .03);
  --shadow-md: 0 6px 18px rgba(18, 18, 40, .07);
  --shadow-lg: 0 24px 60px rgba(18, 18, 40, .18);
  --ease: cubic-bezier(.22, .61, .36, 1);
  --safe-b: env(safe-area-inset-bottom, 0px);
}
html[data-theme="dark"] {
  --purple: #8B79FF; --purple-dark: #7563F2; --purple-light: rgba(139, 121, 255, .14);
  --bg: #0B0B12; --card: #14141D; --card-hover: #1A1A26; --text: #F2F2F8; --text2: #B4B4C7; --text3: #8A8AA0;
  --border: #25253A; --border2: #1D1D2C; --shadow-md: 0 6px 18px rgba(0, 0, 0, .35);
}

html { -webkit-text-size-adjust: 100%; }
body { font-family: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); font-feature-settings: "tnum" 1, "cv11" 1; -webkit-font-smoothing: antialiased; }
h1, h2, h3, h4 { letter-spacing: -.015em; font-weight: 650; }
:focus-visible { outline: 2px solid var(--purple); outline-offset: 2px; border-radius: 8px; }

/* Surfaces */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); transition: box-shadow .2s var(--ease), border-color .2s var(--ease); }
.card:hover { box-shadow: var(--shadow-md); }
.kpi-card { border-radius: var(--radius); border: 1px solid var(--border); background: var(--card); box-shadow: var(--shadow); position: relative; overflow: hidden; }
.kpi-card::before { content: ""; position: absolute; inset: 0 auto 0 0; width: 3px; background: linear-gradient(var(--purple), transparent); opacity: .85; }
.kpi-value { font-variant-numeric: tabular-nums; letter-spacing: -.02em; font-weight: 700; }
.kpi-label { text-transform: uppercase; letter-spacing: .06em; font-size: 11px; font-weight: 600; color: var(--text3); }

/* Shell */
.sidebar { background: var(--sidebar-bg, var(--card)); border-right: 1px solid var(--border); }
.sidebar-link { border-radius: 12px; min-height: 44px; transition: background .15s var(--ease), color .15s var(--ease); }
.sidebar-link.active { background: var(--purple-light); color: var(--purple); box-shadow: inset 3px 0 0 var(--purple); }
.header { backdrop-filter: saturate(160%) blur(14px); -webkit-backdrop-filter: saturate(160%) blur(14px); background: color-mix(in srgb, var(--card) 86%, transparent); border-bottom: 1px solid var(--border); }
.page { max-width: 1280px; }

/* Buttons & inputs */
.btn { min-height: 40px; border-radius: 11px; font-weight: 600; transition: transform .12s var(--ease), box-shadow .15s var(--ease), background .15s var(--ease); }
.btn:active { transform: scale(.97); }
.btn-purple { background: var(--purple); color: #fff; box-shadow: 0 1px 0 rgba(255,255,255,.18) inset, 0 4px 12px var(--purple-glow); }
.btn-purple:hover { background: var(--purple-dark); }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: var(--border2); }
.btn-sm { min-height: 36px; }
.btn-icon { min-width: 44px; min-height: 44px; }
.field-input, select.field-input, textarea.field-input { min-height: 44px; border-radius: 11px; border: 1px solid var(--border); background: var(--card); color: var(--text); font-size: 16px; padding: 10px 12px; transition: border-color .15s, box-shadow .15s; width: 100%; }
.field-input:focus { border-color: var(--purple); box-shadow: 0 0 0 4px var(--purple-light); outline: 0; }
.field-label { font-size: 12px; font-weight: 600; color: var(--text2); letter-spacing: .01em; }
.tag { border-radius: 999px; font-weight: 600; letter-spacing: .01em; }

/* Modals */
.modal-overlay { background: rgba(10, 10, 24, .5); backdrop-filter: blur(3px); }
.modal { border-radius: 20px; box-shadow: var(--shadow-lg); border: 1px solid var(--border); animation: v91-pop .22s var(--ease); }
@keyframes v91-pop { from { opacity: 0; transform: translateY(10px) scale(.98); } to { opacity: 1; transform: none; } }
@keyframes v91-sheet { from { transform: translateY(100%); } to { transform: none; } }

/* Partner workspace */
.partner-panel { margin-top: 16px; padding: 18px; border-color: color-mix(in srgb, var(--purple) 28%, var(--border)); background: linear-gradient(180deg, var(--purple-light), transparent 140px), var(--card); }
.partner-panel-head { display: flex; gap: 12px; align-items: center; margin-bottom: 14px; }
.partner-panel-head h3 { font-size: 17px; margin: 0; }
.partner-panel-head p { font-size: 12.5px; color: var(--text3); margin: 2px 0 0; }
.partner-lock { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--purple); color: #fff; flex: none; }
.pp-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 14px; }
.pp-stats div { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 12px; min-width: 0; }
.pp-stats span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text3); font-weight: 600; }
.pp-stats strong { display: block; font-size: 18px; margin-top: 4px; font-variant-numeric: tabular-nums; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pp-block { background: var(--card); border: 1px solid var(--border); border-radius: 14px; padding: 14px; margin-top: 12px; }
.pp-block-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 10px; }
.pp-block-head h4 { margin: 0; font-size: 14.5px; }
.pp-note { resize: vertical; line-height: 1.55; }
.pp-meta { display: block; margin-top: 6px; color: var(--text3); font-size: 12px; }
.pp-form { display: grid; grid-template-columns: 150px 1fr 1.4fr auto; gap: 8px; margin-bottom: 10px; align-items: center; }
.pp-contact-form { grid-template-columns: 1fr 1fr 1fr auto auto; }
.pp-check { display: flex; align-items: center; gap: 6px; font-size: 13px; min-height: 44px; color: var(--text2); }
.pp-check input { width: 18px; height: 18px; accent-color: var(--purple); }
.pp-list { list-style: none; margin: 0; padding: 0; }
.pp-list li { display: grid; grid-template-columns: 1fr auto auto; gap: 12px; align-items: center; padding: 11px 0; border-top: 1px solid var(--border2); }
.pp-list li > div:first-child { min-width: 0; }
.pp-list li strong { display: block; font-size: 14px; }
.pp-list li span { display: block; font-size: 12.5px; color: var(--text3); overflow: hidden; text-overflow: ellipsis; }
.pp-list li b { font-variant-numeric: tabular-nums; font-size: 15px; }
.pp-phone { color: var(--purple); font-weight: 600; text-decoration: none; min-height: 44px; display: inline-flex; align-items: center; }
.pp-row-actions { display: flex; gap: 6px; }
.pp-badge { font-style: normal; font-size: 10.5px; background: var(--purple-light); color: var(--purple); padding: 2px 8px; border-radius: 999px; margin-left: 6px; font-weight: 700; vertical-align: middle; }
.pp-empty, .partner-loading { color: var(--text3); font-size: 13px; padding: 6px 0; }
.v91-toast { position: fixed; left: 50%; bottom: calc(88px + var(--safe-b)); transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 11px 18px; border-radius: 999px; font-size: 14px; font-weight: 600; z-index: 9999; box-shadow: var(--shadow-lg); transition: opacity .3s; }
.v91-toast.out { opacity: 0; }

/* ---------- Mobile-first refinements ---------- */
@media (max-width: 760px) {
  .page { padding: 14px 14px calc(92px + var(--safe-b)); }
  .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .card { border-radius: 16px; }
  .bottom-nav { padding-bottom: var(--safe-b); background: color-mix(in srgb, var(--card) 92%, transparent); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--border); }
  .bottom-nav-item { min-height: 52px; min-width: 44px; }
  /* bottom-sheet modal */
  .modal-overlay { align-items: flex-end; }
  .modal { position: fixed; left: 0; right: 0; bottom: 0; top: auto; width: 100%; max-width: none; max-height: 92dvh; margin: 0; border-radius: 22px 22px 0 0; border-bottom: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: var(--safe-b); animation: v91-sheet .28s var(--ease); }
  .modal::before { content: ""; display: block; width: 40px; height: 4px; border-radius: 4px; background: var(--border); margin: 8px auto 0; }
  .form-grid.two, .form-grid { grid-template-columns: 1fr; }
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .pp-stats { grid-template-columns: 1fr 1fr; }
  .pp-stats div:last-child { grid-column: 1 / -1; }
  .pp-form, .pp-contact-form { grid-template-columns: 1fr; }
  .pp-form .btn { width: 100%; }
  .pp-list li { grid-template-columns: 1fr auto; }
  .pp-row-actions { grid-column: 1 / -1; }
  .pp-row-actions .btn { flex: 1; min-height: 44px; }
  .partner-panel { padding: 14px; }
}
@media (min-width: 761px) and (max-width: 1023px) { .pp-contact-form { grid-template-columns: 1fr 1fr; } .pp-form { grid-template-columns: 140px 1fr; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; } }

/* Desktop density: KPI rows fill the width instead of two wide columns */
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
@media (max-width: 760px) { .kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
.page-header h1 { font-size: clamp(22px, 2.2vw, 28px); letter-spacing: -.02em; }
.partner-locked { border-style: dashed; background: var(--card); }
.partner-locked .partner-lock { background: var(--text3); }
.client-profile-actions { display: flex; flex-wrap: nowrap; align-items: center; gap: 8px; }
.client-profile-actions .btn { flex: 0 0 auto; white-space: nowrap; width: auto; }
.client-profile-actions .btn-icon { flex: none; }
