/* Finovas Global - Command Palette + UI polish (phase-4 enhancements) */

/* ── Command Palette ──────────────────────────────────────────────── */
.cp-backdrop {
  position: fixed; inset: 0; z-index: 1000;
  background: color-mix(in srgb, var(--bg) 70%, transparent);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex; justify-content: center;
  padding-top: clamp(40px, 12vh, 110px);
  animation: cpFadeIn .12s ease;
}
@keyframes cpFadeIn { from { opacity: 0 } to { opacity: 1 } }

.cp-panel {
  width: min(640px, calc(100% - 32px));
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 22px 60px -10px rgba(15, 23, 42, .35);
  overflow: hidden;
  display: flex; flex-direction: column;
  max-height: 70vh;
  animation: cpRise .14s ease;
}
@keyframes cpRise {
  from { transform: translateY(8px); opacity: 0 }
  to   { transform: translateY(0); opacity: 1 }
}

.cp-header {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.cp-header > svg { color: var(--brand); flex-shrink: 0; }
.cp-input {
  flex: 1; min-width: 0;
  border: 0; outline: 0; background: transparent;
  font-family: inherit; color: var(--text);
  font-size: 16px;
}
.cp-input::placeholder { color: var(--text-muted); }
.cp-list { overflow-y: auto; padding: 6px; flex: 1; }

.cp-item {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  align-items: center; gap: 12px;
  width: 100%;
  padding: 10px 12px; border-radius: 10px;
  background: transparent; border: 0; cursor: pointer;
  color: var(--text); text-align: left;
  font-family: inherit;
  transition: background .12s;
}
.cp-item:hover, .cp-item.on {
  background: var(--surface-2);
}
.cp-item.on {
  background: color-mix(in srgb, var(--brand) 10%, var(--surface-2));
}

.cp-icon {
  width: 36px; height: 36px;
  display: grid; place-items: center;
  background: var(--surface-2);
  border-radius: 9px;
  color: var(--brand);
}
.cp-item.on .cp-icon {
  background: var(--gradient); color: #fff;
}
.cp-avatar {
  display: grid; place-items: center;
  width: 100%; height: 100%; border-radius: 9px;
  color: #fff; font-weight: 700; font-size: 13px;
  background: var(--ac, var(--brand));
}

.cp-main { min-width: 0; }
.cp-label {
  font-weight: 600; font-size: 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cp-hint {
  font-size: 12px; color: var(--text-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  margin-top: 2px;
}

.cp-kind {
  font-size: 10.5px; text-transform: uppercase;
  font-weight: 700; letter-spacing: .04em;
  color: var(--text-soft);
  padding: 3px 8px;
  background: var(--surface-2); border-radius: 99px;
}
.cp-item.on .cp-kind { color: var(--brand); }

.cp-foot {
  display: flex; justify-content: space-between; align-items: center;
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 11.5px; color: var(--text-muted);
}
.cp-tip { display: flex; align-items: center; gap: 6px; }

.cp-empty {
  padding: 36px 18px; text-align: center;
  color: var(--text-muted); font-size: 13.5px;
}

kbd.cp-kbd, .kb-table kbd {
  display: inline-block;
  padding: 2px 7px;
  border-radius: 5px;
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  font: 600 11px ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text);
  box-shadow: inset 0 -1px 0 var(--border-strong);
}

/* ── Keyboard help dialog ─────────────────────────────────────────── */
.kb-table {
  width: 100%; border-collapse: collapse;
  font-size: 13.5px;
}
.kb-table td {
  padding: 10px 8px;
  border-bottom: 1px solid var(--border);
}
.kb-table td:first-child {
  width: 200px;
  font-family: inherit;
}

/* ── Polished tab indicator + count badges ───────────────────────── */
.ws-tabs {
  position: relative;
  gap: 2px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.ws-tabs::-webkit-scrollbar { display: none; }
.ws-tabs a {
  position: relative;
  display: inline-flex; align-items: center; gap: 7px;
  padding: 11px 14px 13px;
  color: var(--text-muted);
  font-weight: 600; font-size: 13.5px;
  white-space: nowrap;
  transition: color .14s, background .14s;
  border-radius: 8px 8px 0 0;
}
.ws-tabs a:hover {
  color: var(--text);
  background: color-mix(in srgb, var(--brand) 4%, transparent);
}
.ws-tabs a.on {
  color: var(--brand);
}
.ws-tabs a::after {
  content: ""; position: absolute;
  left: 14px; right: 14px; bottom: -1px;
  height: 2.5px; border-radius: 2px 2px 0 0;
  background: transparent;
  transition: background .22s var(--ease),
              transform .28s cubic-bezier(.16, 1, .3, 1),
              opacity .18s;
  transform: scaleX(0);
  transform-origin: center;
  opacity: 0;
}
.ws-tabs a.on::after {
  background: linear-gradient(90deg, var(--brand), var(--brand-2));
  transform: scaleX(1);
  opacity: 1;
}
.ws-tabs a:hover:not(.on)::after {
  background: color-mix(in srgb, var(--brand) 28%, transparent);
  transform: scaleX(.55);
  opacity: 1;
}
/* Count badge - only shown when it actually has a count.  An empty span has
   no content and previously rendered as a tiny floating pill ("ขีดต่อท้าย"). */
.ws-tabs a .tab-badge {
  display: inline-grid; place-items: center;
  min-width: 18px; height: 18px;
  padding: 0 6px;
  font-size: 10.5px; font-weight: 700;
  font-feature-settings: "tnum";
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--text-muted);
  transition: background .15s, color .15s;
}
.ws-tabs a .tab-badge:empty {
  display: none;
}
.ws-tabs a.on .tab-badge {
  background: color-mix(in srgb, var(--brand) 14%, var(--surface));
  color: var(--brand);
}

/* ── Standardized empty states ────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 12px;
  padding: 56px 24px;
  text-align: center;
}
.empty-state .es-icon {
  width: 56px; height: 56px;
  border-radius: 14px;
  display: grid; place-items: center;
  background: var(--gradient);
  color: #fff;
  box-shadow: var(--shadow-sm);
}
.empty-state h3 {
  font-size: 16px; font-weight: 700;
  color: var(--text);
  margin: 6px 0 0;
}
.empty-state p {
  color: var(--text-muted); font-size: 13.5px;
  max-width: 380px;
  line-height: 1.55;
}
.empty-state .btn { margin-top: 8px; }

/* ── Animated stat tile (count-up effect) ────────────────────────── */
.stat-value.animating {
  font-feature-settings: "tnum";
  font-variant-numeric: tabular-nums;
}

/* ── Mobile responsive ───────────────────────────────────────────── */
@media (max-width: 1024px) {
  .sidebar {
    width: 64px;
    padding: 16px 8px;
  }
  .sidebar .brand-tag,
  .sidebar .brand-name,
  .sidebar .nav-group-label,
  .sidebar .user-pill > div:nth-child(2),
  .sidebar .nav-item span,
  .sidebar .nav-item .count {
    display: none;
  }
  .sidebar .nav-item {
    justify-content: center;
    padding: 10px 0;
  }
  .sidebar .brand {
    justify-content: center;
  }
  .ws-tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }
  .ws-tabs::-webkit-scrollbar { display: none; }
  .ws-tabs a {
    flex-shrink: 0;
    white-space: nowrap;
  }
}

@media (max-width: 720px) {
  .sidebar {
    display: none;
  }
  .topbar {
    padding: 10px 14px;
  }
  .content {
    padding: 14px;
  }
  .page-head h1 { font-size: 22px; }
  .stat-row { gap: 10px; }
  .dash-cols { grid-template-columns: 1fr; }
  .ws-tabs a { padding: 10px 12px; }
}

/* ── Smooth transitions for everything ───────────────────────────── */
.card, .btn, .input, .select, .chip {
  transition: background .15s, border-color .15s, box-shadow .15s,
              transform .12s;
}
.btn:active:not(:disabled) { transform: translateY(1px); }
