@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

:root {
  --bg: #0a0f1e;
  --bg2: #0d1525;
  --surface: rgba(255, 255, 255, 0.04);
  --border: rgba(255, 255, 255, 0.08);
  --accent: #00d4aa;
  --accent2: #4f8ef7;
  --danger: #ff5f6d;
  --warn: #ffa94d;
  --text: #e2e8f0;
  --text2: #8892a4;
  --radius: 14px;
  --gap: 14px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* ── Wrapper principal: flex row, altura fija ── */
.dashboard-wrapper {
  display: flex;
  flex-direction: row;
  flex: 1;
  min-height: 0;
  gap: var(--gap);
  padding: var(--gap);
}

/* ── Área de contenido izquierda (scrollable) ── */
.dashboard-content {
  flex: 1;
  min-width: 0;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

.dashboard-content::-webkit-scrollbar {
  width: 6px;
}

.dashboard-content::-webkit-scrollbar-track {
  background: transparent;
}

.dashboard-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.dashboard-content::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.15);
}

/* ── Header ── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 20px;
  background: rgba(0, 212, 170, 0.06);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.header-main {
  display: flex;
  align-items: center;
  gap: 24px;
}

.header-title-row {
  display: flex;
  align-items: center;
}

.header-toggle-btn {
  display: none;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  color: var(--text2);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: 4px;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s, transform 0.2s ease;
  font-family: inherit;
  line-height: 1;
}

.header-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.1);
  color: var(--text);
}

header h1 {
  font-size: 1.1rem;
  font-weight: 700;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  letter-spacing: -0.3px;
}

.header-badge {
  display: flex;
  gap: 10px;
  align-items: center;
}

.badge {
  font-size: 0.7rem;
  padding: 3px 10px;
  border-radius: 20px;
  font-weight: 600;
  letter-spacing: 0.5px;
}

.badge-green {
  background: rgba(0, 212, 170, 0.15);
  color: var(--accent);
  border: 1px solid rgba(0, 212, 170, 0.3);
}

.badge-blue {
  background: rgba(79, 142, 247, 0.15);
  color: var(--accent2);
  border: 1px solid rgba(79, 142, 247, 0.3);
}

/* ── Grid interno del contenido (3 columnas) ── */
.dashboard {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  grid-auto-rows: 350px;
  grid-auto-flow: dense;
  gap: var(--gap);
}

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  backdrop-filter: blur(10px);
  display: flex;
  flex-direction: column;
  transition: border-color 0.2s;
  position: relative;
  z-index: 1;
}

.card:focus-within {
  z-index: 10;
}

.card:hover {
  border-color: rgba(255, 255, 255, 0.14);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  flex-shrink: 0;
}

.card-title {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text2);
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-title span {
  font-size: 1rem;
}

.card-body {
  flex: 1;
  overflow-y: auto;
}

.card-body::-webkit-scrollbar {
  width: 4px;
}

.card-body::-webkit-scrollbar-track {
  background: transparent;
}

.card-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

/* ── Card Sizes & Custom Sizing Controls ── */
.card.size-1x1 {
  grid-column: span 1;
  grid-row: span 1;
}

.card.size-1x2 {
  grid-column: span 1;
  grid-row: span 2;
}

.card.size-2x1 {
  grid-column: span 2;
  grid-row: span 1;
}

.card.size-2x2 {
  grid-column: span 2;
  grid-row: span 2;
}

.card-size-selector {
  position: relative;
  display: inline-block;
}

.size-btn {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 0.8rem;
  padding: 2px 6px;
  border-radius: 5px;
  transition: color 0.2s, transform 0.2s;
  display: flex;
  align-items: center;
  justify-content: center;
}

.size-btn:hover {
  color: var(--accent);
  transform: scale(1.15);
}

.size-dropdown {
  display: none;
  position: absolute;
  top: 100%;
  right: 0;
  background: rgba(13, 21, 37, 0.98);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  z-index: 100;
  margin-top: 4px;
  min-width: 130px;
  backdrop-filter: blur(10px);
  overflow: hidden;
}

.size-dropdown.show {
  display: block;
}

.size-option {
  padding: 8px 12px;
  font-size: 0.72rem;
  color: var(--text2);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-align: left;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.size-option:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--text);
}

.size-option.active {
  color: var(--accent);
  font-weight: 600;
  background: rgba(0, 212, 170, 0.05);
}

/* ── Sidebar de Chat (fijo derecha, altura completa, colapsable) ── */
#card-chat {
  width: 340px;
  min-width: 340px;
  flex-shrink: 0;
  height: 100%;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1), min-width 0.3s cubic-bezier(0.4, 0, 0.2, 1), padding 0.3s cubic-bezier(0.4, 0, 0.2, 1);
  border-color: rgba(0, 212, 170, 0.2);
  align-self: stretch;
}

/* ── Collapsible Chat & Grid Column Layouts ── */
.dashboard-wrapper {
  transition: padding 0.3s ease;
}

.dashboard-wrapper.chat-collapsed .dashboard {
  grid-template-columns: 1fr 1fr 1fr 1fr;
}

/* ── Drag & Drop Styling ── */
.card-header {
  cursor: grab;
}

.card-header:active {
  cursor: grabbing;
}

.card.dragging {
  opacity: 0.45;
  border: 2px dashed var(--accent) !important;
  background: rgba(0, 212, 170, 0.05) !important;
  box-shadow: 0 8px 30px rgba(0,0,0,0.5);
  transform: scale(0.98);
}

/* ── Sidebar de Chat Collapsed State ── */
#card-chat.collapsed {
  width: 50px;
  min-width: 50px;
  padding: 12px 6px;
  align-items: center;
}

#card-chat.collapsed .chat-title-text,
#card-chat.collapsed .chat-badge,
#card-chat.collapsed .chat-messages,
#card-chat.collapsed .chat-input-row {
  display: none !important;
}

#card-chat.collapsed .card-header {
  flex-direction: column;
  gap: 15px;
  width: 100%;
  align-items: center;
  margin-bottom: 0;
  border-bottom: none;
}

#card-chat.collapsed .card-title {
  justify-content: center;
}

/* ── Toggle button styling ── */
.chat-toggle-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  color: var(--text2);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 4px 8px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s, border-color 0.2s;
  font-family: inherit;
}

.chat-toggle-btn:hover {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  color: var(--text);
}

/* ── Stat numbers ── */
.stat-big {
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -1px;
  line-height: 1;
}

.stat-label {
  font-size: 0.7rem;
  color: var(--text2);
  margin-top: 2px;
}

.text-green {
  color: var(--accent);
}

.text-blue {
  color: var(--accent2);
}

.text-red {
  color: var(--danger);
}

.text-warn {
  color: var(--warn);
}

.stat-row {
  display: flex;
  gap: 12px;
  margin-bottom: 8px;
}

.stat-item {
  flex: 1;
}

/* ── Account list ── */
.acc-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 7px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.8rem;
  animation: fadeIn 0.3s ease;
}

.acc-item:last-child {
  border-bottom: none;
}

.acc-name {
  color: var(--text);
  font-weight: 500;
}

.acc-type {
  font-size: 0.65rem;
  color: var(--text2);
}

.acc-bal {
  font-weight: 600;
}

/* ── Investment table ── */
.inv-row {
  display: grid;
  grid-template-columns: 1fr auto auto auto;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
  font-size: 0.78rem;
  align-items: center;
  animation: fadeIn 0.3s ease;
}

.inv-row:last-child {
  border-bottom: none;
}

/* ── Summary bars ── */
.summary-item {
  margin-bottom: 10px;
}

.summary-label {
  font-size: 0.72rem;
  color: var(--text2);
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.bar-track {
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.8s cubic-bezier(.4, 0, .2, 1);
}

.bar-income {
  background: linear-gradient(90deg, var(--accent), #00f5c4);
}

.bar-expense {
  background: linear-gradient(90deg, var(--danger), #ff9a9e);
}

.bar-adjustment {
  background: linear-gradient(90deg, var(--accent2), #a1c4fd);
}

/* ── Transaction list ── */
.tx-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.tx-item {
  display: grid;
  grid-template-columns: 36px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.03);
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.78rem;
  animation: fadeIn 0.3s ease;
  transition: background 0.2s;
}

.tx-item > div:nth-child(2) {
  min-width: 0;
}

.tx-item:hover {
  background: rgba(255, 255, 255, 0.06);
}

.tx-icon {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
}

.tx-icon-gasto {
  background: rgba(255, 95, 109, 0.15);
}

.tx-icon-ingreso {
  background: rgba(0, 212, 170, 0.15);
}

.tx-icon-other {
  background: rgba(79, 142, 247, 0.15);
}

.tx-notes {
  font-weight: 500;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
  text-overflow: ellipsis;
  word-break: break-word;
}

.tx-meta {
  font-size: 0.68rem;
  color: var(--text2);
  margin-top: 2px;
}

.tx-amount {
  font-weight: 700;
  white-space: nowrap;
}

.tx-delete-btn {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 0.75rem;
  padding: 2px 5px;
  border-radius: 4px;
  transition: color 0.2s, background 0.2s;
}

.tx-delete-btn:hover {
  color: var(--danger);
  background: rgba(255, 95, 109, 0.1);
}

/* ── Form ── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.form-full {
  grid-column: 1 / -1;
}

label {
  font-size: 0.68rem;
  color: var(--text2);
  font-weight: 500;
  display: block;
  margin-bottom: 3px;
}

input,
select,
textarea {
  width: 100%;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-family: 'Inter', sans-serif;
  font-size: 0.8rem;
  padding: 7px 10px;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

/* Chrome, Safari, Edge, Opera */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  appearance: none;
  margin: 0;
}

/* Firefox */
input[type=number] {
  -moz-appearance: textfield;
  appearance: textfield;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(0, 212, 170, 0.12);
}

select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238892a4' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%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;
  background-size: 14px;
  padding-right: 32px;
}

select option {
  background: #1a2035;
  color: var(--text);
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 8px 16px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
  width: 100%;
  margin-top: 8px;
  font-family: 'Inter', sans-serif;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), #00b894);
  color: #0a0f1e;
}

.btn-primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
  box-shadow: 0 4px 15px rgba(0, 212, 170, 0.3);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-secondary {
  background: rgba(79, 142, 247, 0.15);
  color: var(--accent2);
  border: 1px solid rgba(79, 142, 247, 0.3);
}

.btn-secondary:hover {
  background: rgba(79, 142, 247, 0.25);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.72rem;
  width: auto;
  margin-top: 0;
  border-radius: 6px;
}

/* ── Loans ── */
.loans-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 10px;
}

.loan-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px;
  font-size: 0.78rem;
  animation: fadeIn 0.3s ease;
}

.loan-name {
  font-weight: 600;
  font-size: 0.88rem;
  margin-bottom: 4px;
}

.loan-progress {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 8px 0;
  overflow: hidden;
}

.loan-bar {
  height: 100%;
  border-radius: 2px;
  background: linear-gradient(90deg, var(--accent2), var(--accent));
  transition: width 0.8s;
}

/* ── Chat messages ── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-right: 4px;
}

.chat-messages::-webkit-scrollbar {
  width: 4px;
}

.chat-messages::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.msg {
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.8rem;
  line-height: 1.5;
  max-width: 100%;
  word-break: break-word;
  animation: slideUp 0.3s ease;
}

.msg-user {
  background: linear-gradient(135deg, rgba(79, 142, 247, 0.2), rgba(79, 142, 247, 0.1));
  border: 1px solid rgba(79, 142, 247, 0.25);
  align-self: flex-end;
  border-bottom-right-radius: 3px;
}

.msg-bot {
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--border);
  align-self: flex-start;
  border-bottom-left-radius: 3px;
  white-space: pre-wrap;
}

.msg-bot strong {
  color: var(--accent);
}

.msg-thinking {
  color: var(--text2);
  font-style: italic;
  font-size: 0.75rem;
  display: flex;
  align-items: center;
  gap: 6px;
}

.dot-pulse {
  display: flex;
  gap: 4px;
}

.dot-pulse span {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s infinite;
}

.dot-pulse span:nth-child(2) {
  animation-delay: 0.2s;
}

.dot-pulse span:nth-child(3) {
  animation-delay: 0.4s;
}

.chat-input-row {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-shrink: 0;
}

.chat-input-row input {
  flex: 1;
  border-radius: 10px;
}

.chat-send-btn {
  background: linear-gradient(135deg, var(--accent), #00b894);
  border: none;
  border-radius: 10px;
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition: all 0.2s;
  flex-shrink: 0;
}

.chat-send-btn:hover {
  opacity: 0.85;
  transform: scale(1.05);
}

.chat-send-btn:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

/* ── Toast ── */
#toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 0.82rem;
  font-weight: 500;
  opacity: 0;
  transform: translateY(10px);
  transition: all 0.3s;
  pointer-events: none;
  z-index: 999;
}

#toast.show {
  opacity: 1;
  transform: translateY(0);
}

#toast.success {
  background: rgba(0, 212, 170, 0.15);
  border: 1px solid rgba(0, 212, 170, 0.4);
  color: var(--accent);
}

#toast.error {
  background: rgba(255, 95, 109, 0.15);
  border: 1px solid rgba(255, 95, 109, 0.4);
  color: var(--danger);
}

/* ── Loading skeleton ── */
.skeleton {
  background: linear-gradient(90deg, rgba(255, 255, 255, 0.05) 25%, rgba(255, 255, 255, 0.1) 50%, rgba(255, 255, 255, 0.05) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: 6px;
  height: 14px;
  margin-bottom: 8px;
}

/* ── Animations ── */
@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(4px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes pulse {

  0%,
  60%,
  100% {
    opacity: 0.2;
    transform: scale(1);
  }

  30% {
    opacity: 1;
    transform: scale(1.3);
  }
}

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

  100% {
    background-position: -200% 0;
  }
}

/* ── Refresh btn ── */
.refresh-btn {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 6px;
  border-radius: 5px;
  transition: color 0.2s, transform 0.3s;
}

.refresh-btn:hover {
  color: var(--accent);
  transform: rotate(180deg);
}

.logout-btn {
  background: none;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 2px 6px;
  border-radius: 5px;
  transition: color 0.2s, background-color 0.2s;
  font-family: inherit;
  font-weight: 500;
}

.logout-btn:hover {
  color: #ff5f6d;
  background-color: rgba(255, 95, 109, 0.1);
}

/* ── Scrollbar global ── */
* {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}

/* ── Status dot ── */
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--accent);
  box-shadow: 0 0 6px var(--accent);
  animation: blink 2s infinite;
}

@keyframes blink {

  0%,
  100% {
    opacity: 1;
  }

  50% {
    opacity: 0.3;
  }
}

/* ── Markdown in chat ── */
.msg-bot em {
  color: var(--warn);
  font-style: normal;
}

.msg-bot code {
  background: rgba(0, 0, 0, 0.3);
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 0.75rem;
}

/* ── Error Accordion ── */
.error-accordion {
  margin-top: 8px;
  border: 1px solid rgba(255, 95, 109, 0.2);
  border-radius: 8px;
  overflow: hidden;
  background: rgba(255, 95, 109, 0.04);
  text-align: left;
  width: 100%;
}

.error-accordion-btn {
  background: transparent;
  border: none;
  color: var(--danger);
  font-size: 0.7rem;
  font-weight: 600;
  padding: 6px 10px;
  width: 100%;
  text-align: left;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  outline: none;
  font-family: inherit;
  user-select: none;
}

.error-accordion-btn::after {
  content: '▼';
  font-size: 0.55rem;
  transition: transform 0.2s ease;
}

.error-accordion-content {
  display: none;
  padding: 8px 10px;
  border-top: 1px solid rgba(255, 95, 109, 0.1);
  font-size: 0.72rem;
  color: var(--text2);
  max-height: 150px;
  overflow-y: auto;
  background: rgba(0, 0, 0, 0.25);
  word-break: break-all;
}

.error-accordion.show .error-accordion-content {
  display: block;
}

.error-accordion.show .error-accordion-btn::after {
  transform: rotate(180deg);
}

/* ── Navigation Tabs ── */
.nav-tabs {
  display: flex;
  gap: 8px;
}

.nav-tab {
  background: transparent;
  border: 1px solid transparent;
  color: var(--text2);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 4px;
}

.nav-tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.03);
}

.nav-tab.active {
  color: var(--accent);
  background: rgba(0, 212, 170, 0.1);
  border-color: rgba(0, 212, 170, 0.2);
  box-shadow: 0 0 10px rgba(0, 212, 170, 0.15);
}

/* ── View Containers ── */
.view-container {
  height: 100%;
  animation: fadeIn 0.3s ease;
}

/* ── CRUD Panel ── */
.crud-panel {
  display: flex;
  height: 100%;
  gap: var(--gap);
  min-height: 0;
}

.crud-sidebar {
  width: 180px;
  background: rgba(255, 255, 255, 0.01);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  flex-shrink: 0;
}

.crud-sidebar h3 {
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text2);
  margin-bottom: 8px;
  padding-left: 6px;
}

.crud-tab {
  background: transparent;
  border: none;
  color: var(--text2);
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  text-align: left;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.crud-tab:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.crud-tab.active {
  color: #fff;
  background: rgba(79, 142, 247, 0.25);
  font-weight: 600;
  border-left: 3px solid var(--accent2);
}

.crud-main {
  flex: 1;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100%;
}

.crud-main-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 14px;
  flex-shrink: 0;
}

.crud-main-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text);
}

.crud-table-wrapper {
  flex: 1;
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: rgba(0, 0, 0, 0.1);
}

.crud-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.78rem;
  text-align: left;
}

.crud-table th,
.crud-table td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
}

.crud-table th {
  background: rgba(10, 15, 30, 0.95);
  color: var(--text2);
  font-weight: 600;
  text-transform: uppercase;
  font-size: 0.65rem;
  letter-spacing: 0.5px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.crud-table tbody tr {
  transition: background 0.15s ease;
}

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

.crud-table td {
  color: var(--text);
  white-space: nowrap;
  max-width: 250px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Action buttons in CRUD table */
.crud-actions {
  display: flex;
  gap: 6px;
}

.crud-btn-edit,
.crud-btn-delete,
.crud-btn-pay {
  background: transparent;
  border: none;
  color: var(--text2);
  cursor: pointer;
  font-size: 0.85rem;
  padding: 4px 6px;
  border-radius: 4px;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  justify-content: center;
}

.crud-btn-edit:hover {
  color: var(--accent2);
  background: rgba(79, 142, 247, 0.15);
}

.crud-btn-delete:hover {
  color: var(--danger);
  background: rgba(255, 95, 109, 0.15);
}

.crud-btn-pay:hover {
  color: var(--accent);
  background: rgba(0, 212, 170, 0.15);
}

/* Modal Window styles */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100vw;
  height: 100vh;
  background: rgba(10, 15, 30, 0.6);
  backdrop-filter: blur(15px);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  animation: fadeIn 0.25s cubic-bezier(.4, 0, .2, 1);
}

.modal-content.card {
  box-shadow: 0 10px 40px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.05);
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(20, 28, 48, 0.85);
  animation: slideUp 0.3s cubic-bezier(.4, 0, .2, 1);
}

.crud-badge {
  font-size: 0.65rem;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 4px;
  display: inline-block;
}
.crud-badge-green { background: rgba(0, 212, 170, 0.15); color: var(--accent); border: 1px solid rgba(0, 212, 170, 0.3); }
.crud-badge-red { background: rgba(255, 95, 109, 0.15); color: var(--danger); border: 1px solid rgba(255, 95, 109, 0.3); }
.crud-badge-blue { background: rgba(79, 142, 247, 0.15); color: var(--accent2); border: 1px solid rgba(79, 142, 247, 0.3); }
.crud-badge-warn { background: rgba(255, 169, 77, 0.15); color: var(--warn); border: 1px solid rgba(255, 169, 77, 0.3); }

/* ── Custom Select Autocomplete ── */
.custom-select-wrapper {
  position: relative;
  width: 100%;
}

.custom-select-dropdown {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #121829;
  border: 1px solid var(--border);
  border-radius: 8px;
  max-height: 200px;
  overflow-y: auto;
  z-index: 1000;
  display: none;
  margin-top: 4px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
}

.custom-select-dropdown::-webkit-scrollbar {
  width: 4px;
}

.custom-select-dropdown::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 2px;
}

.custom-select-option {
  padding: 8px 12px;
  font-size: 0.8rem;
  color: var(--text);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
  text-align: left;
}

.custom-select-option:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--accent);
}

.custom-select-option.create-new-option {
  border-top: 1px solid var(--border);
  color: var(--accent2);
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 4px;
}

.custom-select-option.create-new-option:hover {
  background: rgba(79, 142, 247, 0.1);
  color: #fff;
}

/* ── Balance General (Net Worth) Card Styles ── */
.balance-card-grid {
  display: flex;
  flex-direction: column;
  height: 100%;
  justify-content: flex-start;
  padding: 4px 2px;
}

.balance-total-section {
  text-align: center;
  padding: 14px;
  background: linear-gradient(135deg, rgba(0, 212, 170, 0.05), rgba(79, 142, 247, 0.05));
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 12px;
}

.balance-total-title {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  color: var(--text2);
  letter-spacing: 1px;
  margin-bottom: 4px;
}

.balance-total-value {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.5px;
}

.balance-split-row {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.balance-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  background: rgba(255, 255, 255, 0.02);
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 0.76rem;
}

.balance-item-label {
  font-weight: 500;
  color: var(--text);
}

.balance-item-value {
  font-weight: 700;
}

.balance-net-liq {
  background: rgba(79, 142, 247, 0.05);
  border-color: rgba(79, 142, 247, 0.15);
}

.balance-net-liq .balance-item-value {
  font-weight: 700;
}

/* ── ROI Portfolio Chart Card ── */

.roi-canvas-wrapper {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}

.summary-canvas-wrapper {
  position: relative;
  width: 100%;
  height: 140px;
  min-height: 0;
  overflow: hidden;
}

.summary-canvas-wrapper canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  transition: opacity 0.25s;
}

.roi-canvas-wrapper canvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 8px;
  transition: opacity 0.25s;
}

/* Range select inside card header */
.roi-select {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text2);
  font-family: 'Inter', sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 6px;
  cursor: pointer;
  outline: none;
  width: auto;
  transition: border-color 0.2s, color 0.2s;
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238892a4' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  background-size: 10px;
  padding-right: 20px;
}

.roi-select:hover,
.roi-select:focus {
  border-color: var(--accent);
  color: var(--text);
  box-shadow: none;
}

/* ROI Help (?) button */
.roi-help-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 1px solid var(--text2);
  background: transparent;
  color: var(--text2);
  font-size: 0.6rem;
  font-weight: 700;
  font-family: 'Inter', sans-serif;
  cursor: pointer;
  margin-left: 5px;
  line-height: 1;
  padding: 0;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
  vertical-align: middle;
  flex-shrink: 0;
}

.roi-help-btn:hover {
  border-color: var(--accent2);
  color: var(--accent2);
  background: rgba(79, 142, 247, 0.1);
}

/* Force snapshot today button styling */
#btn-force-today {
  transform: none !important;
}

#btn-force-today:hover .reload-icon {
  transform: rotate(180deg);
}

.spinning {
  animation: spin-icon 1s linear infinite;
}

@keyframes spin-icon {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

/* Custom Dropdown Trigger (Pill/Selector style) */
.roi-select-custom {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text2);
  font-family: 'Inter', sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 3px 8px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  user-select: none;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}

.roi-select-custom .caret {
  font-size: 0.55rem;
  transition: transform 0.2s ease;
  color: var(--text2);
}

.roi-select-custom.active .caret {
  transform: rotate(180deg);
}

/* ROI specific custom select hover */
#roi-dropdown-trigger:hover,
#roi-dropdown-trigger.active {
  border-color: var(--accent);
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
}
#roi-dropdown-trigger:hover .caret,
#roi-dropdown-trigger.active .caret {
  color: var(--accent);
}

/* Liquidez specific custom select hover */
#liq-dropdown-trigger:hover,
#liq-dropdown-trigger.active {
  border-color: var(--accent2);
  color: var(--text);
  background: rgba(255, 255, 255, 0.1);
}
#liq-dropdown-trigger:hover .caret,
#liq-dropdown-trigger.active .caret {
  color: var(--accent2);
}

/* Custom Dropdown Menu Container */
.chart-header-dropdown-container {
  position: relative;
  display: inline-block;
}

.chart-header-dropdown-menu {
  position: absolute;
  top: 100%;
  right: 0;
  left: auto;
  background: #121829;
  border: 1px solid var(--border);
  border-radius: 8px;
  min-width: 160px;
  max-height: 250px;
  overflow-y: auto;
  z-index: 1000;
  display: none;
  margin-top: 6px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.6);
  padding: 4px 0;
}

.chart-header-dropdown-menu.show {
  display: block;
  animation: fadeIn 0.15s ease;
}

.chart-header-dropdown-item {
  padding: 8px 12px;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--text2);
  cursor: pointer;
  transition: all 0.15s ease;
  text-align: left;
  white-space: nowrap;
}

.chart-header-dropdown-item:hover {
  background: rgba(255, 255, 255, 0.05);
  color: var(--accent);
}

.chart-header-dropdown-item.selected {
  color: #fff;
  background: rgba(0, 212, 170, 0.15);
  font-weight: 600;
  border-left: 2px solid var(--accent);
}

/* ── Mobile Responsive Layout ── */
.card.card-collapsed > *:not(.card-header) {
  display: none !important;
}

.card.card-collapsed .card-header {
  margin-bottom: 0 !important;
}

@media (max-width: 768px) {
  body {
    height: auto !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
  }

  .dashboard-wrapper {
    flex-direction: column !important;
    height: auto !important;
    overflow: visible !important;
    padding: 10px !important;
    gap: 12px !important;
  }

  .dashboard-content {
    height: auto !important;
    overflow: visible !important;
  }

  .dashboard {
    grid-template-columns: 1fr !important;
    grid-auto-rows: auto !important;
    gap: 12px !important;
  }

  .card {
    grid-column: span 1 !important;
    grid-row: span 1 !important;
    height: auto !important;
    max-height: none !important;
  }

  .card-body {
    max-height: none !important;
    overflow: visible !important;
  }

  /* Specific scroll boundaries for long lists on mobile */
  #card-txs .card-body {
    max-height: 400px !important;
    overflow-y: auto !important;
  }

  /* Prevent chart canvas from collapsing on mobile */
  .roi-canvas-wrapper {
    height: 240px !important;
  }

  .summary-canvas-wrapper {
    height: 160px !important;
  }

  #btn-open-register-modal {
    display: none !important;
  }

  #card-chat {
    width: 100% !important;
    min-width: 0 !important;
    height: auto !important;
    align-self: auto !important;
    margin-top: 8px;
  }

  #card-chat.collapsed {
    height: auto !important;
  }

  #card-chat .chat-messages {
    max-height: 300px !important;
    overflow-y: auto !important;
  }

  /* Rotate chat toggle arrow to point up/down on mobile layout */
  #btn-toggle-chat {
    transform: rotate(90deg) !important;
  }

  /* Header responsiveness & collapsible badge panel on mobile */
  header {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
    padding: 10px 15px !important;
  }

  .header-main {
    display: flex !important;
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 8px !important;
    width: 100% !important;
  }

  .header-title-row {
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    width: 100% !important;
  }

  .header-toggle-btn {
    display: inline-flex !important;
  }

  .header-badge {
    flex-direction: row !important;
    flex-wrap: wrap !important;
    justify-content: flex-start !important;
    align-items: center !important;
    gap: 6px !important;
  }

  /* Collapse badge panel by default on mobile */
  header:not(.header-expanded) .header-badge {
    display: none !important;
  }

  header.header-expanded .header-badge {
    display: flex !important;
  }

  /* Collapsible card title indicator style */
  .dashboard .card:not(#card-chat) .card-title {
    cursor: pointer;
  }

  .dashboard .card:not(#card-chat) .card-title::after {
    content: '▼';
    font-size: 0.65rem;
    color: var(--accent);
    margin-left: 8px;
    display: inline-block;
    transition: transform 0.2s ease;
  }

  .dashboard .card:not(#card-chat):not(.card-collapsed) .card-title::after {
    transform: rotate(180deg);
  }

  .dashboard .card-header {
    cursor: pointer !important;
    flex-wrap: wrap !important;
    gap: 6px !important;
  }

  .card-header > div:last-child {
    display: flex;
    align-items: center;
    gap: 6px;
  }

  /* Modal scrolling overrides for small viewports */
  .modal-overlay {
    align-items: flex-start !important;
    overflow-y: auto !important;
    padding: 20px 0 !important;
  }

  .modal-content.card {
    margin: 20px auto !important;
  }

  /* Adjust form-grid to single column on mobile */
  .form-grid {
    grid-template-columns: 1fr !important;
  }

  /* List account stat values vertically to prevent card widening on mobile */
  .stat-row {
    flex-direction: column !important;
    gap: 8px !important;
  }

  /* CRUD Responsive view */
  .crud-panel {
    flex-direction: column !important;
    height: auto !important;
    gap: 10px !important;
  }

  .crud-sidebar {
    width: 100% !important;
    flex-direction: row !important;
    overflow-x: auto !important;
    white-space: nowrap !important;
    padding: 8px !important;
    gap: 8px !important;
  }

  .crud-sidebar h3 {
    display: none !important;
  }

  .crud-tab {
    padding: 6px 12px !important;
    font-size: 0.72rem !important;
    border-left: none !important;
    border-bottom: 2px solid transparent !important;
  }

  .crud-tab.active {
    border-bottom: 2px solid var(--accent2) !important;
    background: rgba(79, 142, 247, 0.15) !important;
  }

  .crud-main {
    height: 500px !important;
  }
}

/* ── Modal Sizing Classes (Register Modal) ── */
#register-modal.size-normal .modal-content {
  max-width: 650px !important;
  width: 92% !important;
}

#register-modal.size-large .modal-content {
  max-width: 850px !important;
  width: 95% !important;
}
#register-modal.size-large input,
#register-modal.size-large select,
#register-modal.size-large button {
  font-size: 0.96rem !important;
  padding: 10px 14px !important;
}
#register-modal.size-large label {
  font-size: 0.8rem !important;
}
#register-modal.size-large .custom-select-option {
  font-size: 0.95rem !important;
  padding: 8px 12px !important;
}

#register-modal.size-xl .modal-content {
  max-width: 1100px !important;
  width: 98% !important;
}
#register-modal.size-xl input,
#register-modal.size-xl select,
#register-modal.size-xl button {
  font-size: 1.15rem !important;
  padding: 12px 18px !important;
}
#register-modal.size-xl label {
  font-size: 0.95rem !important;
}
#register-modal.size-xl .custom-select-option {
  font-size: 1.1rem !important;
  padding: 10px 14px !important;
}

/* ── Extras View Styles ── */
.extras-grid {
  display: grid;
  grid-template-columns: 1fr 2fr;
  gap: 20px;
  align-items: start;
}

@media (max-width: 768px) {
  .extras-grid {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }
  
  /* Ajustar tabla de IPs en móvil */
  #failed-logins-table-body td,
  .extras-grid th {
    padding: 8px 6px !important;
    font-size: 0.72rem !important;
  }
  
  #failed-logins-table-body td span {
    font-size: 0.65rem !important;
    padding: 1px 4px !important;
  }
}

/* ── Botón para Borrar Inputs (Clear Button) ── */
.input-with-clear {
  position: relative;
  width: 100%;
}

.clear-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  cursor: pointer;
  color: var(--text2);
  font-size: 1.15rem;
  line-height: 1;
  user-select: none;
  display: none;
  z-index: 10;
  transition: color 0.2s, transform 0.2s, opacity 0.2s;
  padding: 4px;
  opacity: 0.5;
}

.clear-btn:hover {
  color: var(--danger);
  opacity: 1;
  transform: translateY(-50%) scale(1.2);
}

.custom-select-wrapper input,
.input-with-clear input {
  padding-right: 32px !important;
}

/* Mostrar botón de limpiar solo si el input tiene texto ingresado */
.custom-select-wrapper input:not(:placeholder-shown) ~ .clear-btn,
.input-with-clear input:not(:placeholder-shown) ~ .clear-btn {
  display: inline-block;
}


