/* ==========================================================================
   ContabilityDailyApp — tema claro, profesional, tipo app.
   ========================================================================== */

:root {
  --primary: #1e3a5f;
  --primary-light: #2563eb;
  --income: #16a34a;
  --income-soft: #ecfdf3;
  --expense: #dc2626;
  --expense-soft: #fef2f2;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --muted: #64748b;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-md: 0 10px 25px -8px rgba(15, 23, 42, .18);
  --font: 'Inter', system-ui, sans-serif;
}

* { box-sizing: border-box; }
/* El atributo hidden SIEMPRE gana, sin importar que clase (.form-row,
   etc.) le haya puesto su propio display -- sin esto, cualquier elemento
   con hidden + una clase que fije display:flex/block queda visible igual
   (el estilo del autor le gana al default del navegador para [hidden],
   pase lo que pase con la especificidad). Bug real encontrado: el campo
   de precio USDT se veia siempre porque .form-row fija display:flex. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

button { font-family: inherit; cursor: pointer; }
a { color: inherit; }
input, select, textarea { font-family: inherit; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .6rem 1.1rem;
  border-radius: var(--radius-sm);
  font-weight: 600; font-size: .88rem;
  border: 1px solid transparent;
  cursor: pointer;
  transition: transform .12s ease, background .15s ease, border-color .15s ease, box-shadow .15s ease;
  white-space: nowrap;
  text-decoration: none;
}
.btn-primary { background: var(--primary-light); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-secondary { background: var(--primary); color: #fff; }
.btn-secondary:hover { background: #16304d; }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { border-color: #cbd5e1; background: #f8fafc; }
.btn-danger { background: var(--expense); color: #fff; }
.btn-danger:hover { background: #b91c1c; }
.btn-block { width: 100%; }
.btn-lg { padding: .85rem 1.3rem; font-size: .96rem; min-height: 48px; }
.btn-sm { padding: .4rem .8rem; font-size: .82rem; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .5; pointer-events: none; }

.btn-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 9px;
  border: 1px solid var(--border); background: #fff;
  font-size: 1rem;
  transition: border-color .15s ease, background .15s ease;
}
.btn-icon:hover { background: #f8fafc; border-color: #cbd5e1; }
.btn-icon-danger:hover { background: var(--expense-soft); border-color: #fecaca; }

/* ---------- auth screen ---------- */
.auth-screen {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: 1.5rem; background: linear-gradient(160deg, #1e3a5f 0%, #16304d 45%, #0f172a 100%);
}
.auth-card {
  width: 100%; max-width: 400px;
  background: #fff; border-radius: 20px; padding: 2.2rem 2rem;
  box-shadow: var(--shadow-md);
}
.auth-brand { display: flex; align-items: center; gap: .6rem; margin-bottom: .4rem; }
.auth-sub { color: var(--muted); font-size: .92rem; margin: 0 0 1.6rem; }
.auth-form { display: flex; flex-direction: column; gap: 1.1rem; }

.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 38px; height: 38px; border-radius: 10px;
  background: var(--primary); color: #fff; font-weight: 800; font-size: .92rem;
}
.brand-word { font-weight: 800; font-size: 1.15rem; color: var(--primary); }
.brand-accent { color: var(--primary-light); }

.alert { padding: .75rem 1rem; border-radius: var(--radius-sm); font-size: .86rem; margin-bottom: 1rem; }
.alert-error { background: var(--expense-soft); color: #991b1b; border: 1px solid #fecaca; }

.form-row { display: flex; flex-direction: column; gap: .4rem; margin-bottom: 1rem; }
.form-row:last-child { margin-bottom: 0; }
.form-row label { font-size: .84rem; font-weight: 600; color: #334155; }
.form-row .optional { font-weight: 400; color: var(--muted); }
.form-row input[type="text"],
.form-row input[type="password"],
.form-row input[type="date"],
.form-row input[type="datetime-local"],
.form-row input[type="file"] {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .7rem .85rem; font-size: .94rem; color: var(--text);
  background: #fff; min-height: 46px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.form-row input:focus { outline: none; border-color: var(--primary-light); box-shadow: 0 0 0 3px rgba(37, 99, 235, .12); }

/* ---------- topbar ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: .9rem 1.4rem;
  background: var(--primary);
  color: #fff;
  position: sticky; top: 0; z-index: 30;
}
.topbar-brand { display: flex; align-items: center; gap: .55rem; }
.topbar .brand-mark { background: rgba(255,255,255,.14); }
.topbar .brand-word { color: #fff; font-size: 1.02rem; }
.topbar .brand-accent { color: #7dd3fc; }
.topbar-user { display: flex; align-items: center; gap: .8rem; }
.user-name { font-size: .86rem; color: rgba(255,255,255,.85); }
.topbar .btn-ghost { border-color: rgba(255,255,255,.3); color: #fff; }
.topbar .btn-ghost:hover { background: rgba(255,255,255,.1); }
.back-link {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px; font-size: 1.1rem;
  color: #fff; background: rgba(255,255,255,.1);
}
.back-link:hover { background: rgba(255,255,255,.2); }

/* ---------- main layout ---------- */
.main { max-width: 1100px; margin: 0 auto; padding: 1.4rem 1.2rem 4rem; }

/* ---------- home: acciones + lista de cuentas ---------- */
.home-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-bottom: 2rem; }
.section-heading { font-size: 1.05rem; margin: 0 0 1rem; color: var(--text); }
.accounts-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 1rem; }
.account-card {
  display: block; background: var(--card); border-radius: var(--radius);
  padding: 1.1rem 1.2rem; box-shadow: var(--shadow); text-decoration: none; color: var(--text);
  transition: transform .12s ease, box-shadow .12s ease;
}
.account-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.account-card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: .3rem; }
.account-card-name { font-weight: 700; font-size: 1.02rem; }
.account-card-count { font-size: .74rem; color: var(--muted); }
.account-card-concept { font-size: .82rem; color: var(--muted); margin: 0 0 .7rem; }
.account-card-balances { display: flex; flex-direction: column; gap: .25rem; font-weight: 700; font-size: .92rem; padding-top: .6rem; border-top: 1px dashed var(--border); }
.account-concept-banner { color: var(--muted); font-size: .9rem; margin: -.6rem 0 1.2rem; }
.usdt-price-hint { display: block; font-size: .72rem; font-weight: 400; color: var(--muted); }

/* ---------- summary cards ---------- */
.summary-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1rem; margin-bottom: 1.4rem; }
.summary-card { background: var(--card); border-radius: var(--radius); padding: 1.2rem 1.3rem; box-shadow: var(--shadow); }
.summary-card-head { display: flex; align-items: center; gap: .6rem; margin-bottom: .9rem; }
.currency-badge { font-size: .72rem; font-weight: 800; padding: .25rem .55rem; border-radius: 6px; letter-spacing: .03em; }
.currency-cop { background: #dbeafe; color: #1d4ed8; }
.currency-usdt { background: #dcfce7; color: #15803d; }
.summary-label { font-size: .82rem; color: var(--muted); }
.summary-rows { display: flex; flex-direction: column; gap: .5rem; margin-bottom: .9rem; }
.summary-row { display: flex; justify-content: space-between; font-size: .9rem; color: #334155; }
.text-income { color: var(--income); }
.text-expense { color: var(--expense); }
.summary-balance {
  display: flex; justify-content: space-between; align-items: center;
  padding-top: .8rem; border-top: 1px dashed var(--border);
  font-size: 1.05rem; font-weight: 800;
}
.summary-balance.is-positive strong { color: var(--income); }
.summary-balance.is-negative strong { color: var(--expense); }

/* ---------- quick actions ---------- */
.pdf-current-bar { margin-bottom: 1rem; }
.pdf-current-bar .btn { min-height: 48px; }

.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; margin-bottom: 1.4rem; }
.btn-action {
  display: flex; align-items: center; justify-content: center; gap: .6rem;
  border: none; border-radius: var(--radius);
  padding: 1.1rem; font-size: 1.05rem; font-weight: 800; color: #fff;
  box-shadow: var(--shadow-md);
  transition: transform .12s ease, filter .12s ease;
  text-decoration: none;
}
.btn-action:active { transform: scale(.98); }
.btn-action-income { background: linear-gradient(135deg, #16a34a, #15803d); }
.btn-action-income:hover { filter: brightness(1.06); }
.btn-action-expense { background: linear-gradient(135deg, #dc2626, #b91c1c); }
.btn-action-expense:hover { filter: brightness(1.06); }
.btn-action-primary { background: linear-gradient(135deg, var(--primary-light), #1d4ed8); }
.btn-action-secondary { background: var(--card); color: var(--text); box-shadow: var(--shadow); border: 1px solid var(--border); }
.btn-action-secondary .btn-action-icon { background: var(--bg); }
.btn-action-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%; background: rgba(255,255,255,.22);
  font-size: 1.2rem; line-height: 1;
}

/* ---------- filter bar ---------- */
.filter-bar { background: var(--card); border-radius: var(--radius); padding: 1rem 1.2rem; box-shadow: var(--shadow); margin-bottom: 1.4rem; }
.filter-form { display: flex; flex-wrap: wrap; align-items: flex-end; gap: .8rem; }
.filter-field { display: flex; flex-direction: column; gap: .3rem; }
.filter-field label { font-size: .78rem; font-weight: 600; color: var(--muted); }
.filter-field input, .filter-field select {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: .55rem .7rem; font-size: .88rem; min-height: 40px;
  background: #fff; color: var(--text);
}
.btn-pdf { margin-left: auto; }
.btn-pdf-current { white-space: nowrap; }
.filter-hint { font-size: .78rem; color: var(--muted); margin: .6rem 0 0; flex-basis: 100%; }

/* ---------- table ---------- */
.table-section { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; }
.table-wrap { overflow-x: auto; }
.movements-table { width: 100%; border-collapse: collapse; min-width: 720px; }
.movements-table thead th {
  background: #f8fafc; text-align: left; font-size: .74rem; text-transform: uppercase;
  letter-spacing: .04em; color: var(--muted); padding: .8rem 1rem; border-bottom: 1px solid var(--border);
}
.movements-table tbody td { padding: .8rem 1rem; border-bottom: 1px solid #f1f5f9; font-size: .88rem; }
.movements-table tbody tr:hover { background: #f8fafc; }
.col-amount { text-align: right; font-weight: 700; white-space: nowrap; }
.col-actions { white-space: nowrap; display: flex; gap: .4rem; }
.type-badge { padding: .22rem .55rem; border-radius: 999px; font-size: .74rem; font-weight: 700; }
.type-ingreso { background: var(--income-soft); color: var(--income); }
.type-egreso { background: var(--expense-soft); color: var(--expense); }
.muted { color: #cbd5e1; }
.empty-state { text-align: center; padding: 2.4rem 1rem; color: var(--muted); }

.pagination { display: flex; gap: .4rem; justify-content: center; padding: 1rem; border-top: 1px solid var(--border); }
.page-link {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; border-radius: 8px; font-size: .84rem; font-weight: 600;
  color: var(--text); text-decoration: none; border: 1px solid var(--border);
}
.page-link.is-active { background: var(--primary-light); border-color: var(--primary-light); color: #fff; }

/* ---------- modals ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, .5);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: #fff; width: 100%; max-width: 460px;
  border-radius: 20px 20px 0 0;
  padding: 1.4rem 1.4rem 1.8rem;
  max-height: 92vh; overflow-y: auto;
  box-shadow: 0 -10px 40px rgba(0,0,0,.2);
  animation: slide-up .25s ease;
}
@keyframes slide-up { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 1rem; }
.modal-head h2 { font-size: 1.1rem; margin: 0; }
.modal-close { background: none; border: none; font-size: 1.5rem; line-height: 1; color: var(--muted); padding: .2rem .4rem; }
.modal-form { display: flex; flex-direction: column; }
.modal-image img { width: 100%; border-radius: 12px; display: block; }
.modal-confirm p { color: var(--muted); margin: 0 0 1.2rem; }
.modal-actions { display: flex; gap: .7rem; justify-content: flex-end; }

@media (min-width: 640px) {
  .modal-overlay { align-items: center; }
  .modal { border-radius: 20px; }
}

/* ---------- currency switch ---------- */
.currency-switch { display: flex; gap: .5rem; }
.currency-option {
  flex: 1; padding: .65rem; border-radius: var(--radius-sm);
  border: 1.5px solid var(--border); background: #fff; font-weight: 700; font-size: .88rem; color: var(--muted);
  transition: border-color .15s ease, background .15s ease, color .15s ease;
}
.currency-option.is-active { border-color: var(--primary-light); background: #eff6ff; color: var(--primary-light); }

.receipt-current { font-size: .78rem; color: var(--muted); margin-top: .4rem; }

.telegram-code {
  text-align: center; font-size: 1.6rem; font-weight: 800; letter-spacing: .12em;
  background: #eff6ff; color: var(--primary-light);
  border: 1.5px dashed var(--primary-light); border-radius: var(--radius-sm);
  padding: .9rem; margin: .8rem 0;
}

.btn-spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.4); border-top-color: #fff;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.form-feedback { font-size: .84rem; margin: .7rem 0 0; min-height: 1.1em; }
.form-feedback.ok { color: var(--income); }
.form-feedback.err { color: var(--expense); }

/* ---------- responsive ---------- */
@media (max-width: 720px) {
  .btn-pdf, .btn-pdf-current { margin-left: 0; width: 100%; }
  .filter-form { flex-direction: column; align-items: stretch; }
  .quick-actions { grid-template-columns: 1fr; }
  .home-actions { grid-template-columns: 1fr; }

  .topbar { flex-wrap: wrap; row-gap: .6rem; }
  .topbar-user { flex-wrap: wrap; gap: .5rem; }
  .topbar-user .user-name { display: none; }
  [data-action="open-telegram"] { font-size: .74rem; padding: .35rem .6rem; }

  /* Tabla -> tarjetas apiladas, sin scroll horizontal (se ve completa). */
  .table-wrap { overflow-x: visible; }
  .movements-table { min-width: 0; display: block; }
  .movements-table thead { display: none; }
  .movements-table tbody { display: block; }
  .movements-table tr {
    display: block;
    border: 1px solid var(--border); border-radius: 12px;
    margin: .8rem; padding: .3rem .9rem;
  }
  .movements-table tbody tr:hover { background: transparent; }
  .movements-table td {
    display: flex; align-items: center; justify-content: space-between; gap: 1rem;
    padding: .6rem 0; border-bottom: 1px solid #f1f5f9;
    text-align: right;
  }
  .movements-table td:last-child { border-bottom: none; }
  .movements-table td::before {
    content: attr(data-label);
    font-size: .74rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
    color: var(--muted); text-align: left; flex: none;
  }
  .movements-table td.col-amount { text-align: right; }
  .movements-table td.col-actions { justify-content: flex-end; }
  .movements-table td.col-actions::before { content: none; }
  .empty-state { padding: 2rem 1rem; }
}
