:root {
  --bg:        #0e1117;
  --panel:     #151a23;
  --panel-2:   #1c222d;
  --border:    #262d3a;
  --text:      #e6e9ef;
  --muted:     #8b95a7;
  --accent:    #4c8dff;
  --up:        #26a69a;
  --down:      #ef5350;
  --warn:      #e9a33a;
  --radius:    8px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

button, input, select { font: inherit; color: inherit; }

button {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 12px; cursor: pointer;
  transition: background .12s, border-color .12s;
}
button:hover:not(:disabled) { background: #232b38; border-color: #38425480; }
button:disabled { opacity: .45; cursor: not-allowed; }
button.active { background: var(--accent); border-color: var(--accent); color: #fff; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.long  { background: var(--up);   border-color: var(--up);   color: #fff; }
button.short { background: var(--down); border-color: var(--down); color: #fff; }
button.ghost { background: transparent; }

input[type="number"], input[type="text"], input[type="password"] {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 10px; width: 100%;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.up { color: var(--up); } .down { color: var(--down); }

/* ---------- acceso ---------- */

.login-body { overflow: hidden; }

/* Velas japonesas del fondo, dibujadas en canvas por index.html. */
.backdrop { position: fixed; inset: 0; z-index: 0; pointer-events: none; }

/* Velo en dos capas: oscurece el centro y los bordes para que las velas se
   vean con claridad pero el texto de la tarjeta siga legible. */
.backdrop-veil {
  position: fixed; inset: 0; z-index: 1; pointer-events: none;
  background:
    radial-gradient(40% 48% at 50% 50%, #0e1117f7 0%, #0e1117bf 58%, #0e111700 100%),
    linear-gradient(180deg, #0e1117cc 0%, #0e111761 24%, #0e111761 76%, #0e1117cc 100%);
}

.login-wrap {
  position: relative; z-index: 2;
  min-height: 100%; display: grid; place-items: center; padding: 24px;
}

.login-card {
  position: relative; overflow: hidden;
  width: 100%; max-width: 372px; padding: 28px;
  background: #141922f7;
  border: 1px solid #2b3342;
  border-radius: 14px;
  box-shadow: 0 28px 64px -26px #000, 0 0 0 1px #ffffff08 inset;
  backdrop-filter: blur(14px) saturate(115%);
  animation: rise .38s cubic-bezier(.2, .8, .3, 1) both;
}
@keyframes rise { from { opacity: 0; transform: translateY(10px) scale(.99); } }

/* Reflejo tenue en el borde superior. Antes habia un degradado de cuatro
   colores aqui y cantaba demasiado para lo que es: una linea de 1 px. */
.card-accent {
  position: absolute; top: 0; left: 22px; right: 22px; height: 1px;
  background: linear-gradient(90deg, #ffffff00, #ffffff40, #ffffff00);
}

.brand-row {
  display: flex; align-items: center; gap: 12px;
  padding-bottom: 20px; margin-bottom: 20px;
  border-bottom: 1px solid #222a37;
}
.brand-row h1 { margin: 0; font-size: 17px; font-weight: 600; letter-spacing: -.1px; }
.brand-row .sub { margin: 3px 0 0; color: var(--muted); font-size: 12.5px; }

.login-card .mark {
  flex: none; width: 40px; height: 40px; border-radius: 11px;
  display: grid; place-items: center; color: var(--accent);
  background: linear-gradient(160deg, #4c8dff2b, #4c8dff0a);
  border: 1px solid #4c8dff3d;
}

.field { margin-bottom: 14px; }
.field label {
  display: block; margin-bottom: 6px;
  font-size: 12px; font-weight: 500; color: var(--muted);
}

/* El contenedor es flex y el input un elemento flexible: sin `flex: 1` y
   `min-width: 0` el ancho de los campos no coincide entre si (el de la
   contrasena lleva boton y el de usuario no). */
.input-wrap {
  position: relative; display: flex; align-items: center;
  background: #0b0e14; border: 1px solid #2a3141; border-radius: 9px;
  transition: border-color .14s, box-shadow .14s;
}
.input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px #4c8dff21; }

.input-wrap input {
  flex: 1 1 auto; min-width: 0; width: auto;
  background: none; border: 0; border-radius: 9px;
  padding: 11px 12px 11px 38px;
  font-size: 14px;
}
.input-wrap input:focus { outline: none; }
.input-wrap input::placeholder { color: #4e5870; }
/* Chrome pinta el autorrelleno de azul claro y rompe el tema oscuro. */
.input-wrap input:-webkit-autofill {
  -webkit-text-fill-color: var(--text);
  -webkit-box-shadow: 0 0 0 1000px #0b0e14 inset;
  caret-color: var(--text);
}

.input-icon {
  position: absolute; left: 13px; width: 16px; height: 16px;
  color: #5b6577; pointer-events: none;
}
.input-wrap:focus-within .input-icon { color: var(--accent); }

.pw-toggle {
  flex: none; margin-right: 5px;
  background: none; border: 0; padding: 5px 9px;
  font-size: 12px; color: var(--muted); border-radius: 6px;
}
.pw-toggle:hover { background: #ffffff12; color: var(--text); }

.caps { margin: 7px 0 0; font-size: 11.5px; color: var(--warn); }

.submit {
  width: 100%; margin-top: 18px; padding: 11px;
  font-size: 14px; font-weight: 500; border-radius: 9px;
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
}
.submit:hover:not(:disabled) { background: #5d99ff; border-color: #5d99ff; }

.spinner {
  width: 13px; height: 13px; border-radius: 50%;
  border: 2px solid #ffffff59; border-top-color: #fff;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.error {
  background: #38191c; border: 1px solid #63272c; color: #ffb4b4;
  border-radius: 8px; padding: 9px 11px; font-size: 12.5px; margin-bottom: 14px;
}
.shake { animation: shake .3s ease; }
@keyframes shake {
  25% { transform: translateX(-5px); } 50% { transform: translateX(5px); }
  75% { transform: translateX(-2px); } 100% { transform: translateX(0); }
}

@media (prefers-reduced-motion: reduce) {
  .login-card, .shake, .spinner { animation: none; }
}

@media (max-width: 420px) {
  .login-wrap { padding: 16px; }
  .login-card { padding: 22px 18px; }
}

/* ---------- layout del entrenador ---------- */

.app { display: grid; grid-template-rows: auto 1fr; height: 100%; }

.topbar {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--border);
}
.topbar .brand {
  display: inline-flex; align-items: center; gap: 7px;
  font-weight: 600; letter-spacing: .2px; color: var(--text);
}
.topbar .brand svg { color: var(--accent); }
.chip {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 999px; padding: 3px 10px; font-size: 12px; letter-spacing: .4px;
}
.topbar .spacer { flex: 1; }
.group { display: flex; gap: 2px; align-items: center; }
.group > button { border-radius: 0; }
.group > button:first-child { border-radius: 6px 0 0 6px; }
.group > button:last-child  { border-radius: 0 6px 6px 0; }
.group-label { font-size: 11px; color: var(--muted); margin-right: 6px; text-transform: uppercase; letter-spacing: .5px; }

.main { display: grid; grid-template-columns: 1fr 320px; min-height: 0; }

.chart-area { position: relative; min-width: 0; }
#chart { position: absolute; inset: 0; }
/* Dos detalles que cuestan una tarde si se pasan por alto:
   - width/height explicitos: 'inset: 0' NO estira un elemento reemplazado
     como <canvas>, se queda en su tamano intrinseco de 300x150.
   - z-index 3: las canvas internas de Lightweight Charts usan z-index 1 y 2,
     asi que sin esto el dibujo se pinta pero queda debajo del grafico. */
#overlay {
  position: absolute; inset: 0; width: 100%; height: 100%;
  z-index: 3; pointer-events: none;
}
/* pointer-events lo gobierna drawings.js: el lienzo solo captura el raton
   cuando hay herramienta activa o el cursor esta sobre un trazo. */
#overlay.drawing { cursor: crosshair; }

.hint {
  position: absolute; left: 12px; top: 12px; z-index: 5;
  background: #000000cc; border: 1px solid var(--border); border-radius: 6px;
  padding: 6px 10px; font-size: 12px; color: var(--muted);
}

.side {
  background: var(--panel); border-left: 1px solid var(--border);
  overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 16px;
}
.card { background: var(--panel-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; }
.card h3 { margin: 0 0 10px; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 600; }

.price { font-size: 26px; font-weight: 600; font-family: var(--mono); }
.row { display: flex; gap: 8px; }
.row > * { flex: 1; }

.kv { display: flex; justify-content: space-between; padding: 3px 0; font-size: 13px; }
.kv span:last-child { font-family: var(--mono); }

.trade {
  border: 1px solid var(--border); border-radius: 6px; padding: 8px;
  margin-bottom: 8px; font-size: 12px; background: var(--bg);
}
.trade .head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.badge { font-size: 10px; padding: 2px 6px; border-radius: 4px; text-transform: uppercase; letter-spacing: .5px; }
.badge.long { background: #14463f; color: #6fe3d3; }
.badge.short { background: #4a1f21; color: #ff9a97; }
.badge.open { background: #3a3417; color: #e9cf7a; }

.replay-bar {
  position: absolute; bottom: 14px; left: 50%; transform: translateX(-50%);
  display: flex; gap: 6px; align-items: center; z-index: 5;
  background: #0e1117e6; border: 1px solid var(--border); border-radius: 999px;
  padding: 6px 10px; backdrop-filter: blur(6px);
}
.replay-bar button { border-radius: 999px; padding: 5px 12px; }

dialog {
  background: var(--panel); color: var(--text); border: 1px solid var(--border);
  border-radius: 12px; padding: 22px; max-width: 460px; width: 92vw;
}
dialog::backdrop { background: #000000aa; }
dialog h2 { margin: 0 0 12px; font-size: 17px; }

.toast {
  position: fixed; bottom: 20px; right: 20px; z-index: 50;
  background: var(--panel-2); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 6px; padding: 10px 14px; font-size: 13px; max-width: 320px;
}
.toast.bad { border-left-color: var(--down); }
.toast.good { border-left-color: var(--up); }

@media (max-width: 900px) {
  .main { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .side { border-left: 0; border-top: 1px solid var(--border); max-height: 45vh; }
}

/* Enlace con aspecto de boton (informes del profesor). */
.btn-link {
  display: inline-block; text-decoration: none;
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 6px 12px; color: var(--text);
}
.btn-link:hover { background: #232b38; }

/* ---------- panel del profesor ---------- */

.admin-body { height: auto; min-height: 100%; }
.admin {
  max-width: 1500px; margin: 0 auto; padding: 22px 20px 60px;
  display: flex; flex-direction: column; gap: 18px;
}
.admin .card { padding: 18px; }
.admin .card h3 { font-size: 13px; }
.card-head { display: flex; align-items: center; gap: 12px; margin-bottom: 12px; }
.card-head h3 { margin: 0; flex: 1; }
.row-inline { display: flex; gap: 8px; align-items: center; }
.note { font-size: 12.5px; line-height: 1.5; margin: -4px 0 14px; }

.select {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  border-radius: 6px; padding: 6px 10px;
}

.tiles {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
}
.tile {
  background: var(--panel-2); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 13px 15px;
  display: flex; flex-direction: column; gap: 5px;
}
.tile-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; }
.tile-value { font-size: 22px; font-weight: 600; font-family: var(--mono); }

/* La tabla puede ser ancha: se desplaza sola en vez de romper la pagina. */
.table-wrap { overflow-x: auto; margin: 0 -4px; }
table { border-collapse: collapse; width: 100%; font-size: 13px; }
th, td { padding: 8px 10px; text-align: left; white-space: nowrap; }
th {
  font-size: 11px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); font-weight: 600;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--panel-2); z-index: 1;
}
td { border-bottom: 1px solid #1f2632; }
tbody tr:hover td { background: #ffffff06; }
.num { text-align: right; }
.small { font-size: 12px; }

.cell-input {
  width: 108px; text-align: right; padding: 5px 8px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 5px; color: var(--text);
}
.badge.done { background: #16341f; color: #7fe0a0; }

@media (max-width: 700px) {
  .admin { padding: 14px 10px 40px; }
  .tile-value { font-size: 18px; }
}
