:root {
  --context-w: 240px;
  --header-h: 95px;
  --topnav-h: 38px;
  --bg: #FAF9F7;
  --sidebar-bg: #4F6D73;
  --sidebar-hover: #3E5960;
  --topnav-bg: #95A7AB;
  --title: #374151;
  --text: #6B7280;
  --icon: #7A9E8E;
  --border: #D8D6D1;
  --bullet: #C77B63;
  --accent: #4F6D73;
  --accent-secondary: #C6A15B;
  --status-ok: #6B9E78;
  --status-pending: #C6A15B;
}

.hidden { display: none; }

* { box-sizing: border-box; }
body { font-family: system-ui, sans-serif; margin: 0; color: var(--text); background: var(--bg); }
h1, h2, h3, h4 { color: var(--title); }

#header {
  height: var(--header-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  background-image: url("header2.png");
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-logo {
  display: flex;
  align-items: center;
}
.header-logo img { height: calc(var(--header-h) - 40px); width: auto; display: block; }

.header-user { display: flex; align-items: center; gap: 0.75rem; position: relative; }
.sync-status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.9);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.sync-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; }
.sync-status.sync-ok .sync-dot { background: var(--status-ok); }
.sync-status.sync-ok .sync-label { color: var(--status-ok); }
.sync-status.sync-pending .sync-dot { background: var(--status-pending); }
.sync-status.sync-pending .sync-label { color: var(--status-pending); }
.user-pill {
  width: 36px; height: 36px; border-radius: 999px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); color: #fff; border: none;
  font-weight: 600; cursor: pointer;
}
.user-dropdown {
  position: absolute; right: 0; top: 44px;
  background: #fff; border: 1px solid var(--border); border-radius: 8px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  min-width: 160px; padding: 0.4rem;
}
.user-dropdown.hidden { display: none; }
.user-dropdown a {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.6rem;
  color: var(--title);
  text-decoration: none;
  border-radius: 6px;
  font-size: 0.9rem;
}
.user-dropdown a svg { width: 16px; height: 16px; flex-shrink: 0; stroke: var(--text); }
.user-dropdown a:hover { background: var(--bg); }

#topnav {
  height: var(--topnav-h);
  background: var(--topnav-bg);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.25rem;
  position: sticky;
  top: var(--header-h);
  z-index: 9;
}
#topnav-links { display: flex; align-items: center; gap: 0.25rem; height: 100%; }
#topnav-links a {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 100%;
  color: rgba(255, 255, 255, 0.85);
  text-decoration: none;
  font-weight: 500;
  padding: 0 0.9rem;
  font-size: 0.9rem;
  border-bottom: 3px solid transparent;
}
#topnav-links a.nav-inicio { --section-color: var(--bullet); }
#topnav-links a.nav-clientes { --section-color: var(--accent); }
#topnav-links a.nav-cuentas { --section-color: var(--icon); }
#topnav-links a.nav-remito { --section-color: var(--accent-secondary); }
#topnav-links a svg { width: 16px; height: 16px; flex-shrink: 0; stroke: currentColor; }
#topnav-links a:hover { color: #fff; border-bottom-color: var(--section-color); }
#topnav-links a.active { color: #fff; border-bottom-color: var(--section-color); font-weight: 600; }

#buscador { position: relative; display: flex; align-items: center; height: 100%; }
#buscador input {
  width: 220px;
  height: 30px;
  padding: 0 0.7rem;
  border-radius: 6px;
  border: 1px solid var(--sidebar-hover);
  background: var(--sidebar-hover);
  color: #fff;
  font-size: 0.85rem;
}
#buscador input::placeholder { color: #cbd5e1; }
.buscador-resultados {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 260px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
  overflow: hidden;
  z-index: 20;
}
.buscador-resultados.hidden { display: none; }
.buscador-item { padding: 0.55rem 0.75rem; font-size: 0.9rem; color: var(--title); cursor: pointer; }
.buscador-item:hover { background: var(--bg); }
.buscador-item.buscador-empty { color: var(--text); cursor: default; }
.buscador-item.buscador-empty:hover { background: none; }

#layout { display: flex; min-height: calc(100vh - var(--header-h) - var(--topnav-h)); }

#context-sidebar {
  width: var(--context-w);
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid var(--border);
  padding: 1rem;
  overflow-y: auto;
}
#context-sidebar.hidden { display: none; }
#context-sidebar input[type="search"] {
  width: 100%;
  padding: 0.45rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 0.9rem;
  margin-bottom: 0.75rem;
}
#context-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
#context-list li { padding: 0.6rem 0.6rem; cursor: pointer; font-size: 0.9rem; color: var(--title); border-bottom: 1px solid var(--border); }
#context-list li:last-child { border-bottom: none; }
#context-list li:hover { background: var(--bg); }
#context-list li.active { background: var(--accent); color: #fff; border-radius: 6px; border-bottom-color: transparent; }
#context-list li.context-empty { color: var(--text); cursor: default; }
#context-list li.context-empty:hover { background: none; }

#app { flex: 1; padding: 2rem; }

.section-title { display: flex; align-items: center; gap: 0.6rem; margin: 0; }
.section-title::before {
  content: "";
  width: 14px;
  height: 14px;
  border-radius: 4px;
  flex-shrink: 0;
  background: var(--section-color);
}
.title-inicio { --section-color: var(--bullet); }
.title-clientes { --section-color: var(--accent); }
.title-cuentas { --section-color: var(--icon); }
.title-remito { --section-color: var(--accent-secondary); }

.hub-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 180px));
  justify-content: center;
  gap: 1.25rem;
  margin-top: 1.5rem;
}
.hub-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 0.6rem;
  padding: 1.75rem 1.25rem;
  min-height: 190px;
  border-radius: 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-top: 4px solid var(--card-color);
  text-decoration: none;
  color: var(--title);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.1);
  transition: box-shadow 0.15s, transform 0.15s;
}
.hub-card:hover { box-shadow: 0 10px 22px rgba(0, 0, 0, 0.15); transform: translateY(-2px); }
.hub-icon-badge {
  width: 46px;
  height: 46px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--card-color);
}
.hub-icon-badge svg { width: 24px; height: 24px; stroke: #fff; }
.hub-card .hub-title { font-weight: 600; font-size: 1.05rem; color: var(--title); }
.hub-card .hub-desc { font-size: 0.85rem; color: var(--text); }
.hub-card.hub-card-clientes { --card-color: var(--accent); }
.hub-card.hub-card-cuentas { --card-color: var(--icon); }
.hub-card.hub-card-cta { --card-color: var(--accent-secondary); }

table { width: 100%; border-collapse: collapse; margin-top: 1rem; }
th, td { text-align: left; padding: 0.5rem; border-bottom: 1px solid var(--border); }
tr.row-highlight { background: rgba(198, 161, 91, 0.15); }
.fav-cell { cursor: pointer; width: 1.5rem; }
.star { width: 18px; height: 18px; color: var(--border); vertical-align: middle; }
.star.star-active { color: var(--accent-secondary); }
form { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: 1rem; }
input, select {
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  color: var(--title);
}
button {
  padding: 0.5rem 1rem;
  cursor: pointer;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: #fff;
  color: var(--title);
  font-size: 0.9rem;
  font-weight: 500;
}
button:hover { background: var(--bg); }
button[type="submit"] { background: var(--accent); border-color: var(--accent); color: #fff; }
button[type="submit"]:hover { background: var(--sidebar-hover); border-color: var(--sidebar-hover); }
.btn {
  display: inline-block;
  padding: 0.5rem 1rem;
  border: none;
  border-radius: 6px;
  background: var(--accent);
  color: #fff;
  text-decoration: none;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
}
.btn:hover { background: var(--sidebar-hover); }
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: none;
  background: none;
  border-radius: 6px;
  color: var(--text);
}
.btn-icon svg { width: 16px; height: 16px; }
.btn-icon:hover { background: var(--bg); color: var(--title); }

.cliente-ficha-header, .cliente-ficha-seccion-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
}
.cliente-ficha-seccion { margin-top: 2rem; }
.cliente-ficha-seccion-header h3 { margin: 0; }

.tabla-items { border: 1px solid var(--border); border-radius: 8px; overflow: hidden; }
.tabla-items th, .tabla-items td { border-bottom: 1px solid var(--border); }
.tabla-items tbody tr:last-child td { border-bottom: none; }
.tabla-items td { vertical-align: top; padding: 0.4rem; }
.tabla-items input, .tabla-items select { width: 100%; }
.tabla-items .item-importe { font-weight: 600; color: var(--title); white-space: nowrap; }

.remito-header {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin-top: 1rem;
}
.remito-header label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--text);
  font-weight: 500;
}
.remito-calle { margin: 0.25rem 0 0; font-size: 0.85rem; color: var(--text); }
.remito-total-bar {
  display: flex;
  justify-content: flex-end;
  padding: 0.75rem 0.5rem;
  font-size: 1.1rem;
}

#auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
}
#auth-screen.hidden { display: none; }
.auth-box {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  width: 100%;
  max-width: 320px;
  padding: 2rem;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 10px;
}
.auth-box img.auth-logo {
  height: 48px;
  width: auto;
  align-self: center;
  margin-bottom: 0.5rem;
  filter: brightness(0); /* el logo es blanco (pensado para el header oscuro); en la tarjeta blanca lo forzamos a negro */
}
.auth-box label { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.85rem; color: var(--text); }
.auth-box select,
.auth-box input {
  padding: 0.5rem 0.6rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  font-size: 0.95rem;
}
.auth-box button[type="submit"] { margin-top: 0.3rem; }
.auth-error { color: #B23A48; font-size: 0.85rem; margin: 0; }

@media (max-width: 640px) {
  :root {
    --header-h: 64px;
  }

  #topnav {
    position: static;
    height: auto;
    flex-wrap: wrap;
    padding: 0.5rem 0.75rem;
    row-gap: 0.5rem;
  }
  #topnav-links { flex-wrap: wrap; height: auto; width: 100%; }
  #topnav-links a { height: auto; padding: 0.4rem 0.6rem; }
  #buscador { width: 100%; height: auto; }
  #buscador input { width: 100%; }
  .buscador-resultados { width: 100%; }

  #layout { flex-direction: column; }
  #context-sidebar { width: 100%; max-height: 240px; }

  #app { padding: 1rem; }

  .hub-grid { grid-template-columns: 1fr; max-width: 260px; }

  table { display: block; overflow-x: auto; white-space: nowrap; }

  .cliente-ficha-header, .cliente-ficha-seccion-header { flex-direction: column; align-items: flex-start; }
}
