/* ==========================================================================
   Torédo Finance Tracker - Components & UI Elements
   ========================================================================== */

/* Form Controls Styling */
input[type="text"],
input[type="number"],
input[type="date"],
select,
textarea,
.search-input {
  background: rgba(15, 23, 42, 0.8) !important;
  border: 1px solid var(--border-glass-strong) !important;
  color: #f8fafc !important;
  padding: 10px 14px !important;
  border-radius: var(--radius-sm) !important;
  font-family: var(--font-main) !important;
  font-size: 14px !important;
  outline: none !important;
  transition: var(--transition) !important;
  width: 100%;
  min-width: 0 !important;
  max-width: 100% !important;
  text-overflow: ellipsis;
}

input[type="date"] {
  max-width: 220px;
}

input[type="number"] {
  max-width: 280px;
}

select {
  max-width: 320px;
}

#summary-notes,
#onetime-title,
#onetime-desc,
#recurring-title,
#prod-name,
#prod-barcode,
#debt-creditor,
#debt-desc,
#acc-name,
#cat-name,
#cat-desc,
#stream-name,
#stream-desc,
#rec-title,
#inv-notes {
  max-width: 520px;
}

input[type="text"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
select:focus,
textarea:focus,
.search-input:focus {
  border-color: var(--color-primary) !important;
  box-shadow: 0 0 0 3px var(--color-primary-glow) !important;
  background: rgba(15, 23, 42, 0.95) !important;
}

input::placeholder, textarea::placeholder {
  color: #64748b !important;
}

input[type="date"]::-webkit-calendar-picker-indicator {
  filter: invert(0.85);
  cursor: pointer;
}

select option {
  background-color: #0f172a !important;
  color: #f8fafc !important;
  padding: 8px !important;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  border: 1px solid transparent;
  touch-action: manipulation;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, #6366f1, #4f46e5);
  color: #ffffff;
  box-shadow: 0 4px 14px var(--color-primary-glow);
}

.btn-primary:hover {
  background: linear-gradient(135deg, #4f46e5, #4338ca);
  transform: translateY(-1px);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  border-color: var(--border-glass-strong);
  color: var(--text-primary);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.15);
}

.btn-success {
  background: linear-gradient(135deg, #10b981, #059669);
  color: #ffffff;
  box-shadow: 0 4px 14px var(--color-success-glow);
}

.btn-success:hover {
  background: linear-gradient(135deg, #059669, #047857);
}

.btn-text {
  background: transparent;
  padding: 4px 8px;
  color: var(--text-secondary);
}

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

.btn-sm {
  padding: 4px 10px;
  font-size: 12px;
}

.btn-lg {
  padding: 12px 24px;
  font-size: 15px;
  font-weight: 600;
}

.btn-block {
  width: 100%;
}

.text-danger { color: #f87171 !important; }
.text-success { color: #34d399 !important; }
.text-warning { color: #fbbf24 !important; }

/* Stats Cards Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
  margin-bottom: 32px;
  min-width: 0;
  max-width: 100%;
}

.stat-card {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: var(--shadow-glass);
  transition: var(--transition);
  min-width: 0;
  max-width: 100%;
}

.stat-card:hover {
  border-color: var(--border-glass-strong);
  transform: translateY(-2px);
}

.stat-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.stat-title {
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
}

.stat-value {
  font-family: var(--font-brand);
  font-size: 32px;
  font-weight: 700;
  margin-bottom: 8px;
}

.stat-subtext {
  font-size: 12px;
  color: var(--text-muted);
}

/* Panels */
.content-panel {
  background: var(--bg-card);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 24px;
  box-shadow: var(--shadow-glass);
  min-width: 0;
  max-width: 100%;
  box-sizing: border-box;
}

.panel-header {
  margin-bottom: 20px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  min-width: 0;
  max-width: 100%;
}

.panel-header h3 {
  font-family: var(--font-brand);
  font-size: 18px;
  font-weight: 600;
}

.panel-subtitle {
  font-size: 12px;
  color: var(--text-muted);
}

/* Tables & Horizontal Scroll Container */
.table-responsive {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  display: block;
  min-width: 0;
  border-radius: var(--radius-sm);
  margin-bottom: 16px;
}

.data-table {
  width: 100%;
  min-width: 480px;
  border-collapse: collapse;
  text-align: left;
  font-size: 13px;
}

.data-table th {
  padding: 12px 14px;
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-secondary);
  font-weight: 600;
  border-bottom: 1px solid var(--border-glass);
  white-space: nowrap;
}

.sortable-header {
  cursor: pointer;
  user-select: none;
  transition: color 0.2s ease;
}

.sortable-header:hover {
  color: var(--text-primary);
}

.sortable-header::after {
  content: ' ↕';
  opacity: 0.3;
  font-size: 0.85em;
  margin-left: 4px;
}

.sort-asc::after {
  content: ' ↑';
  opacity: 1;
  color: var(--color-primary);
}

.sort-desc::after {
  content: ' ↓';
  opacity: 1;
  color: var(--color-primary);
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-glass);
  color: var(--text-primary);
}

.data-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.03);
}

/* A table row or standalone block explaining there is nothing to show yet (e.g. an empty cycle,
   no tournaments uploaded), as opposed to .empty-cell's stronger, whole-table empty state. */
.empty-state {
  text-align: center;
  padding: 24px 12px;
  color: var(--text-muted);
}

.empty-cell {
  text-align: center;
  color: var(--text-muted);
  padding: 64px 24px !important;
  font-style: italic;
}

.empty-state-icon {
  display: block;
  font-size: 2.5rem;
  margin-bottom: 16px;
  opacity: 0.3;
}

.table-input-group {
  display: flex;
  gap: 6px;
  align-items: center;
}

.table-cell-input {
  width: 90px !important;
  min-width: 80px !important;
  padding: 6px 8px !important;
  font-size: 13px !important;
}

/* Progress Tracker Bar */
.budget-panel {
  background: linear-gradient(135deg, rgba(30, 41, 59, 0.8), rgba(15, 23, 42, 0.9));
}

.budget-progress-container {
  margin-top: 16px;
}

.budget-labels {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 8px;
  color: var(--text-secondary);
}

.progress-track {
  height: 12px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 6px;
  overflow: hidden;
  border: 1px solid var(--border-glass);
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--color-primary), var(--color-success));
  border-radius: 6px;
  transition: width 0.6s cubic-bezier(0.4, 0, 0.2, 1);
}

/* Form Layout & Triad Margin Box */
.form-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
  max-width: 100%;
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
}

.form-group label {
  font-size: 13px;
  font-weight: 600;
  color: #e2e8f0;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  min-width: 0;
  max-width: 100%;
}

.triad-box {
  background: rgba(99, 102, 241, 0.08);
  border: 1px dashed rgba(99, 102, 241, 0.3);
  border-radius: var(--radius-md);
  padding: 16px;
  margin: 8px 0;
  min-width: 0;
  max-width: 100%;
}

.triad-header {
  font-size: 12px;
  color: #a5b4fc;
  margin-bottom: 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
  max-width: 100%;
}

/* Unit Toggle Switch for Triad Margin */
.unit-toggle-group {
  display: inline-flex;
  gap: 2px;
  background: rgba(15, 23, 42, 0.9);
  border: 1px solid var(--border-glass-strong);
  border-radius: 6px;
  padding: 2px;
}

.btn-unit {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: 4px;
  cursor: pointer;
  transition: var(--transition);
}

.btn-unit.active {
  background: var(--color-primary);
  color: #ffffff;
  box-shadow: 0 0 8px var(--color-primary-glow);
}

/* Management Pane Subviews */
.management-tabs {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  border-bottom: 1px solid var(--border-glass);
  padding-bottom: 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.mgmt-tab-btn,
.catalog-tab-btn {
  padding: 8px 16px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  border-radius: var(--radius-sm);
  transition: var(--transition);
  white-space: nowrap;
}

.mgmt-tab-btn.active,
.catalog-tab-btn.active {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  font-weight: 600;
}

.mgmt-subview,
.catalog-subview {
  display: none;
  min-width: 0;
  max-width: 100%;
}

.mgmt-subview.active,
.catalog-subview.active {
  display: block;
}

.simple-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.simple-list li {
  padding: 12px 16px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border-glass);
  border-radius: var(--radius-md);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: var(--radius-md);
  background: var(--bg-dark);
  border: 1px solid var(--border-glass-strong);
  color: var(--text-primary);
  font-size: 13px;
  box-shadow: var(--shadow-glass);
  animation: slideUp 0.3s ease-out;
}

.toast-success { border-color: var(--color-success); }
.toast-danger { border-color: var(--color-danger); }

@keyframes slideUp {
  from { opacity: 0; transform: translateY(12px); }
  to { opacity: 1; transform: translateY(0); }
}

/* Custom Modals & Tooltips */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(15, 23, 42, 0.85);
  backdrop-filter: blur(8px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.25s ease-out;
}

.modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.modal-card {
  background: rgba(30, 41, 59, 0.95);
  border: 1px solid var(--border-glass-strong);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.5);
  border-radius: var(--radius-lg);
  width: 90%;
  max-width: 520px;
  overflow: hidden;
  transform: scale(0.95);
  transition: transform 0.25s ease-out;
}

.modal-overlay.active .modal-card {
  transform: scale(1);
}

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

.modal-header h3 {
  font-family: var(--font-brand);
  font-size: 1.1rem;
  color: var(--text-primary);
}

.modal-body {
  padding: 24px;
  font-size: 0.95rem;
  color: var(--text-secondary);
  line-height: 1.5;
}

.modal-footer {
  padding: 16px 24px;
  background: rgba(15, 23, 42, 0.5);
  border-top: 1px solid var(--border-glass);
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.tooltip-trigger {
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 10px;
  margin: -10px -4px -10px 2px;
  position: relative;
  touch-action: manipulation;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  outline: none;
}

.tooltip-trigger-icon {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: rgba(99, 102, 241, 0.18);
  border: 1px solid rgba(99, 102, 241, 0.45);
  color: #a5b4fc;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  transition: all 0.2s ease;
  pointer-events: none;
}

.tooltip-trigger:hover .tooltip-trigger-icon,
.tooltip-trigger:focus .tooltip-trigger-icon,
.tooltip-trigger.active .tooltip-trigger-icon {
  background: var(--color-primary);
  color: #ffffff;
  border-color: var(--color-primary);
  box-shadow: 0 0 12px var(--color-primary-glow);
}

.tooltip-trigger::after {
  content: attr(data-tooltip);
  position: absolute;
  bottom: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%) translateY(4px);
  background: rgba(15, 23, 42, 0.98);
  color: #f8fafc;
  border: 1px solid var(--border-glass-strong);
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  font-weight: 400;
  line-height: 1.4;
  white-space: normal;
  width: max-content;
  max-width: 260px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.5);
  z-index: 2000;
  pointer-events: none;
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.2s ease, transform 0.2s ease, visibility 0.2s;
  text-align: center;
}

.tooltip-trigger:hover::after,
.tooltip-trigger:focus::after,
.tooltip-trigger.active::after {
  opacity: 1;
  visibility: visible;
  transform: translateX(-50%) translateY(0);
}

.warning-alert-banner {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.4);
  color: var(--color-warning);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.85rem;
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
  animation: slideUp 0.2s ease-out;
}

.skeleton-box {
  background: linear-gradient(90deg, rgba(255,255,255,0.03) 25%, rgba(255,255,255,0.08) 50%, rgba(255,255,255,0.03) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
}

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

.input-invalid {
  border-color: var(--color-danger) !important;
  box-shadow: 0 0 10px rgba(239, 68, 68, 0.3) !important;
}

.input-error-msg {
  color: var(--color-danger);
  font-size: 0.78rem;
  margin-top: 2px;
}

/* ==========================================================================
   Print Stylesheet - Receipt Only
   ========================================================================== */
@media print {
  body > *:not(.modal-overlay) {
    display: none !important;
  }

  .modal-overlay {
    position: static !important;
    background: transparent !important;
    overflow: visible !important;
  }

  .modal-overlay .modal-content {
    box-shadow: none !important;
    border: none !important;
    background: #fff !important;
    color: #000 !important;
    max-width: 100% !important;
    width: 100% !important;
    padding: 20px !important;
  }

  .modal-overlay .modal-content .btn {
    display: none !important;
  }

  .modal-overlay .modal-content * {
    color: #000 !important;
  }
}

/* ==========================================================================
   Loading Spinner
   ========================================================================== */
@keyframes spin {
  to { transform: rotate(360deg); }
}
.spinner-loader {
  width: 40px;
  height: 40px;
  border: 4px solid var(--border-glass);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

