/* PokerLog — mesa de poker: tapete verde oscuro, baranda de cuero y oro. Mobile-first.
   Sin estilos en línea (CSP). Lo único llamativo es la mesa del bankroll; el resto, tranquilo. */

:root {
  /* Color */
  --felt-950: #050f0b;   /* fondo, la sala */
  --felt-900: #08170f;
  --felt-850: #0b1f16;
  --panel: #0b2117; /* opaco: la columna fija de las tablas usa el mismo color */
  --tile: rgba(5, 15, 11, 0.55);
  --table-felt: #17583c;
  --table-felt-deep: #0d3a27;
  --leather: #2b1c12;
  --gold: #d6b25e;
  --gold-bright: #f0d48a;
  --gold-deep: #9c7a2e;
  --ink: #edf2ec;
  --ink-2: #a8bbb0;
  --ink-3: #708a7c;
  --pos: #5fe3a1;
  --neg: #ff7a6e;
  --line: rgba(214, 178, 94, 0.15);
  --line-strong: rgba(214, 178, 94, 0.36);
  --line-soft: rgba(214, 178, 94, 0.08);

  /* Tipografía: serif del sistema (New York en iOS) para cifras y títulos, SF para la interfaz */
  --font-ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-display: ui-serif, "New York", "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --step--2: 0.75rem;    /* 12 */
  --step--1: 0.8125rem;  /* 13 */
  --step-0: 1rem;        /* 16 */
  --step-1: 1.25rem;     /* 20 */
  --step-2: 1.5625rem;   /* 25 */
  --step-4: 2.75rem;     /* 44 */

  /* Medidas */
  --tap: 48px;
  --tabbar-h: 64px;
  --r-panel: 20px;
  --r-tile: 14px;
  --r-control: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--felt-950);
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  font: var(--step-0)/1.45 var(--font-ui);
  color: var(--ink);
  background: var(--felt-950);
  font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}

/* La sala: luz cenital sobre la mesa y un grano de tapete muy suave */
body::before {
  content: "";
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(120% 60% at 50% -10%, rgba(46, 120, 84, 0.42), transparent 62%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 0 0 0 .04 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E"),
    linear-gradient(180deg, #0a2017 0%, #071510 50%, var(--felt-950) 100%);
}

h1, h2, p { margin: 0; }
img, svg { display: block; }
strong { font-weight: 650; color: var(--ink); }
:focus-visible { outline: 2px solid var(--gold-bright); outline-offset: 2px; }

.brand {
  font-family: var(--font-display);
  font-size: var(--step-1);
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--gold-bright);
}
.brand-large { font-size: 2.25rem; }

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* ---------- Login ---------- */
.login {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: calc(var(--safe-top) + 24px) 16px calc(var(--safe-bottom) + 24px);
}
.login-card {
  width: min(100%, 380px);
  display: grid;
  gap: 16px;
  padding: 32px 22px 22px;
  border-radius: 24px;
  border: 1px solid var(--line-strong);
  background: var(--panel);
  text-align: center;
}
.login-logo {
  justify-self: center;
  filter: drop-shadow(0 14px 24px rgba(0, 0, 0, 0.6));
  animation: chip-in 0.8s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}
.login-sub {
  margin-top: -10px;
  color: var(--ink-2);
  font-family: var(--font-display);
  font-style: italic;
  line-height: 1.55;
}
.login .field { text-align: left; }
.form-error { color: var(--neg); font-size: 0.9rem; }

/* La ficha cae girando sobre el tapete: el único movimiento que no pide el usuario */
@keyframes chip-in {
  from { opacity: 0; transform: translateY(-18px) rotate(-200deg) scale(0.8); }
  to { opacity: 1; transform: none; }
}

/* ---------- Barra superior ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 8px) 16px 8px;
  background: rgba(5, 15, 11, 0.9);
  border-bottom: 1px solid var(--line);
  -webkit-backdrop-filter: blur(14px) saturate(140%);
  backdrop-filter: blur(14px) saturate(140%);
}
.topbar-brand { display: flex; align-items: center; gap: 10px; }

/* ---------- Contenido ---------- */
.content {
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 16px calc(var(--tabbar-h) + var(--safe-bottom) + 32px);
}
/* minmax(0, 1fr): sin esto las tablas (nowrap) ensanchan la columna y la página se sale de la pantalla */
.tab { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }

.card {
  padding: 16px;
  border-radius: var(--r-panel);
  border: 1px solid var(--line);
  background: var(--panel);
}
.card-head {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 4px 12px;
  margin-bottom: 12px;
}
.card-head h2, .list-head h2 {
  font-family: var(--font-display);
  font-size: var(--step-1);
  font-weight: 600;
  line-height: 1.2;
}
.card-sub { color: var(--ink-3); font-size: var(--step--1); }

/* ---------- La mesa: el bankroll es el bote ---------- */
.felt {
  position: relative;
  display: grid;
  justify-items: center;
  align-content: center;
  gap: 2px;
  min-height: 196px;
  margin: 4px 0 2px;
  padding: 30px 36px;
  text-align: center;
  border: 11px solid transparent;
  border-radius: 50%;
  background:
    radial-gradient(ellipse at 50% 30%, #2a7d57 0%, var(--table-felt) 42%, var(--table-felt-deep) 100%) padding-box,
    linear-gradient(180deg, #4a3220 0%, var(--leather) 45%, #170e08 100%) border-box;
  box-shadow:
    0 0 0 1px rgba(240, 212, 138, 0.28),
    inset 0 0 0 1px rgba(240, 212, 138, 0.5),
    inset 0 12px 34px rgba(0, 0, 0, 0.45),
    0 22px 40px -22px rgba(0, 0, 0, 0.95);
}
.felt::before {
  /* línea de apuestas */
  content: "";
  position: absolute;
  inset: 12px 18px;
  border-radius: 50%;
  border: 1px solid rgba(240, 212, 138, 0.24);
  pointer-events: none;
}
.pot-label { color: var(--gold-bright); font-size: var(--step--1); font-weight: 600; letter-spacing: 0.02em; }
.pot-value {
  font-family: var(--font-display);
  font-size: clamp(2.25rem, 11vw, var(--step-4));
  font-weight: 600;
  line-height: 1.1;
  letter-spacing: -0.01em;
  font-variant-numeric: lining-nums tabular-nums;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.35);
}
.pot-note { max-width: 24ch; color: rgba(237, 242, 236, 0.72); font-size: var(--step--2); line-height: 1.4; }
.period-note { color: var(--ink-3); font-size: var(--step--1); text-align: center; }

/* ---------- Cifras del periodo ---------- */
.stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.stat {
  padding: 12px 14px;
  border-radius: var(--r-tile);
  border: 1px solid var(--line-soft);
  background: var(--tile);
}
.stat-wide { grid-column: 1 / -1; }
.stat-label { color: var(--ink-2); font-size: var(--step--1); }
.stat-hint { margin-left: 4px; color: var(--ink-3); font-size: var(--step--2); }
.stat-value {
  margin-top: 2px;
  font-size: var(--step-1);
  font-weight: 650;
  letter-spacing: -0.01em;
  overflow-wrap: anywhere;
}

.pos { color: var(--pos); }
.neg { color: var(--neg); }
.zero { color: var(--ink); }

/* ---------- Selector segmentado (periodo y tipo de movimiento) ---------- */
.segmented {
  display: grid;
  grid-auto-columns: 1fr;
  grid-auto-flow: column;
  gap: 4px;
  padding: 4px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(5, 15, 11, 0.8);
}
.segment {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 8px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--ink-2);
  font: 600 0.875rem/1.1 var(--font-ui);
  text-align: center;
  cursor: pointer;
  transition: background-color 0.18s, color 0.18s;
}
label.segment { padding: 0; }
.segment input { position: absolute; opacity: 0; pointer-events: none; }
.segment span {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 44px;
  border-radius: 999px;
}
.segment[aria-pressed="true"],
.segment input:checked + span {
  color: #1d1505;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold));
}
.segment input:focus-visible + span { outline: 2px solid var(--gold-bright); outline-offset: 2px; }
.period-picker {
  position: sticky;
  top: calc(var(--safe-top) + 58px);
  z-index: 5;
  box-shadow: 0 8px 18px -10px rgba(0, 0, 0, 0.9);
}

/* ---------- Formularios ---------- */
.form { display: grid; gap: 12px; }
.grid-2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); align-items: start; gap: 10px; }
.field { display: grid; gap: 6px; min-width: 0; margin: 0; padding: 0; border: 0; }
.field-label { padding: 0; color: var(--ink-2); font-size: var(--step--1); font-weight: 600; }
.opt { color: var(--ink-3); font-weight: 400; }

input, select, textarea {
  width: 100%;
  min-height: var(--tap);
  padding: 12px 14px;
  border: 1px solid rgba(168, 187, 176, 0.18);
  border-radius: var(--r-control);
  background: rgba(3, 10, 7, 0.6);
  color: var(--ink);
  font: 16px/1.3 var(--font-ui); /* 16px: iOS no hace zoom al enfocar */
  -webkit-appearance: none;
  appearance: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input[type="date"] { display: block; min-width: 0; }
input::-webkit-date-and-time-value { text-align: left; }
textarea { min-height: 76px; resize: vertical; line-height: 1.45; }
select {
  padding-right: 38px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%23d6b25e' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}
input::placeholder, textarea::placeholder { color: var(--ink-3); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(214, 178, 94, 0.22);
}
[aria-invalid="true"] { border-color: var(--neg) !important; }
.field-error { color: var(--neg); font-size: var(--step--1); }

.mode-tools { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: -4px; }
.mode-add {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: end;
  gap: 10px;
  padding: 12px;
  border-radius: var(--r-tile);
  border: 1px dashed var(--line-strong);
}
.result-preview { font-weight: 650; }
.result-preview:empty { display: none; }
.form-actions { display: flex; gap: 10px; margin-top: 4px; }
.form-actions .btn-primary { flex: 1; }

/* ---------- Botones ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: var(--tap);
  padding: 0 18px;
  border: 1px solid transparent;
  border-radius: var(--r-control);
  font: 650 1rem/1 var(--font-ui);
  text-decoration: none;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  transition: transform 0.08s, background-color 0.15s, border-color 0.15s, opacity 0.15s;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.55; cursor: progress; }
.btn-primary {
  color: #1d1505;
  background: linear-gradient(180deg, var(--gold-bright), var(--gold) 60%, var(--gold-deep));
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.35);
}
.btn-secondary { color: var(--gold-bright); background: rgba(214, 178, 94, 0.08); border-color: var(--line-strong); }
.btn-ghost { color: var(--ink-2); background: transparent; border-color: rgba(168, 187, 176, 0.2); }
.btn-danger { color: #fff; background: #c9443a; }
.btn-danger-text { color: var(--neg); }
.btn-small { min-height: 44px; padding: 0 14px; font-size: 0.9rem; border-radius: 10px; }
.btn-block { width: 100%; }
.export-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* ---------- Listados (libro de cuentas: la fecha manda a la izquierda) ---------- */
.list-head { display: flex; align-items: baseline; justify-content: space-between; margin: 10px 2px 0; }
.count { color: var(--ink-3); font-size: var(--step--1); }
.list { display: grid; gap: 8px; margin: 0; padding: 0; list-style: none; }
.item {
  display: grid;
  grid-template-areas:
    "stub main amount"
    "stub actions actions";
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 8px 12px;
  padding: 12px 14px 12px 10px;
  border-radius: var(--r-tile);
  border: 1px solid var(--line);
  background: var(--panel);
}
.stub {
  grid-area: stub;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 2px 10px 0 0;
  border-right: 1px solid var(--line-soft);
}
.stub-day { font-family: var(--font-display); font-size: var(--step-2); font-weight: 600; line-height: 1; }
.stub-month { margin-top: 3px; color: var(--ink-2); font-size: var(--step--1); line-height: 1.1; }
.stub-year { color: var(--ink-3); font-size: var(--step--2); }
.item-main { grid-area: main; min-width: 0; }
.item-title { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 8px; }
.item-stake { font-weight: 600; overflow-wrap: anywhere; }
.item-meta { margin-top: 6px; color: var(--ink-2); font-size: 0.875rem; }
.item-flow { display: flex; flex-wrap: wrap; gap: 2px 14px; margin-top: 2px; color: var(--ink-3); font-size: 0.875rem; }
.item-notes {
  margin-top: 8px;
  padding-left: 8px;
  border-left: 2px solid var(--line-strong);
  color: var(--ink-2);
  font-size: 0.875rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.item-amount { grid-area: amount; font-size: 1.125rem; font-weight: 700; white-space: nowrap; }
.item-actions {
  grid-area: actions;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--line-soft);
}
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: rgba(214, 178, 94, 0.1);
  color: var(--gold-bright);
  font-size: var(--step--1);
  font-weight: 650;
}
.badge-withdrawal { color: var(--ink); border-color: rgba(168, 187, 176, 0.3); background: rgba(168, 187, 176, 0.08); }
.kind-deposit { color: var(--gold-bright); }
.kind-withdrawal { color: var(--ink); }
.empty {
  padding: 18px;
  border: 1px dashed var(--line);
  border-radius: var(--r-tile);
  color: var(--ink-2);
  font-size: 0.9rem;
  text-align: center;
}

/* ---------- Tablas ---------- */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.875rem;
  white-space: nowrap;
}
.table th, .table td { padding: 10px; text-align: right; border-bottom: 1px solid var(--line-soft); }
.table thead th { color: var(--ink-3); font-size: var(--step--2); font-weight: 600; }
.table th:first-child, .table td:first-child {
  position: sticky;
  left: 0;
  z-index: 1;
  padding-left: 0;
  text-align: left;
  background: var(--panel);
}
.table tbody th { min-width: 112px; max-width: 160px; white-space: normal; font-weight: 600; }
.table tbody tr:last-child > * { border-bottom: 0; }

/* ---------- Gráfica ---------- */
.chart { position: relative; min-height: 160px; touch-action: pan-y; }
.chart svg { width: 100%; height: auto; overflow: visible; }
.chart-grid { stroke: rgba(168, 187, 176, 0.1); stroke-width: 1; }
.chart-zero { stroke: rgba(240, 212, 138, 0.6); stroke-width: 1; stroke-dasharray: 4 4; }
.chart-axis { fill: var(--ink-3); font: 11px var(--font-ui); font-variant-numeric: tabular-nums; }
.chart-line-pos, .chart-line-neg { fill: none; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }
.chart-line-pos { stroke: var(--pos); }
.chart-line-neg { stroke: var(--neg); }
.chart-area-pos { fill: var(--pos); fill-opacity: 0.12; }
.chart-area-neg { fill: var(--neg); fill-opacity: 0.12; }
.chart-dot { fill: var(--felt-900); stroke: var(--gold); stroke-width: 1.5; }
.chart-guide { stroke: var(--gold-bright); stroke-width: 1; stroke-dasharray: 2 3; }
.chart-focus { fill: var(--gold-bright); stroke: var(--felt-950); stroke-width: 2; }
.chart-hit { fill: transparent; cursor: crosshair; }
.chart-empty { display: grid; place-items: center; min-height: 140px; color: var(--ink-2); font-size: 0.9rem; text-align: center; }

/* ---------- Barra de pestañas ---------- */
.tabbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 6px max(8px, env(safe-area-inset-right)) calc(6px + var(--safe-bottom)) max(8px, env(safe-area-inset-left));
  border-top: 1px solid var(--line);
  background: rgba(5, 15, 11, 0.94);
  -webkit-backdrop-filter: blur(16px);
  backdrop-filter: blur(16px);
}
.tabbar-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  min-height: 52px;
  border-radius: 12px;
  color: var(--ink-3);
  font-size: var(--step--2);
  font-weight: 650;
  text-decoration: none;
  transition: color 0.18s;
}
.tabbar-item svg { width: 24px; height: 24px; }
.tabbar-item.active { color: var(--gold-bright); }

/* ---------- Avisos y diálogo ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--tabbar-h) + var(--safe-bottom) + 16px);
  z-index: 30;
  width: max-content;
  max-width: min(92vw, 480px);
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--line-strong);
  background: #10291e;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 600;
  box-shadow: 0 14px 30px -10px rgba(0, 0, 0, 0.85);
  transform: translateX(-50%);
  animation: toast-in 0.2s ease both;
}
.toast-error { border-color: rgba(255, 122, 110, 0.55); background: #3a1513; color: #ffd9d4; }
.toast-ok { border-color: rgba(95, 227, 161, 0.45); }
@keyframes toast-in {
  from { opacity: 0; transform: translate(-50%, 8px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

.dialog {
  width: min(92vw, 380px);
  padding: 20px;
  border-radius: 18px;
  border: 1px solid var(--line-strong);
  background: var(--felt-850);
  color: var(--ink);
}
.dialog::backdrop { background: rgba(0, 0, 0, 0.62); }
.dialog-message { margin-bottom: 18px; line-height: 1.5; }
.dialog-actions { display: flex; gap: 10px; }
.dialog-actions .btn { flex: 1; }

/* ---------- Pantallas anchas ---------- */
@media (min-width: 700px) {
  .felt { min-height: 230px; }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .stat-wide { grid-column: span 2; }
  .tabbar {
    left: 50%;
    right: auto;
    bottom: 14px;
    width: min(640px, calc(100% - 32px));
    padding: 6px;
    border: 1px solid var(--line);
    border-radius: 20px;
    transform: translateX(-50%);
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
