/* ── components.css — buttons, forms, tables, modals, cards, badges ── */

/* ── Card ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  transition: background 0.2s, border 0.2s;
}

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border2);
  background: var(--surface);
  color: var(--text);
  transition: all 0.15s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface2); }
.btn:active { transform: scale(0.98); }

.btn.primary { background: var(--blue); color: #fff; border-color: var(--blue); }
.btn.primary:hover { background: #0c447c; border-color: #0c447c; }

.btn.danger { background: var(--red-bg); color: var(--red-text); border-color: transparent; }
.btn.danger:hover { opacity: 0.85; }

.btn.success { background: var(--green-bg); color: var(--green-text); border-color: transparent; }

.btn.sm { padding: 6px 12px; font-size: 12px; }
.btn.icon-only { padding: 7px; }

/* ── Forms ── */
.form-row { display: grid; gap: 12px; margin-bottom: 16px; }
.form-row.cols-2 { grid-template-columns: 1fr 1fr; }
.form-row.cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.form-row.cols-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

.form-group { display: flex; flex-direction: column; gap: 5px; }

.form-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text2);
}

.form-input {
  padding: 9px 12px;
  border: 1px solid var(--border2);
  border-radius: var(--radius-sm);
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border 0.15s, box-shadow 0.15s;
  font-family: inherit;
}
.form-input:focus {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(24,95,165,0.12);
}
select.form-input { cursor: pointer; }

/* ── Filter bar ── */
.filter-bar {
  display: flex;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
  align-items: center;
}
.filter-bar .form-input { min-width: 140px; padding: 7px 12px; font-size: 13px; }
.search-input { flex: 1; min-width: 180px; }

/* ── Tabs ── */
.tabs {
  display: flex;
  gap: 2px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  padding: 3px;
  width: fit-content;
  margin-bottom: 20px;
}

.tab-btn {
  padding: 7px 16px;
  border-radius: var(--radius-xs);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text2);
  border: none;
  background: none;
  transition: all 0.15s;
}
.tab-btn.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
}

/* ── Tables ── */
.table-wrap { overflow-x: auto; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }

thead th {
  text-align: left;
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  background: var(--surface2);
}

tbody tr { border-bottom: 1px solid var(--border); transition: background 0.1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--surface2); }
tbody td { padding: 12px 14px; color: var(--text); vertical-align: middle; }

.amount-pos { color: var(--green); font-weight: 500; }
.amount-neg { color: var(--red); font-weight: 500; }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 500;
}

.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 500;
}

/* ── Modal ── */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  border: 1px solid var(--border);
}

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

.modal-title { font-size: 17px; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: var(--text2);
  padding: 4px;
  border-radius: var(--radius-xs);
}
.modal-close:hover { background: var(--surface2); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 20px;
}

/* ── Recurring cards ── */
.recurring-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 14px;
}

.recurring-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.rc-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.rc-name { font-weight: 600; font-size: 15px; }
.rc-cat { font-size: 11px; color: var(--text3); margin-top: 2px; }
.rc-amount { font-size: 18px; font-weight: 600; color: var(--red); }
.rc-bottom { display: flex; align-items: center; justify-content: space-between; }
.rc-due { font-size: 12px; color: var(--text3); }
.rc-toggle { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text2); }

/* ── Toggle switch ── */
.toggle-switch {
  width: 32px; height: 18px;
  background: var(--surface3);
  border-radius: 99px;
  position: relative;
  transition: background 0.2s;
  cursor: pointer;
  border: none;
  flex-shrink: 0;
}
.toggle-switch.on { background: var(--green); }
.toggle-switch::after {
  content: '';
  position: absolute;
  top: 2px; left: 2px;
  width: 14px; height: 14px;
  background: white;
  border-radius: 50%;
  transition: left 0.2s;
}
.toggle-switch.on::after { left: 16px; }

/* ── Category management ── */
.cat-list { display: flex; flex-direction: column; gap: 8px; }

.cat-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
}
.cat-item-icon { font-size: 18px; width: 28px; text-align: center; }
.cat-item-name { flex: 1; font-size: 14px; font-weight: 500; }
.cat-item-color { width: 14px; height: 14px; border-radius: 50%; flex-shrink: 0; }
.cat-item-actions { display: flex; gap: 6px; }

/* ── Color picker ── */
.color-options { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 4px; }
.color-opt {
  width: 28px; height: 28px;
  border-radius: 50%;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.15s;
}
.color-opt.selected,
.color-opt:hover { border-color: var(--text); transform: scale(1.1); }

/* ── Auth / Login screen ── */
.auth-screen {
  display: none;
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 9999;
  align-items: center;
  justify-content: center;
  flex-direction: column;
}

.auth-screen.visible { display: flex; }

.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px 36px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 8px 40px rgba(0,0,0,0.12);
  text-align: center;
}

.auth-logo {
  font-size: 40px;
  margin-bottom: 12px;
}

.auth-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.4px;
  color: var(--text);
  margin-bottom: 6px;
}

.auth-sub {
  font-size: 14px;
  color: var(--text2);
  margin-bottom: 32px;
  line-height: 1.5;
}

.auth-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  width: 100%;
  padding: 13px 20px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border2);
  background: var(--surface);
  color: var(--text);
  transition: all 0.15s;
}

.auth-btn:hover {
  background: var(--surface2);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
}

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

.auth-btn-icon {
  width: 22px;
  height: 22px;
}

.auth-error {
  margin-top: 16px;
  padding: 10px 14px;
  background: var(--red-bg);
  color: var(--red-text);
  border-radius: var(--radius-sm);
  font-size: 13px;
  display: none;
}

.auth-error.visible { display: block; }

.auth-footer {
  margin-top: 24px;
  font-size: 12px;
  color: var(--text3);
  line-height: 1.6;
}

/* ── User avatar in sidebar ── */
.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 8px;
}

.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  object-fit: cover;
  flex-shrink: 0;
}

.user-avatar-placeholder {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--blue-bg);
  color: var(--blue);
  font-size: 13px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.signout-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--red-text);
  background: var(--red-bg);
  border: none;
  width: 100%;
  transition: all 0.15s;
}

.signout-btn:hover { opacity: 0.85; }

@media (max-width: 640px) {
  .auth-card {
    margin: 16px;
    padding: 32px 24px;
  }
}

/* ── Transaction cards (mobile list view) ── */
.tx-card-list { display: flex; flex-direction: column; gap: 10px; }

.tx-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  background: var(--surface2);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

.tx-card-left { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }

.tx-card-icon {
  width: 38px; height: 38px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  flex-shrink: 0;
}

.tx-card-info { flex: 1; min-width: 0; }
.tx-card-name { font-size: 14px; font-weight: 500; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tx-card-meta { display: flex; align-items: center; gap: 6px; margin-top: 3px; flex-wrap: wrap; }
.tx-card-date { font-size: 11px; color: var(--text3); }
.tx-card-notes { font-size: 11px; color: var(--text3); margin-top: 2px; }

.tx-card-right { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; flex-shrink: 0; }
.tx-card-amount { font-size: 15px; font-weight: 600; }
.tx-card-actions { display: flex; gap: 5px; }

/* ── Form responsive ── */
@media (max-width: 640px) {
  .form-row.cols-2,
  .form-row.cols-3,
  .form-row.cols-4 { grid-template-columns: 1fr; }

  /* Fix metric grid overflow — always 2 col max, no overflow */
  .metric-grid {
    grid-template-columns: 1fr 1fr !important;
    overflow: hidden;
  }

  /* Modal slides up from bottom */
  .modal-overlay { align-items: flex-end; }
  .modal {
    border-radius: var(--radius) var(--radius) 0 0;
    max-width: 100%;
    max-height: 90vh;
    overflow-y: auto;
  }

  /* Tabs full width */
  .tabs { width: 100%; }
  .tab-btn { flex: 1; text-align: center; }

  /* Recurring card actions */
  .rc-top { flex-wrap: wrap; }

  /* Cat list */
  .cat-item { flex-wrap: wrap; }

  /* Prevent any horizontal overflow */
  .card, .chart-card, .metric-card { overflow: hidden; }
}
