/* ===================================
   COMPONENTS.CSS — Cards, Buttons, Tables, Forms, Badges
   =================================== */

/* --- KPI Cards --- */
.kpi-card {
  background: var(--glass-bg);
  backdrop-filter: blur(var(--glass-blur));
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-lg);
  padding: var(--space-lg);
  transition: all var(--transition-base);
  position: relative;
  overflow: hidden;
}

.kpi-card::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0;
  height: 3px;
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
}

.kpi-card.blue::before   { background: linear-gradient(90deg, var(--accent-blue), var(--accent-cyan)); }
.kpi-card.green::before  { background: linear-gradient(90deg, var(--accent-green), var(--accent-teal)); }
.kpi-card.amber::before  { background: linear-gradient(90deg, var(--accent-amber), #f97316); }
.kpi-card.red::before    { background: linear-gradient(90deg, var(--accent-red), var(--accent-purple)); }
.kpi-card.teal::before   { background: linear-gradient(90deg, var(--accent-teal), #34d399); }
.kpi-card.purple::before { background: linear-gradient(90deg, var(--accent-purple), #c084fc); }

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: rgba(148, 163, 184, 0.25);
}

.kpi-card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-md);
}

.kpi-card-icon {
  width: 42px; height: 42px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
}

.kpi-card.blue .kpi-card-icon   { background: rgba(59,130,246,0.15);  color: var(--accent-blue-light); }
.kpi-card.green .kpi-card-icon  { background: rgba(34,197,94,0.15);   color: var(--accent-green-light); }
.kpi-card.amber .kpi-card-icon  { background: rgba(245,158,11,0.15);  color: var(--accent-amber-light); }
.kpi-card.red .kpi-card-icon    { background: rgba(239,68,68,0.15);   color: var(--accent-red-light); }
.kpi-card.teal .kpi-card-icon   { background: rgba(20,184,166,0.15);  color: #2dd4bf; }
.kpi-card.purple .kpi-card-icon { background: rgba(168,85,247,0.15);  color: #c084fc; }

.kpi-card-trend {
  font-size: var(--fs-xs); font-weight: 600;
  padding: 3px 8px; border-radius: var(--radius-full);
}
.kpi-card-trend.up { background: rgba(34,197,94,0.12); color: var(--accent-green-light); }
.kpi-card-trend.down { background: rgba(239,68,68,0.12); color: var(--accent-red-light); }

.kpi-card-value {
  font-size: var(--fs-3xl); font-weight: 800;
  color: var(--text-primary); line-height: 1.1;
  margin-bottom: var(--space-xs);
}

.kpi-card-label {
  font-size: var(--fs-sm); color: var(--text-secondary); font-weight: 500;
}

/* --- Panel / Card Container --- */
.panel {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.panel-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border-light);
}

.panel-title {
  font-size: var(--fs-md); font-weight: 700; color: var(--text-heading);
}

.panel-body {
  padding: var(--space-lg);
}

/* --- Buttons --- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 20px;
  border-radius: var(--radius-md);
  font-size: var(--fs-sm); font-weight: 600;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent-blue); color: white;
}
.btn-primary:hover { background: var(--accent-blue-dark); box-shadow: var(--shadow-glow-blue); }

.btn-secondary {
  background: var(--bg-secondary); color: var(--text-secondary);
  border: 1px solid var(--border-color);
}
.btn-secondary:hover { color: var(--text-primary); border-color: var(--text-muted); }

.btn-success { background: var(--accent-green); color: white; }
.btn-success:hover { background: #16a34a; }

.btn-danger { background: var(--accent-red); color: white; }
.btn-danger:hover { background: #dc2626; }

.btn-ghost {
  color: var(--text-secondary); padding: 9px 14px;
}
.btn-ghost:hover { background: rgba(255,255,255,0.06); color: var(--text-primary); }

.btn-sm { padding: 6px 14px; font-size: var(--fs-xs); }
.btn-icon { width: 36px; height: 36px; padding: 0; border-radius: var(--radius-md); }

/* --- Toggle Buttons (Day/Week/Month) --- */
.toggle-group {
  display: flex; background: var(--bg-primary);
  border-radius: var(--radius-md); padding: 3px;
  border: 1px solid var(--border-light);
}

.toggle-btn {
  padding: 6px 16px;
  border-radius: var(--radius-sm);
  font-size: var(--fs-xs); font-weight: 600;
  color: var(--text-muted);
  transition: all var(--transition-fast);
}
.toggle-btn:hover { color: var(--text-secondary); }
.toggle-btn.active {
  background: var(--accent-blue); color: white;
  box-shadow: var(--shadow-sm);
}

/* --- Tables --- */
.data-table { width: 100%; }

.data-table thead th {
  padding: 12px 16px;
  text-align: left;
  font-size: var(--fs-xs); font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border-light);
  background: rgba(15, 23, 42, 0.3);
}

.data-table tbody td {
  padding: 12px 16px;
  font-size: var(--fs-sm);
  color: var(--text-secondary);
  border-bottom: 1px solid var(--border-light);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background var(--transition-fast);
}
.data-table tbody tr:hover {
  background: var(--bg-table-hover);
}

.data-table tbody tr:last-child td { border-bottom: none; }

/* --- Badges --- */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 10px; border-radius: var(--radius-full);
  font-size: var(--fs-xs); font-weight: 600;
}

.badge-blue { background: rgba(59,130,246,0.15); color: var(--accent-blue-light); }
.badge-green { background: rgba(34,197,94,0.15); color: var(--accent-green-light); }
.badge-amber { background: rgba(245,158,11,0.15); color: var(--accent-amber-light); }
.badge-red { background: rgba(239,68,68,0.15); color: var(--accent-red-light); }
.badge-purple { background: rgba(168,85,247,0.15); color: #c084fc; }

/* --- Forms --- */
.form-group { margin-bottom: var(--space-lg); }

.form-label {
  display: block; font-size: var(--fs-sm); font-weight: 600;
  color: var(--text-secondary); margin-bottom: var(--space-sm);
}

.form-input {
  width: 100%; padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary); font-size: var(--fs-sm);
  transition: all var(--transition-fast);
}
.form-input:focus {
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}

.form-select {
  width: 100%; padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary); font-size: var(--fs-sm);
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}

/* --- Pagination --- */
.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: var(--space-sm); padding: var(--space-lg) 0;
}

.page-btn {
  width: 34px; height: 34px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-sm); font-weight: 500;
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}
.page-btn:hover { background: var(--bg-secondary); color: var(--text-primary); }
.page-btn.active { background: var(--accent-blue); color: white; }

/* --- Empty State --- */
.empty-state {
  text-align: center; padding: var(--space-2xl);
  color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: var(--space-md); }
.empty-state .empty-text { font-size: var(--fs-md); }

/* --- Modal --- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.modal-overlay.hidden { display: none; }

.modal-box {
  background: var(--bg-secondary);
  border: 1px solid var(--glass-border);
  border-radius: var(--radius-xl);
  padding: var(--space-xl);
  width: 520px; max-width: 95vw;
  animation: scaleIn 0.25s cubic-bezier(0.16, 1, 0.3, 1) both;
  max-height: 90vh; overflow-y: auto;
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: var(--space-lg);
}

.modal-close {
  color: var(--text-muted); font-size: 1.5rem; line-height: 1;
  padding: 4px 8px; border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}
.modal-close:hover { background: var(--bg-primary); color: var(--text-primary); }

/* --- Toast --- */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 999;
  background: var(--bg-secondary);
  border: 1px solid var(--accent-green);
  color: var(--text-primary);
  padding: 12px 20px;
  border-radius: var(--radius-md);
  font-size: var(--fs-sm); font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: fadeInUp 0.3s ease both;
}
.toast.hidden { display: none; }

/* --- Filter Bar --- */
.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  flex-wrap: wrap;
  padding: var(--space-md) 0 var(--space-md);
}

.filter-search-wrap {
  position: relative;
  flex: 1;
  min-width: 240px;
}

.filter-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--fs-sm);
  font-family: inherit;
  transition: border-color var(--transition-fast);
}
.filter-input:focus {
  outline: none;
  border-color: var(--accent-blue);
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.12);
}
.filter-input[type="date"] {
  width: auto;
  color-scheme: dark;
  cursor: pointer;
}

.filter-select {
  padding: 8px 32px 8px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--fs-sm);
  font-family: inherit;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%2394a3b8' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  transition: border-color var(--transition-fast);
}
.filter-select:focus {
  outline: none;
  border-color: var(--accent-blue);
}

/* --- Import Drop Zone --- */
.import-drop-zone {
  border: 2px dashed var(--border-color);
  border-radius: var(--radius-lg);
  padding: var(--space-md);
  text-align: center;
  cursor: pointer;
  transition: all var(--transition-fast);
  background: rgba(15, 23, 42, 0.3);
  min-height: 120px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
}
.import-drop-zone:hover {
  border-color: var(--accent-blue);
  background: rgba(59, 130, 246, 0.05);
}
.import-drop-zone--price:hover {
  border-color: var(--accent-amber);
  background: rgba(245, 158, 11, 0.05);
}

/* --- Status Dot --- */
.status-dot {
  width: 8px; height: 8px; border-radius: 50%;
  display: inline-block; margin-right: 8px;
}
.status-dot.green { background: var(--accent-green); box-shadow: 0 0 6px rgba(34,197,94,0.4); }
.status-dot.amber { background: var(--accent-amber); box-shadow: 0 0 6px rgba(245,158,11,0.4); }
.status-dot.red { background: var(--accent-red); box-shadow: 0 0 6px rgba(239,68,68,0.4); }

/* --- Modal --- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.2s ease;
}
.modal-overlay.hidden { display: none; }

.modal-box {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-xl);
  width: 520px; max-width: 90vw;
  max-height: 85vh; overflow-y: auto;
  box-shadow: var(--shadow-xl);
  animation: scaleIn 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}
.modal-box.modal-fullpage {
  width: 96vw !important; max-width: 96vw !important;
  height: 92vh !important; max-height: 92vh !important;
  border-radius: var(--radius-lg);
  display: flex; flex-direction: column; overflow: hidden;
}
.modal-box.modal-fullpage #modal-body {
  flex: 1; overflow-y: auto; padding: 0;
}

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--space-lg);
  border-bottom: 1px solid var(--border-light);
}

.modal-close {
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.3rem; color: var(--text-muted);
  transition: all var(--transition-fast);
}
.modal-close:hover { background: rgba(239,68,68,0.12); color: var(--accent-red); }

#modal-body { padding: var(--space-lg); }

/* --- Toast --- */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--bg-secondary);
  border: 1px solid var(--accent-green);
  border-left: 4px solid var(--accent-green);
  border-radius: var(--radius-md);
  padding: 14px 24px;
  font-size: var(--fs-sm); font-weight: 500;
  color: var(--text-primary);
  box-shadow: var(--shadow-lg);
  z-index: 2000;
  animation: fadeInUp 0.3s cubic-bezier(0.16, 1, 0.3, 1);
  transition: opacity 0.3s ease;
}
.toast.hidden { display: none; }

/* --- Daily Ops Form --- */
.ops-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.ops-table td { border: 1px solid var(--border); vertical-align: top; }
.ops-cat {
  padding: 10px 12px; font-weight: 700; color: var(--accent-blue-light);
  background: rgba(59,130,246,0.07); white-space: nowrap; width: 110px;
  text-align: center; vertical-align: middle;
}
.ops-sub {
  padding: 8px 12px; color: var(--text-secondary); font-weight: 600;
  white-space: nowrap; width: 100px; vertical-align: middle;
  background: rgba(255,255,255,0.02);
}
.ops-cell { padding: 0; }
.ops-ta {
  width: 100%; border: none; background: transparent; resize: none;
  color: #ffffff !important; padding: 10px 14px; font-size: var(--fs-sm);
  font-family: inherit; outline: none; display: block;
  min-height: 48px; overflow: hidden;
  line-height: 1.7; box-sizing: border-box;
}
.ops-ta::placeholder { color: #ffffff; }
.ops-ta:focus { background: rgba(59,130,246,0.06); outline: none; }

/* --- Missing Master Data row highlight --- */
tr.md-missing-row { background: rgba(239,68,68,0.06) !important; }
tr.md-missing-row:hover { background: rgba(239,68,68,0.12) !important; }

/* --- Master Data Editable Grid --- */
.md-toolbar {
  display: flex; align-items: center; gap: var(--space-sm);
  flex-wrap: wrap; margin-bottom: var(--space-sm);
}
.md-search-input {
  flex: 1; min-width: 200px; max-width: 320px;
  padding: 7px 12px; border-radius: var(--radius-md);
  border: 1px solid var(--border); background: var(--bg-secondary);
  color: var(--text-primary); font-size: var(--fs-sm);
}
.md-search-input:focus { outline: none; border-color: var(--accent-blue); }
.md-count { color: var(--text-muted); font-size: var(--fs-xs); margin-left: auto; white-space: nowrap; }
.md-wrap { overflow: auto; max-height: calc(100vh - 230px); border-radius: var(--radius-md); border: 1px solid var(--border); }
.md-grid { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.md-grid thead th {
  position: sticky; top: 0; z-index: 2;
  background: #1e4d8c; color: #fff;
  padding: 9px 10px; font-weight: 600; text-align: left;
  border-right: 1px solid rgba(255,255,255,0.15); white-space: nowrap;
}
.md-grid thead th.md-th-rn { width: 44px; text-align: center; background: #163d72; }
.md-grid thead th.md-th-del { width: 36px; background: #163d72; }
.md-grid tbody tr:nth-child(even) { background: rgba(255,255,255,0.025); }
.md-grid tbody tr:hover { background: rgba(99,102,241,0.08); }
.md-grid tbody tr:hover .md-del-btn { opacity: 1; }
.md-rn {
  text-align: center; color: var(--text-muted); font-size: var(--fs-xs);
  border-right: 1px solid var(--border); background: var(--bg-secondary);
  width: 44px; padding: 0 4px;
}
.md-cell { border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); padding: 0; }
.md-cell-name { min-width: 320px; }
.md-input {
  width: 100%; border: none; background: transparent;
  color: var(--text-primary); padding: 7px 10px;
  font-size: var(--fs-sm); outline: none; display: block; font-family: inherit;
}
.md-input:focus { background: rgba(30,77,140,0.18); box-shadow: inset 0 0 0 2px var(--accent-blue); }
.md-input.md-code { font-family: monospace; color: var(--accent-blue); }
.md-del { width: 36px; border-bottom: 1px solid var(--border); text-align: center; }
.md-del-btn {
  opacity: 0; background: none; border: none;
  color: var(--accent-red); cursor: pointer; font-size: 1.1rem;
  padding: 2px 6px; border-radius: var(--radius-sm); line-height: 1;
  transition: opacity 0.15s, background 0.15s;
}
.md-del-btn:hover { background: rgba(239,68,68,0.12); }
.md-add-row td { padding: 0; border-top: 2px solid var(--border); }
.md-add-btn {
  width: 100%; background: none; border: none; color: var(--text-muted);
  padding: 10px; cursor: pointer; text-align: left; font-size: var(--fs-sm);
  transition: color 0.15s, background 0.15s;
}
.md-add-btn:hover { color: var(--accent-blue); background: rgba(99,102,241,0.06); }
