/**
 * @file components.css
 * @description Reusable UI Components: Buttons, Cards, KPI Metrics, Tables, Forms, Badges & Toasts
 */

/* --- VIEW LAYOUT & SECTION HEADERS --- */
.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  flex-wrap: wrap;
  gap: 12px;
}
.view-title {
  font-size: 1.4rem;
  font-weight: 800;
  letter-spacing: -0.5px;
  color: var(--text-primary);
  margin-bottom: 4px;
}
.view-subtitle { font-size: 0.82rem; color: var(--text-secondary); }
.view-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dashboard-grid-2col { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .dashboard-grid-2col { grid-template-columns: 1fr; } }
@media (max-width: 640px) {
  .view-header { flex-direction: column; align-items: stretch; gap: 10px; margin-bottom: 16px; }
  .view-title { font-size: 1.25rem; }
  .view-subtitle { font-size: 0.76rem; }
  .view-actions { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; }
  .view-actions .btn { flex: 1 1 auto; font-size: 0.78rem; padding: 8px 10px; justify-content: center; }
}

/* --- BUTTONS & ACTIONS --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  border: 1px solid transparent;
  text-decoration: none;
  line-height: 1.2;
}
.btn:hover { transform: translateY(-1px); }
.btn-primary { background: var(--primary); color: #FFFFFF; box-shadow: 0 4px 12px var(--primary-glow); }
.btn-primary:hover { background: var(--primary-hover); box-shadow: 0 6px 16px var(--primary-glow); }
.btn-outline { background: var(--bg-surface-elevated); border-color: var(--border-subtle); color: var(--text-primary); }
.btn-outline:hover { border-color: var(--border-medium); background: var(--bg-surface); }
.btn-success { background: var(--accent-green); color: #FFFFFF; }
.btn-danger { background: var(--accent-rose); color: #FFFFFF; }

.login-btn {
  width: 100%;
  background: var(--primary);
  color: #FFFFFF;
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s ease;
  box-shadow: 0 4px 14px var(--primary-glow);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.login-btn:hover { background: var(--primary-hover); transform: translateY(-1px); }

.logout-btn {
  background: var(--accent-rose-soft);
  border: 1px solid transparent;
  color: var(--accent-rose);
  font-size: 0.76rem;
  font-weight: 700;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: all 0.2s ease;
  width: 100%;
}
.logout-btn:hover { background: var(--accent-rose); color: #FFFFFF; }

/* --- 3-OPTION EXECUTIVE THEME SWITCHER (Light / Dark / System) --- */
.theme-switcher-segmented {
  display: inline-flex;
  align-items: center;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 3px;
  gap: 2px;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.06);
  user-select: none;
}

.theme-switcher-segmented .theme-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.76rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  line-height: 1;
}

.theme-switcher-segmented .theme-btn svg {
  flex-shrink: 0;
  stroke: currentColor;
  transition: transform 0.2s ease;
}

.theme-switcher-segmented .theme-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

.theme-switcher-segmented .theme-btn.active {
  background: var(--bg-surface);
  color: var(--primary);
  border-color: var(--border-subtle);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.10);
  font-weight: 800;
}

html[data-theme="dark"] .theme-switcher-segmented .theme-btn.active {
  background: var(--brand-masquerade);
  color: #FFFFFF;
  border-color: rgba(54, 96, 255, 0.4);
  box-shadow: 0 2px 10px rgba(54, 96, 255, 0.25);
}

/* Compact Theme Switcher for High-Density Toolbars/Navbars */
.theme-switcher-segmented.theme-switcher-compact {
  padding: 2px;
  gap: 2px;
}

.theme-switcher-segmented.theme-switcher-compact .theme-btn {
  padding: 6px 9px;
  gap: 0;
}

.theme-switcher-segmented.theme-switcher-compact .theme-btn-label {
  display: none !important;
}

/* ==========================================================================
   EXECUTIVE THEME DROPDOWN COMPONENT
   ========================================================================== */
.theme-dropdown {
  position: relative;
  display: inline-block;
}

.theme-dropdown-trigger {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: var(--text-primary, #ffffff);
  padding: 7px 12px;
  border-radius: 9px;
  font-size: 0.82rem;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  user-select: none;
  line-height: 1;
}

.theme-dropdown-trigger:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.25);
  transform: translateY(-1px);
}

.theme-dropdown-trigger-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: inherit;
}

.theme-dropdown-trigger-icon svg {
  display: block;
}

.theme-dropdown-trigger-label {
  font-size: 0.82rem;
  font-weight: 700;
}

.theme-trigger-chevron {
  transition: transform 0.2s ease;
  color: var(--text-muted, #94a3b8);
  margin-left: 1px;
}

.theme-dropdown.open .theme-trigger-chevron {
  transform: rotate(180deg);
}

.theme-dropdown-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  min-width: 175px;
  background: rgba(15, 23, 42, 0.95);
  backdrop-filter: blur(18px);
  -webkit-backdrop-filter: blur(18px);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.05);
  z-index: 1000;
  display: none;
  flex-direction: column;
  gap: 2px;
  transform-origin: top right;
  animation: dropdownPop 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

.theme-dropdown.open .theme-dropdown-menu {
  display: flex;
}

@keyframes dropdownPop {
  from {
    opacity: 0;
    transform: scale(0.95) translateY(-6px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.theme-dropdown-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  padding: 8px 10px;
  border-radius: 8px;
  border: none;
  background: transparent;
  color: var(--text-secondary, #cbd5e1);
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
  user-select: none;
}

.theme-dropdown-item:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #ffffff;
}

.theme-dropdown-item.active {
  background: rgba(54, 96, 255, 0.15);
  color: #38bdf8;
  font-weight: 700;
}

.theme-dropdown-item-left {
  display: flex;
  align-items: center;
  gap: 8px;
}

.theme-dropdown-item-left svg {
  flex-shrink: 0;
}

.theme-dropdown-check {
  display: none;
  color: #38bdf8;
  flex-shrink: 0;
}

.theme-dropdown-item.active .theme-dropdown-check {
  display: block;
}

/* Light Mode Overrides for Theme Dropdown */
html[data-theme="light"] .theme-dropdown-trigger {
  background: var(--bg-surface-elevated, #ffffff);
  border-color: var(--border-subtle, #e2e8f0);
  color: var(--text-primary, #0f172a);
}

html[data-theme="light"] .theme-dropdown-trigger:hover {
  background: #f8fafc;
  border-color: var(--border-medium, #cbd5e1);
}

html[data-theme="light"] .theme-dropdown-menu {
  background: rgba(255, 255, 255, 0.98);
  border-color: #e2e8f0;
  box-shadow: 0 16px 36px rgba(0, 0, 0, 0.12), 0 0 0 1px rgba(0, 0, 0, 0.04);
}

html[data-theme="light"] .theme-dropdown-item {
  color: #475569;
}

html[data-theme="light"] .theme-dropdown-item:hover {
  background: #f1f5f9;
  color: #0f172a;
}

html[data-theme="light"] .theme-dropdown-item.active {
  background: rgba(80, 72, 229, 0.1);
  color: var(--brand-warm-blue, #5048e5);
}

html[data-theme="light"] .theme-dropdown-check {
  color: var(--brand-warm-blue, #5048e5);
}

/* Auth Screen Top-Right Floating Theme Switcher */
.auth-theme-toggle-wrap {
  position: absolute;
  top: 20px;
  right: 24px;
  z-index: 10001;
}

@media (max-width: 640px) {
  .auth-theme-toggle-wrap {
    top: 14px;
    right: 14px;
  }
}

.theme-toggle-btn {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.2s ease;
  color: var(--text-primary);
}
.theme-toggle-btn:hover { border-color: var(--border-medium); transform: scale(1.05); }

.error-pill-btn {
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 2px 7px;
  font-size: 0.68rem;
  font-weight: 800;
  cursor: pointer;
  color: var(--text-primary);
}
.error-pill-btn:hover { background: var(--primary-soft); color: var(--primary); }

/* --- CARDS & CONTAINERS --- */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 20px;
  box-shadow: var(--card-shadow);
  transition: var(--theme-transition);
  max-width: 100%;
  box-sizing: border-box;
}
@media (max-width: 640px) {
  .card { padding: 14px; }
}
.card-title {
  font-size: 0.95rem;
  font-weight: 800;
  color: var(--text-primary);
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.card-subtitle { font-size: 0.78rem; color: var(--text-muted); margin-bottom: 12px; }

/* --- KPI METRICS GRID --- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}
.kpi-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 16px;
  box-shadow: var(--card-shadow);
  display: flex;
  flex-direction: column;
  gap: 4px;
  transition: var(--theme-transition);
}
.kpi-header { display: flex; justify-content: space-between; align-items: center; }
.kpi-title {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.kpi-icon { font-size: 1.1rem; }
.kpi-value {
  font-size: 1.45rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.5px;
}
.kpi-value.warning { color: var(--accent-amber); }
.kpi-value.danger { color: var(--accent-rose); }
.kpi-subtext { font-size: 0.72rem; color: var(--text-secondary); font-weight: 600; }
.kpi-subtext.positive { color: var(--accent-green); }

@media (max-width: 640px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 16px; }
  .kpi-card { padding: 12px; gap: 2px; }
  .kpi-title { font-size: 0.65rem; }
  .kpi-icon { font-size: 1rem; }
  .kpi-value { font-size: 1.15rem; }
  .kpi-subtext { font-size: 0.65rem; }
}

/* --- DATA TABLES (MOBILE-FIRST RESPONSIVE HORIZONTAL SCROLL) --- */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 6px 0;
  position: relative;
  scrollbar-width: thin;
}
.card:has(.data-table),
.card:has(table) {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}
.table-responsive::-webkit-scrollbar,
.card:has(.data-table)::-webkit-scrollbar { height: 6px; }
.table-responsive::-webkit-scrollbar-thumb,
.card:has(.data-table)::-webkit-scrollbar-thumb {
  background: var(--border-medium, #94a3b8);
  border-radius: 4px;
}
.table-responsive::-webkit-scrollbar-track,
.card:has(.data-table)::-webkit-scrollbar-track {
  background: var(--bg-surface-soft, rgba(0, 0, 0, 0.05));
  border-radius: 4px;
}
.table-scroll-hint {
  display: none;
  font-size: 0.72rem;
  color: var(--text-muted);
  align-items: center;
  gap: 4px;
  margin-bottom: 6px;
  user-select: none;
}
@media (max-width: 768px) { .table-scroll-hint { display: inline-flex; } }
.data-table, .operator-table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  font-size: 0.82rem;
  text-align: left;
}
.data-table th, .operator-table th {
  background: var(--bg-surface-elevated);
  padding: 10px 14px;
  font-weight: 700;
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  white-space: nowrap;
}
.data-table td, .operator-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-primary);
  white-space: nowrap;
}
.data-table tr:hover td { background: var(--bg-surface-soft); }
.data-table tr:last-child td, .operator-table tr:last-child td { border-bottom: none; }
.data-table code {
  font-family: 'JetBrains Mono', monospace;
  background: var(--bg-surface-elevated);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 0.75rem;
  white-space: nowrap;
}

/* --- FORMS & INPUTS --- */
.form-group { margin-bottom: 14px; }
.form-label {
  display: block;
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--text-secondary);
  margin-bottom: 5px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-width: 0;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 0.86rem;
  color: var(--text-primary);
  outline: none;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-glow);
}
.password-input-wrap { position: relative; display: flex; align-items: center; }
.password-input-wrap input { padding-right: 42px; }
.password-toggle-btn {
  position: absolute;
  right: 8px;
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  color: var(--text-muted);
  padding: 4px 6px;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* --- BADGES & CHIPS --- */
.badge-tag {
  font-size: 0.65rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-elevated);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.tier-badge {
  font-size: 0.65rem;
  font-weight: 800;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.tier-grosir-pro { background: var(--primary-soft); color: var(--primary); border: 1px solid var(--primary-border); }
.tier-starter-free { background: var(--bg-surface-elevated); color: var(--text-muted); border: 1px solid var(--border-subtle); }
.cogs-value { font-family: 'JetBrains Mono', monospace; font-weight: 700; color: var(--accent-purple); }
.cogs-privacy-tag {
  font-size: 0.62rem;
  font-weight: 800;
  padding: 1px 5px;
  border-radius: 4px;
  background: var(--accent-purple-soft);
  color: var(--accent-purple);
  margin-left: 4px;
}
.user-profile-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  background: var(--bg-surface-elevated);
}
.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--primary);
  color: #FFFFFF;
  font-weight: 800;
  font-size: 0.82rem;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.user-meta { display: flex; flex-direction: column; overflow: hidden; }
.user-name { font-size: 0.8rem; font-weight: 700; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role-tag { font-size: 0.65rem; color: var(--text-muted); font-weight: 600; }

/* --- TOAST NOTIFICATIONS --- */
#toast-container, .toast-container {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}
.toast-pill {
  background: #0F172A;
  color: #FFFFFF;
  padding: 10px 18px;
  border-radius: var(--radius-full);
  font-size: 0.8rem;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(255, 255, 255, 0.15);
  display: inline-flex;
  align-items: center;
  gap: 8px;
  animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  pointer-events: auto;
  white-space: nowrap;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateY(20px) scale(0.95); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
