/* ============================================================
   NOTAS WEB — Tema obsidian estilo hoja de calculo (Excel)
   ============================================================ */

:root {
  --bg:        #0d1117;
  --panel:     #161b22;
  --panel-2:   #1c2230;
  --grid:      #232a35;
  --grid-soft: #1a2029;
  --text:      #e6edf3;
  --text-dim:  #8b949e;
  --text-faint:#6e7681;

  --excel:     #21a366;   /* verde Excel */
  --excel-2:   #33c481;
  --excel-dk:  #185c37;
  --excel-hd:  #12482c;

  --sel:       rgba(33,163,102,.16);
  --sel-line:  #2ea043;

  --danger:    #f85149;
  --amber:     #d29922;
  --blue:      #4493f8;
  --purple:    #bc8cff;

  --radius:    8px;
  --shadow:    0 12px 40px rgba(0,0,0,.55);
  --row-h:     46px;
  --font:      'Segoe UI', Calibri, system-ui, -apple-system, Roboto, sans-serif;
}

* { box-sizing: border-box; }

/* Garantiza que el atributo [hidden] oculte incluso con display en clases.
   (Sin esto, .empty y .modal-overlay quedarian visibles siempre.) */
[hidden] { display: none !important; }

html, body {
  margin: 0; padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
body { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* ---------------- Botones ---------------- */
.btn-primary, .btn-ghost {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 6px;
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  transition: background .15s ease, border-color .15s ease, transform .08s ease, box-shadow .15s ease;
  color: #fff;
}
.btn-primary {
  background: var(--excel);
  box-shadow: 0 1px 0 rgba(255,255,255,.08) inset;
}
.btn-primary:hover { background: var(--excel-2); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .6; cursor: default; }

.btn-ghost {
  background: transparent;
  color: var(--text-dim);
  border-color: var(--grid);
}
.btn-ghost:hover { background: var(--panel-2); color: var(--text); }

.btn-icon { display: inline-flex; align-items: center; gap: 7px; }
.btn-icon svg { flex: 0 0 auto; }

/* ---------------- Ribbon ---------------- */
.ribbon {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px;
  padding: 10px 16px;
  background: linear-gradient(180deg, var(--excel-hd), #0f1a13);
  border-bottom: 1px solid var(--grid);
}
.ribbon-brand { display: flex; align-items: center; gap: 9px; color: #fff; font-weight: 700; letter-spacing: .2px; }
.ribbon-brand svg { color: var(--excel-2); }
.ribbon-file { color: rgba(255,255,255,.55); font-style: normal; font-weight: 500; font-size: 13px; }

.ribbon-actions { display: flex; align-items: center; gap: 10px; }

/* ---------------- Barra de herramientas (busqueda) ---------------- */
.toolbar {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 16px;
  background: var(--panel);
  border-bottom: 1px solid var(--grid);
}
.toolbar .search { width: 320px; max-width: 100%; }
.toolbar-count { color: var(--text-faint); font-size: 12px; margin-left: auto; }

.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg);
  border: 1px solid var(--grid);
  border-radius: 6px;
  padding: 8px 11px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.search:focus-within { border-color: var(--excel); box-shadow: 0 0 0 3px var(--sel); }
.search svg { color: var(--text-faint); flex: 0 0 auto; }
.search input {
  flex: 1; min-width: 0;
  background: transparent; border: none; outline: none;
  color: var(--text); font-size: 13.5px; font-family: var(--font);
}
.search input::placeholder { color: var(--text-faint); }

/* ---------------- Barra de formulas ---------------- */
.formula-bar {
  display: flex; align-items: stretch;
  background: var(--panel);
  border-bottom: 1px solid var(--grid);
  height: 34px;
}
.name-box {
  min-width: 82px;
  display: flex; align-items: center; justify-content: center;
  border-right: 1px solid var(--grid);
  color: var(--text-dim); font-size: 12px; font-weight: 600;
  background: var(--grid-soft);
}
.fx {
  display: flex; align-items: center; padding: 0 12px;
  border-right: 1px solid var(--grid);
  color: var(--text-faint); font-style: italic; font-size: 13px;
}
.formula-value {
  flex: 1; display: flex; align-items: center;
  padding: 0 12px; color: var(--text-dim); font-size: 13px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* ---------------- Hoja / tabla ---------------- */
.sheet-wrap { flex: 1; overflow: auto; position: relative; }

.sheet {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  table-layout: fixed;
}

.sheet thead th {
  position: sticky;
  background: var(--grid-soft);
  color: var(--text-dim);
  font-weight: 600;
  font-size: 12px;
  border-right: 1px solid var(--grid);
  border-bottom: 1px solid var(--grid);
  user-select: none;
}
.col-letters th { top: 0; height: 22px; text-align: center; color: var(--text-faint); z-index: 3; }
.col-titles th  { top: 22px; height: 30px; text-align: left; padding: 0 12px; z-index: 3; }
.col-letters .corner, .col-titles .row-head {
  width: 46px; text-align: center; padding: 0;
  background: var(--grid); position: sticky; left: 0; z-index: 4;
}

/* Anchos de columnas */
.c-pin   { width: 92px;  text-align: center !important; }
.c-titulo{ width: 26%; }
.c-cont  { width: auto; }
.c-fecha { width: 168px; }
.c-acc   { width: 150px; text-align: center !important; }

/* Filas de datos */
.sheet tbody td {
  height: var(--row-h);
  padding: 0 12px;
  border-right: 1px solid var(--grid);
  border-bottom: 1px solid var(--grid);
  color: var(--text);
  font-size: 13.5px;
  vertical-align: middle;
  overflow: hidden;
}
.sheet tbody tr { transition: background .12s ease; }
.sheet tbody tr:hover { background: rgba(255,255,255,.025); }

.cell-num {
  width: 46px; text-align: center; padding: 0;
  color: var(--text-faint); font-size: 12px;
  background: var(--grid-soft);
  position: sticky; left: 0; z-index: 1;
  border-right: 1px solid var(--grid);
}

/* Seleccion estilo Excel */
.sheet tbody tr.sel td { background: var(--sel); }
.sheet tbody tr.sel td:first-child { box-shadow: inset 3px 0 0 var(--sel-line); }

/* Contenido de celdas */
.cell-titulo { font-weight: 600; }
.cell-titulo .txt { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cell-cont .txt {
  display: block; color: var(--text-dim);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.cell-fecha { color: var(--text-dim); font-size: 12.5px; font-variant-numeric: tabular-nums; }

/* Marca "editado" semitransparente */
.editado-tag {
  display: inline-block;
  margin-left: 8px;
  font-size: 10.5px;
  font-style: italic;
  font-weight: 500;
  letter-spacing: .3px;
  color: var(--text);
  opacity: .32;
  vertical-align: middle;
  transition: opacity .3s ease;
}
tr:hover .editado-tag { opacity: .5; }

/* Punto de color a la izquierda del titulo */
.color-dot {
  display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  margin-right: 8px; vertical-align: middle; background: var(--text-faint);
  flex: 0 0 auto;
}
.color-dot.verde  { background: var(--excel-2); }
.color-dot.azul   { background: var(--blue); }
.color-dot.ambar  { background: var(--amber); }
.color-dot.rojo   { background: var(--danger); }
.color-dot.morado { background: var(--purple); }
.color-dot.default{ display: none; }

.cell-titulo .wrap { display: flex; align-items: center; min-width: 0; }
.cell-titulo .wrap .txt { min-width: 0; }

/* Boton anclar (celda pin) */
.pin-btn {
  background: none; border: none; cursor: pointer;
  color: var(--text-faint); padding: 6px; border-radius: 5px;
  transition: color .15s ease, background .15s ease, transform .2s ease;
  display: inline-flex;
}
.pin-btn:hover { background: var(--panel-2); color: var(--text-dim); }
.pin-btn.on { color: var(--amber); }
.pin-btn.on svg { fill: var(--amber); }
tr.anclada .pin-btn { animation: pinPop .35s ease; }

/* Acciones */
.acc { display: flex; gap: 6px; justify-content: center; }
.acc button {
  background: none; border: 1px solid var(--grid); cursor: pointer;
  color: var(--text-dim); padding: 6px; border-radius: 5px;
  display: inline-flex; transition: all .15s ease;
}
.acc button:hover { background: var(--panel-2); color: var(--text); border-color: var(--sel-line); }
.acc button.del:hover { color: var(--danger); border-color: var(--danger); }

/* Fila anclada: leve borde superior verde */
tr.anclada td { background: rgba(210,153,34,.05); }
tr.anclada .cell-num { box-shadow: inset 3px 0 0 var(--amber); }

/* ---------------- Animaciones de fila ---------------- */
@keyframes rowIn {
  from { opacity: 0; transform: translateY(-6px); background: var(--sel); }
  to   { opacity: 1; transform: translateY(0); }
}
tr.entrando { animation: rowIn .32s cubic-bezier(.2,.7,.3,1); }

tr.saliendo {
  animation: rowOut .28s ease forwards;
}
@keyframes rowOut {
  from { opacity: 1; transform: translateX(0); }
  to   { opacity: 0; transform: translateX(24px); }
}

@keyframes flashEdit {
  0%   { background: rgba(33,163,102,.28); }
  100% { background: transparent; }
}
tr.editada-flash td { animation: flashEdit .9s ease; }

@keyframes pinPop {
  0% { transform: scale(1); }
  40% { transform: scale(1.35) rotate(-12deg); }
  100% { transform: scale(1); }
}

/* ---------------- Estado vacio ---------------- */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 14px; padding: 70px 20px; color: var(--text-faint);
  animation: fadeIn .4s ease;
}
.empty p { margin: 0; font-size: 14px; }
.empty strong { color: var(--excel-2); }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ---------------- Barra inferior ---------------- */
.statusbar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--excel-hd);
  border-top: 1px solid var(--grid);
  height: 30px; padding: 0 14px;
  font-size: 12px;
}
.tabs { display: flex; align-items: center; gap: 2px; height: 100%; }
.tab {
  display: flex; align-items: center; padding: 0 14px; height: 100%;
  color: rgba(255,255,255,.6); cursor: pointer; user-select: none;
  border-right: 1px solid rgba(255,255,255,.08);
  transition: background .15s ease, color .15s ease;
}
.tab.active { background: var(--bg); color: #fff; border-top: 2px solid var(--excel-2); }
.tab.add { color: rgba(255,255,255,.5); font-size: 16px; font-weight: 700; }
.tab.add:hover { background: rgba(255,255,255,.08); color: #fff; }
.status { color: rgba(255,255,255,.7); font-variant-numeric: tabular-nums; }

/* ---------------- Modal ---------------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(0,0,0,.6);
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  animation: overlayIn .2s ease;
}
.modal-overlay.cerrando { animation: overlayOut .2s ease forwards; }
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes overlayOut { from { opacity: 1; } to { opacity: 0; } }

.modal {
  width: 100%; max-width: 560px;
  background: var(--panel);
  border: 1px solid var(--grid);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: modalIn .26s cubic-bezier(.2,.8,.25,1);
}
.modal-overlay.cerrando .modal { animation: modalOut .2s ease forwards; }
@keyframes modalIn { from { opacity: 0; transform: translateY(16px) scale(.97); } to { opacity: 1; transform: none; } }
@keyframes modalOut { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(10px) scale(.98); } }

.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  background: linear-gradient(180deg, var(--excel-hd), transparent);
  border-bottom: 1px solid var(--grid);
  font-weight: 700; color: #fff;
}
.modal-close { background: none; border: none; color: var(--text-dim); cursor: pointer; display: inline-flex; padding: 4px; border-radius: 5px; transition: all .15s ease; }
.modal-close:hover { color: var(--danger); background: var(--panel-2); }

.modal-body { padding: 18px; display: flex; flex-direction: column; gap: 6px; }
.lbl { font-size: 12px; color: var(--text-dim); font-weight: 600; margin: 8px 0 2px; }
.modal-body input, .modal-body textarea {
  background: var(--bg); border: 1px solid var(--grid); border-radius: 6px;
  color: var(--text); font-family: var(--font); font-size: 14px;
  padding: 10px 12px; outline: none; resize: vertical;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.modal-body input:focus, .modal-body textarea:focus {
  border-color: var(--excel); box-shadow: 0 0 0 3px var(--sel);
}
.modal-body textarea { min-height: 170px; line-height: 1.55; }

.colors { display: flex; gap: 10px; margin-top: 4px; }
.dot {
  width: 24px; height: 24px; border-radius: 50%; cursor: pointer;
  border: 2px solid transparent; background: var(--text-faint);
  transition: transform .15s ease, border-color .15s ease;
}
.dot:hover { transform: scale(1.15); }
.dot.active { border-color: #fff; }
.dot.default { background: var(--grid); border: 2px dashed var(--text-faint); }
.dot.verde  { background: var(--excel-2); }
.dot.azul   { background: var(--blue); }
.dot.ambar  { background: var(--amber); }
.dot.rojo   { background: var(--danger); }
.dot.morado { background: var(--purple); }

.modal-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 18px; border-top: 1px solid var(--grid);
  background: var(--grid-soft);
}

/* ---------------- Toast ---------------- */
.toast {
  position: fixed; bottom: 46px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--panel-2); border: 1px solid var(--grid);
  color: var(--text); padding: 11px 18px; border-radius: 8px;
  font-size: 13px; box-shadow: var(--shadow); z-index: 60;
  opacity: 0; transition: opacity .25s ease, transform .25s ease;
  display: flex; align-items: center; gap: 9px;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.ok  { border-left: 3px solid var(--excel-2); }
.toast.err { border-left: 3px solid var(--danger); }

/* ============================================================
   LOGIN
   ============================================================ */
.login-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 50% -10%, rgba(33,163,102,.14), transparent 60%),
    var(--bg);
}
.login-card {
  width: 100%; max-width: 340px;
  background: var(--panel);
  border: 1px solid var(--grid);
  border-radius: 14px;
  box-shadow: var(--shadow);
  padding: 34px 30px;
  text-align: center;
  animation: modalIn .4s cubic-bezier(.2,.8,.25,1);
}
.login-logo {
  width: 62px; height: 62px; margin: 0 auto 14px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 14px; color: var(--excel-2);
  background: linear-gradient(160deg, var(--excel-hd), var(--panel-2));
  border: 1px solid var(--grid);
}
.login-title { margin: 0; font-size: 22px; color: #fff; }
.login-sub { margin: 4px 0 22px; color: var(--text-faint); font-size: 13px; }
.login-field input {
  width: 100%; background: var(--bg); border: 1px solid var(--grid);
  border-radius: 8px; color: var(--text); font-family: var(--font);
  font-size: 14px; padding: 12px 14px; outline: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.login-field input:focus { border-color: var(--excel); box-shadow: 0 0 0 3px var(--sel); }
.login-card .btn-primary { width: 100%; margin-top: 14px; padding: 12px; }
.login-error { color: var(--danger); font-size: 12.5px; min-height: 16px; margin: 12px 0 0; }
.login-card.ok { border-color: var(--excel); }

.shake { animation: shake .4s ease; }
@keyframes shake {
  10%,90% { transform: translateX(-2px); }
  20%,80% { transform: translateX(4px); }
  30%,50%,70% { transform: translateX(-7px); }
  40%,60% { transform: translateX(7px); }
}

/* ---------------- Chip de usuario (ribbon) ---------------- */
.user-chip {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 6px 11px; border-radius: 6px;
  background: rgba(0,0,0,.25);
  border: 1px solid rgba(255,255,255,.12);
  color: #fff; font-size: 13px; font-weight: 600;
  max-width: 160px;
}
.user-chip svg { color: var(--excel-2); flex: 0 0 auto; }
.user-chip span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------------- Conmutador registro/login ---------------- */
.auth-switch {
  display: flex; gap: 4px; margin: 0 0 18px;
  background: var(--bg); border: 1px solid var(--grid);
  border-radius: 8px; padding: 4px;
}
.as-btn {
  flex: 1; cursor: pointer; border: none; border-radius: 6px;
  padding: 9px 0; font-family: var(--font); font-size: 13px; font-weight: 600;
  background: transparent; color: var(--text-dim);
  transition: background .15s ease, color .15s ease;
}
.as-btn:hover { color: var(--text); }
.as-btn.active { background: var(--excel); color: #fff; }
.login-field + .login-field { margin-top: 10px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */

/* ---- Tablet / escritorio estrecho: hoja compacta ---- */
@media (max-width: 1000px) {
  .col-letters { display: none; }
  .col-titles th { top: 0; }
  .name-box, .fx { display: none; }
  .c-fecha { width: 132px; }
}

@media (max-width: 820px) {
  .ribbon-file { display: none; }
  .c-cont, .cell-cont { display: none; }        /* la vista tabla oculta contenido */
  .c-fecha, .cell-fecha { width: 116px; font-size: 12px; }
  .btn-primary.btn-icon span { display: none; }  /* boton "Nueva nota" solo icono */
  .btn-primary.btn-icon { padding: 10px; }
}

/* ============================================================
   MOVIL: cada nota se convierte en TARJETA
   ============================================================ */
@media (max-width: 640px) {
  :root { --row-h: auto; }

  /* Header compacto */
  .ribbon { padding: 10px 12px; }
  .user-chip { padding: 6px 9px; max-width: 108px; }
  .toolbar { padding: 8px 12px; }
  .toolbar .search { width: 100%; }
  .toolbar-count { display: none; }
  .formula-bar { display: none; }               /* la barra de formulas no aplica en tactil */

  /* La hoja pasa a ser una lista de tarjetas */
  .sheet-wrap { padding: 12px; }
  .sheet, .sheet tbody { display: block; width: 100%; }
  .sheet thead { display: none; }
  .sheet tbody { display: flex; flex-direction: column; gap: 12px; }

  .sheet tbody tr {
    display: grid;
    grid-template-columns: 1fr auto;
    grid-template-areas:
      "title   pin"
      "content content"
      "meta    actions";
    align-items: center;
    gap: 8px 10px;
    background: var(--panel);
    border: 1px solid var(--grid);
    border-radius: 12px;
    padding: 14px 16px;
    transition: border-color .15s ease, transform .12s ease;
  }
  .sheet tbody tr:hover { background: var(--panel); }
  .sheet tbody tr:active { transform: scale(.99); }
  .sheet tbody tr.sel { border-color: var(--sel-line); box-shadow: 0 0 0 2px var(--sel); }
  .sheet tbody tr.sel td { background: transparent; }
  .sheet tbody tr.anclada { border-left: 3px solid var(--amber); }
  .sheet tbody tr.anclada td { background: transparent; }

  .sheet tbody td {
    display: block;
    height: auto;
    padding: 0;
    border: none;
    font-size: 14px;
  }

  /* Ocultamos el numero de fila en tarjeta */
  .cell-num { display: none !important; }

  /* Titulo arriba a la izquierda */
  .cell-titulo { grid-area: title; min-width: 0; }
  .cell-titulo .wrap { align-items: center; }
  .cell-titulo .txt { font-size: 15px; }

  /* Pin arriba a la derecha, area de toque comoda */
  .cell-pin { grid-area: pin; justify-self: end; align-self: start; }
  .pin-btn { padding: 8px; }

  /* Contenido: hasta 2 lineas */
  .cell-cont { grid-area: content; display: block !important; }
  .cell-cont .txt {
    white-space: normal;
    display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
    overflow: hidden; line-height: 1.45; font-size: 13.5px;
  }

  /* Fecha abajo a la izquierda */
  .cell-fecha {
    grid-area: meta; display: block !important;
    width: auto; font-size: 12px; color: var(--text-faint);
  }

  /* Acciones abajo a la derecha, botones grandes */
  .cell-acc { grid-area: actions; justify-self: end; }
  .acc { gap: 8px; }
  .acc button { padding: 9px; }

  /* Modal casi a pantalla completa y con scroll interno */
  .modal-overlay { padding: 12px; align-items: flex-end; }
  .modal { max-width: 100%; max-height: 90vh; display: flex; flex-direction: column; border-radius: 14px; }
  .modal-body { overflow-y: auto; }
  .modal-body textarea { min-height: 40vh; }
  .modal-foot .btn-primary, .modal-foot .btn-ghost { padding: 12px 16px; }

  /* Toast mas arriba para no chocar con la barra de estado */
  .toast { bottom: 54px; left: 12px; right: 12px; transform: translateY(20px); max-width: none; }
  .toast.show { transform: translateY(0); }
}

/* ---- Moviles muy angostos ---- */
@media (max-width: 380px) {
  .ribbon-brand span { font-size: 14px; }
  .user-chip span { display: none; }             /* solo el icono de usuario */
  .user-chip { max-width: none; padding: 8px; }
}

/* ---- Respeta usuarios que prefieren menos animacion ---- */
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
