/* habitat-dash-v2 Components - Reusable UI Elements */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-2) var(--space-4);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  font-family: inherit;
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.btn--primary {
  background: linear-gradient(135deg, #dfa634 0%, #be8720 100%);
  color: #0c0f14 !important;
  font-weight: 700;
  border: 1px solid #ce9529;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35);
  border-radius: var(--radius-sm);
}

.btn--primary:hover:not(:disabled) {
  background: linear-gradient(135deg, #edba4c 0%, #ce9529 100%);
  color: #0c0f14 !important;
  box-shadow: 0 3px 12px rgba(223, 166, 52, 0.25);
}

.btn--secondary {
  background: #181d29;
  color: #dcd7ca;
  border: 1px solid rgba(223, 166, 52, 0.18);
  border-radius: var(--radius-sm);
}

.btn--secondary:hover:not(:disabled) {
  background: #202737;
  border-color: rgba(223, 166, 52, 0.35);
  color: #f0e6d2;
}

.btn--ghost {
  background: transparent;
  color: var(--text-secondary);
}

.btn--ghost:hover:not(:disabled) {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.btn--danger {
  background: var(--accent-red);
  color: var(--text-on-accent);
}

.btn--danger:hover:not(:disabled) {
  background: var(--accent-red-hover);
}

.btn--success {
  background: var(--accent-green);
  color: var(--text-on-accent);
}

.btn--success:hover:not(:disabled) {
  background: var(--accent-green-hover);
}

.btn--sm {
  padding: var(--space-1) var(--space-3);
  font-size: var(--text-xs);
}

.btn--lg {
  padding: var(--space-3) var(--space-6);
  font-size: var(--text-base);
}

.btn--icon {
  padding: var(--space-2);
}

.btn--block {
  width: 100%;
}

/* Cards */
.card {
  background: var(--app-card-bg, #151a25);
  border: 1px solid rgba(223, 166, 52, 0.16);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
  overflow: hidden;
  transition: all var(--transition-base);
}

.card:hover {
  border-color: var(--border-focus);
  box-shadow: var(--shadow-md);
}

.card__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-primary);
}

.card__title {
  font-size: var(--text-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
}

.card__body {
  padding: var(--space-5);
}

.card__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-5);
  border-top: 1px solid var(--border-primary);
  background: var(--bg-tertiary);
}

/* Panels (for tools/options) */
.panel {
  background: var(--app-card-bg, #151a25);
  border: 1px solid rgba(223, 166, 52, 0.16);
  border-radius: 8px;
  padding: 14px 16px;
  margin-bottom: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25);
}

.panel__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border-primary);
}

.panel__title {
  font-size: var(--text-sm);
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.panel__action {
  font-size: var(--text-xs);
  color: var(--accent-blue);
  text-decoration: none;
}

.panel__action:hover {
  text-decoration: underline;
}

/* Form Elements */
.form-group {
  margin-bottom: var(--space-4);
}

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

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: var(--space-2) var(--space-3);
  background: var(--bg-primary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-size: var(--text-sm);
  font-family: inherit;
  transition: all var(--transition-fast);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(88, 166, 255, 0.15);
}

.form-input::placeholder {
  color: var(--text-muted);
}

.form-select {
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b949e' 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 var(--space-3) center;
  padding-right: var(--space-10);
}

.form-textarea {
  min-height: 100px;
  resize: vertical;
}

.form-checkbox,
.form-radio {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  cursor: pointer;
}

.form-checkbox input,
.form-radio input {
  width: 16px;
  height: 16px;
  accent-color: var(--accent-blue);
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  padding: var(--space-1) var(--space-2);
  font-size: var(--text-xs);
  font-weight: var(--font-weight-semibold);
  border-radius: var(--radius-full);
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge--primary { background: rgba(88, 166, 255, 0.15); color: var(--accent-blue); }
.badge--success { background: rgba(63, 185, 80, 0.15); color: var(--accent-green); }
.badge--warning { background: rgba(210, 153, 34, 0.15); color: var(--accent-yellow); }
.badge--danger { background: rgba(248, 81, 73, 0.15); color: var(--accent-red); }
.badge--info { background: rgba(57, 197, 207, 0.15); color: var(--accent-cyan); }
.badge--purple { background: rgba(163, 113, 247, 0.15); color: var(--accent-purple); }
.badge--neutral { background: var(--bg-tertiary); color: var(--text-secondary); }

/* Tables */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-primary);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.table th,
.table td {
  padding: var(--space-3) var(--space-4);
  text-align: left;
  border-bottom: 1px solid var(--border-primary);
}

.table th {
  background: var(--bg-tertiary);
  font-weight: var(--font-weight-semibold);
  color: var(--text-secondary);
  font-size: var(--text-xs);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  white-space: nowrap;
}

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

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

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

/* Tabs */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--border-primary);
  margin-bottom: var(--space-4);
}

.tab-btn {
  padding: var(--space-2) var(--space-4);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  font-weight: var(--font-weight-medium);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: all var(--transition-fast);
}

.tab-btn:hover {
  color: var(--text-primary);
}

.tab-btn.active {
  color: var(--accent-blue);
  border-bottom-color: var(--accent-blue);
}

/* Dropdown */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown__menu {
  position: absolute;
  top: calc(100% + var(--space-1));
  right: 0;
  min-width: 180px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  padding: var(--space-2);
  opacity: 0;
  visibility: hidden;
  transform: translateY(-8px);
  transition: all var(--transition-fast);
  z-index: var(--z-dropdown);
}

.dropdown.open .dropdown__menu {
  opacity: 1;
  visibility: visible;
  transform: translateY(0);
}

.dropdown__item {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  padding: var(--space-2) var(--space-3);
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-size: var(--text-sm);
  text-align: left;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition-fast);
}

.dropdown__item:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.dropdown__item svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.dropdown__divider {
  height: 1px;
  background: var(--border-primary);
  margin: var(--space-2) 0;
}

/* Tooltips */
.tooltip {
  position: relative;
}

.tooltip::before {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + var(--space-2));
  left: 50%;
  transform: translateX(-50%);
  padding: var(--space-1) var(--space-2);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-sm);
  font-size: var(--text-xs);
  color: var(--text-secondary);
  white-space: nowrap;
  opacity: 0;
  visibility: hidden;
  transition: all var(--transition-fast);
  z-index: var(--z-tooltip);
  pointer-events: none;
}

.tooltip:hover::before {
  opacity: 1;
  visibility: visible;
}

/* Loading States */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg-tertiary) 25%,
    var(--bg-hover) 50%,
    var(--bg-tertiary) 75%
  );
  background-size: 200% 100%;
  animation: skeleton-loading 1.5s infinite;
  border-radius: var(--radius-sm);
}

@keyframes skeleton-loading {
  0% { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border-primary);
  border-top-color: var(--accent-blue);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Empty State */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--space-12) var(--space-6);
  text-align: center;
  color: var(--text-muted);
}

.empty-state svg {
  width: 64px;
  height: 64px;
  margin-bottom: var(--space-4);
  opacity: 0.5;
}

.empty-state__title {
  font-size: var(--text-lg);
  font-weight: var(--font-weight-semibold);
  color: var(--text-secondary);
  margin-bottom: var(--space-1);
}

.empty-state__desc {
  font-size: var(--text-sm);
  max-width: 280px;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: var(--space-6);
  right: var(--space-6);
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  z-index: var(--z-toast);
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  min-width: 280px;
  max-width: 400px;
  padding: var(--space-4);
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
  pointer-events: auto;
  animation: toast-in 0.3s ease;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}

.toast--success { border-left: 4px solid var(--accent-green); }
.toast--error { border-left: 4px solid var(--accent-red); }
.toast--warning { border-left: 4px solid var(--accent-yellow); }
.toast--info { border-left: 4px solid var(--accent-blue); }

.toast__icon {
  width: 20px;
  height: 20px;
  flex-shrink: 0;
  margin-top: 2px;
}

.toast__content {
  flex: 1;
}

.toast__title {
  font-weight: var(--font-weight-semibold);
  color: var(--text-primary);
  margin-bottom: var(--space-1);
}

.toast__message {
  font-size: var(--text-sm);
  color: var(--text-secondary);
}

.toast__close {
  padding: var(--space-1);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.toast__close:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4);
  z-index: var(--z-modal);
  animation: fade-in 0.2s ease;
}

@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal {
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  background: var(--bg-secondary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-xl);
  overflow: hidden;
  animation: modal-in 0.3s ease;
}

@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95) translateY(20px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--space-4) var(--space-5);
  border-bottom: 1px solid var(--border-primary);
}

.modal__title {
  font-size: var(--text-lg);
  font-weight: var(--font-weight-semibold);
}

.modal__close {
  padding: var(--space-1);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}

.modal__close:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.modal__body {
  padding: var(--space-5);
  overflow-y: auto;
  max-height: calc(90vh - 120px);
}

.modal__footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--space-3);
  padding: var(--space-4) var(--space-5);
  border-top: 1px solid var(--border-primary);
  background: var(--bg-tertiary);
}

/* Avatar */
.avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border-radius: var(--radius-full);
  background: var(--accent-blue);
  color: var(--text-on-accent);
  font-weight: var(--font-weight-semibold);
  font-size: var(--text-sm);
  overflow: hidden;
}

.avatar--sm { width: 28px; height: 28px; font-size: var(--text-xs); }
.avatar--lg { width: 48px; height: 48px; font-size: var(--text-base); }
.avatar--xl { width: 64px; height: 64px; font-size: var(--text-xl); }

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Divider */
.divider {
  height: 1px;
  background: var(--border-primary);
  margin: var(--space-4) 0;
}

.divider-text {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  color: var(--text-muted);
  font-size: var(--text-xs);
  text-transform: uppercase;
}

.divider-text::before,
.divider-text::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-primary);
}

/* Grid utilities */
.grid {
  display: grid;
  gap: var(--space-4);
}

.grid--2 { grid-template-columns: repeat(2, 1fr); }
.grid--3 { grid-template-columns: repeat(3, 1fr); }
.grid--4 { grid-template-columns: repeat(4, 1fr); }
.grid--auto { grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }

@media (max-width: 1024px) {
  .grid--3, .grid--4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
  .grid--2, .grid--3, .grid--4 { grid-template-columns: 1fr; }
}

/* Flex utilities */
.flex { display: flex; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: var(--space-1); }
.gap-2 { gap: var(--space-2); }
.gap-3 { gap: var(--space-3); }
.gap-4 { gap: var(--space-4); }
/* ---------- AI Usage HUD (header) ---------- */
.ai-hud {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-1) var(--space-3);
  background: var(--bg-tertiary);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-full);
  color: var(--text-primary);
  font-size: var(--text-xs);
  white-space: nowrap;
  transition: all var(--transition-fast);
}
.ai-hud:hover { border-color: var(--border-focus); background: var(--bg-hover); }
.ai-hud__icon { width: 16px; height: 16px; color: var(--accent-purple); flex-shrink: 0; }
.ai-hud__main { display: flex; flex-direction: column; align-items: flex-start; line-height: 1.15; }
.ai-hud__tokens { font-family: var(--font-mono); font-weight: var(--font-weight-bold); color: var(--text-primary); }
.ai-hud__label { color: var(--text-muted); font-size: 10px; letter-spacing: 0.05em; text-transform: uppercase; }
.ai-hud__vs { display: flex; gap: var(--space-1); }
.ai-chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  padding: 1px var(--space-2);
  border: 1px solid var(--border-primary);
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  font-size: 10px;
  white-space: nowrap;
  background: var(--bg-primary);
}
.ai-chip::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.ai-chip--self   { color: var(--accent-cyan); }
.ai-chip--openai { color: var(--accent-green); }
.ai-chip--claude { color: var(--accent-purple); }
.ai-chip--gemini { color: var(--accent-blue); }
@media (max-width: 1280px) { .ai-hud__vs { display: none; } }
@media (max-width: 720px)  { .ai-hud { display: none; } }

/* --- CERVELLO HUD LED (lampeggio stile HD) --- */
.cv-hud__led {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #555;
  flex-shrink: 0;
  transition: background .15s ease, box-shadow .15s ease;
}
.cv-hud__led--on { background: #56d364; box-shadow: 0 0 6px rgba(86,211,100,.6); }
.cv-hud__led--off { background: #f85149; box-shadow: 0 0 4px rgba(248,81,73,.4); }
.cv-hud__led--working { background: #56d364; animation: cv-hud-blink .38s steps(2, start) infinite; }
@keyframes cv-hud-blink {
  0%, 100% { opacity: 1; box-shadow: 0 0 8px rgba(86,211,100,.9); }
  50% { opacity: .25; box-shadow: 0 0 2px rgba(86,211,100,.3); }
}
.cv-prv-footer { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; padding-top: 8px; border-top: 1px dashed var(--border); font-size: 11px; color: var(--text-muted); }
.cv-prv-footer__lock { display: inline-flex; gap: 4px; align-items: center; padding: 3px 8px; background: rgba(57,197,207,.1); color: var(--accent-cyan); border-radius: 4px; font-weight: 600; }
.cv-prv-footer__model { font-family: var(--font-mono); }
