/* =========================================================
   CLIENTHUB — DESIGN SYSTEM
   Palette: deep navy control-room sidebar + cool neutral canvas
   Type: Space Grotesk (display) / Inter (body) / JetBrains Mono (data)
   Signature: billing-cadence pill system (⚡ one-time / ↻ monthly / ⬡ yearly)
   ========================================================= */

:root {
  --ink:            #12141C;
  --ink-soft:       #3A3D4D;
  --canvas:         #F5F6FA;
  --surface:        #FFFFFF;
  --surface-sunken: #EEF0F6;
  --border:         #E3E5EE;

  --sidebar-top:    #171A26;
  --sidebar-bot:    #1F2333;
  --sidebar-ink:    #C7C9DA;
  --sidebar-ink-dim:#7C8098;

  --accent:         #4F6BFF;
  --accent-ink:     #FFFFFF;
  --accent-soft:    #EEF1FF;
  --accent-dark:    #3A50D9;

  --success:        #16A34A;
  --success-soft:   #E7F7ED;
  --warning:        #D97706;
  --warning-soft:   #FEF3E2;
  --danger:         #DC2626;
  --danger-soft:    #FDECEC;
  --info:           #0EA5E9;
  --info-soft:      #E6F7FE;
  --neutral-soft:   #EEF0F6;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --shadow-card: 0 1px 2px rgba(18,20,28,.04), 0 8px 24px -12px rgba(18,20,28,.10);
  --shadow-pop:  0 12px 32px -8px rgba(18,20,28,.22);

  --font-display: 'Space Grotesk', ui-sans-serif, sans-serif;
  --font-body:    'Inter', ui-sans-serif, sans-serif;
  --font-mono:    'JetBrains Mono', ui-monospace, monospace;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  background: var(--canvas);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4, .display {
  font-family: var(--font-display);
  letter-spacing: -0.02em;
  color: var(--ink);
  margin: 0;
}
a { color: inherit; text-decoration: none; }
.mono { font-family: var(--font-mono); letter-spacing: -0.02em; }

button, input, select, textarea { font-family: inherit; font-size: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Layout shell ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 264px;
  flex-shrink: 0;
  background: linear-gradient(180deg, var(--sidebar-top), var(--sidebar-bot));
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 24px 22px 18px;
}
.sidebar-brand .mark {
  width: 34px; height: 34px;
  border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #8AA0FF);
  display: flex; align-items: center; justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  color: #fff;
  font-size: 15px;
}
.sidebar-brand .name {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 17px;
  color: #fff;
}
.sidebar-nav { padding: 8px 12px; flex: 1; overflow-y: auto; }
.nav-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--sidebar-ink-dim);
  padding: 16px 12px 6px;
  font-weight: 600;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: 10px;
  font-size: 14px;
  font-weight: 500;
  color: var(--sidebar-ink);
  margin-bottom: 2px;
  transition: background .15s ease, color .15s ease;
}
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; opacity: .85; }
.nav-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav-item.active {
  background: rgba(79,107,255,.18);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--accent);
}
.nav-item .count {
  margin-left: auto;
  font-size: 11px;
  font-family: var(--font-mono);
  background: rgba(255,255,255,.09);
  padding: 1px 7px;
  border-radius: 20px;
  color: var(--sidebar-ink);
}
.sidebar-footer {
  padding: 14px 18px 20px;
  border-top: 1px solid rgba(255,255,255,.08);
  display: flex;
  align-items: center;
  gap: 10px;
}
.avatar {
  width: 34px; height: 34px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 13px;
  font-family: var(--font-display);
  flex-shrink: 0;
}
.sidebar-footer .who { flex: 1; min-width: 0; }
.sidebar-footer .who .n { font-size: 13px; font-weight: 600; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer .who .r { font-size: 11.5px; color: var(--sidebar-ink-dim); }
.logout-btn { color: var(--sidebar-ink-dim); }
.logout-btn:hover { color: #fff; }

/* ---------- Main content ---------- */
.main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
}
.topbar {
  height: 68px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 10;
}
.topbar .page-title { font-size: 20px; font-weight: 600; }
.topbar .page-sub { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--surface-sunken);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  width: 280px;
}
.search-box input { border: none; background: transparent; width: 100%; font-size: 13.5px; }
.search-box input:focus { outline: none; }
.search-box svg { width: 16px; height: 16px; color: var(--ink-soft); flex-shrink: 0; }

.content { padding: 26px 28px 60px; }

/* ---------- Cards / grid ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-card);
}
.card-pad { padding: 20px 22px; }
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.card-header h3 { font-size: 15.5px; font-weight: 600; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 22px; }
@media (max-width: 1100px) { .stat-grid { grid-template-columns: repeat(2, 1fr); } }

.stat-grid-2col { grid-template-columns: repeat(2, 1fr); }
@media (max-width: 480px) { .stat-grid-2col { grid-template-columns: 1fr; } }

.stat-grid-3col { grid-template-columns: repeat(3, 1fr); }
@media (max-width: 1100px) { .stat-grid-3col { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 480px) { .stat-grid-3col { grid-template-columns: 1fr; } }

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 18px 20px;
  box-shadow: var(--shadow-card);
  position: relative;
  overflow: hidden;
}
.stat-card .icon-badge {
  width: 36px; height: 36px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px;
}
.stat-card .icon-badge svg { width: 18px; height: 18px; }
.stat-card .label { font-size: 12.5px; color: var(--ink-soft); font-weight: 500; }
.stat-card .value { font-family: var(--font-display); font-size: 26px; font-weight: 600; margin-top: 4px; }
.stat-card .delta { font-size: 12px; margin-top: 6px; font-weight: 500; }
.stat-card .delta.up { color: var(--success); }
.stat-card .delta.down { color: var(--danger); }

.grid-2 { display: grid; grid-template-columns: 1.6fr 1fr; gap: 18px; }
@media (max-width: 1100px) { .grid-2 { grid-template-columns: 1fr; } }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 9px 16px;
  border-radius: 10px;
  font-size: 13.5px;
  font-weight: 600;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform .05s ease, background .15s ease, box-shadow .15s ease;
  line-height: 1.2;
}
.btn svg { width: 15px; height: 15px; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 4px 10px -4px rgba(79,107,255,.55); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-secondary { background: var(--surface); border-color: var(--border); color: var(--ink); }
.btn-secondary:hover { background: var(--surface-sunken); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: #FADCDC; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 8px; }
.btn-icon { width: 34px; height: 34px; padding: 0; border-radius: 9px; }

/* ---------- Forms ---------- */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--ink); }
.form-label .req { color: var(--danger); }
.form-control {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  font-size: 13.5px;
  color: var(--ink);
  transition: border-color .15s ease, box-shadow .15s ease;
}
.form-control:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,107,255,.14); outline: none; }
textarea.form-control { resize: vertical; min-height: 90px; }
.form-hint { font-size: 12px; color: var(--ink-soft); margin-top: 5px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 700px) { .form-row { grid-template-columns: 1fr; } }

.type-picker { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.type-option {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.type-option:hover { background: var(--surface-sunken); }
.type-option input { display: none; }
.type-option .ti { font-size: 18px; margin-bottom: 4px; display: block; }
.type-option .tn { font-weight: 600; font-size: 13px; }
.type-option .td { font-size: 11.5px; color: var(--ink-soft); }
.type-option:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }

/* ---------- Badges (signature billing-cadence system) ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 11.5px; font-weight: 600;
  padding: 3px 10px;
  border-radius: 20px;
  white-space: nowrap;
}
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-danger  { background: var(--danger-soft);  color: var(--danger); }
.badge-info    { background: var(--info-soft);    color: var(--info); }
.badge-neutral { background: var(--neutral-soft); color: var(--ink-soft); }

.badge-onetime { background: #FDF0E6; color: #B45309; }
.badge-monthly { background: #E7F0FF; color: #2952CC; }
.badge-semiannual { background: #E1F7F2; color: #0F766E; }
.badge-yearly  { background: #F0E9FE; color: #6D28D9; }

.dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.dot-success { background: var(--success); }
.dot-warning { background: var(--warning); }
.dot-danger  { background: var(--danger); }
.dot-info    { background: var(--info); }
.dot-neutral { background: #9AA0B4; }
.pulse { animation: pulse 1.8s infinite; }
@keyframes pulse { 0%{ box-shadow:0 0 0 0 rgba(220,38,38,.35);} 70%{ box-shadow:0 0 0 6px rgba(220,38,38,0);} 100%{box-shadow:0 0 0 0 rgba(220,38,38,0);} }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.data-table th {
  text-align: left;
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--ink-soft);
  font-weight: 600;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-sunken);
  white-space: nowrap;
}
.data-table td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr { transition: background .12s ease; }
.data-table tbody tr:hover { background: #FAFBFD; }
.data-table tbody tr:last-child td { border-bottom: none; }
.row-link { cursor: pointer; }
.cell-primary { font-weight: 600; color: var(--ink); }
.cell-muted { color: var(--ink-soft); font-size: 12.5px; }

/* ---------- Misc ---------- */
.empty-state { text-align: center; padding: 60px 20px; color: var(--ink-soft); }
.empty-state .icon { font-size: 34px; margin-bottom: 10px; }
.empty-state h4 { font-size: 15px; margin-bottom: 6px; color: var(--ink); }
.empty-state p { font-size: 13px; margin: 0 0 16px; }

.pill-tabs { display: flex; gap: 6px; background: var(--surface-sunken); padding: 4px; border-radius: 11px; width: fit-content; }
.pill-tab { padding: 7px 14px; border-radius: 8px; font-size: 13px; font-weight: 600; color: var(--ink-soft); }
.pill-tab.active { background: var(--surface); color: var(--ink); box-shadow: var(--shadow-card); }

.alert { padding: 12px 16px; border-radius: 10px; font-size: 13.5px; margin-bottom: 18px; display: flex; align-items: center; gap: 10px; }
.alert-success { background: var(--success-soft); color: #0f7a35; }
.alert-danger { background: var(--danger-soft); color: var(--danger); }

.breadcrumb { font-size: 12.5px; color: var(--ink-soft); margin-bottom: 4px; }
.breadcrumb a:hover { color: var(--accent); }

.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ''; position: absolute; left: 5px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding-bottom: 20px; }
.timeline-item::before { content: ''; position: absolute; left: -22px; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: var(--accent); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--border); }
.timeline-item:last-child { padding-bottom: 0; }

.thread-msg { display: flex; gap: 12px; margin-bottom: 18px; }
.thread-msg .bubble { flex: 1; background: var(--surface-sunken); border-radius: var(--radius-sm); padding: 12px 14px; }
.thread-msg.client .bubble { background: var(--accent-soft); }
.thread-msg .meta { font-size: 11.5px; color: var(--ink-soft); margin-bottom: 4px; display: flex; gap: 8px; align-items: center; }
.thread-msg .meta b { color: var(--ink); }

.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: radial-gradient(circle at 20% 20%, #232744 0%, var(--sidebar-top) 45%, #0E101A 100%);
  padding: 20px;
}
.login-card { width: 100%; max-width: 400px; background: var(--surface); border-radius: var(--radius-lg); padding: 36px 32px; box-shadow: var(--shadow-pop); }
.login-card .mark { width: 44px; height: 44px; border-radius: 12px; background: linear-gradient(135deg, var(--accent), #8AA0FF); display: flex; align-items: center; justify-content: center; color: #fff; font-family: var(--font-display); font-weight: 700; margin-bottom: 18px; }

.progress-bar { height: 6px; border-radius: 6px; background: var(--surface-sunken); overflow: hidden; }
.progress-bar > div { height: 100%; background: var(--accent); border-radius: 6px; }

/* ---------- Mobile menu toggle ---------- */
.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  flex-shrink: 0;
}
.menu-toggle svg { width: 19px; height: 19px; }
.menu-toggle:hover { background: var(--surface-sunken); }

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15,17,26,.5);
  z-index: 40;
}
body.sidebar-open .sidebar-overlay { display: block; }

/* ---------- Responsive breakpoints ---------- */
@media (max-width: 1024px) {
  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    height: 100dvh;
    width: 272px;
    max-width: 84vw;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .28s ease;
    box-shadow: var(--shadow-pop);
  }
  body.sidebar-open .sidebar { transform: translateX(0); }
  .menu-toggle { display: inline-flex; }
  .main { width: 100%; min-width: 0; }
}

@media (max-width: 860px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; }
  .grid-2 { grid-template-columns: 1fr; }
}

@media (max-width: 767px) {
  .topbar { padding: 0 16px; height: 60px; gap: 10px; }
  .topbar .page-title { font-size: 17px; }
  .topbar .page-sub { display: none; }
  .search-box { display: none; }
  .content { padding: 16px 16px 48px; }

  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 14px 15px; }
  .stat-card .value { font-size: 19px; }
  .stat-card .icon-badge { width: 32px; height: 32px; margin-bottom: 10px; }

  .card-header { padding: 14px 16px; flex-wrap: wrap; gap: 8px; }
  .card-pad { padding: 16px; }

  .type-picker { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }

  .pill-tabs {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .pill-tabs::-webkit-scrollbar { display: none; }
  .pill-tab { white-space: nowrap; flex-shrink: 0; }

  .data-table th, .data-table td { padding: 11px 13px; font-size: 12.5px; }

  .btn { padding: 9px 14px; font-size: 13px; }

  .login-card { padding: 28px 22px; }

  /* Buttons/actions that were inline flex-row stack cleanly */
  form.card > div[style*="justify-content:space-between"],
  form.card > div[style*="justify-content: space-between"] {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .sidebar-brand .name { font-size: 16px; }
  .card-header h3 { font-size: 14.5px; }
  .topbar .page-title { font-size: 16px; }
}

/* Larger, easier-to-tap touch targets on coarse pointers (phones/tablets) */
@media (pointer: coarse) {
  .btn, .nav-item, .pill-tab, .form-control, select.form-control { min-height: 40px; }
  .btn-sm { min-height: 32px; }
  .btn-icon { min-height: 34px; }
}

.kv-list { font-size: 13.5px; }
.kv-list .row { display: flex; justify-content: space-between; padding: 9px 0; border-bottom: 1px dashed var(--border); }
.kv-list .row:last-child { border-bottom: none; }
.kv-list .k { color: var(--ink-soft); }
.kv-list .v { font-weight: 600; text-align: right; }

/* ---------- Mini Datepicker (dd/mm/yyyy) ---------- */
input.date-input {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%235A5D70' stroke-width='2'%3E%3Crect x='3' y='4' width='18' height='18' rx='2'/%3E%3Cpath d='M16 2v4M8 2v4M3 10h18'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 15px;
  padding-right: 38px;
}

.mini-datepicker {
  position: absolute;
  z-index: 200;
  width: 264px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-pop);
  padding: 14px;
  font-family: var(--font-body);
}
.mdp-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.mdp-label {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 13.5px;
}
.mdp-nav {
  width: 28px;
  height: 28px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--ink);
  cursor: pointer;
  font-size: 15px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mdp-nav:hover { background: var(--surface-sunken); }
.mdp-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.mdp-dow {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ink-soft);
  text-align: center;
  padding-bottom: 6px;
}
.mdp-day {
  aspect-ratio: 1;
  border: none;
  background: transparent;
  border-radius: 8px;
  font-size: 12.5px;
  color: var(--ink);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}
.mdp-day:hover:not(.mdp-blank) { background: var(--surface-sunken); }
.mdp-day.mdp-blank { cursor: default; }
.mdp-day.mdp-today { font-weight: 700; color: var(--accent); }
.mdp-day.mdp-selected { background: var(--accent); color: #fff; font-weight: 600; }
.mdp-footer {
  display: flex;
  justify-content: space-between;
  margin-top: 10px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.mdp-link-btn {
  border: none;
  background: transparent;
  color: var(--accent);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  padding: 4px 6px;
}
.mdp-link-btn:hover { text-decoration: underline; }
.mdp-link-btn.mdp-clear { color: var(--ink-soft); }
