/* ── KintechAsia CRM — Design System ─────────────────────── */
:root {
  --bg:          #0d0f14;
  --surface:     #161a23;
  --surface2:    #1e2433;
  --border:      #2a3147;
  --accent:      #f0a500;
  --accent-dim:  #b87b00;
  --danger:      #e05252;
  --success:     #3ecf8e;
  --warning:     #f5a623;
  --info:        #5b9cf6;
  --text:        #e8eaf0;
  --text-muted:  #7a849e;
  --text-dim:    #4a5370;
  --font-mono:   'JetBrains Mono', 'Fira Code', monospace;
  --font-ui:     'Inter', system-ui, sans-serif;
  --radius:      8px;
  --radius-lg:   14px;
  --sidebar-w:   240px;
  --topbar-h:    60px;
  --shadow:      0 4px 24px rgba(0,0,0,.4);
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-dim); }

/* ── Layout ──────────────────────────────────────────────── */
.crm-layout { display: flex; height: 100vh; overflow: hidden; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  flex-shrink: 0; overflow-y: auto;
}
.sidebar-brand {
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-brand .logo-mark {
  width: 34px; height: 34px; background: var(--accent);
  border-radius: 8px; display: grid; place-items: center;
  font-weight: 800; font-size: 15px; color: #000;
  flex-shrink: 0; font-family: var(--font-mono);
}
.sidebar-brand .brand-name { font-weight: 700; font-size: 15px; color: var(--text); }
.sidebar-brand .brand-sub  { font-size: 11px; color: var(--text-muted); }
.sidebar-nav { padding: 12px 10px; flex: 1; }
.nav-section-label {
  font-size: 10px; font-weight: 600; letter-spacing: .08em;
  text-transform: uppercase; color: var(--text-dim); padding: 14px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px; border-radius: var(--radius);
  color: var(--text-muted); font-weight: 500;
  transition: all .15s; margin-bottom: 2px; cursor: pointer;
}
.nav-item:hover  { background: var(--surface2); color: var(--text); }
.nav-item.active { background: rgba(240,165,0,.12); color: var(--accent); }
.nav-item .nav-icon { width: 18px; text-align: center; font-size: 15px; }
.sidebar-footer { padding: 14px; border-top: 1px solid var(--border); }
.sidebar-user   { display: flex; align-items: center; gap: 10px; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--accent); color: #000;
  font-weight: 700; font-size: 13px;
  display: grid; place-items: center; flex-shrink: 0;
}
.user-name  { font-size: 13px; font-weight: 600; color: var(--text); }
.user-role  { font-size: 11px; color: var(--text-muted); }
.logout-btn {
  margin-left: auto; background: none; border: none;
  color: var(--text-dim); cursor: pointer; font-size: 16px;
  padding: 4px; border-radius: 4px; transition: color .15s;
}
.logout-btn:hover { color: var(--danger); }

.main-wrap { flex: 1; display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  height: var(--topbar-h); background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center;
  padding: 0 24px; gap: 16px; flex-shrink: 0;
}
.topbar-title { font-size: 16px; font-weight: 700; color: var(--text); flex: 1; }
.topbar-badge {
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 12px;
  font-size: 12px; color: var(--text-muted);
}
.page-content { flex: 1; overflow-y: auto; padding: 24px; }

/* ── Cards ───────────────────────────────────────────────── */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 20px; }
.card-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 18px; }
.card-title    { font-size: 15px; font-weight: 700; color: var(--text); }
.card-subtitle { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* ── Stat Tiles ──────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px; margin-bottom: 24px;
}
.stat-tile {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px;
  position: relative; overflow: hidden;
}
.stat-tile::before { content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px; }
.stat-tile.gold::before   { background: var(--accent); }
.stat-tile.green::before  { background: var(--success); }
.stat-tile.blue::before   { background: var(--info); }
.stat-tile.red::before    { background: var(--danger); }
.stat-tile.orange::before { background: var(--warning); }
.stat-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: 8px; }
.stat-value { font-size: 30px; font-weight: 800; color: var(--text); font-family: var(--font-mono); line-height: 1; }
.stat-sub   { font-size: 12px; color: var(--text-muted); margin-top: 6px; }

/* ── Table ───────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead tr { border-bottom: 2px solid var(--border); }
thead th {
  padding: 10px 14px; text-align: left;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-muted); white-space: nowrap;
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .12s; }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 11px 14px; font-size: 13px; color: var(--text); }
tbody td.mono { font-family: var(--font-mono); font-size: 12px; }

/* ── Badges ──────────────────────────────────────────────── */
.badge { display: inline-flex; align-items: center; padding: 3px 9px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-success { background: rgba(62,207,142,.15);  color: var(--success); }
.badge-danger  { background: rgba(224,82,82,.15);   color: var(--danger); }
.badge-warning { background: rgba(245,166,35,.15);  color: var(--warning); }
.badge-info    { background: rgba(91,156,246,.15);  color: var(--info); }
.badge-gold    { background: rgba(240,165,0,.15);   color: var(--accent); }
.badge-muted   { background: var(--surface2);       color: var(--text-muted); }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 16px; border-radius: var(--radius);
  font-size: 13px; font-weight: 600; cursor: pointer;
  border: 1px solid transparent; transition: all .15s; text-decoration: none;
}
.btn-primary { background: var(--accent); color: #000; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dim); border-color: var(--accent-dim); color: #000; }
.btn-ghost   { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-danger  { background: rgba(224,82,82,.15); color: var(--danger); border-color: rgba(224,82,82,.3); }
.btn-danger:hover { background: rgba(224,82,82,.25); }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.form-control {
  width: 100%; background: var(--bg);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 9px 12px; color: var(--text); font-size: 13px;
  font-family: var(--font-ui); transition: border-color .15s;
}
.form-control:focus { outline: none; border-color: var(--accent); }
.form-control::placeholder { color: var(--text-dim); }
select.form-control { cursor: pointer; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-actions { display: flex; gap: 10px; justify-content: flex-end; padding-top: 8px; }

/* ── Flash ───────────────────────────────────────────────── */
.flash { padding: 12px 16px; border-radius: var(--radius); margin-bottom: 20px; font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 10px; }
.flash-success { background: rgba(62,207,142,.1);  border: 1px solid rgba(62,207,142,.3); color: var(--success); }
.flash-error   { background: rgba(224,82,82,.1);   border: 1px solid rgba(224,82,82,.3);  color: var(--danger); }
.flash-info    { background: rgba(91,156,246,.1);  border: 1px solid rgba(91,156,246,.3); color: var(--info); }

/* ── Modal ───────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 20px;
}
.modal {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); width: 100%; max-width: 560px;
  box-shadow: var(--shadow); max-height: 90vh; overflow-y: auto;
}
.modal-header { padding: 20px 24px 16px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title  { font-size: 16px; font-weight: 700; }
.modal-close  { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 20px; padding: 0 4px; }
.modal-close:hover { color: var(--text); }
.modal-body   { padding: 20px 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border); display: flex; gap: 10px; justify-content: flex-end; }

/* ── Pagination ──────────────────────────────────────────── */
.pagination { display: flex; gap: 4px; align-items: center; margin-top: 16px; }
.page-btn {
  padding: 6px 12px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface2);
  color: var(--text-muted); font-size: 13px; cursor: pointer;
  text-decoration: none; transition: all .12s;
}
.page-btn:hover  { border-color: var(--accent); color: var(--accent); }
.page-btn.active { background: var(--accent); border-color: var(--accent); color: #000; font-weight: 700; }

/* ── Search bar ──────────────────────────────────────────── */
.search-bar { display: flex; gap: 10px; align-items: center; margin-bottom: 18px; flex-wrap: wrap; }
.search-input-wrap { position: relative; flex: 1; min-width: 200px; }
.search-input-wrap .icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--text-dim); font-size: 14px; }
.search-input-wrap input { width: 100%; padding-left: 34px; }

/* ── Settings ────────────────────────────────────────────── */
.setting-row { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--border); }
.setting-key   { font-family: var(--font-mono); font-size: 12px; color: var(--accent); flex: 0 0 220px; }
.setting-value { flex: 1; font-size: 13px; color: var(--text); word-break: break-all; }

/* ── Login ───────────────────────────────────────────────── */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 20px; }
.login-box  { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); padding: 40px; width: 100%; max-width: 400px; }
.login-logo { text-align: center; margin-bottom: 28px; }
.login-logo .mark { display: inline-block; width: 52px; height: 52px; background: var(--accent); border-radius: 14px; font-size: 22px; font-weight: 900; color: #000; font-family: var(--font-mono); line-height: 52px; text-align: center; margin-bottom: 12px; }
.login-logo h1 { font-size: 20px; font-weight: 800; }
.login-logo p  { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

/* ── Misc ────────────────────────────────────────────────── */
.text-muted  { color: var(--text-muted); }
.text-small  { font-size: 12px; }
.mono        { font-family: var(--font-mono); }
.mt-1 { margin-top: 8px; }   .mt-2 { margin-top: 16px; }  .mt-3 { margin-top: 24px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-2 { gap: 8px; }
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-icon  { font-size: 40px; margin-bottom: 12px; }
.empty-text  { font-size: 15px; font-weight: 600; color: var(--text); margin-bottom: 6px; }

/* ── Dashboard grid ──────────────────────────────────────── */
.dash-grid-2col { display: grid; grid-template-columns: 1fr 320px; gap: 16px; margin-bottom: 16px; }

/* ── Notification Bell ───────────────────────────────────── */
.notif-wrap { flex-shrink: 0; }
.notif-btn {
  background: none; border: none;
  color: var(--text-muted);
  cursor: pointer; width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  position: relative; transition: color .15s;
}
.notif-btn:hover { color: var(--accent); }
.notif-count {
  position: absolute; top: 4px; right: 4px;
  width: 8px; height: 8px;
  background: var(--danger); border-radius: 50%;
  border: 2px solid var(--surface);
  pointer-events: none;
}
/* Tippy theme override — force dark, kill all defaults */
.tippy-box[data-theme~='notif'],
.tippy-box[data-theme~='notif'][data-placement^='bottom'] {
  background: var(--surface) !important;
  border: 1px solid var(--border) !important;
  border-radius: var(--radius-lg) !important;
  box-shadow: 0 8px 40px rgba(0,0,0,.8) !important;
  color: var(--text) !important;
  font-family: var(--font-ui) !important;
  font-size: 14px !important;
  width: 340px !important;
  max-width: calc(100vw - 32px) !important;
}
.tippy-box[data-theme~='notif'] > .tippy-content {
  padding: 0 !important;
  background: transparent !important;
  color: var(--text) !important;
  font-family: var(--font-ui) !important;
  overflow: hidden;
  border-radius: var(--radius-lg);
}
.tippy-box[data-theme~='notif'] > .tippy-arrow { display: none !important; }
.notif-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px 12px; border-bottom: 1px solid var(--border);
}
.notif-header-title { font-weight: 700; font-size: 14px; color: var(--text); }
.notif-read-all {
  background: none; border: none; color: var(--accent);
  font-size: 12px; font-weight: 600; cursor: pointer;
  padding: 3px 8px; border-radius: var(--radius);
}
.notif-read-all:hover { background: rgba(240,165,0,.1); }
.notif-list { max-height: 420px; overflow-y: auto; }
.notif-list::-webkit-scrollbar { width: 4px; }
.notif-list::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.notif-empty { padding: 36px 20px; text-align: center; color: var(--text-muted); font-size: 13px; }
.notif-empty-icon { font-size: 28px; margin-bottom: 8px; }
.notif-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 16px; cursor: pointer;
  transition: background .12s; border-bottom: 1px solid var(--border);
}
.notif-item:last-child { border-bottom: none; }
.notif-item:hover { background: var(--surface2); }
.notif-avatar {
  width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700;
}
.notif-avatar.new-type    { background: rgba(62,207,142,.15); color: var(--success); }
.notif-avatar.update-type { background: rgba(91,156,246,.15); color: var(--info); }
.notif-item-body  { flex: 1; min-width: 0; }
.notif-item-title { font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 1px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notif-item-text  { font-size: 12px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.notif-item-time  { font-size: 11px; color: var(--text-dim); margin-top: 2px; }
.notif-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); flex-shrink: 0;
}

/* ── Row highlight ───────────────────────────────────────── */
@keyframes rowFlashNew    { 0%,30% { background: rgba(62,207,142,.15); } 100% { background: transparent; } }
@keyframes rowFlashUpdate { 0%,30% { background: rgba(91,156,246,.12); } 100% { background: transparent; } }
tr.row-highlight-new    { animation: rowFlashNew    2s ease; }
tr.row-highlight-update { animation: rowFlashUpdate 2s ease; }

/* ── Live dot pulse ──────────────────────────────────────── */
@keyframes pulse {
  0%   { box-shadow: 0 0 0 0 rgba(62,207,142,.5); }
  70%  { box-shadow: 0 0 0 8px rgba(62,207,142,0); }
  100% { box-shadow: 0 0 0 0 rgba(62,207,142,0); }
}

/* ── Hamburger ───────────────────────────────────────────── */
.hamburger { display: none; background: none; border: none; color: var(--text); cursor: pointer; padding: 6px; border-radius: var(--radius); flex-direction: column; gap: 5px; flex-shrink: 0; }
.hamburger span { display: block; width: 22px; height: 2px; background: var(--text); border-radius: 2px; transition: all .25s; }
.hamburger.open span:nth-child(1) { transform: translateY(7px) rotate(45deg); }
.hamburger.open span:nth-child(2) { opacity: 0; }
.hamburger.open span:nth-child(3) { transform: translateY(-7px) rotate(-45deg); }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 199; }
.sidebar-backdrop.show { display: block; }

/* ── Expiry button labels ─────────────────────────────────── */
.expiry-short { display: none; }
.expiry-long  { display: inline; }

/* ── Mobile ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  .hamburger { display: flex; }
  .sidebar {
    display: flex !important; position: fixed;
    top: 0; left: -260px; bottom: 0;
    z-index: 200; transition: left .28s cubic-bezier(.4,0,.2,1);
    width: 260px; box-shadow: 4px 0 32px rgba(0,0,0,.5);
  }
  .sidebar.open { left: 0; }
  .topbar { padding: 0 14px; gap: 10px; }
  .topbar-title { font-size: 15px; }
  .topbar-badge { display: none; }
  .topbar .btn-sm { font-size: 11px; padding: 5px 8px; white-space: nowrap; }
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat-tile { padding: 14px; }
  .stat-value { font-size: 24px; }
  .stat-sub   { font-size: 11px; }
  .dash-grid-2col { grid-template-columns: 1fr !important; }
  .page-content { padding: 14px; }
  .card { padding: 14px; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { font-size: 12px; min-width: 560px; }
  thead th { padding: 8px 10px; }
  tbody td  { padding: 9px 10px; }
  .form-row { grid-template-columns: 1fr !important; }
  .modal-backdrop { padding: 12px; align-items: flex-end; }
  .modal { max-width: 100% !important; border-radius: var(--radius-lg) var(--radius-lg) 0 0; }
  .search-bar { flex-direction: column; align-items: stretch; }
  .search-bar .form-control, .search-bar .btn { width: 100% !important; }
  .search-bar button[style*="margin-left:auto"] { margin-left: 0 !important; }
  .pagination { flex-wrap: wrap; }
  .card-header { flex-wrap: wrap; gap: 10px; }
  .expiry-short { display: inline; }
  .expiry-long  { display: none; }
}
@media (max-width: 400px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-value { font-size: 28px; }
}
