@import url('https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;700&family=Roboto:wght@300;400;500&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --primary:   #1a73e8;
  --primary-d: #1557b0;
  --primary-l: #e8f0fe;
  --green:     #34a853;
  --yellow:    #fbbc04;
  --red:       #ea4335;
  --surface:   #ffffff;
  --bg:        #f1f3f4;
  --border:    #dadce0;
  --text:      #202124;
  --text2:     #5f6368;
  --sh-s: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.08);
  --sh-m: 0 4px 16px rgba(0,0,0,.10);
  --sh-l: 0 8px 40px rgba(0,0,0,.14);
  --r:  12px;
  --rs: 8px;
  --tr: all .2s cubic-bezier(.4,0,.2,1);
  --sb: 256px;
  --tb: 58px;
}

html { font-size: 15px; }
body { font-family: 'Roboto', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }

/* ══════════════════════════════════════════
   LOGIN SCREEN
══════════════════════════════════════════ */
#login-screen {
  display: none;
  min-height: 100vh;
  background: linear-gradient(145deg, #1557b0 0%, #1a73e8 55%, #0d47a1 100%);
  align-items: center;
  justify-content: center;
  padding: 20px;
  position: relative;
  overflow: hidden;
}
#login-screen.visible { display: flex; }

#login-screen::before {
  content: ''; position: absolute;
  width: 600px; height: 600px; border-radius: 50%;
  background: rgba(255,255,255,.06);
  top: -180px; right: -120px; pointer-events: none;
}
#login-screen::after {
  content: ''; position: absolute;
  width: 400px; height: 400px; border-radius: 50%;
  background: rgba(255,255,255,.05);
  bottom: -120px; left: -80px; pointer-events: none;
}

.login-card {
  background: #fff; border-radius: 20px;
  padding: 48px 44px 44px; width: 100%; max-width: 420px;
  box-shadow: 0 24px 80px rgba(0,0,0,.28);
  position: relative; z-index: 1;
  animation: lIn .3s cubic-bezier(.4,0,.2,1);
}
@keyframes lIn {
  from { opacity: 0; transform: translateY(18px) scale(.97); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

.login-logo {
  display: flex; align-items: center; gap: 14px; margin-bottom: 36px;
}
.login-logo-icon {
  width: 52px; height: 52px; background: var(--primary); border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-size: 26px; flex-shrink: 0;
}
.login-logo-text { font-family: 'Google Sans', sans-serif; font-size: 22px; font-weight: 700; }
.login-logo-text span { color: var(--primary); }
.login-sub { font-size: 12px; color: var(--text2); margin-top: 2px; }
.login-hint { font-size: 12px; color: var(--text2); text-align: center; margin-top: 18px; line-height: 1.6; }
.login-err {
  background: #fce8e6; border: 1px solid #f5c6c2; border-radius: var(--rs);
  padding: 10px 14px; font-size: 13px; color: var(--red); margin-bottom: 16px;
  display: none;
}

/* ══════════════════════════════════════════
   APP SHELL
══════════════════════════════════════════ */
#main-app { display: none; min-height: 100vh; }
#main-app.visible { display: block; }

/* ── Sidebar ── */
.sidebar {
  width: var(--sb); background: var(--surface);
  border-right: 1px solid var(--border);
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 300;
  display: flex; flex-direction: column;
  transition: transform .28s cubic-bezier(.4,0,.2,1), box-shadow .28s;
  overflow: hidden;
}
.sidebar-header {
  height: var(--tb); padding: 0 20px;
  display: flex; align-items: center; gap: 12px;
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.sidebar-logo-img  { height: 32px; max-width: 120px; object-fit: contain; }
.sidebar-logo-icon { width: 34px; height: 34px; background: var(--primary); border-radius: 9px; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 18px; flex-shrink: 0; }
.sidebar-logo-text { font-family: 'Google Sans', sans-serif; font-size: 17px; font-weight: 700; }
.sidebar-logo-text span { color: var(--primary); }
.sidebar-nav { flex: 1; overflow-y: auto; padding: 10px 0; }
.nav-item {
  display: flex; align-items: center; gap: 14px;
  padding: 12px 20px; cursor: pointer; color: var(--text2);
  font-size: 14px; font-weight: 500;
  border-radius: 0 24px 24px 0; margin-right: 12px;
  transition: var(--tr); user-select: none;
}
.nav-item:hover  { background: var(--bg); color: var(--text); }
.nav-item.active { background: var(--primary-l); color: var(--primary); }
.nav-item .ni    { font-size: 19px; width: 22px; text-align: center; flex-shrink: 0; }
.sidebar-footer  { padding: 14px 20px; border-top: 1px solid var(--border); font-size: 11px; color: var(--text2); }

/* Sidebar overlay (mobile) */
.sb-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 299; }
.sb-overlay.open { display: block; }

/* ── Topbar ── */
.topbar-wrap { margin-left: var(--sb); }
.topbar {
  height: var(--tb); background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  padding: 0 20px; position: sticky; top: 0; z-index: 200;
}
.burger {
  display: none; background: none; border: none; cursor: pointer;
  width: 36px; height: 36px; border-radius: 8px;
  align-items: center; justify-content: center;
  font-size: 20px; color: var(--text2); transition: var(--tr); flex-shrink: 0;
}
.burger:hover { background: var(--bg); color: var(--text); }
.topbar-title { font-family: 'Google Sans', sans-serif; font-size: 17px; font-weight: 500; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* Search */
.search-wrap { position: relative; }
.search-box {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1.5px solid var(--border);
  border-radius: 24px; padding: 7px 16px; width: 280px; transition: var(--tr);
}
.search-box:focus-within { background: #fff; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,115,232,.12); }
.search-box input { border: none; background: none; outline: none; font-size: 14px; color: var(--text); width: 100%; }
.search-box .si   { color: var(--text2); font-size: 17px; flex-shrink: 0; }
.search-clear { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; color: var(--text2); font-size: 16px; display: none; }
.search-clear.show { display: block; }

/* User menu */
.user-menu    { position: relative; margin-left: 4px; }
.user-btn {
  display: flex; align-items: center; gap: 8px;
  background: none; border: 1.5px solid var(--border);
  border-radius: 24px; padding: 5px 12px 5px 5px;
  cursor: pointer; transition: var(--tr);
}
.user-btn:hover { background: var(--bg); }
.u-avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; flex-shrink: 0; overflow: hidden; }
.u-name   { font-size: 13px; font-weight: 500; }
.u-arr    { font-size: 10px; color: var(--text2); }

.u-dropdown {
  position: absolute; right: 0; top: calc(100% + 8px);
  background: #fff; border: 1px solid var(--border);
  border-radius: var(--r); box-shadow: var(--sh-m);
  min-width: 190px; z-index: 400; overflow: hidden;
  animation: ddIn .15s ease;
}
@keyframes ddIn { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }
.u-dd-item { display: flex; align-items: center; gap: 10px; padding: 12px 16px; font-size: 14px; cursor: pointer; transition: background .12s; }
.u-dd-item:hover   { background: var(--bg); }
.u-dd-sep          { height: 1px; background: var(--border); margin: 4px 0; }
.u-dd-danger       { color: var(--red); }
.u-dd-danger:hover { background: #fce8e6; }

/* ── Content ── */
.content { padding: 22px 24px; }
.page { display: none; }
.page.active { display: block; }

/* ── Stats grid ── */
.stats-grid { display: grid; grid-template-columns: repeat(4,1fr); gap: 14px; margin-bottom: 22px; }
.stat-card  { background: var(--surface); border-radius: var(--r); padding: 16px 18px; box-shadow: var(--sh-s); display: flex; align-items: center; gap: 14px; transition: var(--tr); }
.stat-card:hover { box-shadow: var(--sh-m); transform: translateY(-1px); }
.stat-ico   { width: 44px; height: 44px; border-radius: 11px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.si-blue    { background: #e8f0fe; }
.si-green   { background: #e6f4ea; }
.si-yellow  { background: #fef7e0; }
.si-red     { background: #fce8e6; }
.stat-val   { font-family: 'Google Sans', sans-serif; font-size: 22px; font-weight: 700; }
.stat-lbl   { font-size: 12px; color: var(--text2); margin-top: 1px; }

/* ── Card ── */
.card { background: var(--surface); border-radius: var(--r); box-shadow: var(--sh-s); overflow: hidden; }
.card + .card { margin-top: 16px; }
.card-hd { padding: 16px 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); gap: 10px; flex-wrap: wrap; }
.card-title { font-family: 'Google Sans', sans-serif; font-size: 15px; font-weight: 500; }
.card-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Table ── */
.tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead th { background: var(--bg); padding: 10px 14px; text-align: left; font-weight: 500; color: var(--text2); font-size: 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
thead th.sortable { cursor: pointer; }
thead th.sortable:hover { color: var(--primary); }
thead th.sort-asc::after  { content: ' ↑'; color: var(--primary); }
thead th.sort-desc::after { content: ' ↓'; color: var(--primary); }
tbody tr { border-bottom: 1px solid #f1f3f4; transition: background .12s; cursor: pointer; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8f9fa; }
tbody td { padding: 12px 14px; vertical-align: middle; }

/* Alert row highlighting */
tbody tr.row-alert-yellow              { background: #fffde7; }
tbody tr.row-alert-yellow:hover        { background: #fff9c4; }
tbody tr.row-alert-red                 { background: #fff3f3; }
tbody tr.row-alert-red:hover           { background: #ffe5e5; }

.empty-state { text-align: center; padding: 52px 20px; color: var(--text2); }
.empty-state .ei { font-size: 44px; margin-bottom: 10px; }

/* ── Buttons ── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: var(--rs); font-size: 13px; font-weight: 500; border: none; cursor: pointer; transition: var(--tr); white-space: nowrap; font-family: inherit; }
.btn-p { background: var(--primary); color: #fff; }
.btn-p:hover  { background: var(--primary-d); box-shadow: var(--sh-s); }
.btn-o { background: transparent; border: 1.5px solid var(--border); color: var(--text); }
.btn-o:hover  { background: var(--bg); border-color: #aaa; }
.btn-g { background: #e6f4ea; color: #137333; }
.btn-g:hover  { background: var(--green); color: #fff; }
.btn-d { background: #fce8e6; color: var(--red); }
.btn-d:hover  { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 11px; font-size: 12px; border-radius: 6px; }
.btn-ic { padding: 6px; border-radius: 7px; }

/* ── Badges ── */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 9px; border-radius: 20px; font-size: 11px; font-weight: 500; }
/* subscription status */
.b-active     { background: #e6f4ea; color: #137333; }
.b-completed  { background: #e8f0fe; color: #1967d2; }
.b-expired    { background: #f1f3f4; color: var(--text2); }
/* subscription types */
.b-group      { background: #fef7e0; color: #b06000; }
.b-individual { background: #fce8e6; color: #c5221f; }
.b-split      { background: #e8f0fe; color: #1a73e8; }
/* alert badges */
.b-alert-yellow { background: #fff3cd; color: #856404; border: 1px solid #ffd84d; }
.b-alert-red    { background: #fce8e6; color: #c5221f; border: 1px solid #f5a9a4; }

/* ── Avatar ── */
.av { width: 32px; height: 32px; border-radius: 50%; background: var(--primary-l); color: var(--primary); display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 600; flex-shrink: 0; overflow: hidden; }
.av img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.client-cell { display: flex; align-items: center; gap: 10px; }
.c-name { font-weight: 500; font-size: 14px; }
.c-meta { font-size: 11px; color: var(--text2); }

/* ── Progress bar ── */
.prog-wrap { display: flex; align-items: center; gap: 8px; }
.prog-bar  { flex: 1; height: 5px; background: #e8eaed; border-radius: 3px; overflow: hidden; min-width: 50px; }
.prog-fill { height: 100%; border-radius: 3px; transition: width .4s; background: var(--primary); }
.prog-fill.done { background: var(--green); }
.prog-fill.warn { background: var(--yellow); }
.prog-lbl  { font-size: 11px; color: var(--text2); white-space: nowrap; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45);
  z-index: 1000; display: flex; align-items: center; justify-content: center;
  opacity: 0; pointer-events: none; transition: opacity .2s; padding: 16px;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: #fff; border-radius: 16px; width: 100%; max-width: 580px;
  max-height: 92vh; overflow-y: auto; box-shadow: var(--sh-l);
  transform: scale(.96) translateY(8px);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
}
.modal-overlay.open .modal { transform: scale(1) translateY(0); }
.modal-hd    { padding: 22px 24px 0; display: flex; align-items: center; justify-content: space-between; }
.modal-title { font-family: 'Google Sans', sans-serif; font-size: 17px; font-weight: 600; }
.modal-close { width: 32px; height: 32px; border-radius: 50%; border: none; background: var(--bg); cursor: pointer; font-size: 15px; display: flex; align-items: center; justify-content: center; transition: var(--tr); color: var(--text2); }
.modal-close:hover { background: #e8eaed; color: var(--text); }
.modal-body  { padding: 16px 24px 24px; }
.modal-ft    { padding: 12px 24px 20px; display: flex; gap: 10px; justify-content: flex-end; border-top: 1px solid var(--border); }

/* ── Form ── */
.fg2 { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.ff  { grid-column: 1 / -1; }
.fg  { display: flex; flex-direction: column; gap: 5px; }
.fl  { font-size: 12px; font-weight: 500; color: var(--text2); }
.fc  { padding: 9px 12px; border: 1.5px solid var(--border); border-radius: var(--rs); font-size: 14px; color: var(--text); outline: none; transition: var(--tr); background: #fff; font-family: inherit; width: 100%; }
.fc:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,115,232,.1); }
textarea.fc { resize: vertical; min-height: 74px; }
select.fc   { cursor: pointer; }

/* Password field */
.pw { position: relative; }
.pw .fc { padding-right: 40px; }
.pt { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; font-size: 15px; color: var(--text2); padding: 4px; line-height: 1; }
.pt:hover { color: var(--text); }

/* Photo upload */
.photo-upload-area { display: flex; align-items: center; gap: 16px; }
.photo-preview { width: 72px; height: 72px; border-radius: 50%; background: var(--bg); border: 2px dashed var(--border); display: flex; align-items: center; justify-content: center; font-size: 28px; overflow: hidden; flex-shrink: 0; }
.photo-preview img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

/* Custom field rows */
.cf-section { margin-top: 14px; border-top: 1px solid var(--border); padding-top: 14px; }
.cf-row     { display: flex; gap: 8px; align-items: flex-end; margin-bottom: 8px; }
.cf-row .fc { flex: 1; }

/* ── Tabs ── */
.tabs { display: flex; border-bottom: 2px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tab  { padding: 8px 16px; font-size: 14px; font-weight: 500; color: var(--text2); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -2px; transition: var(--tr); white-space: nowrap; }
.tab:hover  { color: var(--primary); }
.tab.active { color: var(--primary); border-color: var(--primary); }

/* ── Profile / Client detail ── */
.profile-hd  { display: flex; gap: 18px; align-items: flex-start; margin-bottom: 18px; }
.profile-pic { width: 72px; height: 72px; border-radius: 50%; background: var(--primary); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 24px; font-weight: 600; flex-shrink: 0; overflow: hidden; }
.profile-pic img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }
.profile-name  { font-family: 'Google Sans', sans-serif; font-size: 18px; font-weight: 600; }
.profile-meta  { font-size: 13px; color: var(--text2); margin-top: 2px; }
.profile-tags  { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.profile-notes { margin-top: 10px; background: var(--bg); border-radius: var(--rs); padding: 10px 13px; font-size: 13px; color: var(--text2); line-height: 1.5; }
.pf-row   { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.pf-field { background: var(--bg); border-radius: var(--rs); padding: 9px 13px; }
.pf-field .pfl { font-size: 10px; color: var(--text2); font-weight: 500; text-transform: uppercase; letter-spacing: .4px; }
.pf-field .pfv { font-size: 13px; margin-top: 3px; word-break: break-all; }

/* ── Actions ── */
.acts { display: flex; gap: 5px; flex-wrap: nowrap; }

/* ── Import result ── */
.import-result { background: var(--bg); border-radius: var(--rs); padding: 12px 16px; margin-top: 14px; font-size: 13px; }
.import-result .ok  { color: #137333; }
.import-result .err { color: var(--red); margin-top: 4px; }

/* ── Toast ── */
.toast-box { position: fixed; bottom: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; }
.toast { background: #323232; color: #fff; border-radius: 8px; padding: 11px 18px; font-size: 14px; box-shadow: var(--sh-l); display: flex; align-items: center; gap: 8px; min-width: 220px; animation: tIn .2s ease; }
.toast.ok  { background: #137333; }
.toast.err { background: var(--red); }
@keyframes tIn { from { transform: translateX(110%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── Spinner ── */
.spin-wrap { display: flex; align-items: center; justify-content: center; padding: 36px; gap: 10px; color: var(--text2); font-size: 14px; }
.spin { width: 20px; height: 20px; border: 2px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: sp .8s linear infinite; flex-shrink: 0; }
@keyframes sp { to { transform: rotate(360deg); } }

/* ══════════════════════════════════════════
   MOBILE NAV
══════════════════════════════════════════ */
.mob-nav { display: none; }

/* ══════════════════════════════════════════
   RESPONSIVE
══════════════════════════════════════════ */
@media (max-width: 900px) {
  .stats-grid { grid-template-columns: repeat(2,1fr); }
}

@media (max-width: 768px) {
  /* Sidebar slides in */
  .sidebar { transform: translateX(-100%); box-shadow: none; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--sh-l); }
  .topbar-wrap { margin-left: 0; }
  .burger { display: flex; }

  .search-box { width: 160px; }
  .content { padding: 14px; }

  .stats-grid { grid-template-columns: repeat(2,1fr); gap: 10px; margin-bottom: 14px; }
  .stat-card  { padding: 12px; gap: 10px; }
  .stat-ico   { width: 38px; height: 38px; font-size: 18px; }
  .stat-val   { font-size: 20px; }

  .hide-sm { display: none !important; }

  /* Modal slides up from bottom */
  .modal-overlay { align-items: flex-end; padding: 0; }
  .modal { border-radius: 16px 16px 0 0; max-height: 95vh; }

  .fg2 { grid-template-columns: 1fr; }

  .profile-hd { flex-direction: column; align-items: center; text-align: center; }
  .profile-tags { justify-content: center; }
  .pf-row { grid-template-columns: 1fr; }

  /* User btn: avatar only */
  .u-name, .u-arr { display: none; }
  .user-btn { padding: 4px; border-radius: 50%; }

  /* Bottom mobile nav */
  .mob-nav {
    display: flex;
    position: fixed; bottom: 0; left: 0; right: 0;
    background: #fff; border-top: 1px solid var(--border);
    z-index: 250; padding-bottom: env(safe-area-inset-bottom, 0);
  }
  .mob-nav-item {
    flex: 1; display: flex; flex-direction: column; align-items: center;
    padding: 8px 4px 6px; gap: 3px; font-size: 10px; color: var(--text2);
    cursor: pointer; transition: var(--tr); border: none; background: none; font-family: inherit;
  }
  .mob-nav-item .ni { font-size: 21px; }
  .mob-nav-item.active { color: var(--primary); }

  .topbar-wrap { padding-bottom: 56px; }
}

@media (max-width: 480px) {
  .search-box { display: none; }
  .stats-grid { gap: 8px; }
}
